Mockito - when thenReturn

The point of Mockito (or any form of mocking, actually) isn't to mock the code you're checking, but to replace external dependencies with mocked code.

E.g., consider you have this trivial interface:

public interface ValueGenerator {
    int getValue();
}

And this is your code that uses it:

public class Incrementor {
    public int increment(ValueGenerator vg) {
        return vg.getValue() + 1;
    }
}

You want to test your Incrementor logic without depending on any specific implementation of ValueGenerator. That's where Mockito comes into play:

// Mock the dependencies:
ValueGenerator vgMock = Mockito.mock(ValueGenerator.class);
when(vgMock.getValue()).thenReturn(7);

// Test your code:
Incrementor inc = new Incrementor();
assertEquals(8, inc.increment(vgMock));