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.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 }