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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-12-10 11:00:00 +0000
Seen: 16 times
Last updated: Jun 22 '21
How can a DateTime Zone be changed to another DateTime Zone?
How can we direct to a randomly selected entry from a list using Nginx?
How can I load a text file in gensim?
How to stop the for-loop when a specific condition is fulfilled?
How can CSS variables in Angular Material 15 be replaced?
How can you obtain several parameters using a single GET request?
How can double quotes be added to strings within an array?
"How can a Boolean variable be saved in SQFLite?"
How can multiple sections be conditionally displayed in Hugo?