summaryrefslogtreecommitdiff
path: root/src/cz/crcs/ectester/reader/test/Test.java
diff options
context:
space:
mode:
authorJ08nY2017-11-05 16:48:30 +0100
committerJ08nY2017-11-05 16:48:30 +0100
commitdaaa7abd91ff8ae12e0b1835045489acbda0539f (patch)
tree1a2a944473285359a9af3691f2ce69b608264f12 /src/cz/crcs/ectester/reader/test/Test.java
parent16f20afbff36a7e048d24d7e7d1db8657f002c5e (diff)
downloadECTester-daaa7abd91ff8ae12e0b1835045489acbda0539f.tar.gz
ECTester-daaa7abd91ff8ae12e0b1835045489acbda0539f.tar.zst
ECTester-daaa7abd91ff8ae12e0b1835045489acbda0539f.zip
Implement Result.ExpectedValue to add more logic to test evaluation.
- Introduces a new enum Result.ExpectedValue, which is used to signify what Test results are expected. - Changes the Result.Value enum to contain information about what was expected. It gains more values: - UXSUCCESS -> Unexpected success. - XFAILURE -> Expected failure. The values SUCCESS and XFAILURE are the OK, values. - Creates a hierarchy of evaluating Responses, Simple tests and Compoung tests. Simple test evaluates the OK property of the response object (using .successfull() method) and again exposes its OK property which depends on the tests ExpectedValue and the response success. Compound test evaluates the OK property of the Simple tests it contains (using the .ok() method) and again exposes its OK property which depends on the concrete Compound test variant, but involves some ExpectedValues and the success of the individual Simple tests it contains.
Diffstat (limited to 'src/cz/crcs/ectester/reader/test/Test.java')
-rw-r--r--src/cz/crcs/ectester/reader/test/Test.java38
1 files changed, 21 insertions, 17 deletions
diff --git a/src/cz/crcs/ectester/reader/test/Test.java b/src/cz/crcs/ectester/reader/test/Test.java
index 3848df2..48280ed 100644
--- a/src/cz/crcs/ectester/reader/test/Test.java
+++ b/src/cz/crcs/ectester/reader/test/Test.java
@@ -7,6 +7,7 @@ import javax.smartcardio.CardException;
import java.util.function.BiFunction;
import java.util.function.Function;
+import static cz.crcs.ectester.reader.test.Result.ExpectedValue;
import static cz.crcs.ectester.reader.test.Result.Value;
/**
@@ -39,6 +40,13 @@ public abstract class Test {
return result.getCause();
}
+ public boolean ok() {
+ if (!hasRun) {
+ return true;
+ }
+ return result.ok();
+ }
+
public abstract String getDescription();
public boolean hasRun() {
@@ -61,18 +69,14 @@ public abstract class Test {
this.callback = callback;
}
- public Simple(Command command, Value expected, String ok, String nok) {
+ public Simple(Command command, ExpectedValue expected, String ok, String nok) {
this(command, (cmd, resp) -> {
- if (expected == Value.ANY) {
- return new Result(Value.SUCCESS, ok);
- }
- Value respResult = resp.successful() ? Value.SUCCESS : Value.FAILURE;
- boolean cond = expected == respResult;
- return new Result(cond ? Value.SUCCESS : Value.FAILURE, cond ? ok : nok);
+ Value resultValue = Value.fromExpected(expected, resp.successful());
+ return new Result(resultValue, resultValue.ok() ? ok : nok);
});
}
- public Simple(Command command, Value expected) {
+ public Simple(Command command, ExpectedValue expected) {
this(command, expected, null, null);
}
@@ -134,10 +138,10 @@ public abstract class Test {
return new Compound(callback, description, tests);
}
- public static Compound all(Value what, Test... all) {
+ public static Compound all(ExpectedValue what, Test... all) {
return new Compound((tests) -> {
for (Test test : tests) {
- if (test.getResultValue() != what) {
+ if (!Value.fromExpected(what, test.ok()).ok()) {
return new Result(Value.FAILURE, "At least one of the sub-tests did not have the expected result.");
}
}
@@ -145,16 +149,16 @@ public abstract class Test {
}, all);
}
- public static Compound all(Value what, String description, Test... all) {
+ public static Compound all(ExpectedValue what, String description, Test... all) {
Compound result = Compound.all(what, all);
result.setDescription(description);
return result;
}
- public static Compound any(Value what, Test... any) {
+ public static Compound any(ExpectedValue what, Test... any) {
return new Compound((tests) -> {
for (Test test : tests) {
- if (test.getResultValue() == what) {
+ if (Value.fromExpected(what, test.ok()).ok()) {
return new Result(Value.SUCCESS, "At least one of the sub-tests did have the expected result.");
}
}
@@ -162,16 +166,16 @@ public abstract class Test {
}, any);
}
- public static Compound any(Value what, String description, Test... any) {
+ public static Compound any(ExpectedValue what, String description, Test... any) {
Compound result = Compound.any(what, any);
result.setDescription(description);
return result;
}
- public static Compound mask(Value[] results, Test... masked) {
+ public static Compound mask(ExpectedValue[] results, Test... masked) {
return new Compound((tests) -> {
for (int i = 0; i < results.length; ++i) {
- if (results[i] != Value.ANY && results[i] != tests[i].getResultValue()) {
+ if (!Value.fromExpected(results[i], tests[i].ok()).ok()) {
return new Result(Value.FAILURE, "At least one of the sub-tests did not match the result mask.");
}
}
@@ -179,7 +183,7 @@ public abstract class Test {
}, masked);
}
- public static Compound mask(Value[] results, String description, Test... masked) {
+ public static Compound mask(ExpectedValue[] results, String description, Test... masked) {
Compound result = Compound.mask(results, masked);
result.setDescription(description);
return result;