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.OverloadMethodsDeclarationOrderCheck.MSG_KEY;
24  
25  import org.junit.jupiter.api.Test;
26  
27  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
28  import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
29  
30  public class OverloadMethodsDeclarationOrderCheckTest
31      extends AbstractModuleTestSupport {
32  
33      @Override
34      protected String getPackageLocation() {
35          return "com/puppycrawl/tools/checkstyle/checks/coding/overloadmethodsdeclarationorder";
36      }
37  
38      @Test
39      public void testDefault() throws Exception {
40  
41          final String[] expected = {
42              "32:5: " + getCheckMessage(MSG_KEY, 21),
43              "60:9: " + getCheckMessage(MSG_KEY, 49),
44              "65:9: " + getCheckMessage(MSG_KEY, 60),
45              "83:5: " + getCheckMessage(MSG_KEY, 81),
46              "127:5: " + getCheckMessage(MSG_KEY, 116),
47              "138:5: " + getCheckMessage(MSG_KEY, 132),
48              "149:9: " + getCheckMessage(MSG_KEY, 143),
49              "152:5: " + getCheckMessage(MSG_KEY, 138),
50          };
51          verifyWithInlineConfigParser(
52                  getPath("InputOverloadMethodsDeclarationOrder.java"), expected);
53      }
54  
55      @Test
56      public void testOverloadMethodsDeclarationOrderRecords() throws Exception {
57  
58          final String[] expected = {
59              "21:9: " + getCheckMessage(MSG_KEY, 15),
60              "41:9: " + getCheckMessage(MSG_KEY, 35),
61              "57:9: " + getCheckMessage(MSG_KEY, 50),
62              "63:9: " + getCheckMessage(MSG_KEY, 57),
63          };
64          verifyWithInlineConfigParser(
65                  getNonCompilablePath("InputOverloadMethodsDeclarationOrderRecords.java"),
66              expected);
67      }
68  
69      @Test
70      public void testOverloadMethodsDeclarationOrderPrivateAndStaticMethods() throws Exception {
71  
72          final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
73  
74          verifyWithInlineConfigParser(
75                  getPath(
76                          "InputOverloadMethodsDeclarationOrderPrivateAndStaticMethods.java"
77                  ), expected);
78      }
79  
80      @Test
81      public void testTokensNotNull() {
82          final OverloadMethodsDeclarationOrderCheck check =
83              new OverloadMethodsDeclarationOrderCheck();
84          assertWithMessage("Acceptable tokens should not be null")
85              .that(check.getAcceptableTokens())
86              .isNotNull();
87          assertWithMessage("Default tokens should not be null")
88              .that(check.getDefaultTokens())
89              .isNotNull();
90          assertWithMessage("Required tokens should not be null")
91              .that(check.getRequiredTokens())
92              .isNotNull();
93      }
94  
95  }