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 ; 9 import java.awt.event.ActionListener ; 10 import java.awt.event.MouseEvent ; 11 import java.awt.event.MouseListener ; 12 13 public class ImplementationHidingComponentAdapterTestCase extends TestCase { 14 15 public void testMultipleInterfacesCanBeHidden() { 16 ComponentAdapter ca = new ConstructorInjectionComponentAdapter(new Class []{ActionListener .class, MouseListener .class}, Footle.class); 17 ImplementationHidingComponentAdapter ihca = new ImplementationHidingComponentAdapter(ca, true); 18 Object comp = ihca.getComponentInstance(null); 19 assertNotNull(comp); 20 assertTrue(comp instanceof ActionListener ); 21 assertTrue(comp instanceof MouseListener ); 22 } 23 24 public void testNonInterfaceInArrayCantBeHidden() { 25 ComponentAdapter ca = new ConstructorInjectionComponentAdapter(new Class []{String .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 , MouseListener { 45 public void actionPerformed(ActionEvent e) { 46 } 47 48 public void mouseClicked(MouseEvent e) { 49 } 50 51 public void mouseEntered(MouseEvent e) { 52 } 53 54 public void mouseExited(MouseEvent e) { 55 } 56 57 public void mousePressed(MouseEvent e) { 58 } 59 60 public void mouseReleased(MouseEvent e) { 61 } 62 63 } 64 } 65 | Popular Tags |