From 82a07fde25aa10847f1d29fb5576172e84c4d31b Mon Sep 17 00:00:00 2001 From: Phil Werli Date: Tue, 17 Jan 2023 07:33:56 +0100 Subject: [PATCH] Extend `MonoIdentity` Refaster rule (#465) By flagging expressions of the form `mono.flux().next()`. --- .../tech/picnic/errorprone/refasterrules/ReactorRules.java | 2 +- .../errorprone/refasterrules/ReactorRulesTestInput.java | 5 ++++- .../errorprone/refasterrules/ReactorRulesTestOutput.java | 2 +- 3 files changed, 6 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 fa8b50cb97..b4cd081f1b 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 @@ -369,7 +369,7 @@ Flux after(Flux flux, T object) { static final class MonoIdentity { @BeforeTemplate Mono before(Mono mono) { - return mono.switchIfEmpty(Mono.empty()); + return Refaster.anyOf(mono.switchIfEmpty(Mono.empty()), mono.flux().next()); } @BeforeTemplate 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 c483d1e320..3377b40e25 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 @@ -116,7 +116,10 @@ ImmutableSet> testFluxDefaultIfEmpty() { } ImmutableSet> testMonoIdentity() { - return ImmutableSet.of(Mono.just(1).switchIfEmpty(Mono.empty()), Mono.empty().then()); + return ImmutableSet.of( + Mono.just(1).switchIfEmpty(Mono.empty()), + Mono.just(2).flux().next(), + Mono.empty().then()); } ImmutableSet> testFluxSwitchIfEmptyOfEmptyPublisher() { 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 619334bab0..e5bee9e4e5 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 @@ -121,7 +121,7 @@ ImmutableSet> testFluxDefaultIfEmpty() { } ImmutableSet> testMonoIdentity() { - return ImmutableSet.of(Mono.just(1), Mono.empty()); + return ImmutableSet.of(Mono.just(1), Mono.just(2), Mono.empty()); } ImmutableSet> testFluxSwitchIfEmptyOfEmptyPublisher() {