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
29 public class CovariantEqualsCheckTest
30 extends AbstractModuleTestSupport {
31
32 @Override
33 protected String getPackageLocation() {
34 return "com/puppycrawl/tools/checkstyle/checks/coding/covariantequals";
35 }
36
37 @Test
38 public void testDefaultOne()
39 throws Exception {
40 final String[] expected = {
41 "17:24: " + getCheckMessage(MSG_KEY),
42 "36:20: " + getCheckMessage(MSG_KEY),
43 "70:20: " + getCheckMessage(MSG_KEY),
44 "84:28: " + getCheckMessage(MSG_KEY),
45 };
46 verifyWithInlineConfigParser(
47 getPath("InputCovariantEqualsOne.java"), expected);
48 }
49
50 @Test
51 public void testDefaultTwo()
52 throws Exception {
53 final String[] expected = {
54 "41:20: " + getCheckMessage(MSG_KEY),
55 "45:9: " + getCheckMessage(MSG_KEY),
56 };
57 verifyWithInlineConfigParser(
58 getPath("InputCovariantEqualsTwo.java"), expected);
59 }
60
61 @Test
62 public void testCovariantEqualsRecords()
63 throws Exception {
64 final String[] expected = {
65 "13:24: " + getCheckMessage(MSG_KEY),
66 "29:28: " + getCheckMessage(MSG_KEY),
67 };
68 verifyWithInlineConfigParser(
69 getNonCompilablePath("InputCovariantEqualsRecords.java"), expected);
70 }
71
72 @Test
73 public void testTokensNotNull() {
74 final CovariantEqualsCheck check = new CovariantEqualsCheck();
75 assertWithMessage("Acceptable tokens should not be null")
76 .that(check.getAcceptableTokens())
77 .isNotNull();
78 assertWithMessage("Default tokens should not be null")
79 .that(check.getDefaultTokens())
80 .isNotNull();
81 assertWithMessage("Required tokens should not be null")
82 .that(check.getRequiredTokens())
83 .isNotNull();
84 }
85
86 }