1 10 package org.picocontainer.tck; 11 12 import junit.framework.TestCase; 13 import org.picocontainer.MutablePicoContainer; 14 import org.picocontainer.PicoException; 15 import org.picocontainer.PicoRegistrationException; 16 17 21 public abstract class AbstractLazyInstantiationTestCase extends TestCase { 22 23 protected abstract MutablePicoContainer createPicoContainer(); 24 25 public static class Kilroy { 26 public Kilroy(Havana havana) { 27 havana.graffiti("Kilroy was here"); 28 } 29 } 30 31 public static class Havana { 32 public String paint = "Clean wall"; 33 34 public void graffiti(String paint) { 35 this.paint = paint; 36 } 37 } 38 39 public void testLazyInstantiation() throws PicoException, PicoRegistrationException { 40 MutablePicoContainer pico = createPicoContainer(); 41 42 pico.registerComponentImplementation(Kilroy.class); 43 pico.registerComponentImplementation(Havana.class); 44 45 assertSame(pico.getComponentInstance(Havana.class), pico.getComponentInstance(Havana.class)); 46 assertNotNull(pico.getComponentInstance(Havana.class)); 47 assertEquals("Clean wall", ((Havana) pico.getComponentInstance(Havana.class)).paint); 48 assertNotNull(pico.getComponentInstance(Kilroy.class)); 49 assertEquals("Kilroy was here", ((Havana) pico.getComponentInstance(Havana.class)).paint); 50 } 51 } 52 | Popular Tags |