aboutsummaryrefslogtreecommitdiff
path: root/common/src/main/java/cz/crcs/ectester/common/test
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/main/java/cz/crcs/ectester/common/test')
-rw-r--r--common/src/main/java/cz/crcs/ectester/common/test/CompoundTest.java38
-rw-r--r--common/src/main/java/cz/crcs/ectester/common/test/TestSuite.java2
2 files changed, 28 insertions, 12 deletions
diff --git a/common/src/main/java/cz/crcs/ectester/common/test/CompoundTest.java b/common/src/main/java/cz/crcs/ectester/common/test/CompoundTest.java
index ba4ad4f..e5d68dc 100644
--- a/common/src/main/java/cz/crcs/ectester/common/test/CompoundTest.java
+++ b/common/src/main/java/cz/crcs/ectester/common/test/CompoundTest.java
@@ -2,6 +2,7 @@ package cz.crcs.ectester.common.test;
import java.util.Arrays;
import java.util.Objects;
+import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
@@ -16,13 +17,35 @@ public class CompoundTest extends Test implements Cloneable {
private Test[] tests;
private String description = "";
- private final static Consumer<Test[]> RUN_ALL = tests -> {
+ public final static BiFunction<Result.ExpectedValue, Test[], Result> EXPECT_ALL = (what, tests) -> {
+ for (Test test : tests) {
+ if (!Result.Value.fromExpected(what, test.ok()).ok()) {
+ return new Result(Result.Value.FAILURE, "Some sub-tests did not have the expected result.");
+ }
+ }
+ return new Result(Result.Value.SUCCESS, "All sub-tests had the expected result.");
+ };
+
+ public final static Function<Test[], Result> EXPECT_ALL_SUCCESS = tests -> EXPECT_ALL.apply(Result.ExpectedValue.SUCCESS, tests);
+ public final static Function<Test[], Result> EXPECT_ALL_FAILURE = tests -> EXPECT_ALL.apply(Result.ExpectedValue.FAILURE, tests);
+ public final static Function<Test[], Result> EXPECT_ALL_ANY = tests -> EXPECT_ALL.apply(Result.ExpectedValue.ANY, tests);
+
+ public final static Consumer<Test[]> RUN_ALL = tests -> {
for (Test t : tests) {
t.run();
}
};
- private final static Consumer<Test[]> RUN_GREEDY_ALL = tests -> {
+ public final static Consumer<Test[]> RUN_ALL_IF_FIRST = tests -> {
+ tests[0].run();
+ if (tests[0].getResult().getValue().equals(Result.Value.SUCCESS) || tests[0].getResult().getValue().equals(Result.Value.UXSUCCESS)) {
+ for (int i = 1; i < tests.length; i++) {
+ tests[i].run();
+ }
+ }
+ };
+
+ public final static Consumer<Test[]> RUN_GREEDY_ALL = tests -> {
for (Test t : tests) {
t.run();
if (!t.ok()) {
@@ -31,7 +54,7 @@ public class CompoundTest extends Test implements Cloneable {
}
};
- private final static Consumer<Test[]> RUN_GREEDY_ANY = tests -> {
+ public final static Consumer<Test[]> RUN_GREEDY_ANY = tests -> {
for (Test t : tests) {
t.run();
if (t.ok()) {
@@ -68,14 +91,7 @@ public class CompoundTest extends Test implements Cloneable {
}
private static CompoundTest expectAll(Result.ExpectedValue what, Consumer<Test[]> runCallback, Test[] all) {
- return new CompoundTest((tests) -> {
- for (Test test : tests) {
- if (!Result.Value.fromExpected(what, test.ok()).ok()) {
- return new Result(Result.Value.FAILURE, "Some sub-tests did not have the expected result.");
- }
- }
- return new Result(Result.Value.SUCCESS, "All sub-tests had the expected result.");
- }, runCallback, all);
+ return new CompoundTest((tests) -> EXPECT_ALL.apply(what, tests), runCallback, all);
}
public static CompoundTest all(Result.ExpectedValue what, Test... all) {
diff --git a/common/src/main/java/cz/crcs/ectester/common/test/TestSuite.java b/common/src/main/java/cz/crcs/ectester/common/test/TestSuite.java
index 091b008..0f2b1b0 100644
--- a/common/src/main/java/cz/crcs/ectester/common/test/TestSuite.java
+++ b/common/src/main/java/cz/crcs/ectester/common/test/TestSuite.java
@@ -53,7 +53,7 @@ public abstract class TestSuite {
* @return The test that was run.
* @throws TestException
*/
- protected <T extends Test> T runTest(T t) {
+ private <T extends Test> T runTest(T t) {
running = t;
writer.beginTest(t);
t.run();