1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.checkstyle.suppressionxpathfilter.coding;
21
22 import java.io.File;
23 import java.util.Collections;
24 import java.util.List;
25
26 import org.checkstyle.suppressionxpathfilter.AbstractXpathTestSupport;
27 import org.junit.jupiter.api.Test;
28
29 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
30 import com.puppycrawl.tools.checkstyle.checks.coding.CovariantEqualsCheck;
31
32 public class XpathRegressionCovariantEqualsTest extends AbstractXpathTestSupport {
33
34 private final String checkName = CovariantEqualsCheck.class.getSimpleName();
35
36 @Override
37 protected String getCheckName() {
38 return checkName;
39 }
40
41 @Override
42 protected String getPackageLocation() {
43 return "org/checkstyle/suppressionxpathfilter/coding/covariantequals";
44 }
45
46 @Test
47 public void testCovariantEqualsInClass() throws Exception {
48 final File fileToProcess =
49 new File(getPath("InputXpathCovariantEqualsInClass.java"));
50
51 final DefaultConfiguration moduleConfig =
52 createModuleConfig(CovariantEqualsCheck.class);
53
54 final String[] expectedViolation = {
55 "5:20: " + getCheckMessage(CovariantEqualsCheck.class,
56 CovariantEqualsCheck.MSG_KEY),
57 };
58
59 final List<String> expectedXpathQueries = Collections.singletonList(
60 "/COMPILATION_UNIT/CLASS_DEF"
61 + "[./IDENT[@text='InputXpathCovariantEqualsInClass']]"
62 + "/OBJBLOCK/METHOD_DEF/IDENT[@text='equals']"
63 );
64
65 runVerifications(moduleConfig, fileToProcess, expectedViolation,
66 expectedXpathQueries);
67 }
68
69 @Test
70 public void testCovariantEqualsInEnum() throws Exception {
71 final File fileToProcess =
72 new File(getPath("InputXpathCovariantEqualsInEnum.java"));
73
74 final DefaultConfiguration moduleConfig =
75 createModuleConfig(CovariantEqualsCheck.class);
76
77 final String[] expectedViolation = {
78 "7:20: " + getCheckMessage(CovariantEqualsCheck.class,
79 CovariantEqualsCheck.MSG_KEY),
80 };
81
82 final List<String> expectedXpathQueries = Collections.singletonList(
83 "/COMPILATION_UNIT/ENUM_DEF"
84 + "[./IDENT[@text='InputXpathCovariantEqualsInEnum']]"
85 + "/OBJBLOCK/METHOD_DEF/IDENT[@text='equals']");
86
87 runVerifications(moduleConfig, fileToProcess, expectedViolation,
88 expectedXpathQueries);
89 }
90
91 @Test
92 public void testCovariantEqualsInRecord() throws Exception {
93 final File fileToProcess =
94 new File(getPath(
95 "InputXpathCovariantEqualsInRecord.java"));
96
97 final DefaultConfiguration moduleConfig =
98 createModuleConfig(CovariantEqualsCheck.class);
99
100 final String[] expectedViolation = {
101 "7:20: " + getCheckMessage(CovariantEqualsCheck.class,
102 CovariantEqualsCheck.MSG_KEY),
103 };
104
105 final List<String> expectedXpathQueries = Collections.singletonList(
106 "/COMPILATION_UNIT/RECORD_DEF"
107 + "[./IDENT[@text='InputXpathCovariantEqualsInRecord']]"
108 + "/OBJBLOCK/METHOD_DEF/IDENT[@text='equals']");
109
110 runVerifications(moduleConfig, fileToProcess, expectedViolation,
111 expectedXpathQueries);
112 }
113
114 }