use of com.tvd12.properties.file.annotation.PropertyAnnotations in project properties-file by tvd12.
the class PropertiesBeanTest method test.
@Test
public void test() {
new PropertiesBean(ClassA.class);
ClassA classA = new ClassA();
PropertiesBean mapping2 = new PropertiesBean(classA, new PropertyAnnotations());
mapping2.put("charValue", "c");
mapping2.put("byteValue", "1");
mapping2.put("doubleValue", "2.0");
mapping2.put("floatValue", "3.0");
mapping2.put("longValue", "4");
mapping2.put("shortValue", "5");
mapping2.put("not found", "not found");
assertEquals(classA.getCharValue(), 'c');
assertEquals(classA.getByteValue(), 1);
assertEquals(classA.getDoubleValue(), 2.0D);
assertEquals(classA.getFloatValue(), 3.0F);
assertEquals(classA.getLongValue(), 4);
assertEquals(classA.getShortValue(), 5);
Properties dataSourceProperties = new Properties();
dataSourceProperties.put("datasource.username", "hello");
dataSourceProperties.put("datasource.password", "world");
PropertiesBean mapping3 = new PropertiesBean(classA, new PropertyAnnotations());
mapping3.put("dataSourceConfig", null, dataSourceProperties);
assert classA.dataSourceConfig.username.equals("hello");
assert classA.dataSourceConfig.password.equals("world");
}
use of com.tvd12.properties.file.annotation.PropertyAnnotations in project properties-file by tvd12.
the class PropertiesMapper method map.
@SuppressWarnings({ "unchecked" })
public <T> T map(Class<T> clazz, Type genericType) {
if (clazz == null && bean == null) {
throw new IllegalArgumentException("there is nothing to map, plase provice clazz, or bean");
}
this.clazz(clazz);
this.readProperties();
if (propertyAnnotations == null) {
propertyAnnotations = new PropertyAnnotations();
}
if (clazz == Map.class) {
return (T) doMapToMapValue(genericType);
} else if (clazz == Properties.class) {
return (T) properties;
} else {
return (T) doMapValue();
}
}
use of com.tvd12.properties.file.annotation.PropertyAnnotations in project properties-file by tvd12.
the class PropertiesBeanTest method test.
@Test
public void test() {
new PropertiesBean(ClassA.class);
ClassA classA = new ClassA();
PropertiesBean mapping2 = new PropertiesBean(classA, new PropertyAnnotations());
mapping2.put("charValue", "c");
mapping2.put("byteValue", "1");
mapping2.put("doubleValue", "2.0");
mapping2.put("floatValue", "3.0");
mapping2.put("longValue", "4");
mapping2.put("shortValue", "5");
mapping2.put("not found", "not found");
assertEquals(classA.getCharValue(), 'c');
assertEquals(classA.getByteValue(), 1);
assertEquals(classA.getDoubleValue(), 2.0D);
assertEquals(classA.getFloatValue(), 3.0F);
assertEquals(classA.getLongValue(), 4);
assertEquals(classA.getShortValue(), 5);
Properties dataSourceProperties = new Properties();
dataSourceProperties.put("datasource.username", "hello");
dataSourceProperties.put("datasource.password", "world");
PropertiesBean mapping3 = new PropertiesBean(classA, new PropertyAnnotations());
mapping3.put("dataSourceConfig", null, dataSourceProperties);
assert classA.dataSourceConfig.username.equals("hello");
assert classA.dataSourceConfig.password.equals("world");
}
use of com.tvd12.properties.file.annotation.PropertyAnnotations in project properties-file by tvd12.
the class SetterMethodTest method testInvalidCase.
@Test(expectedExceptions = { IllegalStateException.class })
public void testInvalidCase() {
Method method = MethodBuilder.create().clazz(ClassA.class).method("setValues").argument(String.class).argument(String.class).build();
SetterMethod setterMethod = new SetterMethod(new PropertyAnnotations());
setterMethod.initWithMethod(method);
setterMethod.invoke(new ClassA(), "123");
}
use of com.tvd12.properties.file.annotation.PropertyAnnotations in project properties-file by tvd12.
the class SetterMethodTest method test.
@Test
public void test() {
Method method = MethodBuilder.create().clazz(ClassA.class).method("setName").argument(String.class).build();
SetterMethod setterMethod = new SetterMethod(new PropertyAnnotations());
setterMethod.initWithMethod(method);
setterMethod.invoke(new ClassA(), "123");
}
Aggregations