001    /*****************************************************************************
002     * Copyright (C) PicoContainer Organization. All rights reserved.            *
003     * ------------------------------------------------------------------------- *
004     * The software in this package is published under the terms of the BSD      *
005     * style license a copy of which has been included with this distribution in *
006     * the LICENSE.txt file.                                                     *
007     *                                                                           *
008     * Original code by                                                          *
009     *****************************************************************************/
010    package org.picocontainer.behaviors;
011    
012    import java.awt.event.ActionEvent;
013    import java.awt.event.ActionListener;
014    import java.awt.event.MouseEvent;
015    import java.awt.event.MouseListener;
016    
017    import junit.framework.TestCase;
018    
019    import org.picocontainer.ComponentAdapter;
020    import org.picocontainer.PicoCompositionException;
021    import org.picocontainer.lifecycle.NullLifecycleStrategy;
022    import org.picocontainer.monitors.NullComponentMonitor;
023    import org.picocontainer.behaviors.ImplementationHidingBehavior;
024    import org.picocontainer.injectors.ConstructorInjector;
025    
026    public class ImplementationHidingBehaviorTestCase extends TestCase {
027    
028        public void testMultipleInterfacesCanBeHidden() {
029            ComponentAdapter ca = new ConstructorInjector(new Class[]{ActionListener.class, MouseListener.class}, Footle.class, null, new NullComponentMonitor(), new NullLifecycleStrategy());
030            ImplementationHidingBehavior ihca = new ImplementationHidingBehavior(ca);
031            Object comp = ihca.getComponentInstance(null);
032            assertNotNull(comp);
033            assertTrue(comp instanceof ActionListener);
034            assertTrue(comp instanceof MouseListener);
035        }
036    
037        public void testNonInterfaceInArrayCantBeHidden() {
038            ComponentAdapter ca = new ConstructorInjector(new Class[]{String.class}, Footle.class, null, new NullComponentMonitor(), new NullLifecycleStrategy());
039            ImplementationHidingBehavior ihca = new ImplementationHidingBehavior(ca);
040            try {
041                ihca.getComponentInstance(null);
042                fail("PicoCompositionException expected");
043            } catch (PicoCompositionException e) {
044                // expected        
045            }
046        }
047        
048        public class Footle implements ActionListener, MouseListener {
049            public void actionPerformed(ActionEvent e) {
050            }
051    
052            public void mouseClicked(MouseEvent e) {
053            }
054    
055            public void mouseEntered(MouseEvent e) {
056            }
057    
058            public void mouseExited(MouseEvent e) {
059            }
060    
061            public void mousePressed(MouseEvent e) {
062            }
063    
064            public void mouseReleased(MouseEvent e) {
065            }
066    
067        }
068    
069    }