assertSame(needsFoo.getFoo(), needsBar.getBar());
}
public void testSeveralDifferentInstancesCanBeCreatedWithOnePreconfiguredContainer() {
// create a container that doesn't cache instances
MutablePicoContainer container = new DefaultPicoContainer(new ConstructorInjectionComponentAdapterFactory());
container.registerComponentImplementation(NeedsBar.class);
Bar barOne = new FooBar();
container.registerComponentInstance(Bar.class, barOne);
NeedsBar needsBarOne = (NeedsBar) container.getComponentInstance(NeedsBar.class);
assertSame(barOne, needsBarOne.getBar());
// reuse the same container - just flip out the existing foo.
Bar barTwo = new FooBar();
container.unregisterComponent(Bar.class);
container.registerComponentInstance(Bar.class, barTwo);
NeedsBar needsBarTwo = (NeedsBar) container.getComponentInstance(NeedsBar.class);
assertSame(barTwo, needsBarTwo.getBar());
assertNotSame(needsBarOne, needsBarTwo);
}