incubator-composer-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hamm...@apache.org
Subject svn commit: r613775 [12/15] - in /incubator/composer: ./ core/ core/src/ core/src/java/ core/src/java/org/ core/src/java/org/apache/ core/src/java/org/apache/composer/ core/src/java/org/apache/composer/core/ core/src/java/org/apache/composer/core/adapt...
Date Mon, 21 Jan 2008 06:41:50 GMT
Added: incubator/composer/core/src/test/org/apache/composer/core/defaults/XStreamSerialisationTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/defaults/XStreamSerialisationTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/defaults/XStreamSerialisationTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/defaults/XStreamSerialisationTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,65 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.defaults;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.MutableContainer;
+import org.apache.composer.core.Container;
+import org.apache.composer.core.testmodel.DependsOnTouchable;
+import org.apache.composer.core.testmodel.SimpleTouchable;
+
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.core.JVM;
+import com.thoughtworks.xstream.io.xml.XppDriver;
+
+/**
+ * @author Aslak Hellesøy
+ */
+public final class XStreamSerialisationTestCase {
+    private final XStream xStream = new XStream(new XppDriver());
+
+    @Test public void testShouldBeAbleToSerialiseEmptyPico() {
+        if (JVM.is14()) {
+            MutableContainer pico = new DefaultContainer();
+            String picoXml = xStream.toXML(pico);
+            Container serializedPico = (Container) xStream.fromXML(picoXml);
+
+            assertEquals(0, serializedPico.getComponents().size());
+        }
+    }
+
+    @Test public void testShouldBeAbleToSerialisePicoWithUninstantiatedComponents() {
+        if (JVM.is14()) {
+            MutableContainer pico = new DefaultContainer();
+            pico.addComponent(SimpleTouchable.class);
+            pico.addComponent(DependsOnTouchable.class);
+            String picoXml = xStream.toXML(pico);
+            Container serializedPico = (Container) xStream.fromXML(picoXml);
+
+            assertEquals(2, serializedPico.getComponents().size());
+        }
+    }
+
+    @Test public void testShouldBeAbleToSerialisePicoWithInstantiatedComponents() {
+        if (JVM.is14()) {
+            MutableContainer pico = new DefaultContainer();
+            pico.addComponent(SimpleTouchable.class);
+            pico.addComponent(DependsOnTouchable.class);
+            pico.getComponents();
+            String picoXml = xStream.toXML(pico);
+            Container serializedPico = (Container) xStream.fromXML(picoXml);
+
+            assertEquals(2, serializedPico.getComponents().size());
+        }
+    }
+}
\ No newline at end of file

Added: incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0191TestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0191TestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0191TestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0191TestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,89 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.defaults.issues;
+
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.MutableContainer;
+import org.apache.composer.core.injectors.AbstractInjector;
+
+public final class Issue0191TestCase {
+
+    static int sharkCount = 0 ;
+    static int codCount = 0 ;
+
+    /*
+      This bug as descripbed in the bug report, cannot be reproduced. Needs work.
+    */
+    @Test public void testTheBug()
+    {
+        MutableContainer pico = new DefaultContainer( ) ;
+        pico.addComponent(Shark.class);
+        pico.addComponent(Cod.class);
+        try {
+            pico.addComponent(Bowl.class);
+            Bowl bowl = pico.getComponent(Bowl.class);
+            fail("Should have barfed here with UnsatisfiableDependenciesException");
+            Fish[] fishes = bowl.getFishes( ) ;
+            for( int i = 0 ; i < fishes.length ; i++ )
+                System.out.println( "fish["+i+"]="+fishes[i] ) ;
+        } catch (AbstractInjector.UnsatisfiableDependenciesException e) {
+            // expected, well except that there is supposed to be a different bug here.
+        }
+    }
+
+
+     class Bowl
+    {
+        private final Fish[] fishes;
+        private final Cod[] cods;
+        public Bowl(Fish[] fishes, Cod[] cods)
+        {
+            this.fishes = fishes;
+            this.cods = cods;
+        }
+        public Fish[] getFishes()
+        {
+            return fishes;
+        }
+        public Cod[] getCods()
+        {
+            return cods;
+        }
+
+    }
+
+    public interface Fish
+    {
+    }
+
+    final class Cod implements Fish
+    {
+        final int instanceNum ;
+        public Cod( ) { instanceNum = codCount++ ; }
+
+        public String toString( ) {
+            return "Cod #" + instanceNum ;
+        }
+    }
+
+    final class Shark implements Fish
+    {
+        final int instanceNum ;
+        public Shark( ) { instanceNum = sharkCount++ ; }
+
+        public String toString( ) {
+            return "Shark #" + instanceNum ;
+        }
+    }
+
+}

Added: incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0196TestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0196TestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0196TestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0196TestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,45 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.defaults.issues;
+
+import static org.junit.Assert.assertNotNull;
+import junit.framework.Assert;
+
+import org.junit.Test;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.MutableContainer;
+
+public class Issue0196TestCase {
+    public static class Descriptor {
+        public static class DescriptorData {
+        }
+    }
+    public static class DescriptorDep {
+        public DescriptorDep(Descriptor.DescriptorData[] datas) {
+            Assert.assertEquals(3, datas.length);
+            Assert.assertNull(datas[0]);
+            Assert.assertNull(datas[1]);
+            Assert.assertNull(datas[2]);
+        }
+    }
+
+    @Test public void testShouldAllowRegistrationOfArrayAsInstance() {
+        MutableContainer pico = new DefaultContainer();
+
+        Descriptor.DescriptorData[] datas = new Descriptor.DescriptorData[3];
+
+        pico.addComponent(datas);
+        pico.addComponent(DescriptorDep.class);
+
+        DescriptorDep descriptorDep = pico.getComponent(DescriptorDep.class);
+
+        assertNotNull(descriptorDep);
+    }
+}

Added: incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0199TestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0199TestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0199TestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0199TestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,99 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.defaults.issues;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.Container;
+import org.apache.composer.core.behaviors.Synchronizing;
+import org.apache.composer.core.injectors.ConstructorInjection;
+
+public final class Issue0199TestCase {
+
+    public static class A {
+        public A(C c) {}
+    }
+
+    public static class B {
+        public B(C c) {}
+    }
+
+    public static class C {}
+
+    final class Runner extends Thread {
+        private final Container container;
+        private final Object componentKey;
+        private Throwable throwable;
+        private boolean finished;
+
+        Runner(String name, Container container, Object componentKey) {
+            super(name);
+            this.container = container;
+            this.componentKey = componentKey;
+        }
+
+        public void run() {
+            try {
+                report("Started instantiating " + componentKey.toString());
+                container.getComponent(componentKey);
+                report("Finished instantiating " + componentKey.toString());
+                finished = true;
+            } catch (Throwable t) {
+                this.throwable = t;
+            }
+        }
+
+        private void report(String messsage) {
+            System.out.println(getName() + ": " + messsage);
+        }
+
+        public boolean isFinished() {
+            return finished;
+        }
+
+        public Throwable getThrowable() {
+            return throwable;
+        }
+    }
+
+    @Test public void testPicoContainerCausesDeadlock() throws InterruptedException {
+        DefaultContainer container = createContainer();
+        container.addComponent("A", A.class);
+        container.addComponent("B", B.class);
+        container.addComponent("C", C.class);
+
+        final int THREAD_COUNT = 2;
+        List runnerList = new ArrayList(THREAD_COUNT);
+
+        for (int i = 0; i < THREAD_COUNT; ++i) {
+            Runner runner = new Runner("Runner " + i, container, (i % 2 == 0) ? "A" : "B");
+            runnerList.add(runner);
+            runner.start();
+        }
+
+        final long WAIT_TIME = 1000;
+
+        for (int i = 0; i < THREAD_COUNT; ++i) {
+            Runner runner = (Runner) runnerList.get(i);
+            runner.join(WAIT_TIME);
+            assertTrue("Deadlock occurred", runner.isFinished());
+        }
+    }
+
+    private DefaultContainer createContainer() {
+        return new DefaultContainer(
+                new Synchronizing().wrap(new ConstructorInjection()));
+    }
+}

