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.AbstractNameCheck.MSG_INVALID_PATTERN;
23 import static com.puppycrawl.tools.checkstyle.checks.naming.TypeNameCheck.DEFAULT_PATTERN;
24
25 import org.junit.jupiter.api.Test;
26
27 import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
28 import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
29
30 public class TypeNameCheckTest
31 extends AbstractModuleTestSupport {
32
33 @Override
34 protected String getPackageLocation() {
35 return "com/puppycrawl/tools/checkstyle/checks/naming/typename";
36 }
37
38 @Test
39 public void testSpecified()
40 throws Exception {
41 final String[] expected = {
42 "25:14: " + getCheckMessage(MSG_INVALID_PATTERN,
43 "InputTypeName", "^inputHe"),
44 };
45 verifyWithInlineConfigParser(
46 getPath("InputTypeName.java"), expected);
47 }
48
49 @Test
50 public void testDefault()
51 throws Exception {
52 final String[] expected = {
53 "15:7: " + getCheckMessage(MSG_INVALID_PATTERN,
54 "inputHeaderClass2", DEFAULT_PATTERN),
55 "17:22: " + getCheckMessage(MSG_INVALID_PATTERN,
56 "inputHeaderInterface", DEFAULT_PATTERN),
57 "19:17: " + getCheckMessage(MSG_INVALID_PATTERN,
58 "inputHeaderEnum", DEFAULT_PATTERN),
59 "21:23: " + getCheckMessage(MSG_INVALID_PATTERN,
60 "inputHeaderAnnotation", DEFAULT_PATTERN),
61 };
62 verifyWithInlineConfigParser(
63 getPath("InputTypeName2.java"), expected);
64 }
65
66 @Test
67 public void testClassSpecific()
68 throws Exception {
69 final String[] expected = {
70 "15:7: " + getCheckMessage(MSG_INVALID_PATTERN,
71 "inputHeaderClass3", DEFAULT_PATTERN),
72 };
73 verifyWithInlineConfigParser(
74 getPath("InputTypeName3.java"), expected);
75 }
76
77 @Test
78 public void testInterfaceSpecific()
79 throws Exception {
80 final String[] expected = {
81 "17:22: " + getCheckMessage(MSG_INVALID_PATTERN,
82 "inputHeaderInterface", DEFAULT_PATTERN),
83 };
84 verifyWithInlineConfigParser(
85 getPath("InputTypeName4.java"), expected);
86 }
87
88 @Test
89 public void testEnumSpecific()
90 throws Exception {
91 final String[] expected = {
92 "19:17: " + getCheckMessage(MSG_INVALID_PATTERN,
93 "inputHeaderEnum", DEFAULT_PATTERN),
94 };
95 verifyWithInlineConfigParser(
96 getPath("InputTypeName5.java"), expected);
97 }
98
99 @Test
100 public void testAnnotationSpecific()
101 throws Exception {
102 final String[] expected = {
103 "21:23: " + getCheckMessage(MSG_INVALID_PATTERN,
104 "inputHeaderAnnotation", DEFAULT_PATTERN),
105 };
106 verifyWithInlineConfigParser(
107 getPath("InputTypeName6.java"), expected);
108 }
109
110 @Test
111 public void testTypeNameRecords() throws Exception {
112
113 final String[] expected = {
114 "23:10: " + getCheckMessage(MSG_INVALID_PATTERN, "Third_Name", DEFAULT_PATTERN),
115 "25:11: " + getCheckMessage(MSG_INVALID_PATTERN, "FourthName_", DEFAULT_PATTERN),
116 "28:12: " + getCheckMessage(MSG_INVALID_PATTERN, "My_Record", DEFAULT_PATTERN),
117 "30:16: " + getCheckMessage(MSG_INVALID_PATTERN, "Inner__Record", DEFAULT_PATTERN),
118 "35:12: " + getCheckMessage(MSG_INVALID_PATTERN, "MyRecord__", DEFAULT_PATTERN),
119 };
120 verifyWithInlineConfigParser(
121 getPath("InputTypeNameRecords.java"), expected);
122 }
123
124 @Test
125 public void testApplyPropertiesSetters() throws Exception {
126
127 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
128
129 verifyWithInlineConfigParser(
130 getPath("InputTypeNameProperties.java"), expected);
131 }
132
133 }