I am new to Mockito.
Given the class below, how can I use Mockito to verify that someMethod was invoked exactly once after foo was invoked?
public class Foo
{
public void foo(){
Bar bar = new Bar();
bar.someMethod();
}
}
I would like to make the following verification call,
verify(bar, times(1)).someMethod();
where bar is a mocked instance of Bar.
Dependency Injection
If you inject the Bar instance, or a factory that is used for creating the Bar instance (or one of the other 483 ways of doing this), you’d have the access necessary to do perform the test.
Factory Example:
Given a Foo class written like this:
in your test method you can inject a BarFactory like this:
Bonus: This is an example of how TDD(Test Driven Development) can drive the design of your code.