View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2026 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      public String getPackageLocation() {
35          return "com/puppycrawl/tools/checkstyle/checks/coding/overloadmethodsdeclarationorder";
36      }
37  
38      @Test
39      public void testDefaultPart1() throws Exception {
40          final String[] expected = {
41              "33:5: " + getCheckMessage(MSG_KEY, 21),
42              "62:9: " + getCheckMessage(MSG_KEY, 50),
43              "67:9: " + getCheckMessage(MSG_KEY, 62),
44              "87:5: " + getCheckMessage(MSG_KEY, 83),
45          };
46          verifyWithInlineConfigParser(
47              getPath("InputOverloadMethodsDeclarationOrder1.java"), expected);
48      }
49  
50      @Test
51      public void testDefaultPart2() throws Exception {
52          final String[] expected = {
53              "53:9: " + getCheckMessage(MSG_KEY, 41),
54              "65:9: " + getCheckMessage(MSG_KEY, 58),
55              "77:13: " + getCheckMessage(MSG_KEY, 70),
56              "80:9: " + getCheckMessage(MSG_KEY, 65),
57          };
58          verifyWithInlineConfigParser(
59              getPath("InputOverloadMethodsDeclarationOrder2.java"), expected);
60      }
61  
62      @Test
63      public void testOverloadMethodsDeclarationOrderRecords() throws Exception {
64  
65          final String[] expected = {
66              "22:9: " + getCheckMessage(MSG_KEY, 15),
67              "43:9: " + getCheckMessage(MSG_KEY, 36),
68              "59:9: " + getCheckMessage(MSG_KEY, 52),
69              "66:9: " + getCheckMessage(MSG_KEY, 59),
70          };
71          verifyWithInlineConfigParser(
72                  getPath("InputOverloadMethodsDeclarationOrderRecords.java"),
73              expected);
74      }
75  
76      @Test
77      public void testOverloadMethodsDeclarationOrderPrivateAndStaticMethods() throws Exception {
78  
79          final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
80  
81          verifyWithInlineConfigParser(
82                  getPath(
83                          "InputOverloadMethodsDeclarationOrderPrivateAndStaticMethods.java"
84                  ), expected);
85      }
86  
87      @Test
88      public void testTokensNotNull() {
89          final OverloadMethodsDeclarationOrderCheck check =
90              new OverloadMethodsDeclarationOrderCheck();
91          assertWithMessage("Acceptable tokens should not be null")
92              .that(check.getAcceptableTokens())
93              .isNotNull();
94          assertWithMessage("Default tokens should not be null")
95              .that(check.getDefaultTokens())
96              .isNotNull();
97          assertWithMessage("Required tokens should not be null")
98              .that(check.getRequiredTokens())
99              .isNotNull();
100     }
101 
102 }