From 69a4116df7b54ddfdaba2f8aa80ecb9e9a2ed9a7 Mon Sep 17 00:00:00 2001 From: J08nY Date: Wed, 25 Oct 2017 18:58:52 +0200 Subject: Simplify test contract. --- src/cz/crcs/ectester/reader/test/Test.java | 35 ++++++++++++------------------ 1 file changed, 14 insertions(+), 21 deletions(-) (limited to 'src/cz/crcs/ectester/reader/test/Test.java') diff --git a/src/cz/crcs/ectester/reader/test/Test.java b/src/cz/crcs/ectester/reader/test/Test.java index f873c19..1890e94 100644 --- a/src/cz/crcs/ectester/reader/test/Test.java +++ b/src/cz/crcs/ectester/reader/test/Test.java @@ -29,8 +29,6 @@ public abstract class Test { return hasRun; } - public abstract boolean ok(); - public abstract void run() throws CardException; @@ -49,17 +47,20 @@ public abstract class Test { */ public static class Simple extends Test { private BiFunction callback; - private Result expected; private Command command; private Response response; public Simple(Command command, Result expected) { - this.command = command; - this.expected = expected; + this(command, (cmd, resp) -> { + if (expected == Result.ANY) + return Result.SUCCESS; + Result respResult = resp.successful() ? Result.SUCCESS : Result.FAILURE; + return respResult == expected ? Result.SUCCESS : Result.FAILURE; + }); } - public Simple(Command command, Result expected, BiFunction callback) { - this(command, expected); + public Simple(Command command, BiFunction callback) { + this.command = command; this.callback = callback; } @@ -71,17 +72,11 @@ public abstract class Test { return response; } - public Result getExpected() { - return expected; - } - - @Override - public boolean ok() { - return result == expected || expected == Result.ANY; - } - @Override public void run() throws CardException { + if (hasRun) + return; + response = command.send(); if (callback != null) { result = callback.apply(command, response); @@ -182,13 +177,11 @@ public abstract class Test { return tests; } - @Override - public boolean ok() { - return result == Result.SUCCESS; - } - @Override public void run() throws CardException { + if (hasRun) + return; + for (Test test : tests) { test.run(); } -- cgit v1.2.3-70-g09d2