I use Mockito to write my test case. I have a simple class that contains a function countPerson(boolean)that I am interested in checking:
public class School {
public void countPerson(boolean includeTeacher) {
if (includeTeacher) {
countIncludeTeacher();
return;
}
countOnlyStudents();
}
public void countIncludeTeacher() {...}
public void countOnlyStudents() {...}
}
In my unit test, I want to test a method countPerson(boolean):
@Test
public void testCountPerson() {
School mSchool = School.getInstance();
School spySchool = Mockito.spy(mSchool);
spySchool.countPerson(true);
verify(spySchool).countIncludeTeacher();
spySchool.countPerson(false);
verify(spySchool, times(0)).countIncludeTeacher();
}
I have the following error:
org.mockito.exceptions.verification.NeverWantedButInvoked: school.countIncludeTeacher (); Never wanted here: (SchoolTest.java 20)
Why does checking 0 times not work?
source
share