1 package org.picocontainer.defaults.issues; 2 import org.picocontainer.MutablePicoContainer; 3 import org.picocontainer.PicoInitializationException; 4 import org.picocontainer.defaults.DefaultPicoContainer; 5 6 import junit.framework.TestCase; 7 8 11 public class Issue0280TestCase extends TestCase 12 { 13 public void testShouldFailIfInstantiationInChildContainerFails() 14 { 15 MutablePicoContainer parent = new DefaultPicoContainer(); 16 MutablePicoContainer child = new DefaultPicoContainer(parent); 17 18 parent.registerComponentImplementation(CommonInterface.class, ParentImplementation.class); 19 child.registerComponentImplementation(CommonInterface.class, ChildImplementation.class); 20 21 parent.start(); 22 23 try 24 { 25 Object result = child.getComponentInstanceOfType(CommonInterface.class); 26 27 assertFalse(result.getClass() == ParentImplementation.class); 29 } 30 catch (Exception e) 31 { 32 assertTrue(e.getClass() == PicoInitializationException.class); 33 } 34 35 } 36 37 public interface CommonInterface 38 { 39 40 } 41 42 public static class ParentImplementation implements CommonInterface 43 { 44 } 45 46 public static class ChildImplementation implements CommonInterface 47 { 48 public ChildImplementation() 49 { 50 throw new PicoInitializationException("Problem during initialization"); 51 } 52 } 53 54 } 55 | Popular Tags |