public void waitAtMost(long patience) throws Exception { long waitedSoFar = 0; while (!endCondition()) { Thread.sleep(200); waitedSoFar += 200; if (waitedSoFar > patience) { throw new AssertionError("Waited more than " + patience + " on a test condition."); } } } }