View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2024 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              "85:7: " + getCheckMessage(MSG_KEY, 81),
46              "90:7: " + getCheckMessage(MSG_KEY, 81),
47              "93:7: " + getCheckMessage(MSG_KEY, 81),
48              "97:5: " + getCheckMessage(MSG_KEY, 19),
49          };
50          verifyWithInlineConfigParser(
51                  getPath("InputConstructorsDeclarationGrouping.java"), expected);
52      }
53  
54      @Test
55      public void testConstructorsDeclarationGroupingRecords() throws Exception {
56  
57          final String[] expected = {
58              "20:9: " + getCheckMessage(MSG_KEY, 12),
59              "23:9: " + getCheckMessage(MSG_KEY, 12),
60              "28:9: " + getCheckMessage(MSG_KEY, 12),
61              "45:9: " + getCheckMessage(MSG_KEY, 39),
62          };
63  
64          verifyWithInlineConfigParser(
65                  getNonCompilablePath("InputConstructorsDeclarationGroupingRecords.java"),
66                  expected);
67      }
68  
69      @Test
70      public void testTokensNotNull() {
71          final ConstructorsDeclarationGroupingCheck check =
72                  new ConstructorsDeclarationGroupingCheck();
73          assertWithMessage("Acceptable tokens should not be null")
74                  .that(check.getAcceptableTokens())
75                  .isNotNull();
76          assertWithMessage("Default tokens should not be null")
77                  .that(check.getDefaultTokens())
78                  .isNotNull();
79          assertWithMessage("Required tokens should not be null")
80                  .that(check.getRequiredTokens())
81                  .isNotNull();
82      }
83  
84  }