diff options
| author | J08nY | 2017-12-12 12:32:25 +0100 |
|---|---|---|
| committer | J08nY | 2017-12-12 12:32:25 +0100 |
| commit | 4dbc748a207bcee2c8fbe22566646b27a9f61dc0 (patch) | |
| tree | fdf069ac9a25ff82f9509826425bd4796c514da0 /src/cz/crcs/ectester/reader/test/SimpleTest.java | |
| parent | e329190e496ecf847cfd7afa886ac08cacb2fc92 (diff) | |
| parent | 9e8fbbc907f4157988ac425af4dce541f7e42328 (diff) | |
| download | ECTester-4dbc748a207bcee2c8fbe22566646b27a9f61dc0.tar.gz ECTester-4dbc748a207bcee2c8fbe22566646b27a9f61dc0.tar.zst ECTester-4dbc748a207bcee2c8fbe22566646b27a9f61dc0.zip | |
Merge branch 'feature/standalone-lib-testing' into devel
Diffstat (limited to 'src/cz/crcs/ectester/reader/test/SimpleTest.java')
| -rw-r--r-- | src/cz/crcs/ectester/reader/test/SimpleTest.java | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/src/cz/crcs/ectester/reader/test/SimpleTest.java b/src/cz/crcs/ectester/reader/test/SimpleTest.java deleted file mode 100644 index 067f43e..0000000 --- a/src/cz/crcs/ectester/reader/test/SimpleTest.java +++ /dev/null @@ -1,71 +0,0 @@ -package cz.crcs.ectester.reader.test; - -import cz.crcs.ectester.common.test.Result; -import cz.crcs.ectester.common.test.Test; -import cz.crcs.ectester.common.test.TestException; -import cz.crcs.ectester.reader.command.Command; -import cz.crcs.ectester.reader.response.Response; - -import javax.smartcardio.CardException; -import java.util.function.BiFunction; - -/** - * A simple test that runs one Command to get and evaluate one Response - * to get a Result and compare it with the expected one. - */ -public class SimpleTest extends Test { - private BiFunction<Command, Response, Result> callback; - private Command command; - private Response response; - - public SimpleTest(Command command, BiFunction<Command, Response, Result> callback) { - this.command = command; - this.callback = callback; - } - - public SimpleTest(Command command, Result.ExpectedValue expected, String ok, String nok) { - this(command, (cmd, resp) -> { - Result.Value resultValue = Result.Value.fromExpected(expected, resp.successful(), resp.error()); - return new Result(resultValue, resultValue.ok() ? ok : nok); - }); - } - - public SimpleTest(Command command, Result.ExpectedValue expected) { - this(command, expected, null, null); - } - - public Command getCommand() { - return command; - } - - public Response getResponse() { - return response; - } - - @Override - public void run() throws TestException { - if (hasRun) - return; - - try { - response = command.send(); - } catch (CardException e) { - throw new TestException(e); - } - if (callback != null) { - result = callback.apply(command, response); - } else { - if (response.successful()) { - result = new Result(Result.Value.SUCCESS); - } else { - result = new Result(Result.Value.FAILURE); - } - } - hasRun = true; - } - - @Override - public String getDescription() { - return response.getDescription(); - } -} |