Added: incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0229TestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0229TestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0229TestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0229TestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,57 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by Michael Rettig                                           *
+ *****************************************************************************/
+package org.apache.composer.core.defaults.issues;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.visitors.VerifyingVisitor;
+
+
+public class Issue0229TestCase {
+    
+    public static class MockRunnable implements Runnable {
+        public void run() {
+        }
+    }
+
+    public static class OtherRunnable implements Runnable {
+        public void run() {
+        }
+    }
+
+    public static class MockRunner {
+        private final Runnable[] _runners;
+
+        public MockRunner(Runnable[] runnables) {
+            _runners = runnables;
+        }
+        
+        public Runnable[] getRunners(){
+            return _runners;
+        }
+    }
+
+    @Test public void testArrayDependenciesAndVerification() {
+        DefaultContainer container = new DefaultContainer();
+        container.addComponent(new MockRunnable());
+        container.addComponent(new OtherRunnable());
+        container.addComponent(MockRunner.class);
+
+        // this will fail to resolve the Runnable array on the MockRunner
+        VerifyingVisitor visitor = new VerifyingVisitor();
+        visitor.traverse(container);
+
+        container.start();
+        assertNotNull(container.getComponent(MockRunner.class));
+    }
+
+}

Propchange: incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0229TestCase.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0265TestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0265TestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0265TestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0265TestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,76 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.defaults.issues;
+
+import static org.junit.Assert.assertNotNull;
+import static org.apache.composer.core.tck.MockFactory.mockeryWithCountingNamingScheme;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.integration.junit4.JMock;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.apache.composer.core.Characteristics;
+import org.apache.composer.core.ComponentAdapter;
+import org.apache.composer.core.ComponentMonitor;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.DefaultContainerTestCase;
+import org.apache.composer.core.Container;
+import org.apache.composer.core.Startable;
+
+@RunWith(JMock.class)
+public class Issue0265TestCase {
+
+	private Mockery mockery = mockeryWithCountingNamingScheme();
+	
+    @Test public void testCanReallyChangeMonitor() throws SecurityException, NoSuchMethodException {
+        final Method start = Startable.class.getMethod("start");
+        final Method stop = Startable.class.getMethod("stop");
+        final ComponentMonitor monitor1 = mockery.mock(ComponentMonitor.class, "Monitor1");
+        final ComponentMonitor monitor2 = mockery.mock(ComponentMonitor.class, "Monitor2");
+        DefaultContainer pico = new DefaultContainer(monitor1);
+        pico.as(Characteristics.CACHE).addComponent(DefaultContainerTestCase.MyStartable.class);
+        mockery.checking(new Expectations(){{
+            one(monitor1).instantiating(with(any(Container.class)), with(any(ComponentAdapter.class)), with(any(Constructor.class)));
+            will(returnValue(DefaultContainerTestCase.MyStartable.class.getConstructor()));
+            one(monitor1).instantiated(with(any(Container.class)), with(any(ComponentAdapter.class)), with(any(Constructor.class)),
+            		with(any(Object.class)), with(any(Object[].class)), with(any(Long.class)));
+            one(monitor1).invoking(with(any(Container.class)), with(any(ComponentAdapter.class)), with(equal(start)),
+            		with(any(Object.class)));
+            one(monitor1).invoked(with(any(Container.class)), with(any(ComponentAdapter.class)), with(equal(start)),
+            		with(any(Object.class)), with(any(Long.class)));
+            one(monitor1).invoking(with(any(Container.class)), with(any(ComponentAdapter.class)), with(equal(stop)),
+            		with(any(Object.class)));
+            one(monitor1).invoked(with(any(Container.class)), with(any(ComponentAdapter.class)), with(equal(stop)),
+            		with(any(Object.class)), with(any(Long.class)));        	
+        }});
+        pico.start();
+        pico.stop();
+        Startable startable = pico.getComponent(DefaultContainerTestCase.MyStartable.class);
+        assertNotNull(startable);
+        pico.changeMonitor(monitor2);
+        mockery.checking(new Expectations(){{
+            one(monitor2).invoking(with(any(Container.class)), with(any(ComponentAdapter.class)), with(equal(start)),
+            		with(any(Object.class)));
+            one(monitor2).invoked(with(any(Container.class)), with(any(ComponentAdapter.class)), with(equal(start)),
+            		with(any(Object.class)), with(any(Long.class)));
+            one(monitor2).invoking(with(any(Container.class)), with(any(ComponentAdapter.class)), with(equal(stop)),
+            		with(any(Object.class)));
+            one(monitor2).invoked(with(any(Container.class)), with(any(ComponentAdapter.class)), with(equal(stop)),
+            		with(any(Object.class)), with(any(Long.class)));        	
+        }});
+        pico.start();
+        pico.stop();
+    }
+
+}

Added: incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0280TestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0280TestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0280TestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/defaults/issues/Issue0280TestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,59 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.defaults.issues;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.MutableContainer;
+import org.apache.composer.core.CompositionException;
+
+/**
+ * Test case for issue http://jira.codehaus.org/browse/PICO-280
+ */
+public class Issue0280TestCase {
+
+	@Test
+	public void testShouldFailIfInstantiationInChildContainerFails() {
+		MutableContainer parent = new DefaultContainer();
+		MutableContainer child = new DefaultContainer(parent);
+
+		parent.addComponent(CommonInterface.class, ParentImplementation.class);
+		child.addComponent(CommonInterface.class, ChildImplementation.class);
+
+		parent.start();
+
+		try {
+			Object result = child.getComponent(CommonInterface.class);
+
+			// should never get here
+			assertFalse(result.getClass() == ParentImplementation.class);
+		} catch (Exception e) {
+			assertTrue(e.getClass() == CompositionException.class);
+		}
+
+	}
+
+	public interface CommonInterface {
+
+	}
+
+	public static class ParentImplementation implements CommonInterface {
+	}
+
+	public static class ChildImplementation implements CommonInterface {
+		public ChildImplementation() {
+			throw new CompositionException("Problem during initialization");
+		}
+	}
+
+}

