feat(test): add Tests for ReflectedMethod and BestCandidateMethod
This commit is contained in:
parent
25b2e49396
commit
2f07ac1822
@ -0,0 +1,26 @@
|
||||
package net.tomatentum.cutin;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class ReflectedMethodTest {
|
||||
|
||||
@Test
|
||||
void methodTest() {
|
||||
ReflectedMethod<String> method = new TestReflectedMethod(new TestMethodClass());
|
||||
Object result = method.run("testContext");
|
||||
assertTrue((boolean)result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBCMethod() {
|
||||
ReflectedMethod<?> method = new BestCandidateMethod<String>(
|
||||
"test",
|
||||
new TestMethodClass(),
|
||||
"ident",
|
||||
"testString");
|
||||
Object result = method.run((double)4);
|
||||
assertTrue((boolean)result);
|
||||
}
|
||||
}
|
18
lib/src/test/java/net/tomatentum/cutin/TestMethodClass.java
Normal file
18
lib/src/test/java/net/tomatentum/cutin/TestMethodClass.java
Normal file
@ -0,0 +1,18 @@
|
||||
package net.tomatentum.cutin;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TestMethodClass {
|
||||
|
||||
boolean test(String context, int testNumber) {
|
||||
assertEquals("testContext", context);
|
||||
assertEquals(2, testNumber);
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean test(double context, String testString) {
|
||||
assertEquals(4, context);
|
||||
assertEquals("testString", testString);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package net.tomatentum.cutin;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class TestReflectedMethod extends ReflectedMethod<String> {
|
||||
|
||||
protected TestReflectedMethod(Object containingObject) {
|
||||
super(getMethod(containingObject), containingObject);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getParameter(Object context, int index) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String identifier() {
|
||||
return method().getName();
|
||||
}
|
||||
|
||||
private static Method getMethod(Object containingObject) {
|
||||
try {
|
||||
return containingObject.getClass().getDeclaredMethod("test", String.class, int.class);
|
||||
} catch (NoSuchMethodException | SecurityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user