1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.checkstyle.suppressionxpathfilter.javadoc;
21
22 import java.io.File;
23 import java.util.Arrays;
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.javadoc.MissingJavadocMethodCheck;
31
32 public class XpathRegressionMissingJavadocMethodTest extends AbstractXpathTestSupport {
33
34 @Override
35 protected String getCheckName() {
36 return MissingJavadocMethodCheck.class.getSimpleName();
37 }
38
39 @Override
40 protected String getPackageLocation() {
41 return "org/checkstyle/suppressionxpathfilter/javadoc/missingjavadocmethod";
42 }
43
44 @Test
45 public void testMissingJavadocMethodCtor() throws Exception {
46 final File fileToProcess = new File(
47 getPath("InputXpathMissingJavadocMethodCtor.java")
48 );
49
50 final DefaultConfiguration moduleConfig =
51 createModuleConfig(MissingJavadocMethodCheck.class);
52 moduleConfig.addProperty("tokens", "CTOR_DEF");
53
54 final String[] expectedViolation = {
55 "4:5: " + getCheckMessage(MissingJavadocMethodCheck.class,
56 MissingJavadocMethodCheck.MSG_JAVADOC_MISSING),
57 };
58
59 final List<String> expectedXpathQueries = Arrays.asList(
60 "/COMPILATION_UNIT/CLASS_DEF[./IDENT"
61 + "[@text='InputXpathMissingJavadocMethodCtor']]"
62 + "/OBJBLOCK/CTOR_DEF[."
63 + "/IDENT[@text='InputXpathMissingJavadocMethodCtor']]",
64
65 "/COMPILATION_UNIT/CLASS_DEF"
66 + "[./IDENT[@text='InputXpathMissingJavadocMethodCtor']]"
67 + "/OBJBLOCK/CTOR_DEF[."
68 + "/IDENT[@text='InputXpathMissingJavadocMethodCtor']]"
69 + "/MODIFIERS",
70
71 "/COMPILATION_UNIT/CLASS_DEF"
72 + "[./IDENT[@text='InputXpathMissingJavadocMethodCtor']]"
73 + "/OBJBLOCK/CTOR_DEF[."
74 + "/IDENT[@text='InputXpathMissingJavadocMethodCtor']]"
75 + "/MODIFIERS/LITERAL_PUBLIC"
76 );
77
78 runVerifications(moduleConfig, fileToProcess, expectedViolation, expectedXpathQueries);
79 }
80
81 @Test
82 public void testMissingJavadocMethod() throws Exception {
83 final File fileToProcess = new File(
84 getPath("InputXpathMissingJavadocMethod.java")
85 );
86
87 final DefaultConfiguration moduleConfig =
88 createModuleConfig(MissingJavadocMethodCheck.class);
89 moduleConfig.addProperty("tokens", "METHOD_DEF");
90
91 final String[] expectedViolation = {
92 "4:5: " + getCheckMessage(MissingJavadocMethodCheck.class,
93 MissingJavadocMethodCheck.MSG_JAVADOC_MISSING),
94 };
95
96 final List<String> expectedXpathQueries = Arrays.asList(
97 "/COMPILATION_UNIT/CLASS_DEF"
98 + "[./IDENT[@text='InputXpathMissingJavadocMethod']]"
99 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='foo']]",
100
101 "/COMPILATION_UNIT/CLASS_DEF"
102 + "[./IDENT[@text='InputXpathMissingJavadocMethod']]"
103 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='foo']]"
104 + "/MODIFIERS",
105
106 "/COMPILATION_UNIT/CLASS_DEF"
107 + "[./IDENT[@text='InputXpathMissingJavadocMethod']]"
108 + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='foo']]"
109 + "/MODIFIERS/LITERAL_PUBLIC"
110 );
111
112 runVerifications(moduleConfig, fileToProcess, expectedViolation, expectedXpathQueries);
113 }
114 }