Compare commits

...

1 Commits

Author SHA1 Message Date
Rick Ossendrijver
13339421e5 Add test case for flagging POJOs while that is not valid 2022-08-19 15:40:30 +02:00
2 changed files with 34 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ import static com.google.errorprone.matchers.ChildMultiMatcher.MatchType.ALL;
import static com.google.errorprone.matchers.ChildMultiMatcher.MatchType.AT_LEAST_ONE;
import static com.google.errorprone.matchers.Matchers.annotations;
import static com.google.errorprone.matchers.Matchers.anyOf;
import static com.google.errorprone.matchers.Matchers.isPrimitiveOrBoxedPrimitiveType;
import static com.google.errorprone.matchers.Matchers.isSameType;
import static com.google.errorprone.matchers.Matchers.isType;
import static com.google.errorprone.matchers.Matchers.methodHasParameters;
@@ -19,6 +20,7 @@ import com.google.errorprone.bugpatterns.BugChecker;
import com.google.errorprone.bugpatterns.BugChecker.MethodTreeMatcher;
import com.google.errorprone.matchers.Description;
import com.google.errorprone.matchers.Matcher;
import com.google.errorprone.util.ASTHelpers;
import com.sun.source.tree.MethodTree;
import com.sun.source.tree.Tree;

View File

@@ -129,4 +129,36 @@ final class RequestMappingAnnotationTest {
"}")
.doTest();
}
// XXX:
// https://tedblob.com/spring-boot-bind-request-parameters-to-object/#2-3-use-pojo-to-bind-multiple-parameters
// https://stackoverflow.com/questions/33157785/in-java-is-there-any-way-to-tell-if-a-class-is-a-simple-java-class
@Test
void identificationIgnorePOJO() {
compilationTestHelper
.addSourceLines(
"com/example/Person.java",
"package com.example;",
"",
" public final class Person {",
" final String name;",
" final int age;",
"",
" Person(String name, int age) {",
" this.name = name;",
" this.age = age;",
" }",
" }")
.addSourceLines(
"com/example/A.java",
"package com.example;",
"",
"import org.springframework.web.bind.annotation.GetMapping;",
"",
"class A {",
" @GetMapping(\"foo\")",
" public void pojoShouldNotBeFlagged(Person person) {}",
"}")
.doTest();
}
}