### Question:
ForkProvider { public SafeFuture<ForkInfo> getForkInfo() { return currentFork.map(SafeFuture::completedFuture).orElseGet(this::loadForkInfo); } ForkProvider(
      final AsyncRunner asyncRunner, final ValidatorApiChannel validatorApiChannel); SafeFuture<ForkInfo> getForkInfo(); SafeFuture<ForkInfo> loadForkInfo(); SafeFuture<ForkInfo> requestForkInfo(); @Override String toString();  }### Answer:
@Test public void shouldRequestForkWhenNotPreviouslyLoaded() { final SafeFuture<Optional<ForkInfo>> forkRequest = new SafeFuture<>(); when(validatorApiChannel.getForkInfo()).thenReturn(forkRequest); final SafeFuture<ForkInfo> result = forkProvider.getForkInfo(); assertThat(result).isNotDone(); forkRequest.complete(Optional.of(fork)); assertThat(result).isCompletedWithValue(fork); }
@Test public void shouldReturnCachedForkWhenPreviouslyLoaded() { when(validatorApiChannel.getForkInfo()).thenReturn(completedFuture(Optional.of(fork))); assertThat(forkProvider.getForkInfo()).isCompletedWithValue(fork); verify(validatorApiChannel).getForkInfo(); assertThat(forkProvider.getForkInfo()).isCompletedWithValue(fork); verifyNoMoreInteractions(validatorApiChannel); }
@Test public void shouldPeriodicallyRequestUpdatedFork() { final ForkInfo updatedFork = dataStructureUtil.randomForkInfo(); when(validatorApiChannel.getForkInfo()) .thenReturn(completedFuture(Optional.of(fork))) .thenReturn(completedFuture(Optional.of(updatedFork))); assertThat(forkProvider.getForkInfo()).isCompletedWithValue(fork); assertThat(asyncRunner.hasDelayedActions()).isTrue(); asyncRunner.executeQueuedActions(); assertThat(forkProvider.getForkInfo()).isCompletedWithValue(updatedFork); }
@Test public void shouldRetryWhenForkFailsToLoad() { when(validatorApiChannel.getForkInfo()) .thenReturn(failedFuture(new RuntimeException("Nope"))) .thenReturn(completedFuture(Optional.of(fork))); final SafeFuture<ForkInfo> result = forkProvider.getForkInfo(); verify(validatorApiChannel).getForkInfo(); assertThat(result).isNotDone(); assertThat(asyncRunner.hasDelayedActions()).isTrue(); asyncRunner.executeQueuedActions(); verify(validatorApiChannel, times(2)).getForkInfo(); assertThat(result).isCompletedWithValue(fork); }