KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > picocontainer > alternatives > ImplementationHidingCachingPicoContainerTestCase


1 /*****************************************************************************
2  * Copyright (C) PicoContainer 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 the committers *
9  *****************************************************************************/

10
11 package org.picocontainer.alternatives;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
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 /**
24  * @author Paul Hammant
25  * @version $Revision: 2381 $
26  */

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         // Jira bug 212 - logical opposite
39
MutablePicoContainer parent = new DefaultPicoContainer();
40         ImplementationHidingCachingPicoContainer pico = new ImplementationHidingCachingPicoContainer(new ConstructorInjectionComponentAdapterFactory(), parent);
41         pico.registerComponentImplementation(List JavaDoc.class, ArrayList JavaDoc.class);
42         List JavaDoc list1 = (List JavaDoc) pico.getComponentInstanceOfType(List JavaDoc.class);
43         List JavaDoc list2 = (List JavaDoc) pico.getComponentInstanceOfType(List JavaDoc.class);
44         assertNotNull(list1);
45         assertNotNull(list2);
46         assertFalse(list1 instanceof ArrayList JavaDoc);
47         assertFalse(list2 instanceof ArrayList JavaDoc);
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 JavaDoc t1 = child.getParent().getComponentInstance("t1");
57         assertNotNull(t1);
58         assertTrue(t1 instanceof SimpleTouchable);
59     }
60
61 }
62
Popular Tags