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.defaults;
011    
012    import org.picocontainer.Parameter;
013    import org.picocontainer.tck.AbstractComponentAdapterFactoryTestCase;
014    import org.picocontainer.tck.AbstractComponentAdapterTestCase.RecordingLifecycleStrategy;
015    import org.picocontainer.testmodel.NullLifecycle;
016    import org.picocontainer.testmodel.RecordingLifecycle;
017    import org.picocontainer.testmodel.RecordingLifecycle.One;
018    
019    /**
020     * @author Mauro Talevi
021     * @version $Revision:  $
022     */
023    public class ConstructorInjectionComponentAdapterFactoryTestCase extends AbstractComponentAdapterFactoryTestCase {
024        protected void setUp() throws Exception {
025            picoContainer = new DefaultPicoContainer(createComponentAdapterFactory());
026        }
027    
028        protected ComponentAdapterFactory createComponentAdapterFactory() {
029            return new ConstructorInjectionComponentAdapterFactory();
030        }
031    
032        public void testCustomLifecycleCanBeInjected() throws NoSuchMethodException {
033            RecordingLifecycleStrategy strategy = new RecordingLifecycleStrategy(new StringBuffer());
034            ConstructorInjectionComponentAdapterFactory caf = 
035                new ConstructorInjectionComponentAdapterFactory(false, strategy);
036            ConstructorInjectionComponentAdapter cica =  (ConstructorInjectionComponentAdapter)
037            caf.createComponentAdapter(NullLifecycle.class, NullLifecycle.class, new Parameter[0]);
038            One one = new RecordingLifecycle.One(new StringBuffer());
039            cica.start(one);
040            cica.stop(one);        
041            cica.dispose(one);
042            assertEquals("<start<stop<dispose", strategy.recording());
043        }    
044    
045    }