Introduce MonoSingle Refaster rule (#703)

This commit is contained in:
Rick Ossendrijver
2023-07-05 13:54:49 +02:00
committed by GitHub
parent 08c49b9a58
commit 006665ee6d
3 changed files with 21 additions and 0 deletions

View File

@@ -418,6 +418,19 @@ final class ReactorRules {
}
}
/** 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

View File

@@ -145,6 +145,10 @@ final class ReactorRulesTest implements RefasterRuleCollectionTestCase {
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()));

View File

@@ -150,6 +150,10 @@ final class ReactorRulesTest implements RefasterRuleCollectionTestCase {
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));
}