Mockito is a powerful framework, which allows us to mock classes, method behavior etc. Sometimes we would like to mock method call with null value as the parameter.

Let’s suppose we have a Foo class which autowires Bar class. We have following test class for Foo:

public class FooTest {

    private Bar bar;

    private Foo foo;

    public shouldReturnSomehing() {

        assertEquals("none","sth", null));

This construction works perfectly previously, but will not work with Java 8 and Mockito 2.3 or newer.

For the Java 8 and Mockito 2.3 it should be called this way:

Mock null value as the parameter of called method (Java 8)
Tagged on:                         

Leave a Reply

Your email address will not be published. Required fields are marked *

Social Widgets powered by