-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
core/src/test/java/com/kloudtek/util/ReflectionUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.kloudtek.util; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.omg.CORBA.OBJ_ADAPTER; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class ReflectionUtilsTest { | ||
@Test | ||
public void testConvertObjectToMap() throws InvocationTargetException, IllegalAccessException { | ||
Map<String, Object> map = ReflectionUtils.objectToMap(new TestObj1()); | ||
HashMap<String, Object> expected = new HashMap<>(); | ||
expected.put("text","text"); | ||
expected.put("nb", 0); | ||
expected.put("varNull",null); | ||
expected.put("optVar","foo"); | ||
expected.put("optVarNull",null); | ||
expected.put("obj2null",null); | ||
HashMap<String, Object> expectedSubMap = new HashMap<>(); | ||
expectedSubMap.put("var1",false); | ||
expectedSubMap.put("var2","ccc"); | ||
expected.put("obj2NonNull",expectedSubMap); | ||
Assert.assertEquals(expected,map); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.kloudtek.util; | ||
|
||
import java.util.Optional; | ||
|
||
public class TestObj1 { | ||
private String text = "text"; | ||
private String varNull; | ||
private int nb; | ||
private TestObj2 obj2NonNull = new TestObj2(); | ||
private TestObj2 obj2null; | ||
private Optional<String> optVar = Optional.of("foo"); | ||
private Optional<String> optVarNull = Optional.ofNullable(null); | ||
|
||
public String getText() { | ||
return text; | ||
} | ||
|
||
public int getNb() { | ||
return nb; | ||
} | ||
|
||
public TestObj2 getObj2NonNull() { | ||
return obj2NonNull; | ||
} | ||
|
||
public TestObj2 getObj2null() { | ||
return obj2null; | ||
} | ||
|
||
public Optional<String> getOptVar() { | ||
return optVar; | ||
} | ||
|
||
public Optional<String> getOptVarNull() { | ||
return optVarNull; | ||
} | ||
|
||
public String getVarNull() { | ||
return varNull; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.kloudtek.util; | ||
|
||
import java.util.Optional; | ||
|
||
public class TestObj2 { | ||
private boolean var1 = false; | ||
private String var2 = "ccc"; | ||
|
||
public boolean isVar1() { | ||
return var1; | ||
} | ||
|
||
public String getVar2() { | ||
return var2; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters