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 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 "33:5: " + getCheckMessage(MSG_KEY, 21),
43 "62:9: " + getCheckMessage(MSG_KEY, 50),
44 "67:9: " + getCheckMessage(MSG_KEY, 62),
45 "87:5: " + getCheckMessage(MSG_KEY, 83),
46 "132:5: " + getCheckMessage(MSG_KEY, 120),
47 "144:5: " + getCheckMessage(MSG_KEY, 137),
48 "156:9: " + getCheckMessage(MSG_KEY, 149),
49 "159:5: " + getCheckMessage(MSG_KEY, 144),
50 };
51 verifyWithInlineConfigParser(
52 getPath("InputOverloadMethodsDeclarationOrder.java"), expected);
53 }
54
55 @Test
56 public void testOverloadMethodsDeclarationOrderRecords() throws Exception {
57
58 final String[] expected = {
59 "22:9: " + getCheckMessage(MSG_KEY, 15),
60 "43:9: " + getCheckMessage(MSG_KEY, 36),
61 "59:9: " + getCheckMessage(MSG_KEY, 52),
62 "66:9: " + getCheckMessage(MSG_KEY, 59),
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 }