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.AbstractModuleTestSupport;
25 import com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck;
26 import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
27
28 public class SuppressionSingleFilterTest extends AbstractModuleTestSupport {
29
30 private static final String FORMAT = "TODO$";
31 private static final String MESSAGE = getCheckMessage(RegexpSinglelineCheck.class,
32 "regexp.exceeded", FORMAT);
33 private static final String[] ALL_MESSAGES = {
34 "25: " + MESSAGE,
35 };
36
37 @Override
38 protected String getPackageLocation() {
39 return "com/puppycrawl/tools/checkstyle/filters/suppressionsinglefilter";
40 }
41
42 @Test
43 public void testDefault() throws Exception {
44 final String[] suppressed = {
45 "25: " + MESSAGE,
46 };
47 verifySuppressedWithParser(getPath("InputSuppressionSingleFilter2.java"), suppressed);
48 }
49
50 @Test
51 public void testMatching() throws Exception {
52 final String[] suppressed = {
53 "25: " + MESSAGE,
54 };
55 verifySuppressedWithParser(getPath("InputSuppressionSingleFilter3.java"), suppressed);
56 }
57
58 @Test
59 public void testNonMatchingLineNumber() throws Exception {
60 final String[] suppressed = CommonUtil.EMPTY_STRING_ARRAY;
61 verifySuppressedWithParser(getPath("InputSuppressionSingleFilter4.java"), suppressed);
62 }
63
64 @Test
65 public void testNonMatchingColumnNumber() throws Exception {
66 final String[] suppressed = CommonUtil.EMPTY_STRING_ARRAY;
67 verifySuppressedWithParser(getPath("InputSuppressionSingleFilter5.java"), suppressed);
68 }
69
70 @Test
71 public void testNonMatchingFileRegexp() throws Exception {
72 final String[] suppressed = CommonUtil.EMPTY_STRING_ARRAY;
73 verifySuppressedWithParser(getPath("InputSuppressionSingleFilter6.java"), suppressed);
74 }
75
76 @Test
77 public void testNonMatchingModuleId() throws Exception {
78 final String[] suppressed = CommonUtil.EMPTY_STRING_ARRAY;
79 verifySuppressedWithParser(getPath("InputSuppressionSingleFilter7.java"), suppressed);
80 }
81
82 @Test
83 public void testMatchingModuleId() throws Exception {
84 final String[] suppressed = {
85 "25: " + MESSAGE,
86 };
87 verifySuppressedWithParser(getPath("InputSuppressionSingleFilter10.java"), suppressed);
88 }
89
90 @Test
91 public void testNonMatchingChecks() throws Exception {
92 final String[] suppressed = CommonUtil.EMPTY_STRING_ARRAY;
93 verifySuppressedWithParser(getPath("InputSuppressionSingleFilter8.java"), suppressed);
94 }
95
96 @Test
97 public void testNotMatchingMessage() throws Exception {
98 final String[] suppressed = CommonUtil.EMPTY_STRING_ARRAY;
99 verifySuppressedWithParser(getPath("InputSuppressionSingleFilter9.java"), suppressed);
100 }
101
102 @Test
103 public void testMatchMessage() throws Exception {
104 final String[] suppressed = {
105 "25: " + MESSAGE,
106 };
107 verifySuppressedWithParser(getPath("InputSuppressionSingleFilter.java"), suppressed);
108 }
109
110 private void verifySuppressedWithParser(String fileName, String... suppressed)
111 throws Exception {
112 verifyFilterWithInlineConfigParser(fileName, ALL_MESSAGES,
113 removeSuppressed(ALL_MESSAGES, suppressed));
114 }
115
116 }