final Component factory =
Components.fromArguments(mycache, new String[]{"name","capacity"})
.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);
assertEquals(MyCache.class, icache.getClass());
assertEquals("tom", icache.getName());
assertEquals(10, icache.getCapacity());
try{
yan.verify();
fail("should have failed with IrresolveableArgumentException");
}
catch(IrresolveableArgumentException e){
//e.printResolutionTrace();
assertTraceSize(e, 5);
assertEntry(e, 3, "tests.jfun.yan.testmodel.ICacheFactory");
final int pos = e.getOrdinalPosition();
if(pos==0)
assertEquals(String.class, e.getParameterType());
else
assertEquals(int.class, e.getParameterType());
}
yan.registerValue("someone");
try{
yan.verify();
fail("should have failed with IrresolveableArgumentException");
}
catch(IrresolveableArgumentException e){
assertTraceSize(e, 5);
assertEntry(e, 3, "tests.jfun.yan.testmodel.ICacheFactory");
final int pos = e.getOrdinalPosition();
if(pos==0)
assertEquals(String.class, e.getParameterType());
else
assertEquals(int.class, e.getParameterType());
}
yan.registerValue(new Integer(0));
yan.verify();
final tests.jfun.yan.testmodel.ICache icache2 = ifactory.createCache("jack", 11);
assertEquals(MyCache.class, icache2.getClass());
assertEquals("jack", icache2.getName());
assertEquals(11, icache2.getCapacity());
final tests.jfun.yan.testmodel.ICache icache3 = ifactory.createCache();
assertEquals(MyCache.class, icache3.getClass());
assertEquals("someone", icache3.getName());
assertEquals(0, icache3.getCapacity());
}