Added: incubator/composer/core/src/test/org/apache/composer/core/injectors/AbstractInjectorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/injectors/AbstractInjectorTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/injectors/AbstractInjectorTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/injectors/AbstractInjectorTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,159 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.injectors;
+
+import static org.junit.Assert.assertSame;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Member;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.apache.composer.core.ComponentAdapter;
+import org.apache.composer.core.ComponentMonitor;
+import org.apache.composer.core.LifecycleStrategy;
+import org.apache.composer.core.Parameter;
+import org.apache.composer.core.CompositionException;
+import org.apache.composer.core.Container;
+import org.apache.composer.core.containers.EmptyContainer;
+import org.apache.composer.core.lifecycle.NullLifecycleStrategy;
+import org.apache.composer.core.monitors.NullComponentMonitor;
+
+public class AbstractInjectorTestCase {
+
+    private AbstractInjector ai;
+    Constructor<HashMap> ctor;
+
+    @Before
+    public void setUp() throws NoSuchMethodException {
+        ai = new MyAbstractInjector(Map.class, HashMap.class, new Parameter[0],
+                                                     new NullComponentMonitor(),
+                                                     new NullLifecycleStrategy(), false);
+        ctor = HashMap.class.getConstructor();
+    }
+
+    @Test public void testCaughtIllegalAccessExceptionInvokesMonitorAndThrows() {
+        final EmptyContainer epc = new EmptyContainer();
+        final IllegalAccessException iae = new IllegalAccessException("foo");
+        NullComponentMonitor ncm = new NullComponentMonitor() {
+            public void instantiationFailed(Container container,
+                                            ComponentAdapter componentAdapter,
+                                            Constructor constructor,
+                                            Exception e) {
+                assertSame(epc, container);
+                assertSame(ai, componentAdapter);
+                assertSame(ctor, constructor);
+                assertSame(iae, e);
+            }
+        };
+        try {
+            ai.caughtIllegalAccessException(ncm, ctor, iae, epc);
+        } catch (CompositionException e) {
+            assertSame(iae, e.getCause());
+        }
+    }
+
+    @Test public void testCaughtInstantiationExceptionInvokesMonitorAndThrows() {
+        final EmptyContainer epc = new EmptyContainer();
+        final InstantiationException ie = new InstantiationException("foo");
+        NullComponentMonitor ncm = new NullComponentMonitor() {
+            public void instantiationFailed(Container container,
+                                            ComponentAdapter componentAdapter,
+                                            Constructor constructor,
+                                            Exception e) {
+                assertSame(epc, container);
+                assertSame(ai, componentAdapter);
+                assertSame(ctor, constructor);
+                assertSame(ie, e);
+            }
+        };
+        try {
+            ai.caughtInstantiationException(ncm, ctor, ie, epc);
+        } catch (CompositionException e) {
+            assertSame("Should never get here", e.getMessage());
+        }
+    }
+
+    @Test public void testCaughtInvocationTargetExceptionInvokesMonitorAndReThrowsRuntimeIfRuntimeInTheFirstPlace() {
+        final InvocationTargetException ite = new InvocationTargetException(new RuntimeException("foo"));
+        NullComponentMonitor ncm = new NullComponentMonitor() {
+            public void invocationFailed(Member member, Object instance, Exception e) {
+                assertSame(ctor, member);
+                assertSame("bar", instance);
+                assertSame(ite, e);
+            }
+        };
+        try {
+            ai.caughtInvocationTargetException(ncm, ctor, "bar", ite);
+        } catch (RuntimeException e) {
+            assertSame("foo", e.getMessage());
+        }
+    }
+
+    @Test public void testCaughtInvocationTargetExceptionInvokesMonitorAndReThrowsErrorIfErrorInTheFirstPlace() {
+        final InvocationTargetException ite = new InvocationTargetException(new Error("foo"));
+        NullComponentMonitor ncm = new NullComponentMonitor() {
+            public void invocationFailed(Member member, Object instance, Exception e) {
+                assertSame(ctor, member);
+                assertSame("bar", instance);
+                assertSame(ite, e);
+            }
+        };
+        try {
+            ai.caughtInvocationTargetException(ncm, ctor, "bar", ite);
+        } catch (Error e) {
+            assertSame("foo", e.getMessage());
+        }
+    }
+
+    @Test public void testCaughtInvocationTargetExceptionInvokesMonitorAndReThrowsAsCompositionIfNotRuntimeOrError() {
+        final InvocationTargetException ite = new InvocationTargetException(new Exception("foo"));
+        NullComponentMonitor ncm = new NullComponentMonitor() {
+            public void invocationFailed(Member member, Object instance, Exception e) {
+                assertSame(ctor, member);
+                assertSame("bar", instance);
+                assertSame(ite, e);
+            }
+        };
+        try {
+            ai.caughtInvocationTargetException(ncm, ctor, "bar", ite);
+        } catch (CompositionException e) {
+            assertSame("foo", e.getCause().getMessage());
+        }
+    }
+
+
+
+    private static class MyAbstractInjector extends AbstractInjector {
+
+        public MyAbstractInjector(Object componentKey,
+                                  Class componentImplementation,
+                                  Parameter[] parameters,
+                                  ComponentMonitor monitor,
+                                  LifecycleStrategy lifecycleStrategy,
+                                  boolean useNames) {
+            super(componentKey, componentImplementation, parameters, monitor, lifecycleStrategy, useNames);
+        }
+
+        public void verify(Container container) throws CompositionException {
+                }
+
+        public Object getComponentInstance(Container container) throws CompositionException {
+            return null;
+        }
+
+        public String getDescriptor() {
+            return null;
+        }
+    }
+}

Added: incubator/composer/core/src/test/org/apache/composer/core/injectors/AdaptingInjectionTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/injectors/AdaptingInjectionTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/injectors/AdaptingInjectionTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/injectors/AdaptingInjectionTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,186 @@
+/*****************************************************************************
+ * Copyright (c) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Idea by Rachel Davies, Original code by Stacy Curl                        *
+ *****************************************************************************/
+
+package org.apache.composer.core.injectors;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.apache.composer.core.Characteristics;
+import org.apache.composer.core.ComponentAdapter;
+import org.apache.composer.core.ComponentFactory;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.Parameter;
+import org.apache.composer.core.CompositionException;
+import org.apache.composer.core.lifecycle.NullLifecycleStrategy;
+import org.apache.composer.core.lifecycle.ReflectionLifecycleStrategy;
+import org.apache.composer.core.monitors.ConsoleComponentMonitor;
+import org.apache.composer.core.monitors.NullComponentMonitor;
+import org.apache.composer.core.tck.AbstractComponentFactoryTest;
+import org.apache.composer.core.testmodel.SimpleTouchable;
+import org.apache.composer.core.testmodel.Touchable;
+
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.converters.Converter;
+import com.thoughtworks.xstream.converters.MarshallingContext;
+import com.thoughtworks.xstream.converters.UnmarshallingContext;
+import com.thoughtworks.xstream.io.HierarchicalStreamReader;
+import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+
+public class AdaptingInjectionTestCase extends AbstractComponentFactoryTest {
+
+    XStream xs;
+
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        xs = new XStream();
+        xs.alias("RLS", ReflectionLifecycleStrategy.class);
+        xs.alias("CCM", ConsoleComponentMonitor.class);
+        xs.alias("Method-Injection", AnnotatedMethodInjector.class);
+        xs.alias("Field-Injection", AnnotatedFieldInjector.class);
+        xs.alias("Constructor-Injection", ConstructorInjector.class);
+        //xs.alias("CCM", ConsoleComponentMonitor.class);
+        xs.registerConverter(new Converter() {
+            public boolean canConvert(Class aClass) {
+                return aClass.getName().equals("org.apache.composer.core.monitors.ConsoleComponentMonitor") ||
+                       aClass.getName().equals("org.apache.composer.core.lifecycle.ReflectionLifecycleStrategy");
+
+            }
+
+            public void marshal(Object object,
+                                HierarchicalStreamWriter hierarchicalStreamWriter,
+                                MarshallingContext marshallingContext)
+            {
+            }
+
+            public Object unmarshal(HierarchicalStreamReader hierarchicalStreamReader,
+                                    UnmarshallingContext unmarshallingContext)
+            {
+                return null;
+            }
+        });
+
+    }
+
+    protected ComponentFactory createComponentFactory() {
+        return new AdaptingInjection();
+    }
+
+    @Test public void testInstantiateComponentWithNoDependencies() throws CompositionException {
+        ComponentAdapter componentAdapter =
+            createComponentFactory().createComponentAdapter(new NullComponentMonitor(),
+                                                            new NullLifecycleStrategy(),
+                                                            new Properties(Characteristics.CDI),
+                                                            Touchable.class,
+                                                            SimpleTouchable.class,
+                                                            (Parameter[])null);
+
+        Object comp = componentAdapter.getComponentInstance(new DefaultContainer());
+        assertNotNull(comp);
+        assertTrue(comp instanceof SimpleTouchable);
+    }
+
+    @Test public void testSingleUsecanBeInstantiatedByDefaultComponentAdapter() {
+        ComponentAdapter componentAdapter = createComponentFactory().createComponentAdapter(new NullComponentMonitor(),
+                                                                                            new NullLifecycleStrategy(),
+                                                                                            new Properties(
+                                                                                                Characteristics.CDI),
+                                                                                            "o",
+                                                                                            Object.class,
+                                                                                            (Parameter[])null);
+        Object component = componentAdapter.getComponentInstance(new DefaultContainer());
+        assertNotNull(component);
+    }
+
+
+    @Test public void testFactoryMakesConstructorInjector() {
+
+        ComponentFactory cf = createComponentFactory();
+
+        ConsoleComponentMonitor cm = new ConsoleComponentMonitor();
+        ComponentAdapter ca = cf.createComponentAdapter(cm, new ReflectionLifecycleStrategy(cm), new Properties(),
+                                                        Map.class, HashMap.class, Parameter.DEFAULT);
+
+        String foo = xs.toXML(ca).replace("\"", "");
+
+        assertEquals("<Constructor-Injection>\n" +
+                     "  <lifecycleStrategy class=RLS/>\n" +
+                     "  <useNames>false</useNames>\n" +
+                     "  <componentKey class=java-class>java.util.Map</componentKey>\n" +
+                     "  <componentImplementation>java.util.HashMap</componentImplementation>\n" +
+                     "  <componentMonitor class=CCM/>\n" +
+                     "</Constructor-Injection>", foo);
+
+
+    }
+
+    @Test public void testFactoryMakesFieldAnnotationInjector() {
+
+        ComponentFactory cf = createComponentFactory();
+
+        ConsoleComponentMonitor cm = new ConsoleComponentMonitor();
+        ComponentAdapter ca = cf.createComponentAdapter(cm,
+                                                        new ReflectionLifecycleStrategy(cm),
+                                                        new Properties(),
+                                                        AnnotatedFieldInjectorTestCase.Helicopter.class,
+                                                        AnnotatedFieldInjectorTestCase.Helicopter.class,
+                                                        Parameter.DEFAULT);
+
+        String foo = xs.toXML(ca).replace("\"", "");
+
+        assertEquals("<Field-Injection>\n" +
+                     "  <injectionAnnotation>org.apache.composer.core.annotations.Inject</injectionAnnotation>\n" +
+                     "  <lifecycleStrategy class=RLS/>\n" +
+                     "  <useNames>false</useNames>\n" +
+                     "  <componentKey class=java-class>org.apache.composer.core.injectors.AnnotatedFieldInjectorTestCase$Helicopter</componentKey>\n" +
+                     "  <componentImplementation>org.apache.composer.core.injectors.AnnotatedFieldInjectorTestCase$Helicopter</componentImplementation>\n" +
+                     "  <componentMonitor class=CCM/>\n" +
+                     "</Field-Injection>", foo);
+
+
+    }
+
+    @Test public void testFactoryMakesMethodAnnotationInjector() {
+
+        ComponentFactory cf = createComponentFactory();
+
+        ConsoleComponentMonitor cm = new ConsoleComponentMonitor();
+        ComponentAdapter ca = cf.createComponentAdapter(cm,
+                                                        new ReflectionLifecycleStrategy(cm),
+                                                        new Properties(),
+                                                        AnnotatedMethodInjectorTestCase.AnnotatedBurp.class,
+                                                        AnnotatedMethodInjectorTestCase.AnnotatedBurp.class,
+                                                        Parameter.DEFAULT);
+
+        String foo = xs.toXML(ca).replace("\"", "");
+
+        assertEquals("<Method-Injection>\n" +
+                     "  <injectionAnnotation>org.apache.composer.core.annotations.Inject</injectionAnnotation>\n" +
+                     "  <setterMethodPrefix></setterMethodPrefix>\n" +
+                     "  <lifecycleStrategy class=RLS/>\n" +
+                     "  <useNames>false</useNames>\n" +                     
+                     "  <componentKey class=java-class>org.apache.composer.core.injectors.AnnotatedMethodInjectorTestCase$AnnotatedBurp</componentKey>\n" +
+                     "  <componentImplementation>org.apache.composer.core.injectors.AnnotatedMethodInjectorTestCase$AnnotatedBurp</componentImplementation>\n" +
+                     "  <componentMonitor class=CCM/>\n" +
+                     "</Method-Injection>", foo);
+
+
+    }
+
+
+}

