Package jfun.yan

Examples of jfun.yan.Container


public class InvocationOrderTestCase extends TestCase {
  public void test1()
  throws Exception{
    final NutsProcessor proc = new NutsProcessor();
    proc.processResource("tests/jfun/finecontrol/config.xml");
    final Container yan = proc.getContainer();
    yan.getInstance("a");
  }
View Full Code Here


    }

    public void testRegisteredComponentsExistAndAreTheCorrectTypes()
    throws Exception{
        Container yan = createPicoContainerWithTouchableAndDependsOnTouchable();
        yan = trans(yan);
        yan.verify();
        assertNotNull("Container should have Touchable component",
                yan.getInstance(Touchable.class));
        assertNotNull("Container should have DependsOnTouchable component",
                yan.getInstance(DependsOnTouchable.class));
        assertTrue("Component should be instance of Touchable",
                yan.getInstance(Touchable.class) instanceof Touchable);
        assertTrue("Component should be instance of DependsOnTouchable",
                yan.getInstance(DependsOnTouchable.class) instanceof DependsOnTouchable);
        assertNull("should not have non existent component", yan.getComponent(Map.class));
    }
View Full Code Here

    }


    public void testCyclicDependencyThrowsCyclicDependencyException()
    throws Exception{
        Container yan = new DefaultContainer();
        yan.registerConstructor(ComponentB.class);
        yan.registerConstructor(ComponentD.class);
        yan.registerConstructor(ComponentE.class);
        yan = trans(yan);

        try {
            yan.getInstance(ComponentD.class);
            fail("CyclicDependencyException expected");
        } catch (jfun.yan.CyclicDependencyException e) {
            // CyclicDependencyException reports now the stack.
            //final List dependencies = Arrays.asList(ComponentD.class.getConstructors()[0].getParameterTypes());
            //final List dependencies = Arrays.asList(new Class[]{ComponentD.class, ComponentE.class, ComponentD.class});
View Full Code Here

        picoContainer.filo(new MemberCallback(Foo.class, "dispose"));
        assertEquals(true, foo.disposed);
    }
*/
    public void testComponentInstancesFromParentsAreDirectlyAccessible2() {
        final Container a = new DefaultContainer();
        final Container b = new DefaultContainer().inherit(a);
        final Container c = new DefaultContainer().inherit(b);

        Object ao = new Object();
        Object bo = new Object();
        Object co = new Object();

        a.registerValue("a", ao);
        b.registerValue("b", bo);
        c.registerValue("c", co);

        assertEquals(1, a.getInstances().size());
        assertEquals(2, b.getInstances().size());
        assertEquals(3, c.getInstances().size());
    }
View Full Code Here

    public static class DerivedTouchable extends SimpleTouchable {
        public DerivedTouchable() {
        }
    }
    protected final Container createYanContainer(){
      final Container yan = getContainerImpl();
      return new DelegatingContainer(yan){
        public void registerComponent(Object key, Component cc){
          test(cc);
          super.registerComponent(key, cc);
        }
View Full Code Here

    }
    protected Container getContainerImpl(){
      return new DefaultContainer();
    }
    public void testSize(){
      final Container yan = createYanContainer();
      String s1 = "hello world";
      yan.registerValue(s1);
      yan.registerValue(s1);
      yan.registerComponent(String.class, Components.value(s1).singleton());
      yan.registerConstructor(java.util.ArrayList.class, (Class[])null);
      assertEquals(2, yan.keys().size());
      assertEquals(2, yan.getInstances().size());
    }
View Full Code Here

      assertEquals(0, ((java.util.ArrayList)yan.getInstanceOfType(java.util.List.class)).size());
      yan.clearHistory();
      assertSize(0, yan);
    }*/
    public void testSubsume(){
      final Container yan = createYanContainer();
      yan.registerComponent(Components.ctor(String.class, null).subsume(CharSequence.class));
      final Object str1 = yan.getInstance(CharSequence.class);
      final Object str2 = yan.getInstanceOfType(CharSequence.class);
      assertEquals(str1, "");
      assertEquals(str2, "");
      if(str1!=str2){
        try{
          yan.getInstanceOfType(String.class);
          fail("should have failed");
        }
        catch(UnresolvedComponentException e){
          assertEquals(1, e.getResolutionTrace().size());
          assertEntry(e, 0, "getInstanceOfType <java.lang.String>");
View Full Code Here

          assertEquals(String.class, e.getComponentKey());
        }
      }
    }
    public void testArray(){
      final Container yan = createYanContainer();
      yan.registerComponent(int[].class,
          Components.static_method(java.lang.reflect.Array.class,
              "newInstance", new Class[]{Class.class, int.class})
          .cast(int[].class)
          .withArgument(0, Components.useKey("array_dimension")));
      yan.registerValue(new Integer(5));
      yan.registerValue("array_dimension", int.class);
      assertTrue(yan.getInstance(int[].class) instanceof int[]);
      assertEquals(5, ((int[])yan.getInstanceOfType(int[].class)).length);
    }
View Full Code Here

       assertEquals(int.class, e.getExpectedType());
       assertEquals(void.class, e.getActualType());
     }
    }
    public void testNullInstance(){
      final Container yan = createYanContainer();
      yan.registerStaticMethod(BaseContainerTestCase.class, "returnNull");
      testNullInstance(yan);
      yan.registerStaticMethod(BaseContainerTestCase.class, "returnNull", null);
      testNullInstance(yan);
      yan.registerStaticMethod(Object.class, BaseContainerTestCase.class, "returnNull");
      testNullInstance(yan);
      yan.registerStaticMethod(Object.class, BaseContainerTestCase.class, "returnNull", new Class[0]);
      testNullInstance(yan);
    }
View Full Code Here

        this.name = name;
      }
    }
    public void testTypeMismatchForPropertyAndParameter()
    throws Exception{
      final Container yan = createYanContainer();
      yan.registerComponent(
          Components.ctor(PersonBean.class, new Class[]{String.class})
          .withArgument(0, Components.value(new int[0])));
      try{
        yan.verify();
        fail("should have type failed");
      }
      catch(ParameterTypeMismatchException e){
        assertEquals(2, e.getResolutionTrace().size());
        assertParameter(e, 0, Functions.ctor(PersonBean.class, new Class[]{String.class}),
            0);
        assertEquals(PersonBean.class, e.getComponentKey());
        assertEquals(0, e.getOrdinalPosition());
        assertEquals(String.class, e.getExpectedType());
        assertEquals(int[].class, e.getActualType());
      }
      //yan.verify();
      final HashMap props = new HashMap();
      props.put("name", Components.ctor(ArrayList.class, null));
      yan.registerComponent(Components.bean(PersonBean.class)
          .withProperties(props));
      try{
        yan.verify();
        fail("should have type failed");
      }
      catch(PropertyTypeMismatchException e){
        //e.printResolutionTrace(System.err);
        assertEquals(3, e.getResolutionTrace().size());
View Full Code Here

TOP

Related Classes of jfun.yan.Container

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.