diff --git a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/completablefuture/CombiningCompletableFuturesUnitTest.java b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/completablefuture/CombiningCompletableFuturesUnitTest.java index a12c0c88d1..d52d8eef16 100644 --- a/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/completablefuture/CombiningCompletableFuturesUnitTest.java +++ b/core-java-modules/core-java-concurrency-2/src/test/java/com/baeldung/concurrent/completablefuture/CombiningCompletableFuturesUnitTest.java @@ -30,7 +30,7 @@ public class CombiningCompletableFuturesUnitTest { assertEquals(123L, resultFuture.get()); } - private static Stream givenMicroserviceClient_whenMultipleCreateResource_thenCombineResults() { + private static Stream clientData() { return Stream.of( Arguments.of(List.of("Good Resource"), 1, 0), Arguments.of(List.of("Bad Resource"), 0, 1), @@ -40,7 +40,7 @@ public class CombiningCompletableFuturesUnitTest { } @ParameterizedTest - @MethodSource + @MethodSource("clientData") public void givenMicroserviceClient_whenMultipleCreateResource_thenCombineResults(List inputs, int expectedSuccess, int expectedFailure) throws ExecutionException, InterruptedException { MicroserviceClient mockMicroservice = mock(MicroserviceClient.class); when(mockMicroservice.createResource("Good Resource")).thenReturn(CompletableFuture.completedFuture(123L)); @@ -50,7 +50,10 @@ public class CombiningCompletableFuturesUnitTest { for (String resource : inputs) { clientCalls.add(mockMicroservice.createResource(resource)); } - CompletableFuture.allOf(clientCalls.toArray(new CompletableFuture[inputs.size()])).exceptionally(ex -> null).join(); + CompletableFuture[] clientCallsAsArray = clientCalls.toArray(new CompletableFuture[inputs.size()]); + CompletableFuture.allOf(clientCallsAsArray) + .exceptionally(ex -> null) + .join(); Map>> resultsByFailure = clientCalls.stream().collect(Collectors.partitioningBy(CompletableFuture::isCompletedExceptionally)); assertThat(resultsByFailure.getOrDefault(false, Collections.emptyList()).size()).isEqualTo(expectedSuccess); assertThat(resultsByFailure.getOrDefault(true, Collections.emptyList()).size()).isEqualTo(expectedFailure);