}
}
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));
*/