View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2026 the original author or authors.
4   //
5   // This library is free software; you can redistribute it and/or
6   // modify it under the terms of the GNU Lesser General Public
7   // License as published by the Free Software Foundation; either
8   // version 2.1 of the License, or (at your option) any later version.
9   //
10  // This library is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  // Lesser General Public License for more details.
14  //
15  // You should have received a copy of the GNU Lesser General Public
16  // License along with this library; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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.MultilineCommentLeadingAsteriskPresenceCheck;
30  
31  public class XpathRegressionMultilineCommentLeadingAsteriskPresenceTest
32          extends AbstractXpathTestSupport {
33  
34      private final String checkName =
35                  MultilineCommentLeadingAsteriskPresenceCheck.class.getSimpleName();
36  
37      @Override
38      protected String getCheckName() {
39          return checkName;
40      }
41  
42      @Test
43      public void testMultilineCommentLeadingAsteriskPresence() throws Exception {
44          final File fileProcess =
45              new File(getPath("InputXpathMultilineCommentLeadingAsteriskPresenceOne.java"));
46          final DefaultConfiguration config =
47              createModuleConfig(MultilineCommentLeadingAsteriskPresenceCheck.class);
48  
49          final String[] expected = {
50              "4:5: " + getCheckMessage(
51                  MultilineCommentLeadingAsteriskPresenceCheck.class,
52                  MultilineCommentLeadingAsteriskPresenceCheck.MSG_MISSING_ASTERISK, "5"),
53          };
54  
55          final List<String> expectedXpathQueries = Collections.singletonList(
56              "/COMPILATION_UNIT/CLASS_DEF[./IDENT"
57                      + "[@text='InputXpathMultilineCommentLeadingAsteriskPresenceOne']]"
58                      + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='method']]/MODIFIERS"
59                      + "/BLOCK_COMMENT_BEGIN[./COMMENT_CONTENT"
60                      + "[@text='  // warn\\n        line5\\n     ']]"
61          );
62  
63          runVerifications(config, fileProcess, expected, expectedXpathQueries);
64      }
65  
66      @Test
67      public void testMultilineCommentLeadingAsteriskPresenceTwo() throws Exception {
68          final File fileProcess =
69                  new File(getPath("InputXpathMultilineCommentLeadingAsteriskPresenceTwo.java"));
70          final DefaultConfiguration config =
71                  createModuleConfig(MultilineCommentLeadingAsteriskPresenceCheck.class);
72  
73          final String[] expected = {
74              "3:1: " + getCheckMessage(
75                      MultilineCommentLeadingAsteriskPresenceCheck.class,
76                      MultilineCommentLeadingAsteriskPresenceCheck.MSG_MISSING_ASTERISK, "4"),
77          };
78  
79          final List<String> expectedXpathQueries = Collections.singletonList(
80                  "/COMPILATION_UNIT/CLASS_DEF[./IDENT"
81                          + "[@text='InputXpathMultilineCommentLeadingAsteriskPresenceTwo']]"
82                          + "/MODIFIERS/BLOCK_COMMENT_BEGIN[./COMMENT_CONTENT"
83                          + "[@text=' // warn\\n   line4\\n ']]"
84          );
85  
86          runVerifications(config, fileProcess, expected, expectedXpathQueries);
87      }
88  
89      @Test
90      public void testMultilineCommentLeadingAsteriskPresenceThree() throws Exception {
91          final File fileProcess =
92                  new File(getPath("InputXpathMultilineCommentLeadingAsteriskPresenceThree.java"));
93          final DefaultConfiguration config =
94                  createModuleConfig(MultilineCommentLeadingAsteriskPresenceCheck.class);
95  
96          final String[] expected = {
97              "5:9: " + getCheckMessage(
98                      MultilineCommentLeadingAsteriskPresenceCheck.class,
99                      MultilineCommentLeadingAsteriskPresenceCheck.MSG_MISSING_ASTERISK, "6"),
100         };
101 
102         final List<String> expectedXpathQueries = Collections.singletonList(
103                 "/COMPILATION_UNIT/CLASS_DEF[./IDENT"
104                         + "[@text='InputXpathMultilineCommentLeadingAsteriskPresenceThree']]"
105                         + "/OBJBLOCK/METHOD_DEF[./IDENT[@text='method']]/SLIST/BLOCK_COMMENT_BEGIN"
106                         + "[./COMMENT_CONTENT[@text='  // warn\\n           line6\\n         ']]"
107         );
108 
109         runVerifications(config, fileProcess, expected, expectedXpathQueries);
110     }
111 
112 }