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.injectors;
011    
012    import static org.junit.Assert.assertNotNull;
013    import org.junit.Test;
014    import org.picocontainer.DefaultPicoContainer;
015    import org.picocontainer.MutablePicoContainer;
016    import org.picocontainer.lifecycle.NullLifecycleStrategy;
017    import org.picocontainer.monitors.NullComponentMonitor;
018    
019    public class TypedFieldInjectorTestCase {
020    
021        public static class Helicopter {
022            private PogoStick pogo;
023        }
024    
025    
026        public static class PogoStick {
027        }
028    
029        @Test public void testFieldInjectionByType() {
030            MutablePicoContainer pico = new DefaultPicoContainer();
031            pico.addAdapter(new TypedFieldInjector(Helicopter.class, Helicopter.class, null,
032                                                        new NullComponentMonitor(),
033                    new NullLifecycleStrategy(),
034                    Integer.class.getName() + " " + PogoStick.class.getName() + " " + Float.class.getName()));
035            pico.addComponent(PogoStick.class, new PogoStick());
036            Helicopter chopper = pico.getComponent(Helicopter.class);
037            assertNotNull(chopper);
038            assertNotNull(chopper.pogo);
039        }
040    
041    
042    }