What is the best way to verify a method was called on an object created within a method using Mockito?
I am new to Mockito and trying to verify that someMethod()
was called exactly once after invoking foo()
. Given the following class:
public class Foo {
public void foo() {
Bar bar = new Bar();
bar.someMethod();
}
}
How can I use Mockito to verify this method call? I would like to make the following verification:
verify(bar, times(1)).someMethod();
where bar
is a mocked instance of Bar
. What is the correct approach to achieve this?