How to mock void methods with Mockito?

Only Fullstack
2 min readMay 1, 2020

Mocking Void Methods
Let’s add a method which internally calls the void method of another component.

public Customer updateCustomer(Customer customer) {
if (customer == null || customer.getId() < 0) {
throw new IllegalArgumentException("Invalid Customer details passed.");
}
repository.updateCustomer(customer);
return customer;
}

--

--