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.CovariantEqualsCheck.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 CovariantEqualsCheckTest
31 extends AbstractModuleTestSupport {
32
33 @Override
34 public String getPackageLocation() {
35 return "com/puppycrawl/tools/checkstyle/checks/coding/covariantequals";
36 }
37
38 @Test
39 public void testDefaultOne()
40 throws Exception {
41 final String[] expected = {
42 "17:24: " + getCheckMessage(MSG_KEY),
43 "36:20: " + getCheckMessage(MSG_KEY),
44 "70:20: " + getCheckMessage(MSG_KEY),
45 "84:28: " + getCheckMessage(MSG_KEY),
46 };
47 verifyWithInlineConfigParser(
48 getPath("InputCovariantEqualsOne.java"), expected);
49 }
50
51 @Test
52 public void testDefaultTwo()
53 throws Exception {
54 final String[] expected = {
55 "41:20: " + getCheckMessage(MSG_KEY),
56 "45:9: " + getCheckMessage(MSG_KEY),
57 };
58 verifyWithInlineConfigParser(
59 getPath("InputCovariantEqualsTwo.java"), expected);
60 }
61
62 @Test
63 public void testCovariantEqualsRecords()
64 throws Exception {
65 final String[] expected = {
66 "13:24: " + getCheckMessage(MSG_KEY),
67 "29:28: " + getCheckMessage(MSG_KEY),
68 };
69 verifyWithInlineConfigParser(
70 getPath("InputCovariantEqualsRecords.java"), expected);
71 }
72
73 @Test
74 public void testTokensNotNull() {
75 final CovariantEqualsCheck check = new CovariantEqualsCheck();
76 assertWithMessage("Acceptable tokens should not be null")
77 .that(check.getAcceptableTokens())
78 .isNotNull();
79 assertWithMessage("Default tokens should not be null")
80 .that(check.getDefaultTokens())
81 .isNotNull();
82 assertWithMessage("Required tokens should not be null")
83 .that(check.getRequiredTokens())
84 .isNotNull();
85 }
86
87 @Test
88 public void testCovariantEqualsCompactSourceFile()
89 throws Exception {
90 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
91 verifyWithInlineConfigParser(
92 getNonCompilablePath(
93 "compact/InputCovariantEqualsCompactSourceFile.java"),
94 expected);
95 }
96
97 @Test
98 public void testCovariantEqualsCompactSourceFileMultiple()
99 throws Exception {
100 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
101 verifyWithInlineConfigParser(
102 getNonCompilablePath(
103 "compact/InputCovariantEqualsCompactSourceFileMultiple.java"),
104 expected);
105 }
106
107 @Test
108 public void testCovariantEqualsCompactSourceFileNoViolation()
109 throws Exception {
110 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
111 verifyWithInlineConfigParser(
112 getNonCompilablePath(
113 "compact/InputCovariantEqualsCompactSourceFileNoViolation.java"),
114 expected);
115 }
116
117 }