From c72898dc758b5045971284880dac329b6710ff7d Mon Sep 17 00:00:00 2001 From: Phil Werli Date: Fri, 18 Nov 2022 15:27:42 +0100 Subject: [PATCH 1/3] Extend `MonoFlux` Refaster rule --- .../tech/picnic/errorprone/refasterrules/ReactorRules.java | 2 +- .../errorprone/refasterrules/ReactorRulesTestInput.java | 4 ++-- .../errorprone/refasterrules/ReactorRulesTestOutput.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) 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 382f1b1cde..0d334758cc 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 @@ -559,7 +559,7 @@ Flux after(Flux flux) { static final class MonoFlux { @BeforeTemplate Flux before(Mono mono) { - return Flux.concat(mono); + return Refaster.anyOf(Flux.concat(mono), mono.flatMapMany(Flux::just)); } @AfterTemplate 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 b56708a238..1ff6c35908 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 @@ -178,8 +178,8 @@ ImmutableSet> testFluxMapNotNull() { Flux.just(1).switchMap(n -> Mono.fromSupplier(() -> n * 2))); } - Flux testMonoFlux() { - return Flux.concat(Mono.just("foo")); + ImmutableSet> testMonoFlux() { + return ImmutableSet.of(Flux.concat(Mono.just("foo")), Mono.just("bar").flatMapMany(Flux::just)); } ImmutableSet>> testMonoCollectToOptional() { 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 03a6788e54..bb10ccb9bc 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 @@ -180,8 +180,8 @@ ImmutableSet> testFluxMapNotNull() { Flux.just(1).mapNotNull(n -> n * 2)); } - Flux testMonoFlux() { - return Mono.just("foo").flux(); + ImmutableSet> testMonoFlux() { + return ImmutableSet.of(Mono.just("foo").flux(), Mono.just("bar").flux()); } ImmutableSet>> testMonoCollectToOptional() { From 600963f4f412e0cbd4f3cdf08276a9f858ecfbbc Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Sat, 19 Nov 2022 10:39:40 +0100 Subject: [PATCH 2/3] Different order --- .../java/tech/picnic/errorprone/refasterrules/ReactorRules.java | 2 +- .../picnic/errorprone/refasterrules/ReactorRulesTestInput.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 0d334758cc..e28d95677c 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 @@ -559,7 +559,7 @@ Flux after(Flux flux) { static final class MonoFlux { @BeforeTemplate Flux before(Mono mono) { - return Refaster.anyOf(Flux.concat(mono), mono.flatMapMany(Flux::just)); + return Refaster.anyOf(mono.flatMapMany(Flux::just), Flux.concat(mono)); } @AfterTemplate 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 1ff6c35908..8d023fa979 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 @@ -179,7 +179,7 @@ ImmutableSet> testFluxMapNotNull() { } ImmutableSet> testMonoFlux() { - return ImmutableSet.of(Flux.concat(Mono.just("foo")), Mono.just("bar").flatMapMany(Flux::just)); + return ImmutableSet.of(Mono.just("foo").flatMapMany(Flux::just), Flux.concat(Mono.just("bar"))); } ImmutableSet>> testMonoCollectToOptional() { From ed20fa8b8027d60291cdc6a35bbdb63f1ed1677d Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Sat, 19 Nov 2022 10:58:29 +0100 Subject: [PATCH 3/3] Suggestion --- .../tech/picnic/errorprone/refasterrules/ReactorRules.java | 3 ++- .../errorprone/refasterrules/ReactorRulesTestInput.java | 5 ++++- .../errorprone/refasterrules/ReactorRulesTestOutput.java | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) 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 e28d95677c..c7715d6e3f 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 @@ -559,7 +559,8 @@ Flux after(Flux flux) { static final class MonoFlux { @BeforeTemplate Flux before(Mono mono) { - return Refaster.anyOf(mono.flatMapMany(Flux::just), Flux.concat(mono)); + return Refaster.anyOf( + mono.flatMapMany(Mono::just), mono.flatMapMany(Flux::just), Flux.concat(mono)); } @AfterTemplate 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 8d023fa979..f8218770f7 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 @@ -179,7 +179,10 @@ ImmutableSet> testFluxMapNotNull() { } ImmutableSet> testMonoFlux() { - return ImmutableSet.of(Mono.just("foo").flatMapMany(Flux::just), Flux.concat(Mono.just("bar"))); + return ImmutableSet.of( + Mono.just("foo").flatMapMany(Mono::just), + Mono.just("bar").flatMapMany(Flux::just), + Flux.concat(Mono.just("baz"))); } ImmutableSet>> testMonoCollectToOptional() { 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 bb10ccb9bc..7b91b7701f 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 @@ -181,7 +181,8 @@ ImmutableSet> testFluxMapNotNull() { } ImmutableSet> testMonoFlux() { - return ImmutableSet.of(Mono.just("foo").flux(), Mono.just("bar").flux()); + return ImmutableSet.of( + Mono.just("foo").flux(), Mono.just("bar").flux(), Mono.just("baz").flux()); } ImmutableSet>> testMonoCollectToOptional() {