feat(test): add Tests for ReflectedMethod and BestCandidateMethod
All checks were successful
Build / Gradle-Build (push) Successful in 1m41s
Publish / Gradle-Publish (push) Successful in 10s
Test / Gradle-Test (push) Successful in 13s

This commit is contained in:
tueem 2025-04-09 17:02:55 +02:00
parent 25b2e49396
commit 2f07ac1822
Signed by: tueem
GPG Key ID: 65C8667EC17A88FB
3 changed files with 76 additions and 0 deletions

View File

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

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

View File

@ -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;
}
}