добавлен тест на generic method
This commit is contained in:
@@ -139,6 +139,23 @@ public class ReflectionObjectTest {
|
||||
assertNotNull(refMethod);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void method_generic() {
|
||||
SomeGenericObject<String, Integer> someGenericObject = new SomeGenericObject<>();
|
||||
String key = "KEY!";
|
||||
int value = 3306;
|
||||
|
||||
ReflectionObject refObj = new ReflectionObject(someGenericObject);
|
||||
|
||||
ReflectionMethod refMethod = refObj.method("genericMethod", Object.class, Object.class);
|
||||
assertNotNull(refMethod);
|
||||
|
||||
refMethod.invoke(key, value);
|
||||
assertFalse(someGenericObject.map.isEmpty());
|
||||
assertTrue(someGenericObject.map.containsKey(key));
|
||||
assertEquals(value, (int) someGenericObject.map.get(key));
|
||||
}
|
||||
|
||||
@Test(expected = ReflectionException.class)
|
||||
public void method_notExists() {
|
||||
ReflectionObject refObj = new ReflectionObject(new SomeObject());
|
||||
|
||||
13
src/test/java/ru/dmitriymx/reflection/SomeGenericObject.java
Normal file
13
src/test/java/ru/dmitriymx/reflection/SomeGenericObject.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package ru.dmitriymx.reflection;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SomeGenericObject<K, V> {
|
||||
|
||||
public Map<K, V> map = new HashMap<>();
|
||||
|
||||
public void genericMethod(K key, V value) {
|
||||
map.put(key, value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user