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     * Idea by Rachel Davies, Original code by Aslak Hellesoy and Paul Hammant   *
009     *****************************************************************************/
010    package org.picocontainer.injectors;
011    
012    import org.picocontainer.injectors.ConstructorInjection;
013    import org.picocontainer.monitors.NullComponentMonitor;
014    import org.picocontainer.DefaultPicoContainer;
015    import org.picocontainer.ComponentFactory;
016    import org.picocontainer.injectors.ConstructorInjector;
017    import org.picocontainer.tck.AbstractComponentFactoryTestCase;
018    import org.picocontainer.tck.AbstractComponentAdapterTestCase.RecordingLifecycleStrategy;
019    import org.picocontainer.testmodel.NullLifecycle;
020    import org.picocontainer.testmodel.RecordingLifecycle;
021    import org.picocontainer.testmodel.RecordingLifecycle.One;
022    
023    /**
024     * @author Mauro Talevi
025     */
026    public class ConstructorInjectionTestCase extends AbstractComponentFactoryTestCase {
027        protected void setUp() throws Exception {
028            picoContainer = new DefaultPicoContainer(createComponentFactory());
029        }
030    
031        protected ComponentFactory createComponentFactory() {
032            return new ConstructorInjection();
033        }
034    
035        public void testCustomLifecycleCanBeInjected() throws NoSuchMethodException {
036            RecordingLifecycleStrategy strategy = new RecordingLifecycleStrategy(new StringBuffer());
037            ConstructorInjection componentFactory =
038                new ConstructorInjection();
039            ConstructorInjector cica =  (ConstructorInjector)
040            componentFactory.createComponentAdapter(new NullComponentMonitor(), strategy, null, NullLifecycle.class, NullLifecycle.class);
041            One one = new RecordingLifecycle.One(new StringBuffer());
042            cica.start(one);
043            cica.stop(one);        
044            cica.dispose(one);
045            assertEquals("<start<stop<dispose", strategy.recording());
046        }    
047    
048    }