Package org.picocontainer.defaults

Examples of org.picocontainer.defaults.DefaultPicoContainer


        new VerifyingVisitor().traverse(pico);
    }

    public void testUsageOfADifferentComponentAdapterFactory() {
        // Jira bug 212
        MutablePicoContainer parent = new DefaultPicoContainer();
        ImplementationHidingPicoContainer pico = new ImplementationHidingPicoContainer(new ConstructorInjectionComponentAdapterFactory(), parent);
        pico.registerComponentImplementation(List.class, ArrayList.class);
        List list1 = (List) pico.getComponentInstanceOfType(List.class);
        List list2 = (List) pico.getComponentInstanceOfType(List.class);
        assertNotNull(list1);
View Full Code Here


        return new ImplementationHidingCachingPicoContainer(parent);
    }

    public void testUsageOfADifferentComponentAdapterFactory() {
        // Jira bug 212 - logical opposite
        MutablePicoContainer parent = new DefaultPicoContainer();
        ImplementationHidingCachingPicoContainer pico = new ImplementationHidingCachingPicoContainer(new ConstructorInjectionComponentAdapterFactory(), parent);
        pico.registerComponentImplementation(List.class, ArrayList.class);
        List list1 = (List) pico.getComponentInstanceOfType(List.class);
        List list2 = (List) pico.getComponentInstanceOfType(List.class);
        assertNotNull(list1);
View Full Code Here

    MutablePicoContainer container;

    protected void setUp() throws Exception {
        super.setUp();
       
        container = new DefaultPicoContainer();
        container.registerComponentImplementation(SimpleTouchable.class);
        container.registerComponentImplementation(DecoratedTouchable.class);
        container.registerComponentImplementation(AlternativeTouchable.class);
        container.registerComponentImplementation(DependsOnTouchable.class);
    }
View Full Code Here

    /**
     * Test automatic assimilation of registered components.
     */
    public void testOnlyOneTouchableComponentKeyPossible() {
        picoContainer = new DefaultPicoContainer(createComponentAdapterFactory());
        picoContainer.registerComponentImplementation(Touchable.class, SimpleTouchable.class);
        try {
            picoContainer.registerComponentImplementation(CompatibleTouchable.class);
            fail("DuplicateComponentKeyRegistrationException expected");
        } catch(final DuplicateComponentKeyRegistrationException e) {
View Full Code Here

    /**
     * Test automatic assimilation of registered components.
     */
    public void testMultipleAssimilatedComponentsWithUserDefinedKeys() {
        picoContainer = new DefaultPicoContainer(createComponentAdapterFactory());
        picoContainer.registerComponentImplementation(Touchable.class, SimpleTouchable.class);
        picoContainer.registerComponentImplementation("1", CompatibleTouchable.class);
        picoContainer.registerComponentImplementation("2", CompatibleTouchable.class);
        picoContainer.registerComponentImplementation("3", CompatibleTouchable.class);
        final List list = picoContainer.getComponentInstancesOfType(Touchable.class);
View Full Code Here

* @version $Revision: 2002 $
*/
public class MulticasterTestCase extends TestCase {
    public void testOrderOfInstantiationShouldBeDependencyOrder() throws Exception {

        DefaultPicoContainer pico = new DefaultPicoContainer();
        pico.registerComponentImplementation("recording", StringBuffer.class);
        pico.registerComponentImplementation(DefaultPicoContainerLifecycleTestCase.Four.class);
        pico.registerComponentImplementation(DefaultPicoContainerLifecycleTestCase.Two.class);
        pico.registerComponentImplementation(DefaultPicoContainerLifecycleTestCase.One.class);
        pico.registerComponentImplementation(DefaultPicoContainerLifecycleTestCase.Three.class);

        ProxyFactory proxyFactory = new StandardProxyFactory();
        Startable startable = (Startable) Multicaster.object(pico, true, proxyFactory);
        Startable stoppable = (Startable) Multicaster.object(pico, false, proxyFactory);
        Disposable disposable = (Disposable) Multicaster.object(pico, false, proxyFactory);

        startable.start();
        stoppable.stop();
        disposable.dispose();

        assertEquals("<One<Two<Three<FourFour>Three>Two>One>!Four!Three!Two!One", pico.getComponentInstance("recording").toString());
    }
View Full Code Here

import org.picocontainer.doc.tutorial.interfaces.Boy;

public class LifecycleTestCase extends TestCase {

    public void testStartStopDispose() {
        MutablePicoContainer pico = new DefaultPicoContainer();
        pico.registerComponentImplementation(Boy.class);
        pico.registerComponentImplementation(Girl.class);

// START SNIPPET: start
        pico.start();
// END SNIPPET: start

// START SNIPPET: stopdispose
        pico.stop();
        pico.dispose();
// END SNIPPET: stopdispose
    }
View Full Code Here

public class HierarchyTestCase extends TestCase {
    public void testHierarchy() {
        try {
            // START SNIPPET: wontwork
            // Create x hierarchy of containers
            MutablePicoContainer x = new DefaultPicoContainer();
            MutablePicoContainer y = new DefaultPicoContainer( x );
            MutablePicoContainer z = new DefaultPicoContainer( x );

            // Assemble components
            x.registerComponentImplementation(Apple.class);
            y.registerComponentImplementation(Juicer.class);
            z.registerComponentImplementation(Peeler.class);

            // Instantiate components
            Peeler peeler = (Peeler) z.getComponentInstance(Peeler.class);
            // WON'T WORK! peeler will be null
            peeler = (Peeler) x.getComponentInstance(Peeler.class);
            // WON'T WORK! This will throw an exception
            Juicer juicer = (Juicer) y.getComponentInstance(Juicer.class);
            // END SNIPPET: wontwork
View Full Code Here

    /**
     * Test instances from different containers.
     */
    public final void testInstancesAreNotSharedBetweenContainers() {
        final MutablePicoContainer picoA = new DefaultPicoContainer();
        final MutablePicoContainer picoB = new DefaultPicoContainer();
        picoA.registerComponent(new ThreadLocalComponentAdapter(new ConstructorInjectionComponentAdapter(
                List.class, ArrayList.class, null)));
        picoB.registerComponent(new ThreadLocalComponentAdapter(new ConstructorInjectionComponentAdapter(
                List.class, ArrayList.class, null)));
        final List hello1 = (List)picoA.getComponentInstance(List.class);
        final List hello2 = (List)picoA.getComponentInstance(List.class);
        hello1.add("foo");
        assertEquals(hello1, hello2);
        final List hello3 = (List)picoB.getComponentInstance(List.class);
        assertEquals(0, hello3.size());
    }
View Full Code Here

    protected MutablePicoContainer createImplementationHidingPicoContainer() {
        return createPicoContainer(null);
    }

    protected MutablePicoContainer createPicoContainer(PicoContainer parent) {
        return new DefaultPicoContainer(new CachingComponentAdapterFactory(new ImplementationHidingComponentAdapterFactory(new ConstructorInjectionComponentAdapterFactory(), false)), parent);
    }
View Full Code Here

TOP

Related Classes of org.picocontainer.defaults.DefaultPicoContainer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.