KickJava   Java API By Example, From Geeks To Geeks.

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


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