Skip to content

Commit

Permalink
Introduce Reactor MonoJustRepeatTakeOne Refaster rule
Browse files Browse the repository at this point in the history
  • Loading branch information
tijana-ninkovic authored and rickie committed Jul 20, 2024
1 parent 4b1c892 commit 246735f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,19 @@ PublisherProbe<T> after() {
}
}

/** Prefer {@link Flux#just(Object)} over more verbose alternatives. */
static final class MonoJustRepeatTakeOne<T> {
@BeforeTemplate
Flux<T> before(T value) {
return Mono.just(value).repeat().take(1);
}

@AfterTemplate
Flux<T> after(T value) {
return Flux.just(value);
}
}

/** Prefer {@link Mono#as(Function)} when creating a {@link StepVerifier}. */
static final class StepVerifierFromMono<T> {
@BeforeTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,10 @@ ImmutableSet<PublisherProbe<Void>> testPublisherProbeEmpty() {
return ImmutableSet.of(PublisherProbe.of(Mono.empty()), PublisherProbe.of(Flux.empty()));
}

Flux<Integer> testMonoJustRepeatTakeOne() {
return Mono.just(5).repeat().take(1);
}

ImmutableSet<StepVerifier.FirstStep<Integer>> testStepVerifierFromMono() {
return ImmutableSet.of(
StepVerifier.create(Mono.just(1)), Mono.just(2).flux().as(StepVerifier::create));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,10 @@ ImmutableSet<PublisherProbe<Void>> testPublisherProbeEmpty() {
return ImmutableSet.of(PublisherProbe.empty(), PublisherProbe.empty());
}

Flux<Integer> testMonoJustRepeatTakeOne() {
return Flux.just(5);
}

ImmutableSet<StepVerifier.FirstStep<Integer>> testStepVerifierFromMono() {
return ImmutableSet.of(
Mono.just(1).as(StepVerifier::create), Mono.just(2).as(StepVerifier::create));
Expand Down

0 comments on commit 246735f

Please sign in to comment.