public void testComponentAdapterRegistrationOrderIsMaintained() {
ConstructorInjectionComponentAdapter c1 = new ConstructorInjectionComponentAdapter("1", Object.class);
ConstructorInjectionComponentAdapter c2 = new ConstructorInjectionComponentAdapter("2", String.class);
MutablePicoContainer picoContainer = createPicoContainer(null);
picoContainer.registerComponent(c1);
picoContainer.registerComponent(c2);
assertEquals("registration order should be maintained",
Arrays.asList(new Object[]{c1, c2}), picoContainer.getComponentAdapters());
picoContainer.getComponentInstances(); // create all the instances at once
assertFalse("instances should be created in same order as adapters are created",
picoContainer.getComponentInstances().get(0) instanceof String);
assertTrue("instances should be created in same order as adapters are created",
picoContainer.getComponentInstances().get(1) instanceof String);
MutablePicoContainer reversedPicoContainer = createPicoContainer(null);
reversedPicoContainer.registerComponent(c2);
reversedPicoContainer.registerComponent(c1);
assertEquals("registration order should be maintained",
Arrays.asList(new Object[]{c2, c1}), reversedPicoContainer.getComponentAdapters());
reversedPicoContainer.getComponentInstances(); // create all the instances at once
assertTrue("instances should be created in same order as adapters are created",
reversedPicoContainer.getComponentInstances().get(0) instanceof String);
assertFalse("instances should be created in same order as adapters are created",
reversedPicoContainer.getComponentInstances().get(1) instanceof String);
}