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 org.junit.jupiter.api.Test;
23
24 import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport;
25
26 public class SuppressWithNearbyCommentFilterExamplesTest extends AbstractExamplesModuleTestSupport {
27 @Override
28 protected String getPackageLocation() {
29 return "com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter";
30 }
31
32 @Test
33 public void testExample1() throws Exception {
34 final String[] expectedWithFilter = {
35
36 };
37 final String[] expectedWithoutFilter = {
38 "13:15: 'int' is followed by whitespace.",
39 };
40
41 verifyFilterWithInlineConfigParser(getPath("Example1.java"), expectedWithoutFilter,
42 expectedWithFilter);
43 }
44
45 @Test
46 public void testExample2() throws Exception {
47 final String[] expectedWithFilter = {
48
49 };
50 final String[] expectedWithoutFilter = {
51 "17:27: Name 'lowerCaseConstant' must match pattern '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.",
52 };
53
54 verifyFilterWithInlineConfigParser(getPath("Example2.java"), expectedWithoutFilter,
55 expectedWithFilter);
56 }
57
58 @Test
59 public void testExample3() throws Exception {
60 final String[] expectedWithFilter = {
61
62 };
63 final String[] expectedWithoutFilter = {
64 "23:5: Catching 'RuntimeException' is not allowed.",
65 };
66
67 verifyFilterWithInlineConfigParser(getPath("Example3.java"), expectedWithoutFilter,
68 expectedWithFilter);
69 }
70
71 @Test
72 public void testExample4() throws Exception {
73 final String[] expectedWithFilter = {
74 "26:20: Name 'lowerCaseConstant5' must match pattern '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.",
75 };
76 final String[] expectedWithoutFilter = {
77 "19:20: Name 'lowerCaseConstant1' must match pattern '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.",
78 "21:20: Name 'lowerCaseConstant2' must match pattern '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.",
79 "23:20: Name 'lowerCaseConstant3' must match pattern '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.",
80 "25:20: Name 'lowerCaseConstant4' must match pattern '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.",
81 "26:20: Name 'lowerCaseConstant5' must match pattern '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.",
82 };
83
84 verifyFilterWithInlineConfigParser(getPath("Example4.java"), expectedWithoutFilter,
85 expectedWithFilter);
86 }
87
88 @Test
89 public void testExample5() throws Exception {
90 final String[] expectedWithFilter = {
91
92 };
93 final String[] expectedWithoutFilter = {
94 "17:15: Name 'D2' must match pattern '^[a-z][a-zA-Z0-9]*$'.",
95 };
96
97 verifyFilterWithInlineConfigParser(getPath("Example5.java"), expectedWithoutFilter,
98 expectedWithFilter);
99 }
100
101 @Test
102 public void testExample6() throws Exception {
103 final String[] expectedWithFilters = {
104
105 };
106 final String[] expectedWithoutFilters = {
107 "19:27: 'int' is followed by whitespace.",
108 "19:30: Name 'array' must match pattern '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.",
109 };
110
111 verifyFilterWithInlineConfigParser(getPath("Example6.java"), expectedWithoutFilters,
112 expectedWithFilters);
113 }
114
115 @Test
116 public void testExample7() throws Exception {
117 final String[] expectedWithFilter = {
118
119 };
120 final String[] expectedWithoutFilter = {
121
122 };
123
124 verifyFilterWithInlineConfigParser(getPath("Example7.java"), expectedWithoutFilter,
125 expectedWithFilter);
126 }
127
128 @Test
129 public void testExample8() throws Exception {
130 final String[] expectedWithFilter = {
131
132 };
133 final String[] expectedWithoutFilter = {
134 "21:1: Class Data Abstraction Coupling is 2 (max allowed is 1) "
135 + "classes [Example1, Example2].",
136 "24:23: '10022' is a magic number.",
137 };
138
139 verifyFilterWithInlineConfigParser(getPath("Example8.java"), expectedWithoutFilter,
140 expectedWithFilter);
141 }
142 }