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.filters;
21  
22  import org.junit.jupiter.api.Test;
23  
24  import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport;
25  import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
26  
27  public class SuppressWithPlainTextCommentFilterExamplesTest
28          extends AbstractExamplesModuleTestSupport {
29  
30      @Override
31      protected String getPackageLocation() {
32          return "com/puppycrawl/tools/checkstyle/filters/suppresswithplaintextcommentfilter";
33      }
34  
35      @Test
36      public void testExample1() throws Exception {
37          final String fileWithConfig = getPath("Example1.java");
38          final String targetFile = getPath("Example1.properties");
39          final String[] expected = {
40              "7: Duplicated property 'keyC' (2 occurrence(s)).",
41          };
42  
43          verifyWithInlineConfigParserSeparateConfigAndTarget(fileWithConfig, targetFile, expected);
44      }
45  
46      @Test
47      public void testExample2() throws Exception {
48          final String fileWithConfig = getPath("Example2.java");
49          final String targetFile = getPath("Example2.properties");
50          final String[] expected = {
51              "7: Duplicated property 'keyC' (2 occurrence(s)).",
52          };
53  
54          verifyWithInlineConfigParserSeparateConfigAndTarget(fileWithConfig, targetFile, expected);
55      }
56  
57      @Test
58      public void testExample3() throws Exception {
59          final String fileWithConfig = getPath("Example3.java");
60          final String targetFile = getPath("Example3.properties");
61          final String[] expected = {
62              "7: Property key 'keyA' is not in the right order with previous property 'keyB'.",
63              "10: Duplicated property 'keyC' (2 occurrence(s)).",
64          };
65  
66          verifyWithInlineConfigParserSeparateConfigAndTarget(fileWithConfig, targetFile, expected);
67      }
68  
69      @Test
70      public void testExample4() throws Exception {
71          final String fileWithConfig = getPath("Example4.java");
72          final String targetFile = getPath("Example4.xml");
73          final String[] expected = {
74              "12: Type code is not allowed. Use type raw instead.",
75          };
76  
77          verifyWithInlineConfigParserSeparateConfigAndTarget(fileWithConfig, targetFile, expected);
78      }
79  
80      @Test
81      public void testExample5() throws Exception {
82          final String fileWithConfig = getPath("Example5.java");
83          final String targetFile = getPath("Example5.xml");
84          final String[] expected = {
85              "6: Type code is not allowed. Use type raw instead.",
86              "13: Type code is not allowed. Use type raw instead.",
87          };
88  
89          verifyWithInlineConfigParserSeparateConfigAndTarget(fileWithConfig, targetFile, expected);
90      }
91  
92      @Test
93      public void testExample6() throws Exception {
94          final String fileWithConfig = getPath("Example6.java");
95          final String targetFile = getPath("Example6.xml");
96          final String[] expected = {
97              "6: Type config is not allowed in this file.",
98          };
99  
100         verifyWithInlineConfigParserSeparateConfigAndTarget(fileWithConfig, targetFile, expected);
101     }
102 
103     @Test
104     public void testExample7() throws Exception {
105         final String fileWithConfig = getPath("Example7.java");
106         final String targetFile = getPath("Example7.xml");
107         final String[] expected = {
108             "6: Type config is not allowed in this file.",
109         };
110 
111         verifyWithInlineConfigParserSeparateConfigAndTarget(fileWithConfig, targetFile, expected);
112     }
113 
114     @Test
115     public void testExample8() throws Exception {
116         final String fileWithConfig = getPath("Example8.java");
117         final String targetFile = getPath("Example8.sql");
118         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
119 
120         verifyWithInlineConfigParserSeparateConfigAndTarget(fileWithConfig, targetFile, expected);
121     }
122 
123     @Test
124     public void testExample9() throws Exception {
125         final String[] expected = {
126             "30: Line is longer than 100 characters (found 183).",
127         };
128 
129         verifyWithInlineConfigParser(getNonCompilablePath("Example9.java"), expected);
130     }
131 }