1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 }