    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 static org.junit.Assert.assertNotNull;
    013    import static org.junit.Assert.assertTrue;
    014    import static org.junit.Assert.fail;
    015
    016    import java.awt.event.ActionEvent;
    017    import java.awt.event.ActionListener;
    018    import java.awt.event.MouseEvent;
    019    import java.awt.event.MouseListener;
    020
    021    import org.junit.Test;
    022    import org.picocontainer.ComponentAdapter;
    023    import org.picocontainer.PicoCompositionException;
    024    import org.picocontainer.injectors.ConstructorInjector;
    025    import org.picocontainer.lifecycle.NullLifecycleStrategy;
    026    import org.picocontainer.monitors.NullComponentMonitor;
    027
    028    public class HiddenImplementationTestCase {
    029
    030        @Test public void testMultipleInterfacesCanBeHidden() {
    031            ComponentAdapter ca = new ConstructorInjector(new Class[]{ActionListener.class, MouseListener.class}, Footle.class, null, new NullComponentMonitor(), new NullLifecycleStrategy(), false);
    032            HiddenImplementation ihca = new HiddenImplementation(ca);
    033            Object comp = ihca.getComponentInstance(null, null);
    034            assertNotNull(comp);
    035            assertTrue(comp instanceof ActionListener);
    036            assertTrue(comp instanceof MouseListener);
    037        }
    038
    039        @Test public void testNonInterfaceInArrayCantBeHidden() {
    040            ComponentAdapter ca = new ConstructorInjector(new Class[]{String.class}, Footle.class, null, new NullComponentMonitor(), new NullLifecycleStrategy(), false);
    041            HiddenImplementation ihca = new HiddenImplementation(ca);
    042            try {
    043                ihca.getComponentInstance(null, null);
    044                fail("PicoCompositionException expected");
    045            } catch (PicoCompositionException e) {
    046                // expected
    047            }
    048        }
    049
    050
    051
    052        public class Footle implements ActionListener, MouseListener {
    053            public void actionPerformed(ActionEvent e) {
    054            }
    055
    056            public void mouseClicked(MouseEvent e) {
    057            }
    058
    059            public void mouseEntered(MouseEvent e) {
    060            }
    061
    062            public void mouseExited(MouseEvent e) {
    063            }
    064
    065            public void mousePressed(MouseEvent e) {
    066            }
    067
    068            public void mouseReleased(MouseEvent e) {
    069            }
    070
    071        }
    072
    073    }