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.google.common.truth.Truth.assertWithMessage;
23 import static com.puppycrawl.tools.checkstyle.checks.coding.ConstructorsDeclarationGroupingCheck.MSG_KEY;
24 import static com.puppycrawl.tools.checkstyle.checks.coding.ConstructorsDeclarationGroupingCheck.MSG_ORDER;
25
26 import org.junit.jupiter.api.Test;
27
28 import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
29
30 public class ConstructorsDeclarationGroupingCheckTest extends AbstractModuleTestSupport {
31 @Override
32 public String getPackageLocation() {
33 return "com/puppycrawl/tools/checkstyle/checks/coding/constructorsdeclarationgrouping";
34 }
35
36 @Test
37 public void testDefault() throws Exception {
38 final String[] expected = {
39 "24:5: " + getCheckMessage(MSG_KEY, 20),
40 "29:5: " + getCheckMessage(MSG_KEY, 20),
41 "46:9: " + getCheckMessage(MSG_KEY, 40),
42 "56:13: " + getCheckMessage(MSG_KEY, 50),
43 "60:9: " + getCheckMessage(MSG_KEY, 40),
44 "64:5: " + getCheckMessage(MSG_KEY, 20),
45 "67:5: " + getCheckMessage(MSG_KEY, 20),
46 };
47 verifyWithInlineConfigParser(
48 getPath("InputConstructorsDeclarationGrouping.java"), expected);
49 }
50
51 @Test
52 public void testConstructorsDeclarationGroupingInner() throws Exception {
53 final String[] expected = {
54 "30:9: " + getCheckMessage(MSG_KEY, 26),
55 "35:9: " + getCheckMessage(MSG_KEY, 26),
56 "38:9: " + getCheckMessage(MSG_KEY, 26),
57 "42:5: " + getCheckMessage(MSG_KEY, 12),
58
59 };
60 verifyWithInlineConfigParser(
61 getPath("InputConstructorsDeclarationGroupingInner.java"), expected);
62 }
63
64 @Test
65 public void testConstructorsDeclarationGroupingRecords() throws Exception {
66
67 final String[] expected = {
68 "21:9: " + getCheckMessage(MSG_KEY, 13),
69 "24:9: " + getCheckMessage(MSG_KEY, 13),
70 "29:9: " + getCheckMessage(MSG_KEY, 13),
71 "46:9: " + getCheckMessage(MSG_KEY, 40),
72 };
73
74 verifyWithInlineConfigParser(
75 getNonCompilablePath("InputConstructorsDeclarationGroupingRecords.java"),
76 expected);
77 }
78
79 @Test
80 public void testConstructorsDeclarationGroupingArity() throws Exception {
81
82 final String[] expected = {
83 "14:5: " + getCheckMessage(MSG_ORDER),
84 "17:5: " + getCheckMessage(MSG_ORDER),
85 "20:5: " + getCheckMessage(MSG_ORDER),
86 "31:5: " + getCheckMessage(MSG_ORDER),
87 };
88
89 verifyWithInlineConfigParser(
90 getPath("InputConstructorsDeclarationGroupingArity.java"),
91 expected);
92 }
93
94 @Test
95 public void testConstructorsDeclarationGroupingRecordArity() throws Exception {
96
97 final String[] expected = {
98 "24:9: " + getCheckMessage(MSG_ORDER),
99 "33:9: " + getCheckMessage(MSG_ORDER),
100 "37:9: " + getCheckMessage(MSG_ORDER),
101 "41:9: " + getCheckMessage(MSG_ORDER),
102 };
103
104 verifyWithInlineConfigParser(
105 getPath("InputConstructorsDeclarationGroupingRecord.java"),
106 expected);
107 }
108
109 @Test
110 public void testConstructorsDeclarationGroupingMisc() throws Exception {
111
112 final String[] expected = {
113 "20:5: " + getCheckMessage(MSG_KEY, 15),
114 "20:5: " + getCheckMessage(MSG_ORDER),
115 "30:9: " + getCheckMessage(MSG_KEY, 25),
116 "35:9: " + getCheckMessage(MSG_KEY, 25),
117 "35:9: " + getCheckMessage(MSG_ORDER),
118 };
119
120 verifyWithInlineConfigParser(
121 getPath("InputConstructorsDeclarationGroupingMisc.java"),
122 expected);
123 }
124
125 @Test
126 public void testTokensNotNull() {
127 final ConstructorsDeclarationGroupingCheck check =
128 new ConstructorsDeclarationGroupingCheck();
129 assertWithMessage("Acceptable tokens should not be null")
130 .that(check.getAcceptableTokens())
131 .isNotNull();
132 assertWithMessage("Default tokens should not be null")
133 .that(check.getDefaultTokens())
134 .isNotNull();
135 assertWithMessage("Required tokens should not be null")
136 .that(check.getRequiredTokens())
137 .isNotNull();
138 }
139
140 }