RestoreRedundancyOperationImpl implements RestoreRedundancyOperation { RestoreRedundancyResults getRestoreRedundancyResults( List<CompletableFuture<RestoreRedundancyResults>> regionFutures) { SerializableRestoreRedundancyResultsImpl finalResult = getEmptyRestoreRedundancyResults(); regionFutures.stream() .map(CompletableFuture::join) .forEach(finalResult::addRegionResults); return finalResult; } RestoreRedundancyOperationImpl(InternalCache cache); @Override RestoreRedundancyOperation includeRegions(Set<String> regions); @Override RestoreRedundancyOperation excludeRegions(Set<String> regions); @Override RestoreRedundancyOperation shouldReassignPrimaries(boolean shouldReassign); @Override CompletableFuture<RestoreRedundancyResults> start(); @Override RestoreRedundancyResults redundancyStatus();  }
@Test @SuppressWarnings("unchecked") public void getRestoreRedundancyResultsReturnsCombinedResultsFromAllFutures() { CompletableFuture<RestoreRedundancyResults> future1 = mock(CompletableFuture.class); RestoreRedundancyResults result1 = mock(RestoreRedundancyResults.class); when(future1.join()).thenReturn(result1); CompletableFuture<RestoreRedundancyResults> future2 = mock(CompletableFuture.class); RestoreRedundancyResults result2 = mock(RestoreRedundancyResults.class); when(future2.join()).thenReturn(result2); List<CompletableFuture<RestoreRedundancyResults>> futures = new ArrayList<>(); futures.add(future1); futures.add(future2); operation.getRestoreRedundancyResults(futures); verify(emptyResults, times(1)).addRegionResults(result1); verify(emptyResults, times(1)).addRegionResults(result2); }