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.ConstructorInjectionFactory;
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 * @version $Revision: $
026 */
027 public class ConstructorInjectionFactoryTestCase extends AbstractComponentFactoryTestCase {
028 protected void setUp() throws Exception {
029 picoContainer = new DefaultPicoContainer(createComponentFactory());
030 }
031
032 protected ComponentFactory createComponentFactory() {
033 return new ConstructorInjectionFactory();
034 }
035
036 public void testCustomLifecycleCanBeInjected() throws NoSuchMethodException {
037 RecordingLifecycleStrategy strategy = new RecordingLifecycleStrategy(new StringBuffer());
038 ConstructorInjectionFactory componentFactory =
039 new ConstructorInjectionFactory();
040 ConstructorInjector cica = (ConstructorInjector)
041 componentFactory.createComponentAdapter(new NullComponentMonitor(), strategy, null, NullLifecycle.class, NullLifecycle.class);
042 One one = new RecordingLifecycle.One(new StringBuffer());
043 cica.start(one);
044 cica.stop(one);
045 cica.dispose(one);
046 assertEquals("<start<stop<dispose", strategy.recording());
047 }
048
049 }