Reputation: 1016
I have a service with the following interface :
public interface accountsService {
public accountRemovalModel purgeAccounts();
}
I have to following test class :
I have a service with the following interface :
public interface AccountsService {
public accountRemovalModel purgeAccounts();
}
I have to following test 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());
}
}
I am getting the following error :
AccountsServiceTest.testNoItemsToDeleteSuccess:23 » Expectation unexpected...
Any help with this is greatly appreciated - as I am having big problems with getting this to work!
Upvotes: 0
Views: 96
Reputation: 1028
Your syntax is slightly off - you need parentheses around the object being mocked (accountsService
):
_m.checking(new Expectations() {{
allowing(accountsService).purgeAccounts();
will(returnValue(new accountRemovalModel(0,0)));
}});
Upvotes: 1