I have a real strange behavior going on. It seems that Mockito is calling the real method on a mocked class, resulting in a NullPointerException. I am mocking the Context object present in the Javalin http framework for Java.
This is the minimal code that results in an exception.
import io.javalin.http.Context;
import org.mockito.Mockito;
public class Main {
public static void main(String[] args) {
Context ctx = Mockito.mock(Context.class);
Mockito.when(ctx.queryParam("hello")).thenReturn("test");
}
}
I get
at io.javalin.http.Context.queryString(Context.kt:285)
at io.javalin.http.Context.queryParamMap(Context.kt:282)
at io.javalin.http.Context.queryParams(Context.kt:279)
at io.javalin.http.Context.queryParam(Context.kt:266)
at io.javalin.http.Context.queryParam$default(Context.kt:266)
at io.javalin.http.Context.queryParam(Context.kt)
at Main.main(Main.java:9)
But its not supposed to call the real code! What is going on?