Skip to content

Commit

Permalink
Introduce MonoSingle Refaster rule
Browse files Browse the repository at this point in the history
  • Loading branch information
rickie committed Jul 5, 2023
1 parent 08c49b9 commit c51b070
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,22 @@ Mono<T> after(Mono<T> mono) {
}
}

/**
* Don't unnecessarily transform a {@link Mono} to a {@link Flux} before calling {@link
* Mono#single()}.
*/
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 c51b070

Please sign in to comment.