use of com.tvd12.properties.file.mapping.PropertiesMapper in project properties-file by tvd12.
the class PropertiesMapperTest method mapToMapValueWithNoGenericType.
@Test
public void mapToMapValueWithNoGenericType() {
// given
Properties properties = new Properties();
properties.put("host", "0.0.0.0");
// when
Object actual = new PropertiesMapper().data(properties).map(Map.class, null);
// then
assertEquals(actual, properties);
}
use of com.tvd12.properties.file.mapping.PropertiesMapper in project properties-file by tvd12.
the class PropertiesMapperTest method mapToMapValueWithInvalidGenericType.
@Test
public void mapToMapValueWithInvalidGenericType() {
// given
Properties properties = new Properties();
properties.put("host", "0.0.0.0");
// when
Object actual = new PropertiesMapper().data(properties).map(Map.class, String.class);
// then
assertEquals(actual, properties);
}
use of com.tvd12.properties.file.mapping.PropertiesMapper in project properties-file by tvd12.
the class PropertiesMapperTest method testMapPropertiesToBean.
@Test
public void testMapPropertiesToBean() {
Properties properties = new Properties();
properties.setProperty("name", "hello");
properties.put("age", 24);
properties.put("clazz", ClassA.class.getName());
properties.put("date", new SimpleDateFormat(Dates.getPattern()).format(new Date()));
ClassA object = new PropertiesMapper().data(properties).clazz(ClassA.class).map();
assertEquals(object.getName(), "hello");
assertEquals(object.getAge(), 24);
assertEquals(object.getMoney(), 10);
assertEquals(object.getClazz(), ClassA.class);
assertNotNull(object.getDate());
}
use of com.tvd12.properties.file.mapping.PropertiesMapper in project properties-file by tvd12.
the class PropertiesMapperTest method testWithNoClassCase.
@Test
public void testWithNoClassCase() {
Properties properties = new Properties();
Object output = new PropertiesMapper().data(properties).map();
assert properties == output;
}
use of com.tvd12.properties.file.mapping.PropertiesMapper in project properties-file by tvd12.
the class PropertiesMapper method doMapToMapValue.
@SuppressWarnings({ "unchecked", "rawtypes" })
private Map doMapToMapValue(Type genericType) {
if (genericType == null) {
return properties;
}
Class<?> mapValueType = ReflectionGenericUtil.getTwoGenericClassArguments(genericType)[1];
if (mapValueType == null) {
return properties;
}
Map answer = new HashMap<>();
Map<String, Properties> propertiesMap = PropertiesUtil.getPropertiesMap(properties);
for (String key : propertiesMap.keySet()) {
Object value = new PropertiesMapper().data(properties).propertyPrefix(key).classLoader(classLoader).valueConverter(valueConverter).propertyAnnotations(propertyAnnotations).map(mapValueType);
answer.put(key, value);
}
return answer;
}
Aggregations