diff options
| author | J08nY | 2017-10-13 21:42:49 +0200 |
|---|---|---|
| committer | J08nY | 2017-10-13 21:42:49 +0200 |
| commit | e78bd5d010bd6ced2b71d83b88748f9cc8d98d5e (patch) | |
| tree | 4b08c9788158a1ef87d226c7b1d5b691d91a0aed /src/cz/crcs/ectester/reader/test/Test.java | |
| parent | d5a549b382db10c34eea35e571b1ba8056eaa5da (diff) | |
| download | ECTester-e78bd5d010bd6ced2b71d83b88748f9cc8d98d5e.tar.gz ECTester-e78bd5d010bd6ced2b71d83b88748f9cc8d98d5e.tar.zst ECTester-e78bd5d010bd6ced2b71d83b88748f9cc8d98d5e.zip | |
Reorganize reader packages.
Diffstat (limited to 'src/cz/crcs/ectester/reader/test/Test.java')
| -rw-r--r-- | src/cz/crcs/ectester/reader/test/Test.java | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/cz/crcs/ectester/reader/test/Test.java b/src/cz/crcs/ectester/reader/test/Test.java new file mode 100644 index 0000000..e22e0a4 --- /dev/null +++ b/src/cz/crcs/ectester/reader/test/Test.java @@ -0,0 +1,85 @@ +package cz.crcs.ectester.reader.test; + +import cz.crcs.ectester.reader.command.Command; +import cz.crcs.ectester.reader.response.Response; + +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() { + 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; + } + + public boolean hasRun() { + return hasRun; + } + + @Override + public String toString() { + if (hasRun) { + return (ok() ? "OK " : "NOK") + " " + response.toString(); + } else { + return ""; + } + } + + public enum Result { + SUCCESS, + FAILURE, + ANY + } +} |
