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 static org.junit.Assert.assertNull;
014 import static org.junit.Assert.assertEquals;
015
016 import java.lang.annotation.ElementType;
017 import java.lang.annotation.Retention;
018 import java.lang.annotation.RetentionPolicy;
019 import java.lang.annotation.Target;
020
021 import org.junit.Test;
022 import org.picocontainer.DefaultPicoContainer;
023 import org.picocontainer.MutablePicoContainer;
024 import org.picocontainer.annotations.Inject;
025 import org.picocontainer.lifecycle.NullLifecycleStrategy;
026 import org.picocontainer.monitors.NullComponentMonitor;
027
028 public class TypedFieldInjectorTestCase {
029
030 public static class Helicopter {
031 private PogoStick pogo;
032 }
033
034
035 public static class PogoStick {
036 }
037
038 @Test public void testFieldInjectionByType() {
039 MutablePicoContainer pico = new DefaultPicoContainer();
040 pico.addAdapter(new TypedFieldInjector(Helicopter.class, Helicopter.class, null,
041 new NullComponentMonitor(),
042 new NullLifecycleStrategy(),
043 Integer.class.getName() + " " + PogoStick.class.getName() + " " + Float.class.getName()));
044 pico.addComponent(PogoStick.class, new PogoStick());
045 Helicopter chopper = pico.getComponent(Helicopter.class);
046 assertNotNull(chopper);
047 assertNotNull(chopper.pogo);
048 }
049
050
051 }