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.tck;
011    
012    import junit.framework.TestCase;
013    
014    import org.picocontainer.ComponentAdapter;
015    import org.picocontainer.PicoCompositionException;
016    import org.picocontainer.Characteristics;
017    import org.picocontainer.lifecycle.NullLifecycleStrategy;
018    import org.picocontainer.monitors.NullComponentMonitor;
019    import org.picocontainer.ComponentFactory;
020    import org.picocontainer.DefaultPicoContainer;
021    import org.picocontainer.testmodel.SimpleTouchable;
022    import org.picocontainer.testmodel.Touchable;
023    
024    import java.util.Properties;
025    
026    /**
027     * @author Aslak Hellesøy
028     * @version $Revision: 3677 $
029     */
030    public abstract class AbstractComponentFactoryTestCase extends TestCase {
031    
032        protected DefaultPicoContainer picoContainer;
033    
034        protected abstract ComponentFactory createComponentFactory();
035    
036        protected void setUp() throws Exception {
037            picoContainer = new DefaultPicoContainer();
038        }
039    
040        public void testEquals() throws PicoCompositionException {
041            ComponentAdapter componentAdapter = createComponentFactory().createComponentAdapter(new NullComponentMonitor(),
042                                                                                                new NullLifecycleStrategy(),
043                                                                                                new Properties(
044                                                                                                    Characteristics
045                                                                                                        .CDI),
046                                                                                                Touchable.class,
047                                                                                                SimpleTouchable.class);
048    
049            assertEquals(componentAdapter, componentAdapter);
050            assertTrue(!componentAdapter.equals("blah"));
051        }
052    
053        public void testRegisterComponent() throws PicoCompositionException {
054            ComponentAdapter componentAdapter =
055                createComponentFactory().createComponentAdapter(new NullComponentMonitor(),
056                                                                new NullLifecycleStrategy(),
057                                                                new Properties(Characteristics
058                                                                    .CDI),
059                                                                Touchable.class,
060                                                                SimpleTouchable.class);
061    
062            picoContainer.addAdapter(componentAdapter);
063    
064            assertTrue(picoContainer.getComponentAdapters().contains(componentAdapter));
065        }
066    
067        public void testUnregisterComponent() throws PicoCompositionException {
068            ComponentAdapter componentAdapter =
069                createComponentFactory().createComponentAdapter(new NullComponentMonitor(),
070                                                                new NullLifecycleStrategy(),
071                                                                new Properties(Characteristics
072                                                                    .CDI),
073                                                                Touchable.class,
074                                                                SimpleTouchable.class);
075    
076            picoContainer.addAdapter(componentAdapter);
077            picoContainer.removeComponent(Touchable.class);
078    
079            assertFalse(picoContainer.getComponentAdapters().contains(componentAdapter));
080        }
081    }