Added: incubator/composer/core/src/test/org/apache/composer/core/injectors/AnnotatedFieldInjectionTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/injectors/AnnotatedFieldInjectionTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/injectors/AnnotatedFieldInjectionTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/injectors/AnnotatedFieldInjectionTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,77 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.injectors;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.junit.Test;
+import org.apache.composer.core.ComponentAdapter;
+import org.apache.composer.core.Parameter;
+import org.apache.composer.core.lifecycle.ReflectionLifecycleStrategy;
+import org.apache.composer.core.monitors.ConsoleComponentMonitor;
+
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.converters.Converter;
+import com.thoughtworks.xstream.converters.MarshallingContext;
+import com.thoughtworks.xstream.converters.UnmarshallingContext;
+import com.thoughtworks.xstream.io.HierarchicalStreamReader;
+import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+
+public class AnnotatedFieldInjectionTestCase {
+
+    @Test public void testFactoryMakesAnnotationInjector() {
+
+        AnnotatedFieldInjection injectionFactory = new AnnotatedFieldInjection();
+
+        ConsoleComponentMonitor cm = new ConsoleComponentMonitor();
+        ComponentAdapter ca = injectionFactory.createComponentAdapter(cm, new ReflectionLifecycleStrategy(cm), new Properties(), Map.class, HashMap.class, Parameter.DEFAULT);
+        
+        XStream xs = new XStream();
+        //xs.alias("CCM", ConsoleComponentMonitor.class);
+        xs.registerConverter(new Converter() {
+            public boolean canConvert(Class aClass) {
+                return aClass.getName().equals("org.apache.composer.core.monitors.ConsoleComponentMonitor") ||
+                       aClass.getName().equals("org.apache.composer.core.lifecycle.ReflectionLifecycleStrategy");
+
+            }
+
+            public void marshal(Object object,
+                                HierarchicalStreamWriter hierarchicalStreamWriter,
+                                MarshallingContext marshallingContext)
+            {
+            }
+
+            public Object unmarshal(HierarchicalStreamReader hierarchicalStreamReader,
+                                    UnmarshallingContext unmarshallingContext)
+            {
+                return null;
+            }
+        });
+
+        String foo = xs.toXML(ca);
+
+        assertEquals("<org.apache.composer.core.injectors.AnnotatedFieldInjector>\n" +
+                     "  <injectionAnnotation>org.apache.composer.core.annotations.Inject</injectionAnnotation>\n" +
+                     "  <lifecycleStrategy class=\"org.apache.composer.core.lifecycle.ReflectionLifecycleStrategy\"/>\n" +
+                     "  <useNames>false</useNames>\n" +
+                     "  <componentKey class=\"java-class\">java.util.Map</componentKey>\n" +
+                     "  <componentImplementation>java.util.HashMap</componentImplementation>\n" +
+                     "  <componentMonitor class=\"org.apache.composer.core.monitors.ConsoleComponentMonitor\"/>\n" +
+                     "</org.apache.composer.core.injectors.AnnotatedFieldInjector>", foo);
+
+
+    }
+
+
+}

Added: incubator/composer/core/src/test/org/apache/composer/core/injectors/AnnotatedFieldInjectorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/injectors/AnnotatedFieldInjectorTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/injectors/AnnotatedFieldInjectorTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/injectors/AnnotatedFieldInjectorTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,101 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.injectors;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.junit.Test;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.MutableContainer;
+import org.apache.composer.core.annotations.Inject;
+import org.apache.composer.core.lifecycle.NullLifecycleStrategy;
+import org.apache.composer.core.monitors.NullComponentMonitor;
+
+public class AnnotatedFieldInjectorTestCase {
+
+    public static class Helicopter {
+        @Inject
+        private PogoStick pogo;
+
+        public Helicopter() {
+        }
+    }
+
+    public static class Helicopter2 {
+        private PogoStick pogo;
+
+        public Helicopter2() {
+        }
+    }
+
+    public static class PogoStick {
+    }
+
+    @Test public void testFieldInjection() {
+        MutableContainer pico = new DefaultContainer();
+        pico.addAdapter(new AnnotatedFieldInjector(Helicopter.class, Helicopter.class, null,
+                                                    new NullComponentMonitor(), new NullLifecycleStrategy(), Inject.class, false));
+        pico.addComponent(PogoStick.class, new PogoStick());
+        Helicopter chopper = pico.getComponent(Helicopter.class);
+        assertNotNull(chopper);
+        assertNotNull(chopper.pogo);
+    }
+
+    @Test public void testFieldInjectionWithoutAnnotationDoesNotWork() {
+        MutableContainer pico = new DefaultContainer();
+        pico.addAdapter(new AnnotatedFieldInjector(Helicopter2.class, Helicopter2.class, null,
+                                                    new NullComponentMonitor(), new NullLifecycleStrategy(), Inject.class, false));
+        pico.addComponent(PogoStick.class, new PogoStick());
+        Helicopter2 chopper = pico.getComponent(Helicopter2.class);
+        assertNotNull(chopper);
+        assertNull(chopper.pogo);
+    }
+
+    @Test public void testFieldDeosNotHappenWithoutRightInjectorDoesNotWork() {
+        MutableContainer pico = new DefaultContainer();
+        pico.addAdapter(new SetterInjector(Helicopter.class, Helicopter.class, null,
+                                                    new NullComponentMonitor(), new NullLifecycleStrategy(),
+                                                    "set", false));
+        pico.addComponent(PogoStick.class, new PogoStick());
+        Helicopter chopper = pico.getComponent(Helicopter.class);
+        assertNotNull(chopper);
+        assertNull(chopper.pogo);
+    }
+
+    @Retention(RetentionPolicy.RUNTIME)
+    @Target(value={ ElementType.METHOD, ElementType.FIELD})
+    public @interface AlternativeInject {
+    }
+
+    public static class Helicopter3 {
+        @AlternativeInject
+        private PogoStick pogo;
+
+        public Helicopter3() {
+        }
+    }
+
+    @Test public void testFieldInjectionWithAlternativeInjectionAnnotation() {
+        MutableContainer pico = new DefaultContainer();
+        pico.addAdapter(new AnnotatedFieldInjector(Helicopter3.class, Helicopter3.class, null,
+                                                    new NullComponentMonitor(), new NullLifecycleStrategy(), AlternativeInject.class, false));
+        pico.addComponent(PogoStick.class, new PogoStick());
+        Helicopter3 chopper = pico.getComponent(Helicopter3.class);
+        assertNotNull(chopper);
+        assertNotNull(chopper.pogo);
+    }
+
+}
\ No newline at end of file

