use of org.simpleflatmapper.util.TypeReference in project SimpleFlatMapper by arnaudroger.
the class CsvMapperBuilderTest method testMapToMapStringString.
@Test
public void testMapToMapStringString() throws Exception {
final CsvMapper<Map<String, String>> mapper = csvMapperFactory.newBuilder(new TypeReference<Map<String, String>>() {
}).addMapping("key1").addMapping("key2").mapper();
final Iterator<Map<String, String>> iterator = mapper.iterator(new StringReader("v1,v2\na1"));
Map<String, String> map;
map = iterator.next();
assertEquals("v1", map.get("key1"));
assertEquals("v2", map.get("key2"));
map = iterator.next();
assertEquals("a1", map.get("key1"));
assertEquals(null, map.get("key2"));
}
use of org.simpleflatmapper.util.TypeReference in project SimpleFlatMapper by arnaudroger.
the class JoolTupleTest method testCsvParser.
@Test
public void testCsvParser() throws IOException {
final CsvParser.StaticMapToDSL<Tuple3<Long, Integer, Short>> mapToDSL = CsvParser.mapTo(new TypeReference<Tuple3<Long, Integer, Short>>() {
}).defaultHeaders();
final Iterator<Tuple3<Long, Integer, Short>> iterator = mapToDSL.iterator(new StringReader("6,7,3\n7,8,9"));
final Tuple3<Long, Integer, Short> tuple1 = iterator.next();
assertEquals(6l, tuple1.v1().longValue());
assertEquals(7, tuple1.v2().intValue());
assertEquals((short) 3, tuple1.v3().shortValue());
final Tuple3<Long, Integer, Short> tuple2 = iterator.next();
assertEquals(7l, tuple2.v1().longValue());
assertEquals(8, tuple2.v2().intValue());
assertEquals((short) 9, tuple2.v3().shortValue());
}
use of org.simpleflatmapper.util.TypeReference in project SimpleFlatMapper by arnaudroger.
the class ConstantSourceMapperBuilderTest method testIssue495Simple.
@Test
public void testIssue495Simple() throws Exception {
TypeReference<List<Tuple3<Foo, Foo, Foo>>> typeReference = new TypeReference<List<Tuple3<Foo, Foo, Foo>>>() {
};
ClassMeta<List<Tuple3<Foo, Foo, Foo>>> classMeta = this.classMeta.getReflectionService().getClassMeta(typeReference.getType());
Predicate<PropertyMeta<?, ?>> propertyFilter = new Predicate<PropertyMeta<?, ?>>() {
@Override
public boolean test(PropertyMeta<?, ?> propertyMeta) {
return true;
}
};
PropertyFinder<?> propertyFinder = classMeta.newPropertyFinder(propertyFilter);
PropertyMeta<?, ?> p1 = propertyFinder.findProperty(new DefaultPropertyNameMatcher("bar", 0, false, false), new Object[0]);
PropertyMeta<?, ?> p2 = propertyFinder.findProperty(new DefaultPropertyNameMatcher("bar", 0, false, false), new Object[0]);
assertEquals("[0].element0.bar", p1.getPath());
assertEquals("[0].element1.bar", p2.getPath());
propertyFinder = classMeta.newPropertyFinder(propertyFilter);
p1 = propertyFinder.findProperty(new DefaultPropertyNameMatcher("elt0_elt0_bar", 0, false, false), new Object[0]);
p2 = propertyFinder.findProperty(new DefaultPropertyNameMatcher("elt1_elt0_bar", 0, false, false), new Object[0]);
assertEquals("[0].element0.bar", p1.getPath());
assertEquals("[1].element0.bar", p2.getPath());
}
use of org.simpleflatmapper.util.TypeReference in project SimpleFlatMapper by arnaudroger.
the class AbstractMapperBuilderTest method testSetDbObject.
@Test
public void testSetDbObject() {
ClassMeta<Set<DbObject>> classMeta = ReflectionService.disableAsm().<Set<DbObject>>getClassMeta(new TypeReference<Set<DbObject>>() {
}.getType());
Mapper<Object[], Set<DbObject>> mapper = new SampleMapperBuilder<Set<DbObject>>(classMeta).addMapping("1_id").addMapping("1_name").addMapping("2_id").addMapping("2_name").mapper();
Set<DbObject> map = mapper.map(new Object[] { 1l, "name1", 2l, "name2" });
assertEquals(2, map.size());
Iterator<DbObject> it = map.iterator();
DbObject o = it.next();
if (o.getId() == 1l) {
assertEquals("name1", o.getName());
o = it.next();
assertEquals(2l, o.getId());
assertEquals("name2", o.getName());
} else {
assertEquals("name2", o.getName());
o = it.next();
assertEquals(1l, o.getId());
assertEquals("name1", o.getName());
}
}
use of org.simpleflatmapper.util.TypeReference in project SimpleFlatMapper by arnaudroger.
the class AbstractMapperFactoryTest method testMeta.
@Test
public void testMeta() {
MapperFactory mapperFactory = new MapperFactory();
ClassMeta<String> stringClassMeta = mapperFactory.getClassMeta(String.class);
Assert.assertEquals(stringClassMeta, mapperFactory.getClassMeta((Type) String.class));
Assert.assertEquals(stringClassMeta, mapperFactory.getClassMeta(new TypeReference<String>() {
}));
assertNotNull(mapperFactory.getClassMetaWithExtraInstantiator(String.class, null));
assertNotNull(mapperFactory.getClassMetaWithExtraInstantiator((Type) String.class, null));
assertNotNull(mapperFactory.getClassMetaWithExtraInstantiator(new TypeReference<String>() {
}, null));
}
Aggregations