1 | initial version |
To make a Mockito mock method return null, you simply need to use the thenReturn
method and pass in a null value. Here's an example:
SomeObject mockObject = Mockito.mock(SomeObject.class);
Mockito.when(mockObject.someMethod()).thenReturn(null);
In this example, we create a Mockito mock object of type SomeObject
. Then we use the when
method to specify that when the someMethod
method is called on this object, it should return null.
Note that you can also use the thenAnswer
method to define more complex behavior, such as returning null only under certain conditions.