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.Arrays;
24 import java.util.Collections;
25 import java.util.List;
26
27 import org.junit.jupiter.api.Test;
28
29 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
30 import com.puppycrawl.tools.checkstyle.checks.blocks.LeftCurlyCheck;
31 import com.puppycrawl.tools.checkstyle.checks.blocks.LeftCurlyOption;
32
33 public class XpathRegressionLeftCurlyTest extends AbstractXpathTestSupport {
34
35 private final String checkName = LeftCurlyCheck.class.getSimpleName();
36
37 @Override
38 protected String getCheckName() {
39 return checkName;
40 }
41
42 @Test
43 public void testOne() throws Exception {
44 final File fileToProcess =
45 new File(getPath("InputXpathLeftCurlyOne.java"));
46
47 final DefaultConfiguration moduleConfig =
48 createModuleConfig(LeftCurlyCheck.class);
49
50 final String[] expectedViolation = {
51 "4:1: " + getCheckMessage(LeftCurlyCheck.class,
52 LeftCurlyCheck.MSG_KEY_LINE_PREVIOUS, "{", 1),
53 };
54
55 final List<String> expectedXpathQueries = Arrays.asList(
56 "/COMPILATION_UNIT/CLASS_DEF"
57 + "[./IDENT[@text='InputXpathLeftCurlyOne']]/OBJBLOCK",
58 "/COMPILATION_UNIT/CLASS_DEF"
59 + "[./IDENT[@text='InputXpathLeftCurlyOne']]/OBJBLOCK/LCURLY"
60 );
61
62 runVerifications(moduleConfig, fileToProcess, expectedViolation,
63 expectedXpathQueries);
64 }
65
66 @Test
67 public void testTwo() throws Exception {
68 final File fileToProcess =
69 new File(getPath("InputXpathLeftCurlyTwo.java"));
70
71 final DefaultConfiguration moduleConfig =
72 createModuleConfig(LeftCurlyCheck.class);
73 moduleConfig.addProperty("option", LeftCurlyOption.NL.toString());
74
75 final String[] expectedViolation = {
76 "3:37: " + getCheckMessage(LeftCurlyCheck.class,
77 LeftCurlyCheck.MSG_KEY_LINE_NEW, "{", 37),
78 };
79
80 final List<String> expectedXpathQueries = Arrays.asList(
81 "/COMPILATION_UNIT/CLASS_DEF"
82 + "[./IDENT[@text='InputXpathLeftCurlyTwo']]/OBJBLOCK",
83 "/COMPILATION_UNIT/CLASS_DEF"
84 + "[./IDENT[@text='InputXpathLeftCurlyTwo']]/OBJBLOCK/LCURLY"
85 );
86
87 runVerifications(moduleConfig, fileToProcess, expectedViolation,
88 expectedXpathQueries);
89 }
90
91 @Test
92 public void testThree() throws Exception {
93 final File fileToProcess =
94 new File(getPath("InputXpathLeftCurlyThree.java"));
95
96 final DefaultConfiguration moduleConfig =
97 createModuleConfig(LeftCurlyCheck.class);
98
99 final String[] expectedViolation = {
100 "5:19: " + getCheckMessage(LeftCurlyCheck.class,
101 LeftCurlyCheck.MSG_KEY_LINE_BREAK_AFTER, "{", 19),
102 };
103
104 final List<String> expectedXpathQueries = Collections.singletonList(
105 "/COMPILATION_UNIT/CLASS_DEF"
106 + "[./IDENT[@text='InputXpathLeftCurlyThree']]/OBJBLOCK"
107 + "/METHOD_DEF[./IDENT[@text='sample']]/SLIST/LITERAL_IF/SLIST"
108 );
109
110 runVerifications(moduleConfig, fileToProcess, expectedViolation,
111 expectedXpathQueries);
112 }
113 }