|
|
@@ -6,9 +6,7 @@
|
|
|
*/
|
|
|
package net.ranides.assira.reflection;
|
|
|
|
|
|
-import java.lang.annotation.Annotation;
|
|
|
import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
import java.util.Set;
|
|
|
import java.util.function.BiFunction;
|
|
|
import java.util.function.Function;
|
|
|
@@ -17,8 +15,8 @@ import static net.ranides.assira.reflection.IAttribute.*;
|
|
|
import static net.ranides.assira.reflection.mockup.ForIClass.*;
|
|
|
import org.junit.Test;
|
|
|
import static net.ranides.assira.junit.NewAssert.*;
|
|
|
-import net.ranides.assira.reflection.impl.CPInspector;
|
|
|
-import org.junit.Ignore;
|
|
|
+import net.ranides.assira.reflection.mockup.MTFunction;
|
|
|
+import net.ranides.assira.reflection.mockup.MTFunction.MTRecord;
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
@@ -93,7 +91,7 @@ public class IMethodTest {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void testFunctor() {
|
|
|
+ public void testFromFunctor() {
|
|
|
int value1 = 1;
|
|
|
int[] array2 = new int[]{1,2,3,4,5};
|
|
|
@SuppressWarnings("Convert2Lambda")
|
|
|
@@ -179,6 +177,49 @@ public class IMethodTest {
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ @Test
|
|
|
+ public void testToHandle() throws Throwable {
|
|
|
+
|
|
|
+ Object that = new MTRecord(300);
|
|
|
+ IMethod m1 = IClass.typefor(that).method("sum");
|
|
|
+ IMethod m2 = IClass.typefor(that).method("mul");
|
|
|
+
|
|
|
+ MTFunction<MTRecord> f11 = (MTFunction<MTRecord>)m1.handle(MTFunction.GENERIC).invokeExact();
|
|
|
+ MTFunction<MTRecord> f12 = (MTFunction)m1.handle(MTFunction.RAW).invokeExact();
|
|
|
+
|
|
|
+ assertEquals(107, f11.calculate(new MTRecord(100), 3, 4));
|
|
|
+ assertEquals(208, f12.calculate(new MTRecord(200), 3, 5));
|
|
|
+
|
|
|
+ MTFunction<MTRecord> f21 = (MTFunction<MTRecord>)m2.handle(MTFunction.GENERIC).invokeExact();
|
|
|
+ MTFunction<MTRecord> f22 = (MTFunction)m2.handle(MTFunction.RAW).invokeExact();
|
|
|
+
|
|
|
+ assertEquals(112, f21.calculate(new MTRecord(100), 3, 4));
|
|
|
+ assertEquals(215, f22.calculate(new MTRecord(200), 3, 5));
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ @Test
|
|
|
+ public void testToFunctor() throws Throwable {
|
|
|
+
|
|
|
+ Object that = new MTRecord(300);
|
|
|
+ IMethod m1 = IClass.typefor(that).method("sum");
|
|
|
+ IMethod m2 = IClass.typefor(that).method("mul");
|
|
|
+
|
|
|
+ MTFunction<MTRecord> f11 = m1.functor(MTFunction.GENERIC);
|
|
|
+ MTFunction<MTRecord> f12 = m1.functor(MTFunction.RAW);
|
|
|
+
|
|
|
+ assertEquals(309, f11.calculate(new MTRecord(300), 3, 6));
|
|
|
+ assertEquals(410, f12.calculate(new MTRecord(400), 3, 7));
|
|
|
+
|
|
|
+ MTFunction<MTRecord> f21 = m2.functor(MTFunction.GENERIC);
|
|
|
+ MTFunction<MTRecord> f22 = m2.functor(MTFunction.RAW);
|
|
|
+
|
|
|
+ assertEquals(318, f21.calculate(new MTRecord(300), 3, 6));
|
|
|
+ assertEquals(421, f22.calculate(new MTRecord(400), 3, 7));
|
|
|
+ }
|
|
|
+
|
|
|
private void testAPI(Set<IAttribute> exp, Object function1, Object function2, Object function3, Object function4, Object function5) {
|
|
|
IMethod m1 = IMethod.function(function1);
|
|
|
IMethod m2 = IMethod.function(function2);
|