I have a method with signature public void save(Object object)
in class DatabaseService
.
I have a code block that invokes the method:
databaseService.save(bypassCode)
if(condition to check if user details have been changed) {
databaseService.save(user)
}
If I want to test that databaseService.save(user) was not called, then how do I do it with Mockito (version 3.3.3)?
I believe you could do something like:
Mockito.verify(databaseService, Mockito.never()).save(user);
Question has already been answered with several options
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
// ...
verify(dependency, never()).someMethod();
or
verifyZeroInteractions(yourMock)
How to verify that a specific method was not called using Mockito?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.