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