|
|
@@ -6,9 +6,16 @@ import lombok.RequiredArgsConstructor;
|
|
|
import net.ranides.assira.functional.Compositor.CompositorBuilder;
|
|
|
import net.ranides.assira.functional.Compositor.CompositorDecorator;
|
|
|
import net.ranides.assira.functional.Compositor.CompositorScope;
|
|
|
+import net.ranides.assira.functional.Consumers.Consumer0;
|
|
|
+import net.ranides.assira.functional.Consumers.Consumer1;
|
|
|
+import net.ranides.assira.functional.Consumers.Consumer2;
|
|
|
+import net.ranides.assira.functional.Consumers.Consumer3;
|
|
|
+import net.ranides.assira.functional.Consumers.Consumer4;
|
|
|
import net.ranides.assira.functional.Functions.*;
|
|
|
import net.ranides.assira.functional.special.AnyFunction;
|
|
|
import net.ranides.assira.junit.NewAssert;
|
|
|
+import net.ranides.assira.reflection.*;
|
|
|
+
|
|
|
import org.junit.Test;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
@@ -711,6 +718,147 @@ public class CompositorTest {
|
|
|
assertEquals(1368, compacted.apply(null).intValue());
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void coverageWithClass() {
|
|
|
+ List<String> out = new ArrayList<>();
|
|
|
+
|
|
|
+ Consumer0 consumer0 = Compositor
|
|
|
+ .compose()
|
|
|
+ .bind(() -> out.add("0#"))
|
|
|
+ .consumer();
|
|
|
+ Consumer1<String> consumer1 = Compositor
|
|
|
+ .compose()
|
|
|
+ .withParam(String.class)
|
|
|
+ .bind((a) -> out.add("1#" + a))
|
|
|
+ .consumer();
|
|
|
+ Consumer2<String, String> consumer2 = Compositor
|
|
|
+ .compose()
|
|
|
+ .withParam(String.class)
|
|
|
+ .withParam(String.class)
|
|
|
+ .bind((a, b) -> out.add("2#" + a + b))
|
|
|
+ .consumer();
|
|
|
+ Consumer3<String, String, String> consumer3 = Compositor
|
|
|
+ .compose()
|
|
|
+ .withParam(String.class)
|
|
|
+ .withParam(String.class)
|
|
|
+ .withParam(String.class)
|
|
|
+ .bind((a, b, c) -> out.add("3#" + a + b + c))
|
|
|
+ .consumer();
|
|
|
+ Consumer4<String, String, String, String> consumer4 = Compositor
|
|
|
+ .compose()
|
|
|
+ .withParam(String.class)
|
|
|
+ .withParam(String.class)
|
|
|
+ .withParam(String.class)
|
|
|
+ .withParam(String.class)
|
|
|
+ .bind((a, b, c, d) -> out.add("4#" + a + b + c + d))
|
|
|
+ .consumer();
|
|
|
+
|
|
|
+ consumer0.accept();
|
|
|
+ consumer1.accept("x");
|
|
|
+ consumer2.accept("p", "q");
|
|
|
+ consumer3.accept("a", "b", "c");
|
|
|
+ consumer4.accept("1", "2", "3", "4");
|
|
|
+
|
|
|
+ assertEquals(Arrays.asList("0#", "1#x", "2#pq", "3#abc", "4#1234"), out);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void coverageWithIClass() {
|
|
|
+ List<String> out = new ArrayList<>();
|
|
|
+
|
|
|
+ Consumer0 consumer0 = Compositor
|
|
|
+ .compose()
|
|
|
+ .bind(() -> out.add("0#"))
|
|
|
+ .consumer();
|
|
|
+ Consumer1<String> consumer1 = Compositor
|
|
|
+ .compose()
|
|
|
+ .withParam(IClass.STRING)
|
|
|
+ .bind((a) -> out.add("1#" + a))
|
|
|
+ .consumer();
|
|
|
+ Consumer2<String, String> consumer2 = Compositor
|
|
|
+ .compose()
|
|
|
+ .withParam(IClass.STRING)
|
|
|
+ .withParam(IClass.STRING)
|
|
|
+ .bind((a, b) -> out.add("2#" + a + b))
|
|
|
+ .consumer();
|
|
|
+ Consumer3<String, String, String> consumer3 = Compositor
|
|
|
+ .compose()
|
|
|
+ .withParam(IClass.STRING)
|
|
|
+ .withParam(IClass.STRING)
|
|
|
+ .withParam(IClass.STRING)
|
|
|
+ .bind((a, b, c) -> out.add("3#" + a + b + c))
|
|
|
+ .consumer();
|
|
|
+ Consumer4<String, String, String, String> consumer4 = Compositor
|
|
|
+ .compose()
|
|
|
+ .withParam(IClass.STRING)
|
|
|
+ .withParam(IClass.STRING)
|
|
|
+ .withParam(IClass.STRING)
|
|
|
+ .withParam(IClass.STRING)
|
|
|
+ .bind((a, b, c, d) -> out.add("4#" + a + b + c + d))
|
|
|
+ .consumer();
|
|
|
+
|
|
|
+ consumer0.accept();
|
|
|
+ consumer1.accept("x");
|
|
|
+ consumer2.accept("p", "q");
|
|
|
+ consumer3.accept("a", "b", "c");
|
|
|
+ consumer4.accept("1", "2", "3", "4");
|
|
|
+
|
|
|
+ assertEquals(Arrays.asList("0#", "1#x", "2#pq", "3#abc", "4#1234"), out);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void coverageSource() {
|
|
|
+ List<String> out = new ArrayList<>();
|
|
|
+ List<String> raw = new ArrayList<>();
|
|
|
+
|
|
|
+ CompositorDecorator<Void, Object, Object> decorator = new CompositorDecorator<Void, Object, Object>() {
|
|
|
+ @Override
|
|
|
+ public AnyFunction<Object> before(CompositorBuilder<Object, Object> function) {
|
|
|
+ return (args) -> raw.add("(" + function.source().apply(args) + ")");
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ Consumer0 consumer0 = Compositor
|
|
|
+ .compose(decorator)
|
|
|
+ .bind(() -> out.add("0#"))
|
|
|
+ .consumer();
|
|
|
+ Consumer1<String> consumer1 = Compositor
|
|
|
+ .compose(decorator)
|
|
|
+ .withParam(IClass.STRING)
|
|
|
+ .bind((a) -> out.add("1#" + a))
|
|
|
+ .consumer();
|
|
|
+ Consumer2<String, String> consumer2 = Compositor
|
|
|
+ .compose(decorator)
|
|
|
+ .withParam(IClass.STRING)
|
|
|
+ .withParam(IClass.STRING)
|
|
|
+ .bind((a, b) -> out.add("2#" + a + b))
|
|
|
+ .consumer();
|
|
|
+ Consumer3<String, String, String> consumer3 = Compositor
|
|
|
+ .compose(decorator)
|
|
|
+ .withParam(IClass.STRING)
|
|
|
+ .withParam(IClass.STRING)
|
|
|
+ .withParam(IClass.STRING)
|
|
|
+ .bind((a, b, c) -> out.add("3#" + a + b + c))
|
|
|
+ .consumer();
|
|
|
+ Consumer4<String, String, String, String> consumer4 = Compositor
|
|
|
+ .compose(decorator)
|
|
|
+ .withParam(IClass.STRING)
|
|
|
+ .withParam(IClass.STRING)
|
|
|
+ .withParam(IClass.STRING)
|
|
|
+ .withParam(IClass.STRING)
|
|
|
+ .bind((a, b, c, d) -> out.add("4#" + a + b + c + d))
|
|
|
+ .consumer();
|
|
|
+
|
|
|
+ consumer0.accept();
|
|
|
+ consumer1.accept("x");
|
|
|
+ consumer2.accept("p", "q");
|
|
|
+ consumer3.accept("a", "b", "c");
|
|
|
+ consumer4.accept("1", "2", "3", "4");
|
|
|
+
|
|
|
+ assertEquals(Arrays.asList("0#", "1#x", "2#pq", "3#abc", "4#1234"), out);
|
|
|
+ assertEquals(Arrays.asList("(true)", "(true)", "(true)", "(true)", "(true)"), raw);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@Test
|
|
|
public void testConditionalEvaluation() {
|