From 40d43888ec0d3d459bb8e781430ca14a6d81bd2d Mon Sep 17 00:00:00 2001 From: Phil Werli Date: Sat, 16 Nov 2024 13:03:58 +0100 Subject: [PATCH 1/5] Introduce `PublisherProbeAssertWas{,Not}Subscribed` --- .../refasterrules/ReactorRules.java | 33 +++++++++++++++++++ .../refasterrules/ReactorRulesTestInput.java | 14 ++++++++ .../refasterrules/ReactorRulesTestOutput.java | 14 ++++++++ 3 files changed, 61 insertions(+) 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 404f78305c..473dc11476 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 @@ -1742,6 +1742,39 @@ PublisherProbe after() { } } + /** Prefer {@link PublisherProbe#assertWasSubscribed()} over more verbose alternatives. */ + static final class PublisherProbeAssertWasSubscribed { + @BeforeTemplate + void before(PublisherProbe probe) { + Refaster.anyOf( + assertThat(probe.wasSubscribed()).isTrue(), + assertThat(probe.subscribeCount()).isNotNegative(), + assertThat(probe.subscribeCount()).isNotZero(), + assertThat(probe.subscribeCount()).isPositive()); + } + + @AfterTemplate + void after(PublisherProbe probe) { + probe.assertWasSubscribed(); + } + } + + /** Prefer {@link PublisherProbe#assertWasNotSubscribed()} over more verbose alternatives. */ + static final class PublisherProbeAssertWasNotSubscribed { + @BeforeTemplate + void before(PublisherProbe probe) { + Refaster.anyOf( + assertThat(probe.wasSubscribed()).isFalse(), + assertThat(probe.subscribeCount()).isZero(), + assertThat(probe.subscribeCount()).isNotPositive()); + } + + @AfterTemplate + void after(PublisherProbe probe) { + probe.assertWasNotSubscribed(); + } + } + /** Prefer {@link Mono#as(Function)} when creating a {@link StepVerifier}. */ static final class StepVerifierFromMono { @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 80375ea4b4..15f09a01cc 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 @@ -44,6 +44,7 @@ public ImmutableSet elidedTypesAndStaticImports() { List.class, ImmutableCollection.class, ImmutableMap.class, + assertThat(false), assertThat(0), maxBy(null), minBy(null), @@ -589,6 +590,19 @@ ImmutableSet> testPublisherProbeEmpty() { return ImmutableSet.of(PublisherProbe.of(Mono.empty()), PublisherProbe.of(Flux.empty())); } + void testPublisherProbeAssertWasSubscribed() { + assertThat(PublisherProbe.of(Mono.just(1)).wasSubscribed()).isTrue(); + assertThat(PublisherProbe.of(Mono.just(2)).subscribeCount()).isNotNegative(); + assertThat(PublisherProbe.of(Mono.just(3)).subscribeCount()).isNotZero(); + assertThat(PublisherProbe.of(Mono.just(4)).subscribeCount()).isPositive(); + } + + void testPublisherProbeAssertWasNotSubscribed() { + assertThat(PublisherProbe.of(Mono.just(1)).wasSubscribed()).isFalse(); + assertThat(PublisherProbe.of(Mono.just(2)).subscribeCount()).isZero(); + assertThat(PublisherProbe.of(Mono.just(3)).subscribeCount()).isNotPositive(); + } + ImmutableSet> testStepVerifierFromMono() { return ImmutableSet.of( StepVerifier.create(Mono.just(1)), Mono.just(2).flux().as(StepVerifier::create)); 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 37f8f4f8eb..0a3284c257 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 @@ -47,6 +47,7 @@ public ImmutableSet elidedTypesAndStaticImports() { List.class, ImmutableCollection.class, ImmutableMap.class, + assertThat(false), assertThat(0), maxBy(null), minBy(null), @@ -577,6 +578,19 @@ ImmutableSet> testPublisherProbeEmpty() { return ImmutableSet.of(PublisherProbe.empty(), PublisherProbe.empty()); } + void testPublisherProbeAssertWasSubscribed() { + PublisherProbe.of(Mono.just(1)).assertWasSubscribed(); + PublisherProbe.of(Mono.just(2)).assertWasSubscribed(); + PublisherProbe.of(Mono.just(3)).assertWasSubscribed(); + PublisherProbe.of(Mono.just(4)).assertWasSubscribed(); + } + + void testPublisherProbeAssertWasNotSubscribed() { + PublisherProbe.of(Mono.just(1)).assertWasNotSubscribed(); + PublisherProbe.of(Mono.just(2)).assertWasNotSubscribed(); + PublisherProbe.of(Mono.just(3)).assertWasNotSubscribed(); + } + ImmutableSet> testStepVerifierFromMono() { return ImmutableSet.of( Mono.just(1).as(StepVerifier::create), Mono.just(2).as(StepVerifier::create)); From b19fe10d711e2fdae30bf24db773fb80add67ace Mon Sep 17 00:00:00 2001 From: Phil Werli Date: Sat, 16 Nov 2024 13:08:39 +0100 Subject: [PATCH 2/5] Introduce `PublisherProbeAssertWas{,Not}Cancelled` --- .../refasterrules/ReactorRules.java | 26 +++++++++++++++++++ .../refasterrules/ReactorRulesTestInput.java | 8 ++++++ .../refasterrules/ReactorRulesTestOutput.java | 8 ++++++ 3 files changed, 42 insertions(+) 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 473dc11476..c2bcc3e1a3 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 @@ -1775,6 +1775,32 @@ void after(PublisherProbe probe) { } } + /** Prefer {@link PublisherProbe#assertWasCancelled()} over more verbose alternatives. */ + static final class PublisherProbeAssertWasCancelled { + @BeforeTemplate + void before(PublisherProbe probe) { + assertThat(probe.wasCancelled()).isTrue(); + } + + @AfterTemplate + void after(PublisherProbe probe) { + probe.assertWasCancelled(); + } + } + + /** Prefer {@link PublisherProbe#assertWasNotCancelled()} over more verbose alternatives. */ + static final class PublisherProbeAssertWasNotCancelled { + @BeforeTemplate + void before(PublisherProbe probe) { + assertThat(probe.wasCancelled()).isFalse(); + } + + @AfterTemplate + void after(PublisherProbe probe) { + probe.assertWasNotCancelled(); + } + } + /** Prefer {@link Mono#as(Function)} when creating a {@link StepVerifier}. */ static final class StepVerifierFromMono { @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 15f09a01cc..38f146b3bd 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 @@ -603,6 +603,14 @@ void testPublisherProbeAssertWasNotSubscribed() { assertThat(PublisherProbe.of(Mono.just(3)).subscribeCount()).isNotPositive(); } + void testPublisherProbeAssertWasCancelled() { + assertThat(PublisherProbe.empty().wasCancelled()).isTrue(); + } + + void testPublisherProbeAssertWasNotCancelled() { + assertThat(PublisherProbe.empty().wasCancelled()).isFalse(); + } + ImmutableSet> testStepVerifierFromMono() { return ImmutableSet.of( StepVerifier.create(Mono.just(1)), Mono.just(2).flux().as(StepVerifier::create)); 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 0a3284c257..9c26d10e40 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 @@ -591,6 +591,14 @@ void testPublisherProbeAssertWasNotSubscribed() { PublisherProbe.of(Mono.just(3)).assertWasNotSubscribed(); } + void testPublisherProbeAssertWasCancelled() { + PublisherProbe.empty().assertWasCancelled(); + } + + void testPublisherProbeAssertWasNotCancelled() { + PublisherProbe.empty().assertWasNotCancelled(); + } + ImmutableSet> testStepVerifierFromMono() { return ImmutableSet.of( Mono.just(1).as(StepVerifier::create), Mono.just(2).as(StepVerifier::create)); From 49f718c0ec8b4ab6717b7a676c253955175422f6 Mon Sep 17 00:00:00 2001 From: Phil Werli Date: Sat, 16 Nov 2024 13:11:22 +0100 Subject: [PATCH 3/5] Introduce `PublisherProbeAssertWas{,Not}Requested` --- .../refasterrules/ReactorRules.java | 26 +++++++++++++++++++ .../refasterrules/ReactorRulesTestInput.java | 8 ++++++ .../refasterrules/ReactorRulesTestOutput.java | 8 ++++++ 3 files changed, 42 insertions(+) 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 c2bcc3e1a3..b68c209848 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 @@ -1801,6 +1801,32 @@ void after(PublisherProbe probe) { } } + /** Prefer {@link PublisherProbe#assertWasRequested()} over more verbose alternatives. */ + static final class PublisherProbeAssertWasRequested { + @BeforeTemplate + void before(PublisherProbe probe) { + assertThat(probe.wasRequested()).isTrue(); + } + + @AfterTemplate + void after(PublisherProbe probe) { + probe.assertWasRequested(); + } + } + + /** Prefer {@link PublisherProbe#assertWasNotRequested()} over more verbose alternatives. */ + static final class PublisherProbeAssertWasNotRequested { + @BeforeTemplate + void before(PublisherProbe probe) { + assertThat(probe.wasRequested()).isFalse(); + } + + @AfterTemplate + void after(PublisherProbe probe) { + probe.assertWasNotRequested(); + } + } + /** Prefer {@link Mono#as(Function)} when creating a {@link StepVerifier}. */ static final class StepVerifierFromMono { @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 38f146b3bd..d18617efef 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 @@ -611,6 +611,14 @@ void testPublisherProbeAssertWasNotCancelled() { assertThat(PublisherProbe.empty().wasCancelled()).isFalse(); } + void testPublisherProbeAssertWasRequested() { + assertThat(PublisherProbe.empty().wasRequested()).isTrue(); + } + + void testPublisherProbeAssertWasNotRequested() { + assertThat(PublisherProbe.empty().wasRequested()).isFalse(); + } + ImmutableSet> testStepVerifierFromMono() { return ImmutableSet.of( StepVerifier.create(Mono.just(1)), Mono.just(2).flux().as(StepVerifier::create)); 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 9c26d10e40..398fcb572a 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 @@ -599,6 +599,14 @@ void testPublisherProbeAssertWasNotCancelled() { PublisherProbe.empty().assertWasNotCancelled(); } + void testPublisherProbeAssertWasRequested() { + PublisherProbe.empty().assertWasRequested(); + } + + void testPublisherProbeAssertWasNotRequested() { + PublisherProbe.empty().assertWasNotRequested(); + } + ImmutableSet> testStepVerifierFromMono() { return ImmutableSet.of( Mono.just(1).as(StepVerifier::create), Mono.just(2).as(StepVerifier::create)); From 575304a2c61c715f735e2f295c84bc63275d7c65 Mon Sep 17 00:00:00 2001 From: Phil Werli Date: Sat, 16 Nov 2024 13:26:09 +0100 Subject: [PATCH 4/5] Don't check AssertJ's `is{,Not}Zero` That's already rewritten by `AbstractLongAssertIsZero`. --- .../tech/picnic/errorprone/refasterrules/ReactorRules.java | 4 ++-- .../errorprone/refasterrules/ReactorRulesTestInput.java | 4 ++-- 2 files changed, 4 insertions(+), 4 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 b68c209848..edbf788eed 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 @@ -1749,7 +1749,7 @@ void before(PublisherProbe probe) { Refaster.anyOf( assertThat(probe.wasSubscribed()).isTrue(), assertThat(probe.subscribeCount()).isNotNegative(), - assertThat(probe.subscribeCount()).isNotZero(), + assertThat(probe.subscribeCount()).isNotEqualTo(0), assertThat(probe.subscribeCount()).isPositive()); } @@ -1765,7 +1765,7 @@ static final class PublisherProbeAssertWasNotSubscribed { void before(PublisherProbe probe) { Refaster.anyOf( assertThat(probe.wasSubscribed()).isFalse(), - assertThat(probe.subscribeCount()).isZero(), + assertThat(probe.subscribeCount()).isEqualTo(0), assertThat(probe.subscribeCount()).isNotPositive()); } 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 d18617efef..ecfe450352 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 @@ -593,13 +593,13 @@ ImmutableSet> testPublisherProbeEmpty() { void testPublisherProbeAssertWasSubscribed() { assertThat(PublisherProbe.of(Mono.just(1)).wasSubscribed()).isTrue(); assertThat(PublisherProbe.of(Mono.just(2)).subscribeCount()).isNotNegative(); - assertThat(PublisherProbe.of(Mono.just(3)).subscribeCount()).isNotZero(); + assertThat(PublisherProbe.of(Mono.just(3)).subscribeCount()).isNotEqualTo(0); assertThat(PublisherProbe.of(Mono.just(4)).subscribeCount()).isPositive(); } void testPublisherProbeAssertWasNotSubscribed() { assertThat(PublisherProbe.of(Mono.just(1)).wasSubscribed()).isFalse(); - assertThat(PublisherProbe.of(Mono.just(2)).subscribeCount()).isZero(); + assertThat(PublisherProbe.of(Mono.just(2)).subscribeCount()).isEqualTo(0); assertThat(PublisherProbe.of(Mono.just(3)).subscribeCount()).isNotPositive(); } From d00d4d5d570b0850381f0e20363ca9debe6aa491 Mon Sep 17 00:00:00 2001 From: Phil Werli Date: Sat, 16 Nov 2024 13:31:08 +0100 Subject: [PATCH 5/5] Fix unrelated typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 838f2556c2..1826bbe3a2 100644 --- a/README.md +++ b/README.md @@ -217,7 +217,7 @@ Other highly relevant commands: - `mvn fmt:format` formats the code using [`google-java-format`][google-java-format]. - [`./run-full-build.sh`][script-run-full-build] builds the project twice, - where the second pass validates compatbility with Picnic's [Error Prone + where the second pass validates compatibility with Picnic's [Error Prone fork][error-prone-fork-repo] and compliance of the code with any rules defined within this project. (Consider running this before [opening a pull request][contributing-pull-request], as the PR checks also perform this