0

добавлены методы поиска Getter и Setter для полей

This commit is contained in:
2020-04-17 18:16:32 +03:00
parent 094318904c
commit a16fed9785
4 changed files with 62 additions and 0 deletions

View File

@@ -30,6 +30,7 @@ public class ReflectionObjectTest {
new ReflectionObject(strObj).getOriginalObject(Integer.class);
}
//region Field tests
@Test
public void fieldsList() {
final List<String> expectedList = Arrays.asList("finalizedField", "simpleField");
@@ -64,6 +65,30 @@ public class ReflectionObjectTest {
refObj.field("field_not_exists");
}
@Test
public void field_getter() {
ReflectionObject refObj = new ReflectionObject(new SomeObject());
ReflectionField refField = refObj.field("someIntField");
assertNotNull(refField);
ReflectionMethod refGetter = refField.getter();
assertNotNull(refGetter);
}
@Test
public void field_setter() {
ReflectionObject refObj = new ReflectionObject(new SomeObject());
ReflectionField refField = refObj.field("someIntField");
assertNotNull(refField);
ReflectionMethod refSetter = refField.setter();
assertNotNull(refSetter);
}
//endregion
//region Method tests
@Test
public void methodsList() {
final List<String> expectedList = Arrays.asList("getSimpleField", "setSimpleField");
@@ -105,4 +130,5 @@ public class ReflectionObjectTest {
ReflectionObject refObj = new ReflectionObject(new SomeObject());
refObj.method("not_exists_method");
}
//endregion
}

View File

@@ -5,6 +5,7 @@ class SomeObject {
private static final int MAGIC_NUMBER = 33;
private final String finalizedField = "value123";
private String simpleField = "defaultValue";
private int someIntField;
public String getSimpleField() {
return simpleField;
@@ -18,6 +19,14 @@ class SomeObject {
simpleField = "123value";
}
public int getSomeIntField() {
return someIntField;
}
public void setSomeIntField(int someIntField) {
this.someIntField = someIntField;
}
public static int getMagicNumber() {
return MAGIC_NUMBER;
}