Added: incubator/composer/core/src/test/org/apache/composer/core/injectors/AnnotatedMethodInjectionTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/injectors/AnnotatedMethodInjectionTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/injectors/AnnotatedMethodInjectionTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/injectors/AnnotatedMethodInjectionTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,105 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Idea by Rachel Davies, Original code by Aslak Hellesoy and Paul Hammant   *
+ *****************************************************************************/
+package org.apache.composer.core.injectors;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.apache.composer.core.ComponentFactory;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.CompositionException;
+import org.apache.composer.core.monitors.NullComponentMonitor;
+import org.apache.composer.core.tck.AbstractComponentFactoryTest;
+import org.apache.composer.core.tck.AbstractComponentAdapterTest.RecordingLifecycleStrategy;
+import org.apache.composer.core.testmodel.NullLifecycle;
+import org.apache.composer.core.testmodel.RecordingLifecycle.One;
+
+/**
+ * @author J&ouml;rg Schaible
+ */
+public class AnnotatedMethodInjectionTestCase extends AbstractComponentFactoryTest {
+	
+	@Before
+    public void setUp() throws Exception {
+        picoContainer = new DefaultContainer(createComponentFactory());
+    }
+
+    protected ComponentFactory createComponentFactory() {
+        return new AnnotatedMethodInjection();
+    }
+
+    public static interface Bean {
+    }
+
+    public static class NamedBean implements Bean {
+        private String name;
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+    }
+
+    public static class NamedBeanWithPossibleDefault extends NamedBean {
+        private boolean byDefault;
+
+        public NamedBeanWithPossibleDefault() {
+        }
+
+        public NamedBeanWithPossibleDefault(String name) {
+            setName(name);
+            byDefault = true;
+        }
+
+        public boolean getByDefault() {
+            return byDefault;
+        }
+    }
+
+    public static class NoBean extends NamedBean {
+        public NoBean(String name) {
+            setName(name);
+        }
+    }
+
+    @Test public void testContainerUsesStandardConstructor() {
+        picoContainer.addComponent(Bean.class, NamedBeanWithPossibleDefault.class);
+        picoContainer.addComponent("Tom");
+        NamedBeanWithPossibleDefault bean = (NamedBeanWithPossibleDefault) picoContainer.getComponent(Bean.class);
+        assertFalse(bean.getByDefault());
+    }
+
+    @Test public void testContainerUsesOnlyStandardConstructor() {
+        picoContainer.addComponent(Bean.class, NoBean.class);
+        picoContainer.addComponent("Tom");
+        try {
+            picoContainer.getComponent(Bean.class);
+            fail("Instantiation should have failed.");
+        } catch (CompositionException e) {
+        }
+    }
+
+    @Test public void testCustomLifecycleCanBeInjected() throws NoSuchMethodException {
+        RecordingLifecycleStrategy strategy = new RecordingLifecycleStrategy(new StringBuffer());
+        AnnotatedMethodInjection componentFactory = new AnnotatedMethodInjection();
+        AnnotatedMethodInjector aica = (AnnotatedMethodInjector)componentFactory.createComponentAdapter(new NullComponentMonitor(), strategy, null, NullLifecycle.class, NullLifecycle.class);
+        One one = new One(new StringBuffer());
+        aica.start(one);
+        aica.stop(one);
+        aica.dispose(one);
+        assertEquals("<start<stop<dispose", strategy.recording());
+    }
+}
\ No newline at end of file

Added: incubator/composer/core/src/test/org/apache/composer/core/injectors/AnnotatedMethodInjectorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/injectors/AnnotatedMethodInjectorTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/injectors/AnnotatedMethodInjectorTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/injectors/AnnotatedMethodInjectorTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,99 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.injectors;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.junit.Test;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.MutableContainer;
+import org.apache.composer.core.Parameter;
+import org.apache.composer.core.annotations.Inject;
+import org.apache.composer.core.lifecycle.NullLifecycleStrategy;
+import org.apache.composer.core.monitors.NullComponentMonitor;
+
+public class AnnotatedMethodInjectorTestCase  {
+
+    public static class AnnotatedBurp {
+
+        private Wind wind;
+
+        @Inject
+        public void windyWind(Wind wind) {
+            this.wind = wind;
+        }
+    }
+
+    public static class SetterBurp {
+
+        private Wind wind;
+
+        public void setWind(Wind wind) {
+            this.wind = wind;
+        }
+    }
+
+    public static class Wind {
+    }
+
+    @Test public void testSetterMethodInjectionToContrastWithThatBelow() {
+
+        MutableContainer pico = new DefaultContainer();
+        pico.addAdapter(new SetterInjector(SetterBurp.class, SetterBurp.class, Parameter.DEFAULT, new NullComponentMonitor(), new NullLifecycleStrategy(),
+                                           "set", false));
+        pico.addComponent(Wind.class, new Wind());
+        SetterBurp burp = pico.getComponent(SetterBurp.class);
+        assertNotNull(burp);
+        assertNotNull(burp.wind);
+    }
+
+    @Test public void testNonSetterMethodInjection() {
+        MutableContainer pico = new DefaultContainer();
+        pico.addAdapter(new AnnotatedMethodInjector(AnnotatedBurp.class, AnnotatedBurp.class, Parameter.DEFAULT,
+                                               new NullComponentMonitor(), new NullLifecycleStrategy(),
+                                               Inject.class, false));
+        pico.addComponent(Wind.class, new Wind());
+        AnnotatedBurp burp = pico.getComponent(AnnotatedBurp.class);
+        assertNotNull(burp);
+        assertNotNull(burp.wind);
+    }
+
+    @Retention(RetentionPolicy.RUNTIME)
+    @Target(value={ ElementType.METHOD, ElementType.FIELD})
+    public @interface AlternativeInject {
+    }
+
+    public static class AnotherAnnotatedBurp {
+        private Wind wind;
+        @AlternativeInject
+        public void windyWind(Wind wind) {
+            this.wind = wind;
+        }
+    }
+
+    
+    @Test public void testNonSetterMethodInjectionWithAlternativeAnnotation() {
+        MutableContainer pico = new DefaultContainer();
+        pico.addAdapter(new AnnotatedMethodInjector(AnotherAnnotatedBurp.class, AnotherAnnotatedBurp.class, Parameter.DEFAULT,
+                                               new NullComponentMonitor(), new NullLifecycleStrategy(),
+                                               AlternativeInject.class, false));
+        pico.addComponent(Wind.class, new Wind());
+        AnotherAnnotatedBurp burp = pico.getComponent(AnotherAnnotatedBurp.class);
+        assertNotNull(burp);
+        assertNotNull(burp.wind);
+    }
+
+
+}

Added: incubator/composer/core/src/test/org/apache/composer/core/injectors/ConstructorInjectionTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/injectors/ConstructorInjectionTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/injectors/ConstructorInjectionTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/injectors/ConstructorInjectionTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,54 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Idea by Rachel Davies, Original code by Aslak Hellesoy and Paul Hammant   *
+ *****************************************************************************/
+package org.apache.composer.core.injectors;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Properties;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.apache.composer.core.ComponentFactory;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.monitors.NullComponentMonitor;
+import org.apache.composer.core.tck.AbstractComponentFactoryTest;
+import org.apache.composer.core.tck.AbstractComponentAdapterTest.RecordingLifecycleStrategy;
+import org.apache.composer.core.testmodel.NullLifecycle;
+import org.apache.composer.core.testmodel.RecordingLifecycle;
+import org.apache.composer.core.testmodel.RecordingLifecycle.One;
+
+/**
+ * @author Mauro Talevi
+ */
+public class ConstructorInjectionTestCase extends AbstractComponentFactoryTest {
+
+	@Before
+    public void setUp() throws Exception {
+        picoContainer = new DefaultContainer(createComponentFactory());
+    }
+
+    protected ComponentFactory createComponentFactory() {
+        return new ConstructorInjection();
+    }
+
+    @Test public void testCustomLifecycleCanBeInjected() throws NoSuchMethodException {
+        RecordingLifecycleStrategy strategy = new RecordingLifecycleStrategy(new StringBuffer());
+        ConstructorInjection componentFactory =
+            new ConstructorInjection();
+        ConstructorInjector cica =  (ConstructorInjector)
+        componentFactory.createComponentAdapter(new NullComponentMonitor(), strategy, new Properties(), NullLifecycle.class, NullLifecycle.class);
+        One one = new RecordingLifecycle.One(new StringBuffer());
+        cica.start(one);
+        cica.stop(one);        
+        cica.dispose(one);
+        assertEquals("<start<stop<dispose", strategy.recording());
+    }    
+
+}
\ No newline at end of file

