View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2025 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 com.puppycrawl.tools.checkstyle.checks.indentation;
21  
22  import org.junit.jupiter.api.Test;
23  
24  import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport;
25  
26  public class CommentsIndentationCheckExamplesTest extends AbstractExamplesModuleTestSupport {
27      @Override
28      protected String getPackageLocation() {
29          return "com/puppycrawl/tools/checkstyle/checks/indentation/commentsindentation";
30      }
31  
32      @Test
33      public void testExample1() throws Exception {
34          final String[] expected = {
35              "18:7: " + getCheckMessage(
36                      CommentsIndentationCheck.MSG_KEY_BLOCK, 21, 6, 4),
37              "31:9: " + getCheckMessage(
38                      CommentsIndentationCheck.MSG_KEY_SINGLE, 30, 8, 4),
39          };
40  
41          verifyWithInlineConfigParser(getPath("Example1.java"), expected);
42      }
43  
44      @Test
45      public void testExample2() throws Exception {
46          final String[] expected = {
47              "33:9: " + getCheckMessage(
48                      CommentsIndentationCheck.MSG_KEY_SINGLE, 32, 8, 4),
49          };
50  
51          verifyWithInlineConfigParser(getPath("Example2.java"), expected);
52      }
53  
54      @Test
55      public void testExample3() throws Exception {
56          final String[] expected = {
57              "17:5: " + getCheckMessage(
58                      CommentsIndentationCheck.MSG_KEY_SINGLE, 20, 4, 2),
59          };
60  
61          verifyWithInlineConfigParser(getPath("Example3.java"), expected);
62      }
63  
64      @Test
65      public void testExample4() throws Exception {
66          final String[] expected = {
67              "21:2: " + getCheckMessage(
68                      CommentsIndentationCheck.MSG_KEY_SINGLE, 22, 1, 2),
69          };
70  
71          verifyWithInlineConfigParser(getPath("Example4.java"), expected);
72      }
73  
74      @Test
75      public void testExample5() throws Exception {
76          final String[] expected = {
77              "20:13: " + getCheckMessage(
78                      CommentsIndentationCheck.MSG_KEY_SINGLE, 21, 12, 8),
79              "26:6: " + getCheckMessage(
80                      CommentsIndentationCheck.MSG_KEY_SINGLE, "25, 27", 5, "6, 6"),
81          };
82  
83          verifyWithInlineConfigParser(getPath("Example5.java"), expected);
84      }
85  
86      @Test
87      public void testExample6() throws Exception {
88          final String[] expected = {
89              "15:5: " + getCheckMessage(
90                      CommentsIndentationCheck.MSG_KEY_SINGLE, 16, 4, 8),
91          };
92  
93          verifyWithInlineConfigParser(getPath("Example6.java"), expected);
94      }
95  
96      @Test
97      public void testExample7() throws Exception {
98          final String[] expected = {
99              "22:15: " + getCheckMessage(
100                     CommentsIndentationCheck.MSG_KEY_SINGLE, 25, 14, 4),
101             "23:10: " + getCheckMessage(
102                     CommentsIndentationCheck.MSG_KEY_SINGLE, 25, 9, 4),
103             "24:8: " + getCheckMessage(
104                     CommentsIndentationCheck.MSG_KEY_SINGLE, 25, 7, 4),
105         };
106 
107         verifyWithInlineConfigParser(getPath("Example7.java"), expected);
108     }
109 
110     @Test
111     public void testExample8() throws Exception {
112         final String[] expected = {
113             "24:6: " + getCheckMessage(
114                     CommentsIndentationCheck.MSG_KEY_SINGLE, "23, 25", 5, "6, 4"),
115         };
116 
117         verifyWithInlineConfigParser(getPath("Example8.java"), expected);
118     }
119 
120 }