Package jfun.yan.containers

Examples of jfun.yan.containers.DefaultContainer


    tests.jfun.yan.Utils.runTest(suite());
  }
  private static TestSuite suite(){
    return new TestSuite(BaseLazyInstantiationTestCase.class);
  }
    protected Container createPicoContainer(){return new DefaultContainer();}
View Full Code Here


  }
  private static TestSuite suite(){
    return new TestSuite(ChildContainerTestCase.class);
  }
  protected Container getContainerImpl(){
    return new DefaultContainer().inherit(new jfun.yan.containers.SingletonProxyContainer());
  }
View Full Code Here

  }
  protected Container getContainerImpl(){
    return new DefaultContainer().inherit(new jfun.yan.containers.SingletonProxyContainer());
  }
    public void testParentContainerWithComponentWithEqualKeyShouldBeShadowedByChild() throws Exception {
        DefaultContainer parent = new DefaultContainer();
        Container child = new DefaultContainer().inherit(parent);

        parent.registerConstructor("key", AlternativeTouchable.class);
        child.registerConstructor("key", SimpleTouchable.class);
        child.registerConstructor(DependsOnTouchable.class);

        DependsOnTouchable dot = (DependsOnTouchable) child.getInstanceOfType(DependsOnTouchable.class);
        assertEquals(SimpleTouchable.class, dot.getTouchable().getClass());
View Full Code Here

      DependsOnTouchable dot = (DependsOnTouchable) child.getInstanceOfType(DependsOnTouchable.class);
      assertEquals(SimpleTouchable.class, dot.getTouchable().getClass());
  }*/

    public void testParentComponentRegisteredAsClassShouldBePreffered() throws Exception {
        DefaultContainer parent = new DefaultContainer();
        Container child = new DefaultContainer().inherit(parent);

        parent.registerConstructor(Touchable.class, AlternativeTouchable.class);
        child.registerConstructor("key", SimpleTouchable.class);
        child.registerConstructor(DependsOnTouchable.class);

        DependsOnTouchable dot = (DependsOnTouchable) child.getInstanceOfType(DependsOnTouchable.class);
        assertEquals(AlternativeTouchable.class, dot.getTouchable().getClass());
View Full Code Here

        DependsOnTouchable dot = (DependsOnTouchable) child.getInstanceOfType(DependsOnTouchable.class);
        assertEquals(AlternativeTouchable.class, dot.getTouchable().getClass());
    }

    public void testResolveFromParentByType() {
        Container parent = new DefaultContainer();
        parent.registerConstructor(Touchable.class, SimpleTouchable.class);

        Container child = new DefaultContainer().inherit(parent);
        child.registerConstructor(DependsOnTouchable.class);

        assertNotNull(child.getInstance(DependsOnTouchable.class));
    }
View Full Code Here

        assertNotNull(child.getInstance(DependsOnTouchable.class));
    }

    public void testResolveFromParentByKey() {
        Container parent = new DefaultContainer();
        parent.registerConstructor(Touchable.class, SimpleTouchable.class);

        Container child = new DefaultContainer().inherit(parent);
        child.registerComponent(Components.ctor(DependsOnTouchable.class).
            withArguments(new Creator[]{Components.useType(Touchable.class)}));
        /*
        child.registerConstructor(DependsOnTouchable.class, DependsOnTouchable.class,
                new Parameter[]{new ComponentParameter((Object) Touchable.class)});
View Full Code Here

*/
        assertNotNull(child.getInstance(DependsOnTouchable.class));
    }

    public void testResolveFromGrandParentByType() {
        Container grandParent = new DefaultContainer();
        grandParent.registerConstructor(Touchable.class, SimpleTouchable.class);

        Container parent = new DefaultContainer().inherit(grandParent);

        Container child = new DefaultContainer().inherit(parent);
        child.registerConstructor(DependsOnTouchable.class);

        assertNotNull(child.getInstance(DependsOnTouchable.class));
    }
View Full Code Here

        assertNotNull(child.getInstance(DependsOnTouchable.class));
    }

    public void testResolveFromGrandParentByKey() {
        Container grandParent = new DefaultContainer();
        grandParent.registerConstructor(Touchable.class, SimpleTouchable.class);

        Container parent = new DefaultContainer().inherit(grandParent);

        Container child = new DefaultContainer().inherit(parent);
        child.registerComponent(Components.ctor(DependsOnTouchable.class)
            .withArguments(new Creator[]{Components.useType(Touchable.class)}));
        child.verify();
        parent.verify();
        /*
 
View Full Code Here

      }
    }
   
    public void testUnregisterOnlyAffectsChild()
    throws Exception{
      final Container parent = new DefaultContainer();
      final Container child = new DefaultContainer();
      final Container cc = child.inherit(parent);
      cc.registerConstructor(HashMap.class, (Class[])null);
      assertNull(parent.getComponent(HashMap.class));
      cc.verify();
      parent.registerValue(new Character('a'));
      assertTrue(cc.getComponent(Character.class)!=null);
      cc.verify();
      parent.registerValue("parent");
      child.registerValue("child");
      cc.verify();
      assertEquals("child", cc.getInstance(String.class));
      assertEquals("child", child.getInstance(String.class));
      cc.unregisterComponent(String.class);
      cc.verify();
      assertEquals("parent", cc.getInstance(String.class));
      assertEquals("parent", cc.getInstanceOfType(String.class));
      assertEquals(1, cc.getInstancesOfType(String.class).size());
      child.registerComponent(Components.ctor(X.class)
          .withArgument(0, Components.static_method(Y.class, "instance")));
      assertEquals(4, cc.getInstances().size());
      cc.verify();
      final Object[] expecting = new Object[]{
          "child", "parent", new Character('a'), new HashMap(),
          Y.instance(), new X(Y.instance())};
      /*
      final InstanceListener cb = new InstanceListener(){
        private int seq = 0;
        public void onInstance(Object obj, Component c){
          assertEquals(expecting[seq++], obj);
        }
      };
      cc.fifo(cb);
      final InstanceListener cb2 = new InstanceListener(){
        private int seq = expecting.length;
        public void onInstance(Object obj, Component c){
          assertEquals(expecting[--seq], obj);
        }
      };
      cc.filo(cb2);
      */
      cc.verify();
      cc.registerComponent(Components.value("proxy").proxy().proxy(CharSequence.class));
      cc.verify();
      assertEquals("proxy", ""+cc.getInstanceOfType(CharSequence.class));
      assertEquals("proxy", ""+child.getInstanceOfType(CharSequence.class));
      /*
      cc.clearHistory();
      assertEquals(0, InstanceCounter.countInstance(child));
      assertEquals(0, InstanceCounter.countInstance(parent));
      */
 
View Full Code Here

     *               necessary.
     */
    protected abstract Component prepDEF_verifyWithoutDependencyWorks(Container picoContainer);

    final public void testDEF_verifyWithoutDependencyWorks() {
        final Container yan = new DefaultContainer();
        final Component component = prepDEF_verifyWithoutDependencyWorks(yan);
        //assertSame(getComponentAdapterType(), component.getClass());
        //component.verify(yan.getDependency(component.getType(), yan));
        verify(component, yan);
    }
View Full Code Here

TOP

Related Classes of jfun.yan.containers.DefaultContainer

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.