use of org.simpleflatmapper.reflect.impl.BuilderBiInstantiator in project SimpleFlatMapper by arnaudroger.
the class BuilderBiInstantiatorDefinitionFactoryTest method testBuilderFromMethodVoidNoAsm.
@Test
public void testBuilderFromMethodVoidNoAsm() throws Exception {
final List<InstantiatorDefinition> instantiatorDefinitions = BuilderInstantiatorDefinitionFactory.extractDefinitions(ClassBuilderWithMethod.class);
assertEquals(1, instantiatorDefinitions.size());
BuilderInstantiatorDefinition b = (BuilderInstantiatorDefinition) instantiatorDefinitions.get(0);
final Parameter[] parameters = b.getParameters();
Arrays.sort(parameters, new Comparator<Parameter>() {
@Override
public int compare(Parameter o1, Parameter o2) {
return o1.getName().compareTo(o2.getName());
}
});
Map<Parameter, BiFunction<? super Void, ? super Object, ?>> params = new HashMap<Parameter, BiFunction<? super Void, ? super Object, ?>>();
params.put(parameters[2], new ConstantBiFunction<Void, Object, String>("zrux"));
params.put(parameters[0], new ConstantBiFunction<Void, Object, Integer>(3));
final InstantiatorFactory instantiatorFactory = new InstantiatorFactory(null, true);
final BiInstantiator<Void, Object, ClassBuilderWithMethod> instantiator = instantiatorFactory.<Void, Object, ClassBuilderWithMethod>getBiInstantiator(b, Void.class, Object.class, params, true, true);
final ClassBuilderWithMethod o = instantiator.newInstance(null, null);
assertTrue((instantiator instanceof BuilderBiInstantiator));
assertEquals(3, o.getId());
assertEquals("zrux", o.getZrux());
}
Aggregations