Search in sources :

Example 6 with PropertyAnnotations

use of com.tvd12.properties.file.annotation.PropertyAnnotations in project properties-file by tvd12.

the class SetterMethodTest method getKeyStartWithNotSet.

@Test
public void getKeyStartWithNotSet() throws Exception {
    // given
    SetterMethod method = new SetterMethod(new PropertyAnnotations());
    method.initWithMethod(ClassA.class.getDeclaredMethod("value", String.class));
    // when
    String key = method.getKey();
    // then
    assertEquals(key, "value");
}
Also used : PropertyAnnotations(com.tvd12.properties.file.annotation.PropertyAnnotations) SetterMethod(com.tvd12.properties.file.struct.SetterMethod) Test(org.testng.annotations.Test)

Example 7 with PropertyAnnotations

use of com.tvd12.properties.file.annotation.PropertyAnnotations 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;
}
Also used : HashMap(java.util.HashMap) Properties(java.util.Properties) PropertiesUtil.toProperties(com.tvd12.properties.file.util.PropertiesUtil.toProperties) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with PropertyAnnotations

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");
}
Also used : PropertyAnnotations(com.tvd12.properties.file.annotation.PropertyAnnotations) SetterMethod(com.tvd12.properties.file.struct.SetterMethod) SetterMethod(com.tvd12.properties.file.struct.SetterMethod) Method(java.lang.reflect.Method) Test(org.testng.annotations.Test)

Example 9 with PropertyAnnotations

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");
}
Also used : PropertyAnnotations(com.tvd12.properties.file.annotation.PropertyAnnotations) SetterMethod(com.tvd12.properties.file.struct.SetterMethod) SetterMethod(com.tvd12.properties.file.struct.SetterMethod) Method(java.lang.reflect.Method) Test(org.testng.annotations.Test)

Example 10 with PropertyAnnotations

use of com.tvd12.properties.file.annotation.PropertyAnnotations in project properties-file by tvd12.

the class SetterMethodTest method getKeyStartWithNotSet.

@Test
public void getKeyStartWithNotSet() throws Exception {
    // given
    SetterMethod method = new SetterMethod(new PropertyAnnotations());
    method.initWithMethod(ClassA.class.getDeclaredMethod("value", String.class));
    // when
    String key = method.getKey();
    // then
    assertEquals(key, "value");
}
Also used : PropertyAnnotations(com.tvd12.properties.file.annotation.PropertyAnnotations) SetterMethod(com.tvd12.properties.file.struct.SetterMethod) Test(org.testng.annotations.Test)

Aggregations

PropertyAnnotations (com.tvd12.properties.file.annotation.PropertyAnnotations)9 Test (org.testng.annotations.Test)8 SetterMethod (com.tvd12.properties.file.struct.SetterMethod)6 Method (java.lang.reflect.Method)4 Properties (java.util.Properties)4 PropertiesBean (com.tvd12.properties.file.struct.PropertiesBean)2 PropertiesUtil.toProperties (com.tvd12.properties.file.util.PropertiesUtil.toProperties)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1