KickJava   Java API By Example, From Geeks To Geeks.

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


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  *****************************************************************************/

9 package org.picocontainer.alternatives;
10
11 import java.util.ArrayList JavaDoc;
12 import java.util.List JavaDoc;
13
14 import org.picocontainer.MutablePicoContainer;
15 import org.picocontainer.PicoContainer;
16 import org.picocontainer.defaults.ConstructorInjectionComponentAdapterFactory;
17 import org.picocontainer.defaults.DefaultPicoContainer;
18 import org.picocontainer.defaults.VerifyingVisitor;
19 import org.picocontainer.tck.AbstractImplementationHidingPicoContainerTestCase;
20 import org.picocontainer.testmodel.SimpleTouchable;
21
22 public class ImplementationHidingPicoContainerTestCase extends AbstractImplementationHidingPicoContainerTestCase {
23
24     protected MutablePicoContainer createImplementationHidingPicoContainer() {
25         return new ImplementationHidingPicoContainer();
26     }
27
28     protected MutablePicoContainer createPicoContainer(PicoContainer parent) {
29         return new ImplementationHidingPicoContainer(parent);
30     }
31
32     public void testStartStopAndDisposeNotCascadedtoRemovedChildren() {
33         super.testStartStopAndDisposeNotCascadedtoRemovedChildren();
34     }
35
36     public static class MyThread extends Thread JavaDoc {
37         public MyThread(String JavaDoc s) {
38             super(s);
39         }
40     }
41
42     public void testHidingWithoutParameter() {
43         // this was a bug reported by Arnd Kors on 21st Sept on the mail list.
44
ImplementationHidingPicoContainer pico = new ImplementationHidingPicoContainer();
45         pico.registerComponentImplementation(String JavaDoc.class);
46         pico.registerComponentImplementation(Runnable JavaDoc.class, MyThread.class);
47         new VerifyingVisitor().traverse(pico);
48     }
49
50     public void testUsageOfADifferentComponentAdapterFactory() {
51         // Jira bug 212
52
MutablePicoContainer parent = new DefaultPicoContainer();
53         ImplementationHidingPicoContainer pico = new ImplementationHidingPicoContainer(new ConstructorInjectionComponentAdapterFactory(), parent);
54         pico.registerComponentImplementation(List JavaDoc.class, ArrayList JavaDoc.class);
55         List JavaDoc list1 = (List JavaDoc) pico.getComponentInstanceOfType(List JavaDoc.class);
56         List JavaDoc list2 = (List JavaDoc) pico.getComponentInstanceOfType(List JavaDoc.class);
57         assertNotNull(list1);
58         assertNotNull(list2);
59         assertFalse(list1 instanceof ArrayList JavaDoc);
60         assertFalse(list2 instanceof ArrayList JavaDoc);
61         assertFalse(list1 == list2);
62     }
63    
64     public void testMakeChildContainer(){
65         MutablePicoContainer parent = new ImplementationHidingPicoContainer();
66         parent.registerComponentImplementation("t1", SimpleTouchable.class);
67         MutablePicoContainer child = parent.makeChildContainer();
68         Object JavaDoc t1 = child.getParent().getComponentInstance("t1");
69         assertNotNull(t1);
70         assertTrue(t1 instanceof SimpleTouchable);
71     }
72
73     public void testSameInstanceCanBeUsedAsDifferentTypeWhenCaching() {
74         // IHPC does not cache by default.
75
}
76
77
78 }
79
Popular Tags