    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.assertTrue;
    013    import static org.junit.Assert.assertEquals;
    014
    015    import java.util.HashMap;
    016    import java.util.Map;
    017    import java.util.Properties;
    018
    019    import org.junit.Test;
    020    import org.picocontainer.ComponentAdapter;
    021    import org.picocontainer.Parameter;
    022    import org.picocontainer.Characteristics;
    023    import org.picocontainer.lifecycle.ReflectionLifecycleStrategy;
    024    import org.picocontainer.monitors.ConsoleComponentMonitor;
    025
    026    public class NamedFieldInjectionTestCase {
    027
    028        @Test public void testFactoryMakesNamedInjector() {
    029
    030            NamedFieldInjection injectionFactory = new NamedFieldInjection();
    031
    032            ConsoleComponentMonitor cm = new ConsoleComponentMonitor();
    033            Properties props = new Properties();
    034            props.setProperty("injectionFieldNames", " aa pogo bb ");
    035            ComponentAdapter ca = injectionFactory.createComponentAdapter(cm, new ReflectionLifecycleStrategy(cm),
    036                    props, Map.class, HashMap.class, Parameter.DEFAULT);
    037
    038            assertTrue(ca instanceof NamedFieldInjector);
    039
    040            NamedFieldInjector nfi = (NamedFieldInjector) ca;
    041
    042            assertEquals(3, nfi.getInjectionFieldNames().size());
    043            assertEquals("pogo", nfi.getInjectionFieldNames().get(1));
    044        }
    045
    046        @Test public void testPropertiesAreRight() {
    047            Properties props = NamedFieldInjection.injectionFieldNames("aa","pogo","bb");
    048            assertTrue(props instanceof Characteristics.ImmutableProperties);
    049            assertEquals("aa pogo bb", props.getProperty("injectionFieldNames"));
    050            assertEquals(1, props.size());
    051        }
    052
    053
    054    }