Added: incubator/composer/core/src/test/org/apache/composer/core/injectors/ConstructorInjectorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/injectors/ConstructorInjectorTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/injectors/ConstructorInjectorTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/injectors/ConstructorInjectorTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,376 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.injectors;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.apache.composer.core.tck.MockFactory.mockeryWithCountingNamingScheme;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.swing.AbstractButton;
+
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.junit.Test;
+import org.apache.composer.core.ComponentAdapter;
+import org.apache.composer.core.ComponentMonitor;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.MutableContainer;
+import org.apache.composer.core.Parameter;
+import org.apache.composer.core.CompositionException;
+import org.apache.composer.core.Container;
+import org.apache.composer.core.lifecycle.NullLifecycleStrategy;
+import org.apache.composer.core.monitors.AbstractComponentMonitor;
+import org.apache.composer.core.monitors.NullComponentMonitor;
+import org.apache.composer.core.parameters.ComponentParameter;
+import org.apache.composer.core.parameters.ConstantParameter;
+import org.apache.composer.core.tck.AbstractComponentAdapterTest;
+import org.apache.composer.core.testmodel.DependsOnTouchable;
+import org.apache.composer.core.testmodel.NullLifecycle;
+import org.apache.composer.core.testmodel.SimpleTouchable;
+import org.apache.composer.core.testmodel.Touchable;
+
+
+public class ConstructorInjectorTestCase extends AbstractComponentAdapterTest {
+
+	private Mockery mockery = mockeryWithCountingNamingScheme();
+	
+    protected Class getComponentAdapterType() {
+        return ConstructorInjector.class;
+    }
+
+    protected ComponentAdapter prepDEF_verifyWithoutDependencyWorks(MutableContainer picoContainer) {
+        return new ConstructorInjector("foo", A.class, null, new NullComponentMonitor(), new NullLifecycleStrategy(), false);
+    }
+
+    public static class A {
+        public A() {
+            fail("verification should not instantiate");
+        }
+    }
+
+    public static class B {
+        public B(A a) {
+            fail("verification should not instantiate");
+        }
+    }
+
+    protected ComponentAdapter prepDEF_verifyDoesNotInstantiate(MutableContainer picoContainer) {
+        picoContainer.addComponent(A.class);
+        return new ConstructorInjector(B.class, B.class, null, new NullComponentMonitor(), new NullLifecycleStrategy(), false);
+    }
+
+    protected ComponentAdapter prepDEF_visitable() {
+        return new ConstructorInjector("bar", B.class, new Parameter[] {ComponentParameter.DEFAULT} , new NullComponentMonitor(), new NullLifecycleStrategy(), false);
+    }
+
+    protected ComponentAdapter prepDEF_isAbleToTakeParameters(MutableContainer picoContainer) {
+        picoContainer.addComponent(SimpleTouchable.class);
+        return new ConstructorInjector(
+                NamedDependsOnTouchable.class, NamedDependsOnTouchable.class,
+                new Parameter[] {ComponentParameter.DEFAULT, new ConstantParameter("Name")} , new NullComponentMonitor(), new NullLifecycleStrategy(), false);
+    }
+
+    protected ComponentAdapter prepSER_isSerializable(MutableContainer picoContainer) {
+        return new ConstructorInjector(SimpleTouchable.class, SimpleTouchable.class, null, new NullComponentMonitor(), new NullLifecycleStrategy(), false);
+    }
+
+    protected ComponentAdapter prepSER_isXStreamSerializable(final MutableContainer picoContainer) {
+        return prepSER_isSerializable(picoContainer);
+    }
+
+    public static class NamedDependsOnTouchable extends DependsOnTouchable {
+        public NamedDependsOnTouchable(Touchable t, String name) {
+            super(t);
+        }
+    }
+
+    protected ComponentAdapter prepVER_verificationFails(MutableContainer picoContainer) {
+        return new ConstructorInjector(DependsOnTouchable.class, DependsOnTouchable.class, null, new NullComponentMonitor(), new NullLifecycleStrategy(), false);
+    }
+
+    protected ComponentAdapter prepINS_createsNewInstances(MutableContainer picoContainer) {
+        return new ConstructorInjector(SimpleTouchable.class, SimpleTouchable.class, null, new NullComponentMonitor(), new NullLifecycleStrategy(), false);
+    }
+
+    public static class Erroneous {
+        public Erroneous() {
+            throw new VerifyError("test");
+        }
+    }
+
+    protected ComponentAdapter prepINS_errorIsRethrown(MutableContainer picoContainer) {
+        return new ConstructorInjector(Erroneous.class, Erroneous.class, null, new NullComponentMonitor(), new NullLifecycleStrategy(), false);
+    }
+
+    public static class RuntimeThrowing {
+        public RuntimeThrowing() {
+            throw new RuntimeException("test");
+        }
+    }
+
+    protected ComponentAdapter prepINS_runtimeExceptionIsRethrown(MutableContainer picoContainer) {
+        return new ConstructorInjector(RuntimeThrowing.class, RuntimeThrowing.class, null, new NullComponentMonitor(), new NullLifecycleStrategy(), false);
+    }
+
+    public static class NormalExceptionThrowing {
+        public NormalExceptionThrowing() throws Exception {
+            throw new Exception("test");
+        }
+    }
+
+    protected ComponentAdapter prepINS_normalExceptionIsRethrownInsidePicoInitializationException(
+            MutableContainer picoContainer) {
+        return new ConstructorInjector(NormalExceptionThrowing.class, NormalExceptionThrowing.class, null, new NullComponentMonitor(), new NullLifecycleStrategy(), false);
+    }
+
+    protected ComponentAdapter prepRES_dependenciesAreResolved(MutableContainer picoContainer) {
+        picoContainer.addComponent(SimpleTouchable.class);
+        return new ConstructorInjector(DependsOnTouchable.class, DependsOnTouchable.class, null, new NullComponentMonitor(), new NullLifecycleStrategy(), false);
+    }
+
+    public static class C1 {
+        public C1(C2 c2) {
+            fail("verification should not instantiate");
+        }
+    }
+
+    public static class C2 {
+        public C2(C1 c1) {
+            fail("verification should not instantiate");
+        }
+    }
+
+    protected ComponentAdapter prepRES_failingVerificationWithCyclicDependencyException(MutableContainer picoContainer) {
+        final ComponentAdapter componentAdapter = new ConstructorInjector(C1.class, C1.class, null, new NullComponentMonitor(), new NullLifecycleStrategy(), false);
+        picoContainer.addAdapter(componentAdapter);
+        picoContainer.addComponent(C2.class, C2.class);
+        return componentAdapter;
+    }
+
+    protected ComponentAdapter prepRES_failingInstantiationWithCyclicDependencyException(MutableContainer picoContainer) {
+        final ComponentAdapter componentAdapter = new ConstructorInjector(C1.class, C1.class, null, new NullComponentMonitor(), new NullLifecycleStrategy(), false);
+        picoContainer.addAdapter(componentAdapter);
+        picoContainer.addComponent(C2.class, C2.class);
+        return componentAdapter;
+    }
+
+    @Test public void testNormalExceptionThrownInCtorIsRethrownInsideInvocationTargetExeption() {
+        DefaultContainer picoContainer = new DefaultContainer();
+        picoContainer.addComponent(NormalExceptionThrowing.class);
+        try {
+            picoContainer.getComponent(NormalExceptionThrowing.class);
+            fail();
+        } catch (CompositionException e) {
+            assertEquals("test", e.getCause().getMessage());
+        }
+    }
+
+    public static class InstantiationExceptionThrowing {
+        public InstantiationExceptionThrowing() {
+            throw new RuntimeException("Barf");
+        }
+    }
+
+    @Test public void testInstantiationExceptionThrownInCtorIsRethrownInsideInvocationTargetExeption() {
+        DefaultContainer picoContainer = new DefaultContainer();
+        try {
+            picoContainer.addComponent(InstantiationExceptionThrowing.class);
+            picoContainer.getComponent(InstantiationExceptionThrowing.class);
+            fail();
+        } catch (RuntimeException e) {
+            assertEquals("Barf", e.getMessage());
+        }
+    }
+
+    public static class AllConstructorsArePrivate {
+        private AllConstructorsArePrivate() {
+        }
+    }
+
+    @Test public void testPicoInitializationExceptionThrownBecauseOfFilteredConstructors() {
+        DefaultContainer picoContainer = new DefaultContainer();
+        try {
+            picoContainer.addComponent(AllConstructorsArePrivate.class);
+            picoContainer.getComponent(AllConstructorsArePrivate.class);
+            fail();
+        } catch (CompositionException e) {
+            String s = e.getMessage();
+            assertTrue(s.indexOf("constructors were not accessible") > 0);
+            assertTrue(s.indexOf(AllConstructorsArePrivate.class.getName()) > 0);
+        }
+    }
+
+    @Test public void testRegisterInterfaceShouldFail() throws CompositionException {
+        MutableContainer pico = new DefaultContainer();
+
+        try {
+            pico.addComponent(Runnable.class);
+            fail("Shouldn't be allowed to register abstract classes or interfaces.");
+        } catch (AbstractInjector.NotConcreteRegistrationException e) {
+            assertEquals(Runnable.class, e.getComponentImplementation());
+            assertTrue(e.getMessage().indexOf(Runnable.class.getName()) > 0);
+        }
+    }
+
+    @Test public void testRegisterAbstractShouldFail() throws CompositionException {
+        MutableContainer pico = new DefaultContainer();
+
+        try {
+            pico.addComponent(AbstractButton.class);
+            fail("Shouldn't be allowed to register abstract classes or interfaces.");
+        } catch (AbstractInjector.NotConcreteRegistrationException e) {
+            assertEquals(AbstractButton.class, e.getComponentImplementation());
+            assertTrue(e.getMessage().indexOf(AbstractButton.class.getName()) > 0);
+        }
+    }
+
+    private static class Private {
+        private Private() {
+        }
+    }
+
+    private static class NotYourBusiness {
+        private NotYourBusiness(Private aPrivate) {
+            assertNotNull(aPrivate);
+        }
+    }
+
+    static public class Component201 {
+        public Component201(final String s) {
+        }
+
+        protected Component201(final Integer i, final Boolean b) {
+            fail("Wrong constructor taken.");
+        }
+    }
+
+    // http://jira.codehaus.org/browse/PICO-201
+    @Test public void testShouldNotConsiderNonPublicConstructors() {
+        DefaultContainer pico = new DefaultContainer();
+        pico.addComponent(Component201.class);
+        pico.addComponent(new Integer(2));
+        pico.addComponent(Boolean.TRUE);
+        pico.addComponent("Hello");
+        assertNotNull(pico.getComponent(Component201.class));
+    }
+
+    @Test public void testMonitoringHappensBeforeAndAfterInstantiation() throws NoSuchMethodException {
+    	final ComponentMonitor monitor = mockery.mock(ComponentMonitor.class);
+        final Constructor emptyHashMapCtor = HashMap.class.getConstructor();
+        final Matcher<Long> durationIsGreaterThanOrEqualToZero = new BaseMatcher<Long>() {
+        	public boolean matches(Object item) {
+                Long duration = (Long)item;
+                return 0 <= duration;
+			}
+
+			public void describeTo(Description description) {
+                description.appendText("The endTime wasn't after the startTime");				
+			}
+        };
+        
+        final Matcher<Object> isAHashMapThatWozCreated = new BaseMatcher<Object>() {
+        	public boolean matches(Object item) {
+                return item instanceof HashMap;
+            }
+
+			public void describeTo(Description description) {
+                description.appendText("Should have been a hashmap");				
+			}
+        };
+
+        final Matcher<Object[]> injectedIsEmptyArray = new BaseMatcher<Object[]>() {
+        	public boolean matches(Object item) {
+                Object[] injected = (Object[])item;
+                return 0 == injected.length;
+            }
+        	public void describeTo(Description description) {
+                description.appendText("Should have had nothing injected into it");
+            }
+        };
+
+        mockery.checking(new Expectations(){{
+        	one(monitor).instantiating(with(any(Container.class)), (ComponentAdapter)with(a(ConstructorInjector.class)), with(equal(emptyHashMapCtor)));
+        	will(returnValue(emptyHashMapCtor));
+        	one(monitor).instantiated(with(any(Container.class)), (ComponentAdapter)with(a(ConstructorInjector.class)), with(equal(emptyHashMapCtor)),
+        			with(isAHashMapThatWozCreated), with(injectedIsEmptyArray), 
+        			with(durationIsGreaterThanOrEqualToZero));
+        }});
+
+        ConstructorInjector cica = new ConstructorInjector(
+                Map.class, HashMap.class, new Parameter[0], monitor, new NullLifecycleStrategy(), false);
+        cica.getComponentInstance(null);
+    }
+
+    @Test public void testMonitoringHappensBeforeAndOnFailOfImpossibleComponentsInstantiation() throws NoSuchMethodException {
+    	final ComponentMonitor monitor = mockery.mock(ComponentMonitor.class);
+        final Constructor barfingActionListenerCtor = BarfingActionListener.class.getConstructor();
+
+        final Matcher<Exception> isITE = new BaseMatcher<Exception>() {
+        	public boolean matches(Object item) {
+        		 Exception ex = (Exception)item;
+                 return ex instanceof InvocationTargetException;
+            }
+
+			public void describeTo(Description description) {
+                description.appendText("Should have been unable to instantiate");				
+			}
+        };
+
+        mockery.checking(new Expectations(){{
+        	one(monitor).instantiating(with(any(Container.class)), (ComponentAdapter)with(a(ConstructorInjector.class)), with(equal(barfingActionListenerCtor)));
+        	will(returnValue(barfingActionListenerCtor));
+        	one(monitor).instantiationFailed(with(any(Container.class)), (ComponentAdapter)with(a(ConstructorInjector.class)), with(equal(barfingActionListenerCtor)),
+        			with(isITE));
+        }});
+
+
+        ConstructorInjector cica = new ConstructorInjector(
+                ActionListener.class, BarfingActionListener.class, new Parameter[0], monitor, new NullLifecycleStrategy(), false);
+        try {
+            cica.getComponentInstance(null);
+            fail("Should barf");
+        } catch (RuntimeException e) {
+            assertEquals("Barf!", e.getMessage());
+        }
+    }
+
+    private static class BarfingActionListener implements ActionListener {
+        public BarfingActionListener() {
+            throw new RuntimeException("Barf!");
+        }
+
+        public void actionPerformed(ActionEvent e) {
+        }
+    }
+
+    @Test public void testCustomLifecycleCanBeInjected() throws NoSuchMethodException {
+        RecordingLifecycleStrategy strategy = new RecordingLifecycleStrategy(new StringBuffer());
+        ConstructorInjector cica = new ConstructorInjector(
+                NullLifecycle.class, NullLifecycle.class, new Parameter[0],
+                new AbstractComponentMonitor(), strategy, false);
+        Touchable touchable = new SimpleTouchable();
+        cica.start(touchable);
+        cica.stop(touchable);
+        cica.dispose(touchable);
+        assertEquals("<start<stop<dispose", strategy.recording());
+    }
+}

