Package jfun.yan

Examples of jfun.yan.Component


        assertEquals(new java.util.ArrayList(), a.getList());
        assertSame(b, a.getB());
    }
    public void testVerifyAllUnsatisfiableDependenciesAreSignalled()
    throws IntrospectionException{
        Component aAdapter =
          Components.bean(A.class);
        //new SetterInjectionComponentAdapter("a", A.class, null);
        Component bAdapter =
          Components.bean(B.class);
          //new SetterInjectionComponentAdapter("b", B.class, null);

        Container yan = new DefaultContainer();
        yan.verify();
View Full Code Here


        }
    }

    public void testHybridBeans()
    throws IntrospectionException{
        Component bAdapter =Components.bean(B.class);
          //new Component("b", B.class, null);
        Component cAdapter =Components.bean(C.class);
          //new Component("c", C.class, null);
        //Component cNullAdapter = Components.bean(C.class);
          //new Component("c0", C.class, null);

        Container yan = new DefaultContainer();
View Full Code Here

      return name;
    }
  }
  public void testHashmapComponent(){
    final Container yan = createYanContainer();
    final Component newAvenue = Components.static_method(Avenue.class, "instance");
    yan.registerComponent("target", Components.hashmap(
        new String[]{"first", "second", "third"},
        new Creator[]{newAvenue.withArgument(0, Components.value("Randolph")),
            newAvenue.withArgument(0, Components.value("Lincoln")),
            newAvenue.withArgument(0, Components.value("Fullerton"))}
        )
    );
    assertEquals(java.util.LinkedHashMap.class, yan.verifyType(HashMap.class));
    final HashMap hmap = (HashMap)yan.getInstanceOfType(java.util.Map.class);
    verifyLinkedHashMap((LinkedHashMap)hmap);
    final Component bad_hash = Components.hashmap(
        new String[]{"a","b"},
        new Creator[]{
            Components.useKey("a").withState("hello"),
            Components.useState(new Predicate(){
              public boolean isObject(Object obj){
View Full Code Here

      assertEntry(e, 2, "getInstance <bad_hash>");
    }
  }
  public void testHashMapComponentWithLessKey(){
    final Container yan = createYanContainer();
    final Component newAvenue = Components.static_method(Avenue.class, "instance");
    try{
      yan.registerComponent("target", Components.hashmap(
          new String[]{"first", "second"},
          new Creator[]{newAvenue.withArgument(0, Components.value("Randolph")),
              newAvenue.withArgument(0, Components.value("Lincoln")),
              newAvenue.withArgument(0, Components.value("Fullerton"))}
          )
      );
      fail("should have failed");
    }
    catch(IllegalArgumentException e){
View Full Code Here

  }
  public void testHashMapComponentWithDuplicateKey(){
    //in the new design, we do not check key dups.
    //wrappers such as Nuts check duplicates.
    final Container yan = createYanContainer();
    final Component newAvenue = Components.static_method(Avenue.class, "instance");
    //try{
      yan.registerComponent("target", Components.hashmap(
          new String[]{"first", "second", "second"},
          new Creator[]{newAvenue.withArgument(0, Components.value("Randolph")),
              newAvenue.withArgument(0, Components.value("Lincoln")),
              newAvenue.withArgument(0, Components.value("Fullerton"))}
          )
      );
      //fail("should have failed");
    //}
    //catch(IllegalArgumentException e){
View Full Code Here

    //  assertEquals("duplicate key: second", e.getMessage());
    //}
  }
  public void testCreateLinkedHashMapUsingMap(){
    final Container yan = createYanContainer();
    final Component newAvenue = Components.useKey("factory");
    final Component factory = Components.static_method(Avenue.class, "instance")
    .incomplete();
    final String[] keys = new String[]{"first", "second", "third"};
    final Component vals = Components.array(new Component[]{newAvenue.withArgument(0, Components.value("Randolph")),
        newAvenue.withArgument(0, Components.value("Lincoln")),
        newAvenue.withArgument(0, Components.value("Fullerton"))});
    final Component cc = vals.map(new jfun.yan.Map(){
      public Object map(Object obj){
        final Object[] vs = (Object[])obj;
        final LinkedHashMap lhm = new LinkedHashMap(vs.length);
        for(int i=0; i<vs.length; i++){
          lhm.put(keys[i], vs[i]);
View Full Code Here

    verifyLinkedHashMap(lhm);

  }
  public void testCreateLinkedHashMapUsingMap2(){
    final Container yan = createYanContainer();
    final Component newAvenue = Components.useKey("factory");
    final Component factory = Components.static_method(Avenue.class, "instance")
    .incomplete();
    final Component keys = Components.value(new String[]{"first", "second", "third"});
    final Component vals = Components.list(new Creator[]{newAvenue.withArgument(0, Components.value("Randolph")),
        newAvenue.withArgument(0, Components.value("Lincoln")),
        newAvenue.withArgument(0, Components.value("Fullerton"))});
    final Component cc = Monad.map(keys, vals, new Map2(){
      public Object map(Object o1, Object o2){
        final Object[] ks = (Object[])o1;
        final java.util.List vs = (java.util.List)o2;
        final LinkedHashMap lhm = new LinkedHashMap(ks.length);
        for(int i=0;i<vs.size();i++){
View Full Code Here

    final LinkedHashMap lhm = (LinkedHashMap)yan.getInstance(LinkedHashMap.class);
    verifyLinkedHashMap(lhm);
  }
  public void testCreateLinkedHashMapUsingBind(){
    final Container yan = createYanContainer();
    final Component newAvenue = Components.useKey("factory");
    final Component factory = Components.static_method(Avenue.class, "instance")
    .incomplete();
    //final Component keys = Components.value(new String[]{"first", "second", "third"});
    final Component vals = Components.list(new Creator[]{newAvenue.withArgument(0, Components.value("Randolph")),
        newAvenue.withArgument(0, Components.value("Lincoln")),
        newAvenue.withArgument(0, Components.value("Fullerton"))});
    final Component cc = Monad.bind(vals, new jfun.yan.Binder(){
      public Creator bind(Object obj){
        final Object[] ks = new String[]{"first", "second", "third"};
        final java.util.List vs = (java.util.List)obj;
        final LinkedHashMap lhm = new LinkedHashMap();
        for(int i=0; i<ks.length; i++){
View Full Code Here

    return p1.getName();
  }
  public void testSharedArgument()
  throws Exception{
    final Container yan = createYanContainer();
    final Component signup = Components.method(this, "signup");
    yan.registerComponent("target",
        Monad.bind(Components.useType(Person.class),
          new jfun.yan.Binder(){
            public Creator bind(Object v){
              final Component c = Components.value(v);
              return signup.withArguments(
                  new Creator[]{c,c}
              );
            }
          }
View Full Code Here

    yan.registerValue(name);
    assertEquals(name, yan.getInstance("target"));
  }
  public void testFactory(){
    final Container yan = createYanContainer();
    final Component mycache =
      Components.ctor(MyCache.class,
          new Class[]{String.class, int.class});
   
    final Component factory =
      mycache.factory(ICacheFactory.class);
    yan.registerComponent("target", factory);
    final ICacheFactory ifactory =
      (ICacheFactory)yan.getInstance("target");
    final tests.jfun.yan.testmodel.ICache icache = ifactory.createCache("tom", 10);
View Full Code Here

TOP

Related Classes of jfun.yan.Component

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.