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.naming;
21
22 import static com.puppycrawl.tools.checkstyle.checks.naming.AbbreviationAsWordInNameCheck.MSG_KEY;
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 AbbreviationAsWordInNameExamplesTest extends AbstractExamplesModuleTestSupport {
30 private static final int DEFAULT_EXPECTED_CAPITAL_COUNT = 4;
31
32 @Override
33 protected String getPackageLocation() {
34 return "com/puppycrawl/tools/checkstyle/checks/naming/abbreviationaswordinname";
35 }
36
37 @Test
38 public void testExample1() throws Exception {
39 final String[] expected = {
40 "18:7: " + getCheckMessage(MSG_KEY, "CURRENT_COUNTER", DEFAULT_EXPECTED_CAPITAL_COUNT),
41 "27:8: " + getCheckMessage(MSG_KEY, "incrementCOUNTER", DEFAULT_EXPECTED_CAPITAL_COUNT),
42 "31:15: " + getCheckMessage(MSG_KEY, "incrementGLOBAL", DEFAULT_EXPECTED_CAPITAL_COUNT),
43 };
44
45 verifyWithInlineXmlConfig(getPath("Example1.java"), expected);
46 }
47
48 @Test
49 public void testExample2() throws Exception {
50 final String[] expected = {
51 "21:7: " + getCheckMessage(MSG_KEY, "CURRENT_COUNTER", DEFAULT_EXPECTED_CAPITAL_COUNT),
52 "23:14: " + getCheckMessage(MSG_KEY, "GLOBAL_COUNTER", DEFAULT_EXPECTED_CAPITAL_COUNT),
53 "27:15: " + getCheckMessage(MSG_KEY, "printCOUNTER", DEFAULT_EXPECTED_CAPITAL_COUNT),
54 "31:8: " + getCheckMessage(MSG_KEY, "incrementCOUNTER", DEFAULT_EXPECTED_CAPITAL_COUNT),
55 "35:15: " + getCheckMessage(MSG_KEY, "incrementGLOBAL", DEFAULT_EXPECTED_CAPITAL_COUNT),
56 };
57
58 verifyWithInlineXmlConfig(getPath("Example2.java"), expected);
59 }
60
61 @Test
62 public void testExample3() throws Exception {
63 final int expectedCapitalCount = 1;
64
65 final String[] expected = {
66 "21:7: " + getCheckMessage(MSG_KEY, "secondNUM", expectedCapitalCount),
67 "23:14: " + getCheckMessage(MSG_KEY, "fourthNUm", expectedCapitalCount),
68 };
69
70 verifyWithInlineXmlConfig(getPath("Example3.java"), expected);
71 }
72
73 @Test
74 public void testExample4() throws Exception {
75 final int expectedCapitalCount = 2;
76
77 final String[] expected = {
78 "22:7: " + getCheckMessage(MSG_KEY, "secondMYNum", expectedCapitalCount),
79 "23:7: " + getCheckMessage(MSG_KEY, "thirdNUM", expectedCapitalCount),
80 "26:10: " + getCheckMessage(MSG_KEY, "firstXML", expectedCapitalCount),
81 };
82
83 verifyWithInlineXmlConfig(getPath("Example4.java"), expected);
84 }
85
86 @Test
87 public void testExample5() throws Exception {
88 final int expectedCapitalCount = 1;
89
90 final String[] expected = {
91 "21:7: " + getCheckMessage(MSG_KEY, "counterXYZ", expectedCapitalCount),
92 "23:13: " + getCheckMessage(MSG_KEY, "customerID", expectedCapitalCount),
93 "24:14: " + getCheckMessage(MSG_KEY, "nextID", expectedCapitalCount),
94 };
95
96 verifyWithInlineXmlConfig(getPath("Example5.java"), expected);
97 }
98
99 @Test
100 public void testExample6() throws Exception {
101 final int expectedCapitalCount = 1;
102
103 final String[] expected = {
104 "21:7: " + getCheckMessage(MSG_KEY, "counterXYZ", expectedCapitalCount),
105 "23:13: " + getCheckMessage(MSG_KEY, "customerID", expectedCapitalCount),
106 "26:20: " + getCheckMessage(MSG_KEY, "MAX_ALLOWED", expectedCapitalCount),
107 };
108
109 verifyWithInlineXmlConfig(getPath("Example6.java"), expected);
110 }
111
112 @Test
113 public void testExample7() throws Exception {
114 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
115
116 verifyWithInlineXmlConfig(getPath("Example7.java"), expected);
117 }
118 }