boolean (@NotNull BooleanSupplier awaitCondition, long timeoutMillis) { CountDownLatch latch = new CountDownLatch(1); AtomicBoolean ok = new AtomicBoolean(false); TerminalModelListener listener = new TerminalModelListener() { @Override public void modelChanged() { if (awaitCondition.getAsBoolean()) { ok.set(true); latch.countDown(); } } }; myBuffer.addModelListener(listener); if (awaitCondition.getAsBoolean()) { myBuffer.removeModelListener(listener); return true; } try { latch.await(timeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { LOG.debug("Could not get response in " + timeoutMillis + "ms. Terminal screen lines are: " + getScreenLines()); throw new AssertionError(e); } finally { myBuffer.removeModelListener(listener); } return ok.get(); }