You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Niek Haarman edited this page Jan 3, 2018
·
6 revisions
Mockito often returns null when calling methods like any(), eq() etcetera. Passing these instances to methods that are not properly mocked, can cause NullPointerExceptions:
openclassFoo {
funbar(s:String) { }
}
@Test
funmyTest() {
whenever(foo.bar(any())) // This fails, since null is passed to bar.
}
Since the bar method is not marked open, it is final and Mockito cannot mock it. As a consequence, the method is executed when calling bar(any()). Since Kotlin inserts null-checks, an NPE is thrown.