1 10 package org.nanocontainer.integrationkit; 11 12 import org.jmock.Mock; 13 import org.jmock.MockObjectTestCase; 14 import org.picocontainer.MutablePicoContainer; 15 import org.picocontainer.PicoContainer; 16 import org.picocontainer.Startable; 17 import org.picocontainer.defaults.DefaultPicoContainer; 18 import org.picocontainer.defaults.ObjectReference; 19 import org.picocontainer.defaults.SimpleReference; 20 21 25 public class LifecycleContainerBuilderTestCase extends MockObjectTestCase { 26 public void testBuildContainerCreatesANewChildContainerAndStartsItButNotTheParent() { 27 final Mock childStartable = mock(Startable.class); 28 childStartable.expects(once()).method("start").withNoArguments(); 29 childStartable.expects(once()).method("stop").withNoArguments(); 30 31 ContainerComposer containerComposer = new ContainerComposer() { 32 public void composeContainer(MutablePicoContainer container, Object assemblyScope) { 33 container.registerComponentInstance(childStartable.proxy()); 34 } 35 }; 36 LifecycleContainerBuilder builder = new DefaultLifecycleContainerBuilder(containerComposer); 37 38 ObjectReference parentRef = new SimpleReference(); 39 MutablePicoContainer parent = new DefaultPicoContainer(); 40 41 Mock parentStartable = mock(Startable.class); 42 parent.registerComponentInstance(parentStartable.proxy()); 43 parentRef.set(parent); 44 45 ObjectReference childRef = new SimpleReference(); 46 47 builder.buildContainer(childRef, parentRef, null, true); 48 PicoContainer childContainer = (PicoContainer) childRef.get(); 49 assertNotSame(parent, childContainer.getParent()); 51 52 builder.killContainer(childRef); 53 } 54 55 } 56 | Popular Tags |