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.checks.regexp;
21
22 import static com.puppycrawl.tools.checkstyle.checks.regexp.RegexpCheck.MSG_ILLEGAL_REGEXP;
23
24 import org.junit.jupiter.api.Test;
25
26 import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport;
27 import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
28
29 public class RegexpSinglelineJavaCheckExamplesTest extends AbstractExamplesModuleTestSupport {
30
31 @Override
32 public String getPackageLocation() {
33 return "com/puppycrawl/tools/checkstyle/checks/regexp/regexpsinglelinejava";
34 }
35
36 @Test
37 public void testExample1() throws Exception {
38 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
39 verifyWithInlineConfigParser(getPath("Example1.java"), expected);
40 }
41
42 @Test
43 public void testExample2() throws Exception {
44 final String[] expected = {
45 "25: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "System\\.out\\.println"),
46 "47: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "System\\.out\\.println"),
47 };
48
49 verifyWithInlineConfigParser(getPath("Example2.java"), expected);
50 }
51
52 @Test
53 public void testExample3() throws Exception {
54 final String[] expected = {
55 "23: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "debug"),
56
57 };
58
59 verifyWithInlineConfigParser(getPath("Example3.java"), expected);
60 }
61
62 @Test
63 public void testExample4() throws Exception {
64 final String[] expected = {
65 "5: " + "IO found",
66 "30: " + "IO found",
67 "33: " + "IO found",
68 "37: " + "IO found",
69 };
70
71 verifyWithInlineConfigParser(getPath("Example4.java"), expected);
72 }
73
74 @Test
75 public void testExample5() throws Exception {
76 final String[] expected = {
77 "43: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "\\.info(.*)"),
78 "44: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "\\.info(.*)"),
79 "46: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "\\.info(.*)"),
80 };
81
82 verifyWithInlineConfigParser(getPath("Example5.java"), expected);
83 }
84
85 @Test
86 public void testExample6() throws Exception {
87 final String[] expected = {
88 "42: " + "public member found",
89 };
90
91 verifyWithInlineConfigParser(getPath("Example6.java"), expected);
92 }
93
94 @Test
95 public void testExample7() throws Exception {
96 final String[] expected = {
97 "5: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "public"),
98 "40: " + getCheckMessage(MSG_ILLEGAL_REGEXP, "public"),
99 };
100
101 verifyWithInlineConfigParser(getPath("Example7.java"), expected);
102 }
103
104 @Test
105 public void testUseCase1() throws Exception {
106 final String[] expected = {
107 "23: " + "private member found",
108 "30: " + "private member found",
109 };
110
111 verifyWithInlineConfigParser(getPath("UseCase1.java"), expected);
112 }
113
114 }