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