From 7f9ec035e8f4fa6139b57949a4be5f37c5445ad3 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Sun, 4 Dec 2022 13:55:02 +0100 Subject: [PATCH] Suggestions --- .../refasterrules/ReactorRules.java | 26 ++++++++++++++----- .../refasterrules/ReactorRulesTestInput.java | 11 +++++--- .../refasterrules/ReactorRulesTestOutput.java | 8 ++++-- 3 files changed, 32 insertions(+), 13 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 94d80a5c87..06b2d97f40 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 @@ -64,7 +64,7 @@ Mono after(Supplier supplier) { static final class MonoEmpty { @BeforeTemplate Mono before() { - return Refaster.anyOf(Mono.just(null), Mono.justOrEmpty(null)); + return Refaster.anyOf(Mono.justOrEmpty(null), Mono.justOrEmpty(Optional.empty())); } @AfterTemplate @@ -73,16 +73,28 @@ Mono after() { } } - /** Prefer {@link Mono#justOrEmpty(Optional)} over more contrived alternatives. */ - static final class MonoJustOrEmpty { + /** Prefer {@link Mono#just(Object)} over more contrived alternatives. */ + static final class MonoJust { @BeforeTemplate - @SuppressWarnings("NullAway") - Mono before(@Nullable T value) { - return Mono.justOrEmpty(Refaster.anyOf(Optional.of(value), Optional.ofNullable(value))); + Mono before(T value) { + return Mono.justOrEmpty(Optional.of(value)); } @AfterTemplate - Mono after(@Nullable T value) { + Mono after(T value) { + return Mono.just(value); + } + } + + /** Prefer {@link Mono#justOrEmpty(Object)} over more contrived alternatives. */ + static final class MonoJustOrEmpty<@Nullable T> { + @BeforeTemplate + Mono before(T value) { + return Mono.justOrEmpty(Optional.ofNullable(value)); + } + + @AfterTemplate + Mono after(T value) { return Mono.justOrEmpty(value); } } 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 e187eb487f..ab1abfc97c 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 @@ -35,12 +35,15 @@ ImmutableSet> testMonoFromSupplier() { } ImmutableSet> testMonoEmpty() { - return ImmutableSet.of(Mono.just(null), Mono.justOrEmpty(null)); + return ImmutableSet.of(Mono.justOrEmpty(null), Mono.justOrEmpty(Optional.empty())); } - ImmutableSet> testMonoJustOrEmpty() { - return ImmutableSet.of( - Mono.justOrEmpty(Optional.of(1)), Mono.justOrEmpty(Optional.ofNullable(2))); + Mono testMonoJust() { + return Mono.justOrEmpty(Optional.of(1)); + } + + Mono testMonoJustOrEmpty() { + return Mono.justOrEmpty(Optional.ofNullable(1)); } ImmutableSet> testMonoFromOptional() { 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 c143647f84..33edca43a6 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 @@ -41,8 +41,12 @@ ImmutableSet> testMonoEmpty() { return ImmutableSet.of(Mono.empty(), Mono.empty()); } - ImmutableSet> testMonoJustOrEmpty() { - return ImmutableSet.of(Mono.justOrEmpty(1), Mono.justOrEmpty(2)); + Mono testMonoJust() { + return Mono.just(1); + } + + Mono testMonoJustOrEmpty() { + return Mono.justOrEmpty(1); } ImmutableSet> testMonoFromOptional() {