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.google.common.truth.Truth.assertWithMessage;
23 import static com.puppycrawl.tools.checkstyle.checks.naming.AbstractNameCheck.MSG_INVALID_PATTERN;
24
25 import org.junit.jupiter.api.Test;
26
27 import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
28 import com.puppycrawl.tools.checkstyle.api.TokenTypes;
29
30 public class RecordComponentNameCheckTest extends AbstractModuleTestSupport {
31
32 @Override
33 protected String getPackageLocation() {
34 return "com/puppycrawl/tools/checkstyle/checks/naming/recordcomponentname";
35 }
36
37 @Test
38 public void testGetClassRequiredTokens() {
39 final RecordComponentNameCheck checkObj =
40 new RecordComponentNameCheck();
41 final int[] expected = {TokenTypes.RECORD_COMPONENT_DEF};
42 assertWithMessage("Default required tokens are invalid")
43 .that(checkObj.getRequiredTokens())
44 .isEqualTo(expected);
45 }
46
47 @Test
48 public void testRecordDefault()
49 throws Exception {
50
51 final String pattern = "^[a-z][a-zA-Z0-9]*$";
52
53 final String[] expected = {
54 "19:34: " + getCheckMessage(MSG_INVALID_PATTERN, "value_123", pattern),
55 "20:15: " + getCheckMessage(MSG_INVALID_PATTERN, "Values", pattern),
56 "23:35: " + getCheckMessage(MSG_INVALID_PATTERN, "_value123", pattern),
57 "24:9: " + getCheckMessage(MSG_INVALID_PATTERN, "$age", pattern),
58 };
59 verifyWithInlineConfigParser(
60 getNonCompilablePath("InputRecordComponentNameDefault.java"), expected);
61 }
62
63 @Test
64 public void testClassFooName()
65 throws Exception {
66
67 final String pattern = "^[a-z0-9]+$";
68
69 final String[] expected = {
70 "19:36: " + getCheckMessage(MSG_INVALID_PATTERN, "value_123", pattern),
71 "20:15: " + getCheckMessage(MSG_INVALID_PATTERN, "Values", pattern),
72 "23:37: " + getCheckMessage(MSG_INVALID_PATTERN, "V", pattern),
73 "24:9: " + getCheckMessage(MSG_INVALID_PATTERN, "$age", pattern),
74 };
75 verifyWithInlineConfigParser(
76 getNonCompilablePath("InputRecordComponentNameLowercase.java"), expected);
77 }
78
79 @Test
80 public void testGetAcceptableTokens() {
81 final RecordComponentNameCheck typeParameterNameCheckObj =
82 new RecordComponentNameCheck();
83 final int[] actual = typeParameterNameCheckObj.getAcceptableTokens();
84 final int[] expected = {
85 TokenTypes.RECORD_COMPONENT_DEF,
86 };
87 assertWithMessage("Default acceptable tokens are invalid")
88 .that(actual)
89 .isEqualTo(expected);
90 }
91 }