我有以下界面的服务:
public interface accountsService {
public accountRemovalModel purgeAccounts();
}
我必须关注测试类:
我有以下界面的服务:
public interface AccountsService {
public accountRemovalModel purgeAccounts();
}
我必须关注测试类:
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»期望出乎意料......
非常感谢任何对此的帮助 - 因为我遇到了很大的问题!
答案 0 :(得分:1)
您的语法略有偏差 - 您需要围绕被模拟对象的括号(accountsService
):
_m.checking(new Expectations() {{
allowing(accountsService).purgeAccounts();
will(returnValue(new accountRemovalModel(0,0)));
}});