Skip to content

Commit

Permalink
Suggestions for identification test
Browse files Browse the repository at this point in the history
  • Loading branch information
rickie committed Aug 19, 2022
1 parent ad67fe9 commit d858ec2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.errorprone.util.ASTHelpers;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.MethodInvocationTree;
import java.util.function.BiFunction;
import reactor.core.publisher.Mono;
import tech.picnic.errorprone.bugpatterns.util.SourceCode;

Expand Down Expand Up @@ -62,6 +63,10 @@ public final class NonEmptyMono extends BugChecker implements MethodInvocationTr
"last",
"reduceWith",
"single"),
instanceMethod()
.onDescendantOf("reactor.core.publisher.Flux")
.named("reduce")
.withParameters(Object.class.getName(), BiFunction.class.getName()),
instanceMethod()
.onDescendantOf("reactor.core.publisher.Mono")
.namedAnyOf("defaultIfEmpty", "hasElement", "single"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,48 @@ void identification() {
"class A {",
" void m() {",
" // BUG: Diagnostic contains:",
" Flux.just().all(x -> true).defaultIfEmpty(true);",
" Flux.just(1).all(x -> true).defaultIfEmpty(true);",
" // BUG: Diagnostic contains:",
" Flux.just().any(x -> true).single();",
" Flux.just(1).any(x -> true).single();",
"",
" // BUG: Diagnostic contains:",
" Flux.just().collect(toImmutableList()).switchIfEmpty(Mono.just(ImmutableList.of()));",
" Flux.just(1).collect(toImmutableList()).switchIfEmpty(Mono.just(ImmutableList.of()));",
" // BUG: Diagnostic contains:",
" Flux.just().collectList().defaultIfEmpty(ImmutableList.of());",
" Flux.just(1).collectList().defaultIfEmpty(ImmutableList.of());",
" // BUG: Diagnostic contains:",
" Flux.just().collectMap(identity()).single();",
" Flux.just()",
" Flux.just(1).collectMap(identity()).single();",
" Flux.just(1)",
" .collectMultimap(identity(), identity(), ImmutableMap::of)",
" // BUG: Diagnostic contains:",
" .switchIfEmpty(Mono.just(ImmutableMap.of()));",
" // BUG: Diagnostic contains:",
" Flux.just().collectSortedList((o1, o2) -> 1).defaultIfEmpty(ImmutableList.of());",
" Flux.just(1).collectSortedList((o1, o2) -> 1).defaultIfEmpty(ImmutableList.of());",
"",
" // BUG: Diagnostic contains:",
" Flux.just().count().single();",
" Flux.just(1).count().single();",
" // BUG: Diagnostic contains:",
" Flux.just(1).elementAt(0).defaultIfEmpty(1);",
" // BUG: Diagnostic contains:",
" Flux.just(1).hasElement(0).single();",
" // BUG: Diagnostic contains:",
" Flux.just(1).hasElements().switchIfEmpty(Mono.just(true));",
" // BUG: Diagnostic contains:",
" Flux.just().elementAt(0).defaultIfEmpty(1);",
" Flux.just(1).last().defaultIfEmpty(1);",
" // BUG: Diagnostic contains:",
" Flux.just().hasElement(0).single();",
" Flux.just(1).reduceWith(() -> 1, (x, y) -> x).single();",
" // BUG: Diagnostic contains:",
" Flux.just().hasElements().switchIfEmpty(Mono.just(true));",
" Flux.just(1).single().switchIfEmpty(Mono.just(1));",
"",
" Flux.just(1).reduce(Integer::sum).single();",
" // BUG: Diagnostic contains:",
" Flux.just(1).reduce(2, Integer::sum).single();",
"",
" // BUG: Diagnostic contains:",
" Flux.just().last().defaultIfEmpty(1);",
" Mono.just(1).defaultIfEmpty(1).defaultIfEmpty(2);",
" // BUG: Diagnostic contains:",
" Flux.just().reduceWith(() -> 1, (x, y) -> x).single();",
" Mono.just(1).hasElement().single();",
" // BUG: Diagnostic contains:",
" Flux.just().single().switchIfEmpty(Mono.just(1));",
" Mono.just(1).single().switchIfEmpty(Mono.just(2));",
" }",
"}")
.doTest();
Expand Down

0 comments on commit d858ec2

Please sign in to comment.