View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2025 the original author or authors.
4   //
5   // This library is free software; you can redistribute it and/or
6   // modify it under the terms of the GNU Lesser General Public
7   // License as published by the Free Software Foundation; either
8   // version 2.1 of the License, or (at your option) any later version.
9   //
10  // This library is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  // Lesser General Public License for more details.
14  //
15  // You should have received a copy of the GNU Lesser General Public
16  // License along with this library; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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  
25  import org.junit.jupiter.api.Test;
26  
27  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
28  
29  public class ConstructorsDeclarationGroupingCheckTest extends AbstractModuleTestSupport {
30      @Override
31      protected String getPackageLocation() {
32          return "com/puppycrawl/tools/checkstyle/checks/coding/constructorsdeclarationgrouping";
33      }
34  
35      @Test
36      public void testDefault() throws Exception {
37          final String[] expected = {
38              "23:5: " + getCheckMessage(MSG_KEY, 19),
39              "28:5: " + getCheckMessage(MSG_KEY, 19),
40              "45:9: " + getCheckMessage(MSG_KEY, 39),
41              "55:13: " + getCheckMessage(MSG_KEY, 49),
42              "59:9: " + getCheckMessage(MSG_KEY, 39),
43              "63:5: " + getCheckMessage(MSG_KEY, 19),
44              "66:5: " + getCheckMessage(MSG_KEY, 19),
45          };
46          verifyWithInlineConfigParser(
47                  getPath("InputConstructorsDeclarationGrouping.java"), expected);
48      }
49  
50      @Test
51      public void testConstructorsDeclarationGroupingInner() throws Exception {
52          final String[] expected = {
53              "29:9: " + getCheckMessage(MSG_KEY, 25),
54              "34:9: " + getCheckMessage(MSG_KEY, 25),
55              "37:9: " + getCheckMessage(MSG_KEY, 25),
56              "41:5: " + getCheckMessage(MSG_KEY, 11),
57  
58          };
59          verifyWithInlineConfigParser(
60                  getPath("InputConstructorsDeclarationGroupingInner.java"), expected);
61      }
62  
63      @Test
64      public void testConstructorsDeclarationGroupingRecords() throws Exception {
65  
66          final String[] expected = {
67              "20:9: " + getCheckMessage(MSG_KEY, 12),
68              "23:9: " + getCheckMessage(MSG_KEY, 12),
69              "28:9: " + getCheckMessage(MSG_KEY, 12),
70              "45:9: " + getCheckMessage(MSG_KEY, 39),
71          };
72  
73          verifyWithInlineConfigParser(
74                  getNonCompilablePath("InputConstructorsDeclarationGroupingRecords.java"),
75                  expected);
76      }
77  
78      @Test
79      public void testTokensNotNull() {
80          final ConstructorsDeclarationGroupingCheck check =
81                  new ConstructorsDeclarationGroupingCheck();
82          assertWithMessage("Acceptable tokens should not be null")
83                  .that(check.getAcceptableTokens())
84                  .isNotNull();
85          assertWithMessage("Default tokens should not be null")
86                  .that(check.getDefaultTokens())
87                  .isNotNull();
88          assertWithMessage("Required tokens should not be null")
89                  .that(check.getRequiredTokens())
90                  .isNotNull();
91      }
92  
93  }