### Question:
StateTransferManager { @VisibleForTesting ImmutableList<Long> getUnknownAddressesInRange(long rangeStart, long rangeEnd) { Set<Long> knownAddresses = CFUtils.getUninterruptibly(logUnitClient .requestKnownAddresses(rangeStart, rangeEnd)) .getKnownAddresses(); return LongStream.range(rangeStart, rangeEnd + 1L) .filter(address -> !knownAddresses.contains(address)) .boxed() .collect(ImmutableList.toImmutableList()); }  ImmutableList<TransferSegment> handleTransfer(List<TransferSegmentRange> beforeTransferRanges);  }### Answer:
@Test void testGetUnknownAddressesInRangeTimeOutException() { LogUnitClient client = mock(LogUnitClient.class); BasicTransferProcessor mock1 = mock(BasicTransferProcessor.class); ParallelTransferProcessor mock2 = mock(ParallelTransferProcessor.class); long rangeStart = 0L; long rangeEnd = 1000L; doAnswer(invoke -> { throw new RuntimeException(new TimeoutException()); }).when(client).requestKnownAddresses(rangeStart, rangeEnd); StateTransferManager configuredInstance = getConfiguredInstance(client, mock1, mock2); assertThatThrownBy(() -> configuredInstance.getUnknownAddressesInRange(rangeStart, rangeEnd)) .isInstanceOf(RuntimeException.class) .hasRootCauseInstanceOf(TimeoutException.class); }
@Test void testGetUnknownAddressesInRangeNetworkException() { LogUnitClient client = mock(LogUnitClient.class); BasicTransferProcessor mock1 = mock(BasicTransferProcessor.class); ParallelTransferProcessor mock2 = mock(ParallelTransferProcessor.class); long rangeStart = 0L; long rangeEnd = 1000L; doAnswer(invoke -> { throw new RuntimeException(new NetworkException("localhost", NodeLocator.builder().host("localhost").build())); }).when(client).requestKnownAddresses(rangeStart, rangeEnd); StateTransferManager configuredInstance = getConfiguredInstance(client, mock1, mock2); assertThatThrownBy(() -> configuredInstance.getUnknownAddressesInRange(rangeStart, rangeEnd)) .isInstanceOf(RuntimeException.class) .hasRootCauseInstanceOf(NetworkException.class); }
@Test void testGetUnknownAddressesInRangeWrongEpochException() { LogUnitClient client = mock(LogUnitClient.class); BasicTransferProcessor mock1 = mock(BasicTransferProcessor.class); ParallelTransferProcessor mock2 = mock(ParallelTransferProcessor.class); long rangeStart = 0L; long rangeEnd = 1000L; doAnswer(invoke -> { throw new RuntimeException(new WrongEpochException(1L)); }).when(client).requestKnownAddresses(rangeStart, rangeEnd); StateTransferManager configuredInstance = getConfiguredInstance(client, mock1, mock2); assertThatThrownBy(() -> configuredInstance.getUnknownAddressesInRange(rangeStart, rangeEnd)) .isInstanceOf(RuntimeException.class) .hasRootCauseInstanceOf(WrongEpochException.class); }
@Test void testGetUnknownAddressesInRange() { LogUnitClient client = mock(LogUnitClient.class); BasicTransferProcessor mock1 = mock(BasicTransferProcessor.class); ParallelTransferProcessor mock2 = mock(ParallelTransferProcessor.class); long rangeStart = 0L; long rangeEnd = 1000L; Set<Long> known = LongStream.range(0L, 501L).boxed().collect(Collectors.toSet()); doReturn(CompletableFuture.completedFuture(new KnownAddressResponse(known))).when(client) .requestKnownAddresses(rangeStart, rangeEnd); StateTransferManager configuredInstance = getConfiguredInstance(client, mock1, mock2); ImmutableList<Long> unknown = LongStream.range(501L, 1001L).boxed() .collect(ImmutableList.toImmutableList()); assertThat(configuredInstance.getUnknownAddressesInRange(rangeStart, rangeEnd)) .isEqualTo(unknown); }