aboutsummaryrefslogtreecommitdiff
path: root/src/cz/crcs/ectester/reader/Test.java
diff options
context:
space:
mode:
authorJ08nY2017-04-19 01:10:17 +0200
committerJ08nY2017-04-19 01:10:17 +0200
commita7eef06134bef0861e43261640d61153ebb2a6e5 (patch)
tree2ef308843b4e8b1770be6681c15b98dcd78d40ff /src/cz/crcs/ectester/reader/Test.java
parentf4a66768ed6dfcfd7156ad0c8c364cdbf6e45e9c (diff)
downloadECTester-a7eef06134bef0861e43261640d61153ebb2a6e5.tar.gz
ECTester-a7eef06134bef0861e43261640d61153ebb2a6e5.tar.zst
ECTester-a7eef06134bef0861e43261640d61153ebb2a6e5.zip
Diffstat (limited to 'src/cz/crcs/ectester/reader/Test.java')
-rw-r--r--src/cz/crcs/ectester/reader/Test.java81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/cz/crcs/ectester/reader/Test.java b/src/cz/crcs/ectester/reader/Test.java
new file mode 100644
index 0000000..78efef5
--- /dev/null
+++ b/src/cz/crcs/ectester/reader/Test.java
@@ -0,0 +1,81 @@
+package cz.crcs.ectester.reader;
+
+import javax.smartcardio.CardException;
+import java.util.function.BiFunction;
+
+/**
+ * @author Jan Jancar johny@neuromancer.sk
+ */
+public class Test {
+ private boolean hasRun = false;
+ private BiFunction<Command, Response, Result> callback;
+ private Result result;
+ private Result expected;
+ private Command command;
+ private Response response;
+
+ public Test(Command command, Result expected) {
+ this.command = command;
+ this.expected = expected;
+ }
+
+ public Test(Command command, Result expected, BiFunction<Command, Response, Result> callback) {
+ this(command, expected);
+ this.callback = callback;
+ }
+
+ public Command getCommand() {
+ return command;
+ }
+
+ public Response getResponse() {
+ if (!hasRun) {
+ return null;
+ }
+ return response;
+ }
+
+ public Result getResult() {
+ if (!hasRun) {
+ return null;
+ }
+ return result;
+ }
+
+ public Result getExpected() {
+ return expected;
+ }
+
+ public boolean ok() {
+ return result == expected || expected == Result.ANY;
+ }
+
+ public void run() throws CardException {
+ response = command.send();
+ if (callback != null) {
+ result = callback.apply(command, response);
+ } else {
+ if (response.successful()) {
+ result = Result.SUCCESS;
+ } else {
+ result = Result.FAILURE;
+ }
+ }
+ hasRun = true;
+ }
+
+ @Override
+ public String toString() {
+ if (hasRun) {
+ return (ok() ? "OK " : "NOK") + " " + response.toString();
+ } else {
+ return "";
+ }
+ }
+
+ public enum Result {
+ SUCCESS,
+ FAILURE,
+ ANY
+ }
+}