프로퍼티 읽기 추가
parent
4ece563336
commit
24624103ef
@ -0,0 +1,70 @@
|
||||
package cokr.xit.foundation.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
public class PropertyTest {
|
||||
private TestObject testObject() {
|
||||
TestObject obj = new TestObject();
|
||||
obj.str = "abc";
|
||||
obj.array = new String[]{"1", "2", "3"};
|
||||
obj.list = List.of("a", "b", "c");
|
||||
obj.map = Map.of("k1", "v1", "k2", "v2", "k3", "v3");
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Test
|
||||
void read() {
|
||||
TestObject obj = testObject();
|
||||
|
||||
try {
|
||||
String name = "str";
|
||||
Object val = Property.value(obj, name);
|
||||
System.out.println(name + " = " + val);
|
||||
|
||||
val = Property.value(obj, name = "array");
|
||||
System.out.println(name + " = " + val);
|
||||
|
||||
val = Property.value(obj, name = "list");
|
||||
System.out.println(name + " = " + val);
|
||||
|
||||
val = Property.value(obj, name = "map");
|
||||
System.out.println(name + " = " + val);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void write() {
|
||||
TestObject obj = new TestObject();
|
||||
|
||||
String name = "str";
|
||||
Object val = "abc";
|
||||
Property.write(obj, name, val);
|
||||
System.out.println(name + ": " + Property.value(obj, name));
|
||||
|
||||
Property.write(obj, name = "array", val = new String[] {"1", "2", "3"});
|
||||
System.out.println(name + ": " + Property.value(obj, name));
|
||||
|
||||
Property.write(obj, name = "list", val = List.of("a", "b", "c"));
|
||||
System.out.println(name + ": " + Property.value(obj, name));
|
||||
|
||||
Property.write(obj, name = "map", val = Map.of("k1", "v1", "k2", "v2", "k3", "v3"));
|
||||
System.out.println(name + ": " + Property.value(obj, name));
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public static class TestObject {
|
||||
private String str;
|
||||
private String[] array;
|
||||
private List<String> list;
|
||||
private Map<String, String> map;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue