Skip to content

Commit

Permalink
Add a test for invalid flags
Browse files Browse the repository at this point in the history
  • Loading branch information
chamil-prabodha committed Dec 28, 2022
1 parent 5f70f62 commit 2cf48d9
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ private static ImmutableList<String> includedClassNames(ErrorProneFlags flags) {
private static ImmutableList<Matcher<Tree>> getSupportedClasses(
ImmutableList<String> inclusions) {
return inclusions.stream()
.filter(inclusion -> !inclusion.isEmpty())
.map(String::trim)
.filter(inclusion -> !inclusion.isEmpty())
.map(inclusion -> isSubtypeOf(createClass(inclusion)))
.collect(toImmutableList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ final class RequestParamTypeTest {
.setArgs(
ImmutableList.of(
"-XepOpt:RequestParamType:Includes=com.google.common.collect.ImmutableSet"));
private final CompilationTestHelper restrictedWithInvalidFlagCompilationTestHelper =
CompilationTestHelper.newInstance(RequestParamType.class, getClass())
.setArgs(ImmutableList.of("-XepOpt:RequestParamType:Includes="));

@Test
void identification() {
Expand Down Expand Up @@ -167,4 +170,61 @@ void identificationOfIncludedSubClass() {
"}")
.doTest();
}

@Test
void identificationOfInvalidFlag() {
restrictedWithInvalidFlagCompilationTestHelper
.addSourceLines(
"A.java",
"import com.google.common.collect.ImmutableBiMap;",
"import com.google.common.collect.ImmutableList;",
"import com.google.common.collect.ImmutableMap;",
"import com.google.common.collect.ImmutableSet;",
"import java.util.List;",
"import java.util.Map;",
"import java.util.Set;",
"import org.jspecify.annotations.Nullable;",
"import org.springframework.web.bind.annotation.DeleteMapping;",
"import org.springframework.web.bind.annotation.GetMapping;",
"import org.springframework.web.bind.annotation.PostMapping;",
"import org.springframework.web.bind.annotation.PutMapping;",
"import org.springframework.web.bind.annotation.RequestBody;",
"import org.springframework.web.bind.annotation.RequestParam;",
"",
"interface A {",
" @PostMapping",
" A properRequestParam(@RequestBody String body);",
"",
" @GetMapping",
" A properRequestParam(@RequestParam int param);",
"",
" @GetMapping",
" A properRequestParam(@RequestParam List<String> param);",
"",
" @PostMapping",
" A properRequestParam(@RequestBody String body, @RequestParam Set<String> param);",
"",
" @PutMapping",
" A properRequestParam(@RequestBody String body, @RequestParam Map<String, String> param);",
"",
" @GetMapping",
" // BUG: Diagnostic contains:",
" A get(@RequestParam ImmutableBiMap<String, String> param);",
"",
" @PostMapping",
" // BUG: Diagnostic contains:",
" A post(@Nullable @RequestParam ImmutableList<String> param);",
"",
" @PutMapping",
" // BUG: Diagnostic contains:",
" A put(@RequestBody String body, @RequestParam ImmutableSet<String> param);",
"",
" @DeleteMapping",
" // BUG: Diagnostic contains:",
" A delete(@RequestBody String body, @RequestParam ImmutableMap<String, String> param);",
"",
" void negative(ImmutableSet<Integer> set, ImmutableMap<String, String> map);",
"}")
.doTest();
}
}

0 comments on commit 2cf48d9

Please sign in to comment.