1 10 11 package org.picocontainer.alternatives; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.picocontainer.MutablePicoContainer; 17 import org.picocontainer.PicoContainer; 18 import org.picocontainer.defaults.ConstructorInjectionComponentAdapterFactory; 19 import org.picocontainer.defaults.DefaultPicoContainer; 20 import org.picocontainer.tck.AbstractImplementationHidingPicoContainerTestCase; 21 import org.picocontainer.testmodel.SimpleTouchable; 22 23 27 public class ImplementationHidingCachingPicoContainerTestCase extends AbstractImplementationHidingPicoContainerTestCase { 28 29 protected MutablePicoContainer createImplementationHidingPicoContainer() { 30 return new ImplementationHidingCachingPicoContainer(); 31 } 32 33 protected MutablePicoContainer createPicoContainer(PicoContainer parent) { 34 return new ImplementationHidingCachingPicoContainer(parent); 35 } 36 37 public void testUsageOfADifferentComponentAdapterFactory() { 38 MutablePicoContainer parent = new DefaultPicoContainer(); 40 ImplementationHidingCachingPicoContainer pico = new ImplementationHidingCachingPicoContainer(new ConstructorInjectionComponentAdapterFactory(), parent); 41 pico.registerComponentImplementation(List .class, ArrayList .class); 42 List list1 = (List ) pico.getComponentInstanceOfType(List .class); 43 List list2 = (List ) pico.getComponentInstanceOfType(List .class); 44 assertNotNull(list1); 45 assertNotNull(list2); 46 assertFalse(list1 instanceof ArrayList ); 47 assertFalse(list2 instanceof ArrayList ); 48 assertSame(list1, list2); 49 } 50 51 52 public void testMakeChildContainer(){ 53 MutablePicoContainer parent = new ImplementationHidingCachingPicoContainer(); 54 parent.registerComponentImplementation("t1", SimpleTouchable.class); 55 MutablePicoContainer child = parent.makeChildContainer(); 56 Object t1 = child.getParent().getComponentInstance("t1"); 57 assertNotNull(t1); 58 assertTrue(t1 instanceof SimpleTouchable); 59 } 60 61 } 62 | Popular Tags |