assertSame(null, person.getNickname());
assertEquals(1, person.getId());
}
public int expectArray(int[][] arr){return 1;}
public void testBasics(){
final Container yan = createYanContainer();
yan.registerValue("abc");
try{
yan.getInstance("x");
fail("should have failed with UnresolvedComponentException");
}
catch(UnresolvedComponentException e){
assertEquals("x", e.getComponentKey());
}
assertEquals(yan, yan);
assertEquals(yan.toString(), yan.toString());
yan.registerComponent("target", Components.method(this, "expectArray"));
try{
yan.verify();
fail("should have failed with IrresolveableArgumentException");
}
catch(IrresolveableArgumentException e){
assertEquals("target", e.getComponentKey());
assertEquals(int[][].class, e.getParameterType());
assertEquals(0, e.getOrdinalPosition());
assertEquals("The #0 argument of type int[][] for component <target> is not resolveable", e.getMessage());
}
try{
yan.registerComponent(Components.useKey("target"));
fail("should have failed with UnknownComponentTypeException");
}
catch(UnknownComponentTypeException e){}
try{
yan.registerComponent(Components.useType(String.class));
fail("should have failed with UnknownComponentTypeException");
}
catch(UnknownComponentTypeException e){
assertTraceSize(e, 0);
}
yan.unregisterComponentsOfType(int.class);
yan.verify();
yan.registerComponent("target_also", Components.useKey("target"));
try{
yan.verify();
fail("should have failed with UnresolvedComponentException");
}
catch(UnresolvedComponentException e){
assertEquals("target", e.getComponentKey());
}
yan.registerComponent("target",
Components.method(this, "expectArray")
.withArgument(0, Components.value(new int[10])));
try{
yan.verify();
fail("should have failed with ParameterTypeMismatchException");
}
catch(ParameterTypeMismatchException e){
assertTraceSize(e, 3);
assertParameter(e, 0, Functions.method(this, "expectArray"), 0);
assertEntry(e, 1, "useKey <target>");
assertEntry(e, 2, "verify <target_also>");
assertEquals("target_also", e.getComponentKey());
assertEquals(int[][].class, e.getExpectedType());
assertEquals(int[].class, e.getActualType());
assertEquals(0, e.getOrdinalPosition());
assertTrue(e.getMessage().startsWith(
"type mismatch for The #0 parameter of component <target_also>")
);
}
final Container yan2 = createYanContainer();
yan.registerComponent("target", Components.useType(yan2, String.class));
try{
yan.verify();
fail("should have failed with UnresolvedComponentException");
}
catch(UnresolvedComponentException e){
assertEquals(String.class, e.getComponentKey());
}
try{
yan.getInstance("target_also");
fail("should have failed with UnresolvedComponentException");
}
catch(UnresolvedComponentException e){
assertEquals(String.class, e.getComponentKey());
}
yan2.registerValue("target arrived!");
assertEquals("target arrived!", yan.getInstance("target"));
}