The problem: Mockito throws an NPE in the test code statement, specifically the verify
call with an argument matcher, with no further indication of the cause than the test code line.
The actual Exception when executing the test code is not only lacking information, but is also misleading:
java.lang.NullPointerException at de.example.testing.TmpTest.testSomething(TmpTest.java:31)
Very shrunk down example of the code to be tested:
class Medium {
void setLock(boolean locked) {
// do stuff
}
// and other functionality ...
}
Testing code:
@Test
void testSomething() {
// call testing code
verify(_medium, never())
.setLock(any()); // <-- NPE
}
In this example, _medium
is a valid Mock and the execution of verify(_medium, never())
also returns a non-null MockitoMock instance.