use of org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition in project SimpleFlatMapper by arnaudroger.
the class InstantiatorDefinitionTest method testDefaultCompatibilityScorers.
@Test
public void testDefaultCompatibilityScorers() {
InstantiatorDefinitions.CompatibilityScorer compatibilityScorer = InstantiatorDefinitions.getCompatibilityScorer(new Object());
assertEquals(0, compatibilityScorer.score(new ExecutableInstantiatorDefinition(null, new Parameter(0, "", InputStream.class))));
assertEquals(1, compatibilityScorer.score(new ExecutableInstantiatorDefinition(null, new Parameter(0, "", Number.class))));
}
use of org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition in project SimpleFlatMapper by arnaudroger.
the class InstantiatorDefinitionTest method testLookForCompatibleOneArgumentIgnoreNegativeScore.
@Test
public void testLookForCompatibleOneArgumentIgnoreNegativeScore() {
InstantiatorDefinition id1 = new ExecutableInstantiatorDefinition(c, parameter);
InstantiatorDefinition sid = InstantiatorDefinitions.lookForCompatibleOneArgument(Arrays.asList(id1), new InstantiatorDefinitions.CompatibilityScorer() {
@Override
public int score(InstantiatorDefinition id) {
return -1;
}
});
assertNull(sid);
}
use of org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition in project SimpleFlatMapper by arnaudroger.
the class InstantiatorDefinitionTest method testLookForCompatibleOneArgumentReturnBestScore.
@Test
public void testLookForCompatibleOneArgumentReturnBestScore() {
InstantiatorDefinition id1 = new ExecutableInstantiatorDefinition(c, parameter);
InstantiatorDefinition id2 = new ExecutableInstantiatorDefinition(c, parameter);
InstantiatorDefinition sid = InstantiatorDefinitions.lookForCompatibleOneArgument(Arrays.asList(id1, id2), new InstantiatorDefinitions.CompatibilityScorer() {
int i;
@Override
public int score(InstantiatorDefinition id) {
return i++;
}
});
assertSame(sid, id2);
sid = InstantiatorDefinitions.lookForCompatibleOneArgument(Arrays.asList(id1, id2), new InstantiatorDefinitions.CompatibilityScorer() {
int i = 10;
@Override
public int score(InstantiatorDefinition id) {
return i--;
}
});
assertSame(sid, id1);
}
use of org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition in project SimpleFlatMapper by arnaudroger.
the class InstantiatorDefinitionTest method testTypeAffinityCompatibilityScorers.
@Test
public void testTypeAffinityCompatibilityScorers() {
InstantiatorDefinitions.CompatibilityScorer compatibilityScorer = InstantiatorDefinitions.getCompatibilityScorer(new TypeAffinity() {
@Override
public Class<?>[] getAffinities() {
return new Class<?>[] { Date.class, URL.class };
}
});
assertEquals(0, compatibilityScorer.score(new ExecutableInstantiatorDefinition(null, new Parameter(0, "", InputStream.class))));
assertEquals(12, compatibilityScorer.score(new ExecutableInstantiatorDefinition(null, new Parameter(0, "", Date.class))));
assertEquals(11, compatibilityScorer.score(new ExecutableInstantiatorDefinition(null, new Parameter(0, "", URL.class))));
assertEquals(1, compatibilityScorer.score(new ExecutableInstantiatorDefinition(null, new Parameter(0, "", Number.class))));
}
use of org.simpleflatmapper.reflect.instantiator.ExecutableInstantiatorDefinition in project SimpleFlatMapper by arnaudroger.
the class InstantiatorFactoryTest method testOneArgInstantiator.
@Test
public void testOneArgInstantiator() throws Exception {
InstantiatorDefinition def = new ExecutableInstantiatorDefinition(String.class.getDeclaredMethod("valueOf", Object.class), new Parameter[] { new Parameter(0, "value", Object.class) });
assertNotNull(def.toString());
Instantiator<Object, String> instantiator = DISABLE_ASM.getOneArgIdentityInstantiator(def, true);
assertEquals("12345", instantiator.newInstance(12345));
Instantiator<Object, String> instantiatorAsm = ASM.getOneArgIdentityInstantiator(def, true);
assertEquals("12345", instantiatorAsm.newInstance(12345));
}
Aggregations