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.coding;
21  
22  import static com.google.common.truth.Truth.assertWithMessage;
23  import static com.puppycrawl.tools.checkstyle.checks.coding.MultipleVariableDeclarationsCheck.MSG_MULTIPLE;
24  import static com.puppycrawl.tools.checkstyle.checks.coding.MultipleVariableDeclarationsCheck.MSG_MULTIPLE_COMMA;
25  
26  import org.junit.jupiter.api.Test;
27  
28  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
29  
30  public class MultipleVariableDeclarationsCheckTest extends AbstractModuleTestSupport {
31  
32      @Override
33      protected String getPackageLocation() {
34          return "com/puppycrawl/tools/checkstyle/checks/coding/multiplevariabledeclarations";
35      }
36  
37      @Test
38      public void testIt() throws Exception {
39  
40          final String[] expected = {
41              "11:5: " + getCheckMessage(MSG_MULTIPLE_COMMA),
42              "12:5: " + getCheckMessage(MSG_MULTIPLE),
43              "15:9: " + getCheckMessage(MSG_MULTIPLE_COMMA),
44              "16:9: " + getCheckMessage(MSG_MULTIPLE),
45              "20:5: " + getCheckMessage(MSG_MULTIPLE),
46              "23:5: " + getCheckMessage(MSG_MULTIPLE),
47              "42:9: " + getCheckMessage(MSG_MULTIPLE),
48              "42:31: " + getCheckMessage(MSG_MULTIPLE),
49              "42:44: " + getCheckMessage(MSG_MULTIPLE),
50          };
51  
52          verifyWithInlineConfigParser(
53                  getPath("InputMultipleVariableDeclarations.java"),
54                 expected);
55      }
56  
57      @Test
58      public void testTokensNotNull() {
59          final MultipleVariableDeclarationsCheck check = new MultipleVariableDeclarationsCheck();
60          assertWithMessage("Acceptable tokens should not be null")
61              .that(check.getAcceptableTokens())
62              .isNotNull();
63          assertWithMessage("Default tokens should not be null")
64              .that(check.getDefaultTokens())
65              .isNotNull();
66          assertWithMessage("Required tokens should not be null")
67              .that(check.getRequiredTokens())
68              .isNotNull();
69      }
70  
71      @Test
72      public void test() throws Exception {
73  
74          final String[] expected = {
75              "11:5: " + getCheckMessage(MSG_MULTIPLE),
76              "14:5: " + getCheckMessage(MSG_MULTIPLE),
77          };
78  
79          verifyWithInlineConfigParser(
80                  getPath("InputMultipleVariableDeclarations2.java"),
81                 expected);
82      }
83  
84  }