Skip to content

Commit

Permalink
Introduce MonoSingle Refaster rule (#703)
Browse files Browse the repository at this point in the history
  • Loading branch information
rickie authored Jul 5, 2023
1 parent 08c49b9 commit 006665e
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 @@ -418,6 +418,19 @@ Mono<T> after(Mono<T> mono) {
}
}

/** Don't unnecessarily transform a {@link Mono} to a {@link Flux} to expect exactly one item. */
static final class MonoSingle<T> {
@BeforeTemplate
Mono<T> before(Mono<T> mono) {
return mono.flux().single();
}

@AfterTemplate
Mono<T> after(Mono<T> mono) {
return mono.single();
}
}

/** Don't unnecessarily pass an empty publisher to {@link Flux#switchIfEmpty(Publisher)}. */
static final class FluxSwitchIfEmptyOfEmptyPublisher<T> {
@BeforeTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ ImmutableSet<Mono<?>> testMonoIdentity() {
Mono.<ImmutableList<String>>empty().map(ImmutableList::copyOf));
}

Mono<Integer> testMonoSingle() {
return Mono.just(1).flux().single();
}

ImmutableSet<Flux<Integer>> testFluxSwitchIfEmptyOfEmptyPublisher() {
return ImmutableSet.of(
Flux.just(1).switchIfEmpty(Mono.empty()), Flux.just(2).switchIfEmpty(Flux.empty()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ ImmutableSet<Mono<?>> testMonoIdentity() {
Mono.<ImmutableList<String>>empty());
}

Mono<Integer> testMonoSingle() {
return Mono.just(1).single();
}

ImmutableSet<Flux<Integer>> testFluxSwitchIfEmptyOfEmptyPublisher() {
return ImmutableSet.of(Flux.just(1), Flux.just(2));
}
Expand Down

0 comments on commit 006665e

Please sign in to comment.