1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.checkstyle.suppressionxpathfilter;
21
22 import java.io.File;
23 import java.util.Collections;
24 import java.util.List;
25
26 import org.junit.jupiter.api.Test;
27
28 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
29 import com.puppycrawl.tools.checkstyle.checks.coding.UnnecessarySemicolonInEnumerationCheck;
30
31 public class XpathRegressionUnnecessarySemicolonInEnumerationTest
32 extends AbstractXpathTestSupport {
33
34 private final String checkName =
35 UnnecessarySemicolonInEnumerationCheck.class.getSimpleName();
36
37 @Override
38 protected String getCheckName() {
39 return checkName;
40 }
41
42 @Test
43 public void testSimple() throws Exception {
44 final File fileToProcess = new File(
45 getPath("InputXpathUnnecessarySemicolonInEnumerationSimple.java"));
46
47 final DefaultConfiguration moduleConfig =
48 createModuleConfig(UnnecessarySemicolonInEnumerationCheck.class);
49
50 final String[] expectedViolation = {
51 "11:10: " + getCheckMessage(UnnecessarySemicolonInEnumerationCheck.class,
52 UnnecessarySemicolonInEnumerationCheck.MSG_SEMI),
53 };
54
55 final List<String> expectedXpathQueries = Collections.singletonList(
56 "/COMPILATION_UNIT/ENUM_DEF[./IDENT[@text='Bad']]/OBJBLOCK/SEMI"
57 );
58
59 runVerifications(moduleConfig, fileToProcess, expectedViolation, expectedXpathQueries);
60 }
61
62 @Test
63 public void testAll() throws Exception {
64 final File fileToProcess = new File(getPath(
65 "InputXpathUnnecessarySemicolonInEnumerationAll.java"
66 ));
67
68 final DefaultConfiguration moduleConfig =
69 createModuleConfig(UnnecessarySemicolonInEnumerationCheck.class);
70
71 final String[] expectedViolation = {
72 "4:52: " + getCheckMessage(UnnecessarySemicolonInEnumerationCheck.class,
73 UnnecessarySemicolonInEnumerationCheck.MSG_SEMI),
74 };
75
76 final List<String> expectedXpathQueries = Collections.singletonList(
77 "/COMPILATION_UNIT/ENUM_DEF[./IDENT[@text="
78 + "'InputXpathUnnecessarySemicolonInEnumerationAll']]"
79 + "/OBJBLOCK/SEMI"
80 );
81
82 runVerifications(moduleConfig, fileToProcess, expectedViolation, expectedXpathQueries);
83 }
84 }