Added: incubator/composer/core/src/test/org/apache/composer/core/injectors/MethodInjectionTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/injectors/MethodInjectionTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/injectors/MethodInjectionTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/injectors/MethodInjectionTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,82 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ * Original code by                                                          *
+ *****************************************************************************/
+package org.apache.composer.core.injectors;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.apache.composer.core.Characteristics;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.MutableContainer;
+import org.apache.composer.core.ContainerBuilder;
+import org.apache.composer.core.lifecycle.NullLifecycleStrategy;
+import org.apache.composer.core.monitors.NullComponentMonitor;
+
+public class MethodInjectionTestCase {
+
+    public static class Foo {
+        private Bar bar;
+        private String string;
+
+        public void inject(Bar bar, String string) {
+            this.bar = bar;
+            this.string = string;
+        }
+    }
+
+    public static class Bar {
+    }
+
+    @Test public void testMethodInjection() {
+        DefaultContainer pico = new DefaultContainer(new MethodInjection());
+        pico.addComponent("hello");
+        pico.addComponent(Foo.class);
+        pico.addComponent(Bar.class);
+        Foo foo = pico.getComponent(Foo.class);
+        assertNotNull(foo.bar);
+        assertNotNull(foo.string);
+        assertEquals("MethodInjector-class org.apache.composer.core.injectors.MethodInjectionTestCase$Foo", pico.getComponentAdapter(Foo.class).toString());
+    }
+
+    @Test public void testMethodInjectionViaCharacteristics() {
+        DefaultContainer pico = new DefaultContainer();
+        pico.addComponent("hello");
+        pico.as(Characteristics.METHOD_INJECTION).addComponent(Foo.class);
+        pico.addComponent(Bar.class);
+        Foo foo = pico.getComponent(Foo.class);
+        assertNotNull(foo.bar);
+        assertNotNull(foo.string);
+        assertEquals("MethodInjector-class org.apache.composer.core.injectors.MethodInjectionTestCase$Foo", pico.getComponentAdapter(Foo.class).toString());
+    }
+
+    @Test public void testMethodInjectionViaAdapter() {
+        DefaultContainer pico = new DefaultContainer(new MethodInjection());
+        pico.addComponent("hello");
+        pico.addAdapter(new MethodInjector(Foo.class, Foo.class, null, new NullComponentMonitor(), new NullLifecycleStrategy(), "inject", false));
+        pico.addComponent(Bar.class);
+        Foo foo = pico.getComponent(Foo.class);
+        assertNotNull(foo.bar);
+        assertNotNull(foo.string);
+        assertEquals("MethodInjector-class org.apache.composer.core.injectors.MethodInjectionTestCase$Foo", pico.getComponentAdapter(Foo.class).toString());
+    }
+
+    @Test public void testMethodInjectionByBuilder() {
+        MutableContainer pico = new ContainerBuilder().withMethodInjection().build();
+        pico.addComponent("hello");
+        pico.addComponent(Foo.class);
+        pico.addComponent(Bar.class);
+        Foo foo = pico.getComponent(Foo.class);
+        assertNotNull(foo.bar);
+        assertNotNull(foo.string);
+        assertEquals("MethodInjector-class org.apache.composer.core.injectors.MethodInjectionTestCase$Foo", pico.getComponentAdapter(Foo.class).toString());
+    }
+
+}
\ No newline at end of file

Added: incubator/composer/core/src/test/org/apache/composer/core/injectors/MultiInjectionTestCase.java
URL: http://svn.apache.org/viewvc/incubator/composer/core/src/test/org/apache/composer/core/injectors/MultiInjectionTestCase.java?rev=613775&view=auto
==============================================================================
--- incubator/composer/core/src/test/org/apache/composer/core/injectors/MultiInjectionTestCase.java (added)
+++ incubator/composer/core/src/test/org/apache/composer/core/injectors/MultiInjectionTestCase.java Sun Jan 20 22:41:26 2008
@@ -0,0 +1,111 @@
+/*****************************************************************************
+ * Copyright (C) PicoContainer Organization. All rights reserved.            *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD      *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file.                                                     *
+ *                                                                           *
+ *****************************************************************************/
+package org.apache.composer.core.injectors;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+import org.apache.composer.core.DefaultContainer;
+import org.apache.composer.core.annotations.Inject;
+
+/**
+ * @author Paul Hammant
+ */
+public class MultiInjectionTestCase {
+
+    public static class Bar {
+    }
+    public static class Baz {
+    }
+    public static class Foo {
+        private final Bar bar;
+        private Baz baz;
+
+        public Foo(Bar bar) {
+            this.bar = bar;
+        }
+
+        public void setBaz(Baz baz) {
+            this.baz = baz;
+        }
+    }
+
+    public static class Foo2 {
+        private final Bar bar;
+        private Baz baz;
+
+        public Foo2(Bar bar) {
+            this.bar = bar;
+        }
+
+        public void injectBaz(Baz baz) {
+            this.baz = baz;
+        }
+    }
+
+    public static class Foo3 {
+        private final Bar bar;
+        private Baz baz;
+
+        public Foo3(Bar bar) {
+            this.bar = bar;
+        }
+
+        @Inject
+        public void fjshdfkjhsdkfjh(Baz baz) {
+            this.baz = baz;
+        }
+    }
+
+    @Test public void testComponentWithCtorAndSetterDiCanHaveAllDepsSatisfied() throws NoSuchMethodException {
+        DefaultContainer dpc = new DefaultContainer(new MultiInjection());
+        dpc.addComponent(Bar.class);
+        dpc.addComponent(Baz.class);
+        dpc.addComponent(Foo.class);
+        Foo foo = dpc.getComponent(Foo.class);
+        assertNotNull(foo);
+        assertNotNull(foo.bar);
+        assertNotNull(foo.baz);
+    }
+
+    @Test public void testComponentWithCtorAndSetterDiCanHaveAllDepsSatisfiedWithANonSetInjectMethod() throws NoSuchMethodException {
+        DefaultContainer dpc = new DefaultContainer(new MultiInjection("inject"));
+        dpc.addComponent(Bar.class);
+        dpc.addComponent(Baz.class);
+        dpc.addComponent(Foo2.class);
+        Foo2 foo = dpc.getComponent(Foo2.class);
+        assertNotNull(foo);
+        assertNotNull(foo.bar);
+        assertNotNull(foo.baz);
+    }
+
+    @Test public void testComponentWithCtorAndMethodAnnotatedDiCanHaveAllDepsSatisfied() throws NoSuchMethodException {
+        DefaultContainer dpc = new DefaultContainer(new MultiInjection());
+        dpc.addComponent(Bar.class);
+        dpc.addComponent(Baz.class);
+        dpc.addComponent(Foo3.class);
+        Foo3 foo = dpc.getComponent(Foo3.class);
+        assertNotNull(foo);
+        assertNotNull(foo.bar);
+        assertNotNull(foo.baz);
+    }
+
+
+    @Test public void testComponentWithCtorAndSetterDiCanHaveAllCtorDepsAndSomeSetterDepsSatisfiedSubjectToAvailability() throws NoSuchMethodException {
+        DefaultContainer dpc = new DefaultContainer(new MultiInjection());
+        dpc.addComponent(Bar.class);
+        dpc.addComponent(Foo.class);
+        Foo foo = dpc.getComponent(Foo.class);
+        assertNotNull(foo);
+        assertNotNull(foo.bar);
+        assertNull(foo.baz); // baz was never added to the container.s
+    }
+
+}
\ No newline at end of file



Mime
View raw message