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.whitespace;
21  
22  import static com.google.common.truth.Truth.assertWithMessage;
23  import static com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck.MSG_WS_FOLLOWED;
24  import static com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck.MSG_WS_NOT_FOLLOWED;
25  import static com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck.MSG_WS_NOT_PRECEDED;
26  import static com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck.MSG_WS_PRECEDED;
27  
28  import org.junit.jupiter.api.Test;
29  
30  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
31  import com.puppycrawl.tools.checkstyle.api.TokenTypes;
32  import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
33  
34  public class TypecastParenPadCheckTest
35      extends AbstractModuleTestSupport {
36  
37      @Override
38      protected String getPackageLocation() {
39          return "com/puppycrawl/tools/checkstyle/checks/whitespace/typecastparenpad";
40      }
41  
42      @Test
43      public void testDefault()
44              throws Exception {
45          final String[] expected = {
46              "86:13: " + getCheckMessage(MSG_WS_FOLLOWED, "("),
47              "86:22: " + getCheckMessage(MSG_WS_PRECEDED, ")"),
48          };
49          verifyWithInlineConfigParser(
50                  getPath("InputTypecastParenPadWhitespace.java"), expected);
51      }
52  
53      @Test
54      public void testSpace()
55              throws Exception {
56          final String[] expected = {
57              "84:20: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
58              "84:27: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
59              "85:13: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
60              "85:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
61              "87:13: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
62              "87:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
63              "238:17: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "("),
64              "238:21: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ")"),
65          };
66          verifyWithInlineConfigParser(
67                  getPath("InputTypecastParenPadWhitespaceTestSpace.java"), expected);
68      }
69  
70      @Test
71      public void test1322879() throws Exception {
72          final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
73          verifyWithInlineConfigParser(
74                  getPath("InputTypecastParenPadWhitespaceAround.java"),
75                 expected);
76      }
77  
78      @Test
79      public void testGetAcceptableTokens() {
80          final TypecastParenPadCheck typecastParenPadCheckObj = new TypecastParenPadCheck();
81          final int[] actual = typecastParenPadCheckObj.getAcceptableTokens();
82          final int[] expected = {
83              TokenTypes.RPAREN,
84              TokenTypes.TYPECAST,
85          };
86          assertWithMessage("Invalid acceptable tokens")
87              .that(actual)
88              .isEqualTo(expected);
89      }
90  
91  }