KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > picocontainer > defaults > ImplementationHidingComponentAdapterTestCase


1 package org.picocontainer.defaults;
2
3 import java.awt.event.ActionEvent JavaDoc;
4 import java.awt.event.ActionListener JavaDoc;
5 import java.awt.event.MouseEvent JavaDoc;
6 import java.awt.event.MouseListener JavaDoc;
7
8 import junit.framework.TestCase;
9
10 import org.picocontainer.ComponentAdapter;
11 import org.picocontainer.Parameter;
12 import org.picocontainer.PicoIntrospectionException;
13 import org.picocontainer.defaults.ComponentAdapterFactory;
14 import org.picocontainer.defaults.ConstructorInjectionComponentAdapter;
15 import org.picocontainer.defaults.ConstructorInjectionComponentAdapterFactory;
16 import org.picocontainer.defaults.ImplementationHidingComponentAdapter;
17 import org.picocontainer.defaults.ImplementationHidingComponentAdapterFactory;
18
19 public class ImplementationHidingComponentAdapterTestCase extends TestCase {
20
21     public void testMultipleInterfacesCanBeHidden() {
22         ComponentAdapter ca = new ConstructorInjectionComponentAdapter(new Class JavaDoc[]{ActionListener JavaDoc.class, MouseListener JavaDoc.class}, Footle.class);
23         ImplementationHidingComponentAdapter ihca = new ImplementationHidingComponentAdapter(ca, true);
24         Object JavaDoc comp = ihca.getComponentInstance(null);
25         assertNotNull(comp);
26         assertTrue(comp instanceof ActionListener JavaDoc);
27         assertTrue(comp instanceof MouseListener JavaDoc);
28     }
29
30     public void testNonInterfaceInArrayCantBeHidden() {
31         ComponentAdapter ca = new ConstructorInjectionComponentAdapter(new Class JavaDoc[]{String JavaDoc.class}, Footle.class);
32         ImplementationHidingComponentAdapter ihca = new ImplementationHidingComponentAdapter(ca, true);
33         try {
34             ihca.getComponentInstance(null);
35             fail("PicoIntrospectionException expected");
36         } catch (PicoIntrospectionException e) {
37             // expected
38
}
39     }
40
41     public void testFactoryWithDefaultStrictMode(){
42         ComponentAdapterFactory factory = new ImplementationHidingComponentAdapterFactory(new ConstructorInjectionComponentAdapterFactory());
43         ComponentAdapter ihca = factory.createComponentAdapter("ww", Footle.class, new Parameter[0]);
44         try {
45             ihca.getComponentInstance(null);
46             fail("PicoIntrospectionException expected");
47         } catch (PicoIntrospectionException e) {
48             // expected
49
}
50     }
51     
52     public void testShouldThrowExceptionWhenAccessingNonInterfaceKeyedComponentInStrictMode() {
53         ComponentAdapter ca = new ConstructorInjectionComponentAdapter("ww", Footle.class);
54         ImplementationHidingComponentAdapter ihca = new ImplementationHidingComponentAdapter(ca, true);
55         try {
56             ihca.getComponentInstance(null);
57             fail("PicoIntrospectionException expected");
58         } catch (PicoIntrospectionException e) {
59             // expected
60
}
61     }
62
63     public class Footle implements ActionListener JavaDoc, MouseListener JavaDoc {
64         public void actionPerformed(ActionEvent JavaDoc e) {
65         }
66
67         public void mouseClicked(MouseEvent JavaDoc e) {
68         }
69
70         public void mouseEntered(MouseEvent JavaDoc e) {
71         }
72
73         public void mouseExited(MouseEvent JavaDoc e) {
74         }
75
76         public void mousePressed(MouseEvent JavaDoc e) {
77         }
78
79         public void mouseReleased(MouseEvent JavaDoc e) {
80         }
81
82     }
83
84 }
85
Popular Tags