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 static org.junit.Assert.assertEquals; 013 014 import java.util.Properties; 015 016 import org.junit.Before; 017 import org.junit.Test; 018 import org.picocontainer.ComponentFactory; 019 import org.picocontainer.DefaultPicoContainer; 020 import org.picocontainer.monitors.NullComponentMonitor; 021 import org.picocontainer.tck.AbstractComponentFactoryTest; 022 import org.picocontainer.tck.AbstractComponentAdapterTest.RecordingLifecycleStrategy; 023 import org.picocontainer.testmodel.NullLifecycle; 024 import org.picocontainer.testmodel.RecordingLifecycle; 025 import org.picocontainer.testmodel.RecordingLifecycle.One; 026 027 /** 028 * @author Mauro Talevi 029 */ 030 public class ConstructorInjectionTestCase extends AbstractComponentFactoryTest { 031 032 @Before 033 public void setUp() throws Exception { 034 picoContainer = new DefaultPicoContainer(createComponentFactory()); 035 } 036 037 protected ComponentFactory createComponentFactory() { 038 return new ConstructorInjection(); 039 } 040 041 @Test public void testCustomLifecycleCanBeInjected() throws NoSuchMethodException { 042 RecordingLifecycleStrategy strategy = new RecordingLifecycleStrategy(new StringBuffer()); 043 ConstructorInjection componentFactory = 044 new ConstructorInjection(); 045 ConstructorInjector cica = (ConstructorInjector) 046 componentFactory.createComponentAdapter(new NullComponentMonitor(), strategy, new Properties(), NullLifecycle.class, NullLifecycle.class); 047 One one = new RecordingLifecycle.One(new StringBuffer()); 048 cica.start(one); 049 cica.stop(one); 050 cica.dispose(one); 051 assertEquals("<start<stop<dispose", strategy.recording()); 052 } 053 054 }