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 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.MemberNameCheck;
27  import com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck;
28  import com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceAfterCheck;
29  
30  public class SuppressWarningsHolderExamplesTest extends AbstractExamplesModuleTestSupport {
31  
32      @Override
33      public 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[] expected = {
41              "20:15: " + getCheckMessage(MemberNameCheck.class,
42                          AbstractNameCheck.MSG_INVALID_PATTERN, "K", pattern1),
43              "28:15: " + getCheckMessage(NoWhitespaceAfterCheck.class,
44                          NoWhitespaceAfterCheck.MSG_KEY, "int"),
45              "28:18: " + getCheckMessage(MemberNameCheck.class,
46                          AbstractNameCheck.MSG_INVALID_PATTERN, "ARR", pattern1),
47              "34:17: " + getCheckMessage(ParameterNumberCheck.class,
48                          ParameterNumberCheck.MSG_KEY, 7, 8),
49  
50          };
51  
52          verifyWithInlineConfigParser(getPath("Example1.java"), expected);
53      }
54  
55      @Test
56      public void testExample2() throws Exception {
57          final String pattern1 = "^[a-z][a-zA-Z0-9]*$";
58          final String[] expected = {
59              "24:15: " + getCheckMessage(MemberNameCheck.class,
60                          AbstractNameCheck.MSG_INVALID_PATTERN, "K", pattern1),
61              "32:15: " + getCheckMessage(NoWhitespaceAfterCheck.class,
62                          NoWhitespaceAfterCheck.MSG_KEY, "int"),
63              "32:18: " + getCheckMessage(MemberNameCheck.class,
64                          AbstractNameCheck.MSG_INVALID_PATTERN, "ARR", pattern1),
65          };
66  
67          verifyWithInlineConfigParser(getPath("Example2.java"), expected);
68      }
69  
70      @Test
71      public void testUseCase1() throws Exception {
72          final String[] expected = {
73              "29:15: " + getCheckMessage(ParameterNumberCheck.class,
74                          ParameterNumberCheck.MSG_KEY, 7, 8),
75              "35:15: " + getCheckMessage(ParameterNumberCheck.class,
76                          ParameterNumberCheck.MSG_KEY, 7, 8),
77          };
78  
79          verifyWithInlineConfigParser(getPath("UseCase1.java"), expected);
80      }
81  
82      @Test
83      public void testUseCase2() throws Exception {
84          final String[] expected = {
85              "29:15: " + getCheckMessage(ParameterNumberCheck.class,
86                          ParameterNumberCheck.MSG_KEY, 7, 8),
87              "35:15: " + getCheckMessage(ParameterNumberCheck.class,
88                          ParameterNumberCheck.MSG_KEY, 7, 8),
89          };
90  
91          verifyWithInlineConfigParser(getPath("UseCase2.java"), expected);
92      }
93  
94  }