/**
* Test the building of a type handler.
*/
@Test
public void typeHandler() {
TypeHandlerBuilder builder = GenericMementoUtils.newTypeHandler();
TypeHandler1 th1 = new TypeHandler1();
TypeHandler2 th2 = new TypeHandler2();
// Check default type names
Assert.assertEquals(TypeHandler1.class.getName(), builder.getHandler().getTypeName(th1));
Assert.assertEquals(TypeHandler2.class.getName(), builder.getHandler().getTypeName(th2));
// Check default instantiation
Assert.assertEquals(TypeHandler1.class, builder.getHandler().newInstance(TypeHandler1.class.getName()).getClass());
// Check automatic mapping without field
builder.addMapping(TypeHandler1.class);
Assert.assertEquals(TypeHandler1.class.getName(), builder.getHandler().getTypeName(th1));
// Check automatic mapping with field
builder.addMapping(TypeHandler2.class);
Assert.assertEquals("H2", builder.getHandler().getTypeName(th2));
Assert.assertEquals(TypeHandler2.class, builder.getHandler().newInstance("H2").getClass());
// Create instance of private class
Assert.assertEquals(TypeHandler3.class, builder.getHandler().newInstance(TypeHandler3.class.getName()).getClass());
}