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.List;
25
26 import org.junit.jupiter.api.Test;
27
28 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
29 import com.puppycrawl.tools.checkstyle.checks.whitespace.NoLineWrapCheck;
30
31 public class XpathRegressionNoLineWrapTest extends AbstractXpathTestSupport {
32
33 @Override
34 protected String getCheckName() {
35 return NoLineWrapCheck.class.getSimpleName();
36 }
37
38 @Test
39 public void testDefault() throws Exception {
40 final File fileToProcess = new File(
41 getPath("InputXpathNoLineWrapDefault.java")
42 );
43
44 final DefaultConfiguration moduleConfig =
45 createModuleConfig(NoLineWrapCheck.class);
46
47 final String[] expectedViolation = {
48 "1:1: " + getCheckMessage(NoLineWrapCheck.class,
49 NoLineWrapCheck.MSG_KEY, "package"),
50 };
51
52 final List<String> expectedXpathQueries = Arrays.asList(
53 "/COMPILATION_UNIT", "/COMPILATION_UNIT/PACKAGE_DEF"
54 );
55
56 runVerifications(moduleConfig, fileToProcess, expectedViolation, expectedXpathQueries);
57 }
58
59 @Test
60 public void testMethodDef() throws Exception {
61 final File fileToProcess = new File(
62 getPath("InputXpathNoLineWrapTokensMethodDef.java")
63 );
64
65 final DefaultConfiguration moduleConfig =
66 createModuleConfig(NoLineWrapCheck.class);
67 moduleConfig.addProperty("tokens", "METHOD_DEF");
68
69 final String[] expectedViolation = {
70 "4:5: " + getCheckMessage(NoLineWrapCheck.class,
71 NoLineWrapCheck.MSG_KEY, "METHOD_DEF"),
72 };
73
74 final List<String> expectedXpathQueries = Arrays.asList(
75 "/COMPILATION_UNIT/CLASS_DEF[./IDENT"
76 + "[@text='InputXpathNoLineWrapTokensMethodDef']]"
77 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='test2']]",
78
79 "/COMPILATION_UNIT/CLASS_DEF[./IDENT"
80 + "[@text='InputXpathNoLineWrapTokensMethodDef']]"
81 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='test2']]"
82 + "/MODIFIERS",
83
84 "/COMPILATION_UNIT/CLASS_DEF[./IDENT"
85 + "[@text='InputXpathNoLineWrapTokensMethodDef']]"
86 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='test2']]"
87 + "/MODIFIERS/LITERAL_PUBLIC"
88
89 );
90
91 runVerifications(moduleConfig, fileToProcess, expectedViolation, expectedXpathQueries);
92 }
93
94 @Test
95 public void testTokensCtorDef() throws Exception {
96 final File fileToProcess = new File(
97 getPath("InputXpathNoLineWrapTokensCtorDef.java")
98 );
99
100 final DefaultConfiguration moduleConfig =
101 createModuleConfig(NoLineWrapCheck.class);
102 moduleConfig.addProperty("tokens", "CTOR_DEF");
103
104 final String[] expectedViolation = {
105 "4:5: " + getCheckMessage(NoLineWrapCheck.class,
106 NoLineWrapCheck.MSG_KEY, "CTOR_DEF"),
107 };
108
109 final List<String> expectedXpathQueries = Arrays.asList(
110 "/COMPILATION_UNIT/CLASS_DEF"
111 + "[./IDENT[@text='InputXpathNoLineWrapTokensCtorDef']]"
112 + "/OBJBLOCK/CTOR_DEF[./IDENT[@text='InputXpathNoLineWrapTokensCtorDef']]",
113
114 "/COMPILATION_UNIT/CLASS_DEF"
115 + "[./IDENT[@text='InputXpathNoLineWrapTokensCtorDef']]"
116 + "/OBJBLOCK/CTOR_DEF[./IDENT[@text='InputXpathNoLineWrapTokensCtorDef']]"
117 + "/MODIFIERS",
118
119 "/COMPILATION_UNIT/CLASS_DEF"
120 + "[./IDENT[@text='InputXpathNoLineWrapTokensCtorDef']]"
121 + "/OBJBLOCK/CTOR_DEF/IDENT[@text='InputXpathNoLineWrapTokensCtorDef']"
122 );
123
124 runVerifications(moduleConfig, fileToProcess, expectedViolation, expectedXpathQueries);
125 }
126
127 }