Recently, during a code review at work there was a discussion about
whether Mockito’s verify is necessary when when (or given,
which is a synonym) is parameterized. The quick answer is "no".
Imagine this contrived example. I have two classes, Calculator and
ComplexOperationService, where the latter requires the former. The
goal is to write a unit test for ComplexOperationService and mock
all usages of Calculator.
Here are the two classes.
public class Calculator {
public int sum(final int a, final int b) {
return a + b;
}
}
@RequiredArgsConstructor
public class ComplexOperationService {
private final Calculator calculator;
public void doComplexOperation(final int a, final int b) {
System.out.println(calculator.sum(a, b));
}
}