Package org.picocontainer.testmodel

Examples of org.picocontainer.testmodel.Touchable


        final ComponentAdapter componentAdapter = new CachingComponentAdapter(new ConstructorInjectionComponentAdapter(
                CompatibleTouchable.class, CompatibleTouchable.class));
        mpc.registerComponent(new AssimilatingComponentAdapter(Touchable.class, componentAdapter));
        final CompatibleTouchable compatibleTouchable = (CompatibleTouchable) componentAdapter
                .getComponentInstance(mpc);
        final Touchable touchable = (Touchable) mpc.getComponentInstanceOfType(Touchable.class);
        assertFalse(compatibleTouchable.wasTouched());
        touchable.touch();
        assertTrue(compatibleTouchable.wasTouched());
        assertTrue(Proxy.isProxyClass(touchable.getClass()));
    }
View Full Code Here


        final ComponentAdapter componentAdapter = new CachingComponentAdapter(new ConstructorInjectionComponentAdapter(
                "Touchy", CompatibleTouchable.class));
        mpc.registerComponent(new AssimilatingComponentAdapter(Touchable.class, componentAdapter));
        final CompatibleTouchable compatibleTouchable = (CompatibleTouchable) componentAdapter
                .getComponentInstance(mpc);
        final Touchable touchable = (Touchable) mpc.getComponentInstance("Touchy");
        assertFalse(compatibleTouchable.wasTouched());
        touchable.touch();
        assertTrue(compatibleTouchable.wasTouched());
        assertTrue(Proxy.isProxyClass(touchable.getClass()));
    }
View Full Code Here

        return new CachingComponentAdapterFactory(new ConstructorInjectionComponentAdapterFactory());
    }

    public void testContainerReturnsSameInstaceEachCall() {
        picoContainer.registerComponentImplementation(Touchable.class, SimpleTouchable.class);
        Touchable t1 = (Touchable) picoContainer.getComponentInstance(Touchable.class);
        Touchable t2 = (Touchable) picoContainer.getComponentInstance(Touchable.class);
        assertSame(t1, t2);
    }
View Full Code Here

    //TODO - move
    public void testRegistrationByName() throws Exception {
        DefaultPicoContainer pico = new DefaultPicoContainer();

        Webster one = new Webster(new ArrayList());
        Touchable two = new SimpleTouchable();

        pico.registerComponentInstance("one", one);
        pico.registerComponentInstance("two", two);

        assertEquals("Wrong number of comps in the internals", 2, pico.getComponentInstances().size());
View Full Code Here

    public void testComponentParameterFetches() throws PicoInstantiationException, PicoRegistrationException, PicoInitializationException {
        DefaultPicoContainer pico = new DefaultPicoContainer();
        ComponentAdapter adapter = pico.registerComponentImplementation(Touchable.class, SimpleTouchable.class);

        assertNotNull(pico.getComponentInstance(Touchable.class));
        Touchable touchable = (Touchable) ComponentParameter.DEFAULT.resolveInstance(pico, null, Touchable.class);
        assertNotNull(touchable);
    }
View Full Code Here

    public void testComponentParameterExcludesSelf() throws PicoInstantiationException, PicoRegistrationException, PicoInitializationException {
        DefaultPicoContainer pico = new DefaultPicoContainer();
        ComponentAdapter adapter = pico.registerComponentImplementation(Touchable.class, SimpleTouchable.class);

        assertNotNull(pico.getComponentInstance(Touchable.class));
        Touchable touchable = (Touchable) ComponentParameter.DEFAULT.resolveInstance(pico, adapter, Touchable.class);
        assertNull(touchable);
    }
View Full Code Here

    public void testIsKeyTypeConstraint() {
        container.registerComponentImplementation("Simple", SimpleTouchable.class);
        container.registerComponentImplementation(new Integer(5), SimpleTouchable.class);
        container.registerComponentImplementation(Boolean.TRUE, SimpleTouchable.class);
        Touchable t = (Touchable) container.getComponentInstance(Boolean.TRUE);
       
        Constraint c = new IsKeyType(Boolean.class);

        assertSame(t, c.resolveInstance(container,
                container.getComponentAdapter(DependsOnTouchable.class),
View Full Code Here

    }

    public void testSerializedContainerCanRetrieveImplementation() throws PicoException, PicoInitializationException,
            IOException, ClassNotFoundException {

        Touchable touchable = getTouchableFromSerializedContainer();

        SimpleTouchable simpleTouchable = (SimpleTouchable) touchable;

        assertTrue(simpleTouchable.wasTouched);
    }
View Full Code Here

    public final void testInstancesUsedFromMultipleThreads() throws InterruptedException {
        final Set set = Collections.synchronizedSet(new HashSet());
        final List list = Collections.synchronizedList(new ArrayList());
        final ComponentAdapter componentAdapter = new ThreadLocalComponentAdapter(new ConstructorInjectionComponentAdapter(
                Touchable.class, SimpleTouchable.class, null));
        final Touchable touchable = (Touchable)componentAdapter.getComponentInstance(null);

        final Thread[] threads = {
                new Thread(new Runner(touchable, list, set), "junit-1"), new Thread(new Runner(touchable, list, set), "junit-2"),
                new Thread(new Runner(touchable, list, set), "junit-3"),};
        for (int i = threads.length; i-- > 0;) {
View Full Code Here

*/
public class InstanceComponentAdapterTestCase
        extends AbstractComponentAdapterTestCase {

    public void testComponentAdapterReturnsSame() {
        final Touchable touchable = new SimpleTouchable();
        final ComponentAdapter componentAdapter = new InstanceComponentAdapter(Touchable.class, touchable);
        assertSame(touchable, componentAdapter.getComponentInstance(null));
    }
View Full Code Here

TOP

Related Classes of org.picocontainer.testmodel.Touchable

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.