Say I have a class like this:
public class Foo {
private Bar bar;
public Foo(Bar bar) {
this.bar = bar;
}
public void someMethod() {
bar.someOtherMethod();
}
}
How would I verify that bar.someOtherMethod() is called once when someMethod() is called? In my test, I am passing in a mocked Bar class into the constructor.
My test looks something like this:
private Bar bar;
private Foo foo;
@Before
public void setUp() throws Exception {
bar = mock(Bar.class);
foo = new Foo(bar);
}
@Test
public void testSomeMethod() {
foo.someMethod();
verify(Bar).someOtherMethod();
}