@Test public void testDoFoo() { Bar bar = mock(Bar.class); BarFactory myFactory = new BarFactory() { public Bar createBar() { return bar;} }; TestClass foo = new TestClass(myFactory); foo.foo(); verify(bar, times(1)).someMethod(); }Source:www.lautturi.com