KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nanocontainer > integrationkit > LifecycleContainerBuilderTestCase


1 /*****************************************************************************
2  * Copyright (C) NanoContainer Organization. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  * *
8  * Original code by *
9  *****************************************************************************/

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 /**
22  * @author Aslak Hellesøy
23  * @version $Revision: 1631 $
24  */

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 JavaDoc 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         //PicoContainer.getParent() is now ImmutablePicoContainer
50
assertNotSame(parent, childContainer.getParent());
51
52         builder.killContainer(childRef);
53     }
54
55 }
56
Popular Tags