TimeoutBudget { public boolean hasTimeLeft() { return clock.instant().isBefore(endTime); } TimeoutBudget(Clock clock, Duration duration); Duration timeout(); Duration timeLeft(); boolean hasTimeLeft(); boolean hasTimeLeft(String step); String timesUsed(); void assertNotTimedOut(Supplier<String> exceptionMessage);  }
@Test public void testHasTimeLeft() { ManualClock clock = new ManualClock(); TimeoutBudget budget = new TimeoutBudget(clock, Duration.ofMillis(7)); assertThat(budget.hasTimeLeft(), is(true)); clock.advance(Duration.ofMillis(1)); assertThat(budget.hasTimeLeft(), is(true)); clock.advance(Duration.ofMillis(5)); assertThat(budget.hasTimeLeft(), is(true)); assertThat(budget.hasTimeLeft(), is(true)); clock.advance(Duration.ofMillis(1)); assertThat(budget.hasTimeLeft(), is(false)); clock.advance(Duration.ofMillis(5)); assertThat(budget.hasTimeLeft(), is(false)); clock.advance(Duration.ofMillis(1)); assertThat(budget.timesUsed(), is("[total: 13 ms]")); }