mirror of
https://github.com/jlengrand/error-prone-support.git
synced 2026-03-10 08:11:25 +00:00
Introduce MonoSingle Refaster rule
This commit is contained in:
@@ -418,6 +418,22 @@ final class ReactorRules {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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)}. */
|
/** Don't unnecessarily pass an empty publisher to {@link Flux#switchIfEmpty(Publisher)}. */
|
||||||
static final class FluxSwitchIfEmptyOfEmptyPublisher<T> {
|
static final class FluxSwitchIfEmptyOfEmptyPublisher<T> {
|
||||||
@BeforeTemplate
|
@BeforeTemplate
|
||||||
|
|||||||
@@ -145,6 +145,10 @@ final class ReactorRulesTest implements RefasterRuleCollectionTestCase {
|
|||||||
Mono.<ImmutableList<String>>empty().map(ImmutableList::copyOf));
|
Mono.<ImmutableList<String>>empty().map(ImmutableList::copyOf));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Mono<Integer> testMonoSingle() {
|
||||||
|
return Mono.just(1).flux().single();
|
||||||
|
}
|
||||||
|
|
||||||
ImmutableSet<Flux<Integer>> testFluxSwitchIfEmptyOfEmptyPublisher() {
|
ImmutableSet<Flux<Integer>> testFluxSwitchIfEmptyOfEmptyPublisher() {
|
||||||
return ImmutableSet.of(
|
return ImmutableSet.of(
|
||||||
Flux.just(1).switchIfEmpty(Mono.empty()), Flux.just(2).switchIfEmpty(Flux.empty()));
|
Flux.just(1).switchIfEmpty(Mono.empty()), Flux.just(2).switchIfEmpty(Flux.empty()));
|
||||||
|
|||||||
@@ -150,6 +150,10 @@ final class ReactorRulesTest implements RefasterRuleCollectionTestCase {
|
|||||||
Mono.<ImmutableList<String>>empty());
|
Mono.<ImmutableList<String>>empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Mono<Integer> testMonoSingle() {
|
||||||
|
return Mono.just(1).single();
|
||||||
|
}
|
||||||
|
|
||||||
ImmutableSet<Flux<Integer>> testFluxSwitchIfEmptyOfEmptyPublisher() {
|
ImmutableSet<Flux<Integer>> testFluxSwitchIfEmptyOfEmptyPublisher() {
|
||||||
return ImmutableSet.of(Flux.just(1), Flux.just(2));
|
return ImmutableSet.of(Flux.just(1), Flux.just(2));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user