@Override public void run() { if (clock.getCurrentTime() >= endTime) { loadTimeoutCallback.onLoadTimeout(); cancel(); } else { handler.postDelayed(this, DELAY_MILLIS); } } };
@Test public void givenTimeoutIsReached_whenStarting_thenOnLoadTimeoutIsCalled() { when(clock.getCurrentTime()).thenReturn(START_TIME, END_TIME); loadTimeout.start(TIMEOUT_REACHED, loadTimeoutCallback); verify(loadTimeoutCallback).onLoadTimeout(); }