diff options
Diffstat (limited to 'src/cz/crcs/ectester/common/test/CompoundTest.java')
| -rw-r--r-- | src/cz/crcs/ectester/common/test/CompoundTest.java | 75 |
1 files changed, 33 insertions, 42 deletions
diff --git a/src/cz/crcs/ectester/common/test/CompoundTest.java b/src/cz/crcs/ectester/common/test/CompoundTest.java index 2c851b2..607dadb 100644 --- a/src/cz/crcs/ectester/common/test/CompoundTest.java +++ b/src/cz/crcs/ectester/common/test/CompoundTest.java @@ -22,6 +22,24 @@ public class CompoundTest extends Test { } }; + private final static Consumer<Test[]> RUN_GREEDY_ALL = tests -> { + for (Test t : tests) { + t.run(); + if (!t.ok()) { + break; + } + } + }; + + private final static Consumer<Test[]> RUN_GREEDY_ANY = tests -> { + for (Test t : tests) { + t.run(); + if (t.ok()) { + break; + } + } + }; + private CompoundTest(Function<Test[], Result> resultCallback, Consumer<Test[]> runCallback, Test... tests) { this.resultCallback = resultCallback; this.runCallback = runCallback; @@ -49,7 +67,7 @@ public class CompoundTest extends Test { return new CompoundTest(callback, runCallback, description, tests); } - public static CompoundTest all(Result.ExpectedValue what, Test... all) { + 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()) { @@ -57,7 +75,11 @@ public class CompoundTest extends Test { } } return new Result(Result.Value.SUCCESS, "All sub-tests had the expected result."); - }, RUN_ALL, all); + }, runCallback, all); + } + + public static CompoundTest all(Result.ExpectedValue what, Test... all) { + return expectAll(what, RUN_ALL, all); } public static CompoundTest all(Result.ExpectedValue what, String description, Test... all) { @@ -67,21 +89,7 @@ public class CompoundTest extends Test { } public static CompoundTest greedyAll(Result.ExpectedValue what, 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."); - }, (tests) -> { - for (Test t : tests) { - t.run(); - if (!t.ok()) { - break; - } - } - }, all); + return expectAll(what, RUN_GREEDY_ALL, all); } public static CompoundTest greedyAll(Result.ExpectedValue what, String description, Test... all) { @@ -111,14 +119,7 @@ public class CompoundTest extends Test { } else { return new Result(Result.Value.SUCCESS, "All considered sub-tests had the expected result."); } - }, (tests) -> { - for (Test t : tests) { - t.run(); - if (!t.ok()) { - break; - } - } - }, all); + }, RUN_GREEDY_ALL, all); } public static CompoundTest greedyAllTry(Result.ExpectedValue what, String description, Test... all) { @@ -127,7 +128,7 @@ public class CompoundTest extends Test { return result; } - public static CompoundTest greedyAny(Result.ExpectedValue what, Test... any) { + private static CompoundTest expectAny(Result.ExpectedValue what, Consumer<Test[]> runCallback, Test[] any) { return new CompoundTest((tests) -> { for (Test test : tests) { if (Result.Value.fromExpected(what, test.ok()).ok()) { @@ -135,14 +136,11 @@ public class CompoundTest extends Test { } } return new Result(Result.Value.FAILURE, "None of the sub-tests had the expected result."); - }, (tests) -> { - for (Test t : tests) { - t.run(); - if (t.ok()) { - break; - } - } - }, any); + }, runCallback, any); + } + + public static CompoundTest greedyAny(Result.ExpectedValue what, Test... any) { + return expectAny(what, RUN_GREEDY_ANY, any); } public static CompoundTest greedyAny(Result.ExpectedValue what, String description, Test... any) { @@ -152,14 +150,7 @@ public class CompoundTest extends Test { } public static CompoundTest any(Result.ExpectedValue what, Test... any) { - return new CompoundTest((tests) -> { - for (Test test : tests) { - if (Result.Value.fromExpected(what, test.ok()).ok()) { - return new Result(Result.Value.SUCCESS, "Some sub-tests did have the expected result."); - } - } - return new Result(Result.Value.FAILURE, "None of the sub-tests had the expected result."); - }, RUN_ALL, any); + return expectAny(what, RUN_ALL, any); } public static CompoundTest any(Result.ExpectedValue what, String description, Test... any) { |
