diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index 2b36c5ee9de..9b20ea23cb3 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -1328,11 +1328,13 @@ StepVerifier.Step after(StepVerifier.Step step, T object) { } } - /** Avoid value collection when verifying that a {@link Flux} emits exactly one value. */ - static final class FluxAsStepVerifierExpectNext { + /** Avoid list collection when verifying that a {@link Flux} emits exactly one value. */ + // XXX: This rule assumes that the matched collector does not drop elements. Consider introducing + // a `@Matches(DoesNotDropElements.class)` or `@NotMatches(MayDropElements.class)` guard. + static final class FluxAsStepVerifierExpectNext> { @BeforeTemplate - StepVerifier.Step> before(Flux flux, T object) { - return flux.collect(toImmutableList()) + StepVerifier.Step before(Flux flux, Collector listCollector, T object) { + return flux.collect(listCollector) .as(StepVerifier::create) .assertNext(list -> assertThat(list).containsExactly(object)); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index 07bfd9d45d8..4bb35ca921e 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -422,12 +422,16 @@ ImmutableSet> testStepVerifierStepExpectNext() { StepVerifier.create(Mono.just("baz")).expectNextMatches("qux"::equals)); } - Duration testFluxAsStepVerifierExpectNext() { - return Flux.just(1) - .collect(toImmutableList()) - .as(StepVerifier::create) - .assertNext(list -> assertThat(list).containsExactly(2)) - .verifyComplete(); + ImmutableSet> testFluxAsStepVerifierExpectNext() { + return ImmutableSet.of( + Flux.just(1) + .collect(toImmutableList()) + .as(StepVerifier::create) + .assertNext(list -> assertThat(list).containsExactly(2)), + Flux.just(3) + .collect(toCollection(ArrayList::new)) + .as(StepVerifier::create) + .assertNext(list -> assertThat(list).containsExactly(4))); } Duration testStepVerifierLastStepVerifyComplete() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index 7d6cb098983..099daa1bd6a 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -413,8 +413,10 @@ ImmutableSet> testStepVerifierStepExpectNext() { StepVerifier.create(Mono.just("baz")).expectNext("qux")); } - Duration testFluxAsStepVerifierExpectNext() { - return Flux.just(1).as(StepVerifier::create).expectNext(2).verifyComplete(); + ImmutableSet> testFluxAsStepVerifierExpectNext() { + return ImmutableSet.of( + Flux.just(1).as(StepVerifier::create).expectNext(2), + Flux.just(3).as(StepVerifier::create).expectNext(4)); } Duration testStepVerifierLastStepVerifyComplete() {