View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2024 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.annotation;
21  
22  import org.junit.jupiter.api.Test;
23  
24  import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport;
25  import com.puppycrawl.tools.checkstyle.checks.naming.AbstractNameCheck;
26  import com.puppycrawl.tools.checkstyle.checks.naming.ConstantNameCheck;
27  import com.puppycrawl.tools.checkstyle.checks.naming.MemberNameCheck;
28  import com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck;
29  import com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceAfterCheck;
30  
31  public class SuppressWarningsHolderExamplesTest extends AbstractExamplesModuleTestSupport {
32      @Override
33      protected String getPackageLocation() {
34          return "com/puppycrawl/tools/checkstyle/checks/annotation/suppresswarningsholder";
35      }
36  
37      @Test
38      public void testExample1() throws Exception {
39          final String pattern1 = "^[a-z][a-zA-Z0-9]*$";
40          final String pattern2 = "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$";
41          final String[] expected = {
42              "21:15: " + getCheckMessage(MemberNameCheck.class,
43                          AbstractNameCheck.MSG_INVALID_PATTERN, "K", pattern1),
44              "25:28: " + getCheckMessage(ConstantNameCheck.class,
45                          AbstractNameCheck.MSG_INVALID_PATTERN, "i", pattern2),
46              "35:15: " + getCheckMessage(NoWhitespaceAfterCheck.class,
47                          NoWhitespaceAfterCheck.MSG_KEY, "int"),
48              "35:18: " + getCheckMessage(MemberNameCheck.class,
49                          AbstractNameCheck.MSG_INVALID_PATTERN, "ARR", pattern1),
50  
51          };
52  
53          verifyWithInlineConfigParser(getPath("Example1.java"), expected);
54      }
55  
56      @Test
57      public void testExample2() throws Exception {
58          final String[] expected = {
59              "19:15: " + getCheckMessage(ParameterNumberCheck.class,
60                          ParameterNumberCheck.MSG_KEY, 7, 8),
61  
62          };
63  
64          verifyWithInlineConfigParser(getPath("Example2.java"), expected);
65      }
66  }