I use nice mocks all the time in order to have very clean tests, testing usually a single functionality per test. A lot of times I find myself wanting to make sure that a method has not been called on a mock, but this is not possible with niceMocks, since they sort of ignore methods without expectations. In order to support this testing methodology, it is imperative that 0 be a legal amount of times to specify on a method. The only current alternative is to use strict mocks which is very painful to use due to ridiculously large amount of setup if there is a lot of interaction with the mock around the tested interaction (essentially replicating the entire method in each test).
example:
public void setOneOrTheOtherButNotBoth(Long first, Long second){
if (first != null){
setFirst(first);
} else {
setSecond(second);
}
}
@Test
public void testSecondIsNotSetIfFirstIsNotNull() {
niceMockOfTestedObject.setSecond(anyObject());
expectLastCall().times(0);
replay(niceMockOfTestedObject);
mainTestedObject.setOneOrTheOtherButNotBoth(13L, 2L);
verify(niceMockOfTestedObject);
}
View and moderate all "feature-requests Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Feature Requests"
I wanted to udpate the example to remove any confusion:
public void setOneOrTheOtherButNotBoth(Long first, Long second){
if (first != null){
someObject.setFirst(first);
} else {
someObject.setSecond(second);
}
}
@Test
public void testSecondIsNotSetIfFirstIsNotNull() {
niceMockOfSomeObject.setSecond(anyObject());
expectLastCall().times(0);
replay(niceMockOfSomeObject);
mainTestedObject.setOneOrTheOtherButNotBoth(13L, 2L);
verify(niceMockOfSomeObject);
}
Last edit: Anonymous 2013-11-26
see http://jira.codehaus.org/browse/EASYMOCK-85