import org.junit.Test;
public class FooBarTest {
@Test
public void usesMockedInitialContext() throws Exception {
HelloCollector collector = new HelloCollector();
MockedInitialContextFactory.bind("services/Hello", collector);
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, MockedInitialContextFactory.class.getName());
FooBar fb = new FooBar();
fb.sayHelloTo("Pietro");
assertEquals("Pietro", collector.getLastTarget());
}