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.UnnecessarySemicolonAfterOuterTypeDeclarationCheck.MSG_SEMI;
24  
25  import org.junit.jupiter.api.Test;
26  
27  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
28  import com.puppycrawl.tools.checkstyle.api.TokenTypes;
29  import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
30  
31  public class UnnecessarySemicolonAfterOuterTypeDeclarationCheckTest
32      extends AbstractModuleTestSupport {
33  
34      @Override
35      protected String getPackageLocation() {
36          return "com/puppycrawl/tools/checkstyle/checks/coding/"
37              + "unnecessarysemicolonafteroutertypedeclaration";
38      }
39  
40      @Test
41      public void testDefault() throws Exception {
42  
43          final String[] expected = {
44              "28:2: " + getCheckMessage(MSG_SEMI),
45              "32:2: " + getCheckMessage(MSG_SEMI),
46              "36:2: " + getCheckMessage(MSG_SEMI),
47              "40:2: " + getCheckMessage(MSG_SEMI),
48          };
49  
50          verifyWithInlineConfigParser(
51                  getPath("InputUnnecessarySemicolonAfterOuterTypeDeclaration.java"),
52              expected);
53      }
54  
55      @Test
56      public void testUnnecessarySemicolonAfterOuterTypeDeclarationRecords() throws Exception {
57  
58          final String[] expected = {
59              "17:2: " + getCheckMessage(MSG_SEMI),
60              "23:2: " + getCheckMessage(MSG_SEMI),
61          };
62  
63          verifyWithInlineConfigParser(
64              getNonCompilablePath("InputUnnecessarySemicolonAfterOuterTypeDeclarationRecords.java"),
65              expected);
66      }
67  
68      @Test
69      public void testTokens() {
70          final UnnecessarySemicolonAfterOuterTypeDeclarationCheck check =
71              new UnnecessarySemicolonAfterOuterTypeDeclarationCheck();
72          final int[] expected = {
73              TokenTypes.CLASS_DEF,
74              TokenTypes.INTERFACE_DEF,
75              TokenTypes.ENUM_DEF,
76              TokenTypes.ANNOTATION_DEF,
77              TokenTypes.RECORD_DEF,
78          };
79          assertWithMessage("Acceptable required tokens are invalid")
80              .that(check.getAcceptableTokens())
81              .isEqualTo(expected);
82          assertWithMessage("Default required tokens are invalid")
83              .that(check.getDefaultTokens())
84              .isEqualTo(expected);
85          assertWithMessage("Required required tokens are invalid")
86              .that(check.getRequiredTokens())
87              .isEqualTo(CommonUtil.EMPTY_INT_ARRAY);
88      }
89  }