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