1 package org.picocontainer.defaults; 2 3 import java.awt.event.ActionEvent ; 4 import java.awt.event.ActionListener ; 5 import java.awt.event.MouseEvent ; 6 import java.awt.event.MouseListener ; 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 []{ActionListener .class, MouseListener .class}, Footle.class); 23 ImplementationHidingComponentAdapter ihca = new ImplementationHidingComponentAdapter(ca, true); 24 Object comp = ihca.getComponentInstance(null); 25 assertNotNull(comp); 26 assertTrue(comp instanceof ActionListener ); 27 assertTrue(comp instanceof MouseListener ); 28 } 29 30 public void testNonInterfaceInArrayCantBeHidden() { 31 ComponentAdapter ca = new ConstructorInjectionComponentAdapter(new Class []{String .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 } 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 } 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 } 61 } 62 63 public class Footle implements ActionListener , MouseListener { 64 public void actionPerformed(ActionEvent e) { 65 } 66 67 public void mouseClicked(MouseEvent e) { 68 } 69 70 public void mouseEntered(MouseEvent e) { 71 } 72 73 public void mouseExited(MouseEvent e) { 74 } 75 76 public void mousePressed(MouseEvent e) { 77 } 78 79 public void mouseReleased(MouseEvent e) { 80 } 81 82 } 83 84 } 85 | Popular Tags |