SfcGeniusSfStatesReader { public CompletableFuture<List<SfpName>> readSfpNames(List<SfName> sfNames) { SfcGeniusSfStateReader sfStateReader = getSfStateReader(); return sfNames.stream() .map(sfStateReader::readSfpNames) .map(futureList -> futureList.thenApply(List::stream)) .reduce(CompletableFuture.completedFuture(Stream.empty()), (f1, f2) -> f1.thenCombine(f2, Stream::concat)) .thenApply(s -> s.distinct().collect(Collectors.toList())); } SfcGeniusSfStatesReader(ReadTransaction readTransaction, Executor executor); CompletableFuture<List<SfpName>> readSfpNames(List<SfName> sfNames);  }
@Test public void readSfpNames() throws Exception { when(sfcGeniusSfStateReader.readSfpNames(new SfName("SF1"))).thenReturn( CompletableFuture.completedFuture(Arrays.asList(new SfpName("SFP1"), new SfpName("SFP2"))) ); when(sfcGeniusSfStateReader.readSfpNames(new SfName("SF2"))).thenReturn( CompletableFuture.completedFuture(Arrays.asList(new SfpName("SFP2"), new SfpName("SFP3"))) ); doReturn(sfcGeniusSfStateReader).when(sfcGeniusSfStatesReader).getSfStateReader(); List<SfpName> sfpNames = sfcGeniusSfStatesReader.readSfpNames(Arrays.asList(new SfName("SF1"), new SfName("SF2"))).get(); assertThat(sfpNames.size(), is(3)); assertThat(sfpNames, containsInAnyOrder(new SfpName("SFP1"), new SfpName("SFP2"), new SfpName("SFP3"))); }