0

добавлен тест на generic method

This commit is contained in:
2021-01-08 16:27:20 +03:00
parent aab3b43e57
commit cc1592f8e3
2 changed files with 30 additions and 0 deletions

View File

@@ -139,6 +139,23 @@ public class ReflectionObjectTest {
assertNotNull(refMethod); 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) @Test(expected = ReflectionException.class)
public void method_notExists() { public void method_notExists() {
ReflectionObject refObj = new ReflectionObject(new SomeObject()); ReflectionObject refObj = new ReflectionObject(new SomeObject());

View 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);
}
}