Scenario extends Observable implements Runnable { public void addPause(int length) { commands.add(productionSite1 -> sleep(length)); }  @Override void run(); void appendRunnable(Consumer<ProductionSite> runnable); void addPause(int length); void startScenario(); void cancelScenario(); boolean isRunning(); void setProductionSite(ProductionSite productionSite); void setScenarioFinishedListener(Runnable listener); void setRepeat(boolean repeat);  }
@Test public void testAddPause() { CompletableFuture<Boolean> future1 = new CompletableFuture<>(); CompletableFuture<Boolean> future2 = new CompletableFuture<>(); scenario.appendRunnable(productionSite -> future1.complete(Boolean.TRUE)); scenario.addPause(500); scenario.appendRunnable(productionSite -> future2.complete(Boolean.TRUE)); scenario.setProductionSite(fakeSite); scenario.startScenario(); try { assertTrue(future1.get(100, TimeUnit.MILLISECONDS)); assertFalse(future2.isDone()); assertTrue(scenario.isRunning()); } catch (InterruptedException | ExecutionException | TimeoutException ex) { fail("CompletableFuture.get() failed: " + ex.getMessage()); } try { sleep(300); } catch (InterruptedException ex) { System.err.println("Sleep failed in ScenarioTest: " + ex.getMessage()); } assertFalse(future2.isDone()); assertTrue(scenario.isRunning()); try { assertTrue(future2.get(300, TimeUnit.MILLISECONDS)); sleep(50); assertFalse(scenario.isRunning()); } catch (InterruptedException | ExecutionException | TimeoutException ex) { fail("CompletableFuture.get() failed: " + ex.getMessage()); } }