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