您的位置:首页 > 数据库 > SQL

zabbix监控mysql主从复制

2012-08-04 22:01 651 查看
package jmockit.sample;

import jmockit.target.OfferPostAction;
import jmockit.target.WinportUrlServiceImpl;
import junit.framework.Assert;
import mockit.Expectations;
import mockit.Mocked;

import org.junit.Test;

/**
* 静态部分mock示例,靜態Mock是通过注解@Mocked中的字段methods声明的。
*
* @see
* @author Ginge
*
*/
public class StaticPartialMockingTest {
@Mocked(methods = { "[hH]asWinport" }, inverse = false)
// 声明的方法可以使用正则表达式
// methods 代表只有声明的方法才会进行mock, inverse
// 代表是否反转声明,如果inverse=true,那么就是除了声明的方法不mock
private WinportUrlServiceImpl winportUrlService = null;

private OfferPostAction offerPostAction = new OfferPostAction();

@Test
public void testofferPostActionExecute() {
final String memberId = "test2009";

new Expectations() {
{
// 期望被mock的调用,以及被调用时返回的结果
winportUrlService.hasWinport(memberId);
result = false; // 也可以是returns(false);
// 总共可以调用的次数
times = 1;
}
};

// 步骤二、replay 在此阶段,录制的方法可能会被调用
Assert.assertEquals(false, offerPostAction.hasWinport(memberId));

try {
// static partial mock,根据上述@Mocked注解的声明,WinportUrlServiceImpl#
// getWinportUrlmock将不会被mock
offerPostAction.getWinportUrlThrowException(memberId);
Assert.fail();
} catch (Exception e) {

}
}
}

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: