1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.puppycrawl.tools.checkstyle.filters;
21
22 import static com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck.MSG_KEY;
23 import static com.puppycrawl.tools.checkstyle.checks.regexp.RegexpCheck.MSG_ILLEGAL_REGEXP;
24
25 import org.junit.jupiter.api.Test;
26
27 import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport;
28 import com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck;
29 import com.puppycrawl.tools.checkstyle.checks.naming.MemberNameCheck;
30 import com.puppycrawl.tools.checkstyle.checks.regexp.RegexpCheck;
31 import com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceAfterCheck;
32
33 public class SuppressionSingleFilterExamplesTest extends AbstractExamplesModuleTestSupport {
34 @Override
35 protected String getPackageLocation() {
36 return "com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter";
37 }
38
39 @Test
40 public void testExample1() throws Exception {
41 final String[] expectedWithoutFilter = {
42 "21:17: " + getCheckMessage(MagicNumberCheck.class, MSG_KEY, "100"),
43 };
44 final String[] expectedWithFilter = {};
45
46 verifyFilterWithInlineConfigParser(getPath("Example1.java"),
47 expectedWithoutFilter, expectedWithFilter);
48 }
49
50 @Test
51 public void testExample2() throws Exception {
52 final String[] expectedWithoutFilter = {
53 "19:12: " + getCheckMessage(NoWhitespaceAfterCheck.class,
54 NoWhitespaceAfterCheck.MSG_KEY, "."),
55 "23:9: " + getCheckMessage(NoWhitespaceAfterCheck.class,
56 NoWhitespaceAfterCheck.MSG_KEY, "int"),
57 };
58 final String[] expectedWithFilter = {
59 "23:9: " + getCheckMessage(NoWhitespaceAfterCheck.class,
60 NoWhitespaceAfterCheck.MSG_KEY, "int"),
61 };
62
63 verifyFilterWithInlineConfigParser(getPath("Example2.java"),
64 expectedWithoutFilter, expectedWithFilter);
65 }
66
67 @Test
68 public void testExample3() throws Exception {
69 final String[] expectedWithoutFilter = {
70 "19: " + getCheckMessage(RegexpCheck.class, MSG_ILLEGAL_REGEXP, "example"),
71 "4: " + getCheckMessage(RegexpCheck.class, MSG_ILLEGAL_REGEXP, "example"),
72 };
73 final String[] expectedWithFilter = {};
74
75 verifyFilterWithInlineConfigParser(getPath("Example3.java"),
76 expectedWithoutFilter, expectedWithFilter);
77 }
78
79 @Test
80 public void testExample4() throws Exception {
81 final String[] expectedWithoutFilter = {
82 "18:15: " + getCheckMessage(MemberNameCheck.class, "name.invalidPattern",
83 "MyVariable", "^[a-z][a-zA-Z0-9]*$"),
84 };
85 final String[] expectedWithFilter = {};
86
87 verifyFilterWithInlineConfigParser(getPath("Example4.java"),
88 expectedWithoutFilter, expectedWithFilter);
89 }
90 }