diff --git a/voting-booth/src/test/java/meerkat/voting/NetworkVirtualPrinterTest.java b/voting-booth/src/test/java/meerkat/voting/NetworkVirtualPrinterTest.java index 827bf93..80c9b72 100644 --- a/voting-booth/src/test/java/meerkat/voting/NetworkVirtualPrinterTest.java +++ b/voting-booth/src/test/java/meerkat/voting/NetworkVirtualPrinterTest.java @@ -37,6 +37,7 @@ public class NetworkVirtualPrinterTest { private static final String SUB_ADDRESS = ""; private static final int PORT = 8080; + private Semaphore semaphore0; private Semaphore semaphore1; private Semaphore semaphore2; private Throwable thrown; @@ -45,6 +46,9 @@ public class NetworkVirtualPrinterTest { private NetworkVirtualPrinter networkPrinter; + + + private class ScanHandler implements FutureCallback { private final ScannedData expectedData; @@ -70,9 +74,11 @@ public class NetworkVirtualPrinterTest { private class CommitHandler extends OutputDeviceCommitCallback { private boolean success; + public String errorMessage; public CommitHandler(int requestId, long serialNumber) { super(requestId, serialNumber, null, null); + errorMessage = null; success = false; } @@ -80,11 +86,13 @@ public class NetworkVirtualPrinterTest { public void onSuccess(Void v) { System.out.println("CommitHandler success"); success = true; + semaphore0.release(); } @Override public void onFailure(Throwable t) { - assertThat("Commit to ballot failed " + t.getMessage(), false); + errorMessage = "Commit to ballot failed " + t.getMessage(); + semaphore0.release(); } public boolean gotSuccess() { @@ -95,9 +103,11 @@ public class NetworkVirtualPrinterTest { private class CastHandler extends OutputDeviceFinalizeCallback { private boolean success; + public String errorMessage; public CastHandler(int requestId, long serialNumber) { super(requestId, serialNumber, null, null); + errorMessage = null; success = false; } @@ -110,8 +120,8 @@ public class NetworkVirtualPrinterTest { @Override public void onFailure(Throwable t) { + errorMessage = "Cast to ballot failed " + t.getMessage(); semaphore1.release(); - assertThat("Cast ballot failed " + t.getMessage(), false); } public boolean gotSuccess() { @@ -126,6 +136,7 @@ public class NetworkVirtualPrinterTest { scanner = new PollingStationWebScanner(PORT, SUB_ADDRESS); + semaphore0 = new Semaphore(0); semaphore1 = new Semaphore(0); semaphore2 = new Semaphore(0); thrown = null; @@ -136,11 +147,11 @@ public class NetworkVirtualPrinterTest { assertThat("Could not start server: " + e.getMessage(), false); } + networkPrinter = new NetworkVirtualPrinter(ADDRESS + ":" + PORT); Thread outputThread = new Thread(networkPrinter); outputThread.setName("Meerkat VB-Output Thread"); outputThread.start(); - } @Test @@ -191,12 +202,14 @@ public class NetworkVirtualPrinterTest { CommitHandler commitHandler = new CommitHandler(0, serialNumber); networkPrinter.commitToBallot(plaintextBallot, signedEncryptedBallot, commitHandler); + + semaphore0.acquire(); + CastHandler castHandler = new CastHandler(1, serialNumber); networkPrinter.castBallot(castHandler); - - semaphore1.acquire(); + semaphore2.acquire(); // Make sure the response was valid