public class FooTest { testDoSomething() { class MockBar extends Bar { // code to simulate a "Bar" } ... bar = new MockBar(); foo = new Foo(); foo.doSomething(bar); // check that the right things happened to bar } }