我有一个具有以下接口(interface)的服务:
public interface accountsService {
public accountRemovalModel purgeAccounts();
}
我必须遵循测试类(class):
我有一个具有以下接口(interface)的服务:
public interface AccountsService {
public accountRemovalModel purgeAccounts();
}
我必须遵循测试类(class):
public class AccountsServiceTest extends BaseTestClass {
private Mockery _m = new Mockery() {
{
setImposteriser(ClassImposteriser.INSTANCE);
}};
private accountsService _accountsService;
@Before
public void beforeTests() throws Exception {
accountsService = _m.mock(AccountsService.class);
}
@Test
public void testNoItemsToDeleteSuccess() throws Exception {
// Return a simple AccountsRemovalModel
// APPARENTLY THIS EXPECTATION IS UNEXPECTED?
_m.checking(new Expectations() {{
allowing(accountsService.purgeAccounts());
will(returnValue(new accountRemovalModel(0,0)));
}});
accountsRemovalModel result = accountsService.purgeAccounts();
Assert.assertEquals(0, result.getDeleteCount());
Assert.assertEquals(0, result.getTotalCount());
}
}
我收到以下错误:
AccountsServiceTest.testNoItemsToDeleteSuccess:23 » 预期意外...
非常感谢任何有关此问题的帮助 - 因为我在使其正常工作方面遇到了很大的问题!
最佳答案
您的语法稍有偏差 - 您需要在被模拟的对象周围加上括号(accountsService
):
_m.checking(new Expectations() {{
allowing(accountsService).purgeAccounts();
will(returnValue(new accountRemovalModel(0,0)));
}});
关于java - mock - 意外的期望 - 不知道我做错了什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42937153/