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.NoWhitespaceBeforeCaseDefaultColonCheck.MSG_KEY;
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
30 public class NoWhitespaceBeforeCaseDefaultColonCheckTest
31 extends AbstractModuleTestSupport {
32
33 @Override
34 public String getPackageLocation() {
35 return "com/puppycrawl/tools/checkstyle/checks/whitespace"
36 + "/nowhitespacebeforecasedefaultcolon";
37 }
38
39 @Test
40 public void testDefault() throws Exception {
41 final String[] expected = {
42 "15:20: " + getCheckMessage(MSG_KEY, ":"),
43 "19:21: " + getCheckMessage(MSG_KEY, ":"),
44 "32:37: " + getCheckMessage(MSG_KEY, ":"),
45 "40:21: " + getCheckMessage(MSG_KEY, ":"),
46 "44:28: " + getCheckMessage(MSG_KEY, ":"),
47 "47:1: " + getCheckMessage(MSG_KEY, ":"),
48 "50:27: " + getCheckMessage(MSG_KEY, ":"),
49 "61:38: " + getCheckMessage(MSG_KEY, ":"),
50 "66:38: " + getCheckMessage(MSG_KEY, ":"),
51 "79:24: " + getCheckMessage(MSG_KEY, ":"),
52 "82:21: " + getCheckMessage(MSG_KEY, ":"),
53 "89:38: " + getCheckMessage(MSG_KEY, ":"),
54 "92:35: " + getCheckMessage(MSG_KEY, ":"),
55 };
56 verifyWithInlineConfigParser(
57 getPath("InputNoWhitespaceBeforeCaseDefaultColon.java"),
58 expected);
59 }
60
61 @Test
62 public void testDefaultNonCompilable() throws Exception {
63 final String[] expected = {
64 "36:22: " + getCheckMessage(MSG_KEY, ":"),
65 "39:21: " + getCheckMessage(MSG_KEY, ":"),
66 "42:25: " + getCheckMessage(MSG_KEY, ":"),
67 "61:20: " + getCheckMessage(MSG_KEY, ":"),
68 "74:32: " + getCheckMessage(MSG_KEY, ":"),
69 "91:17: " + getCheckMessage(MSG_KEY, ":"),
70 "94:20: " + getCheckMessage(MSG_KEY, ":"),
71 "97:21: " + getCheckMessage(MSG_KEY, ":"),
72 };
73 verifyWithInlineConfigParser(
74 getPath("InputNoWhitespaceBeforeCaseDefaultColonEnumAndStrings.java"),
75 expected);
76 }
77
78 @Test
79 public void testAcceptableTokenIsColon() {
80 final NoWhitespaceBeforeCaseDefaultColonCheck check =
81 new NoWhitespaceBeforeCaseDefaultColonCheck();
82 assertWithMessage("Acceptable token should be colon")
83 .that(new int[] {TokenTypes.COLON})
84 .isEqualTo(check.getAcceptableTokens());
85 }
86
87 @Test
88 public void testPatternMatchingForSwitch() throws Exception {
89 final String[] expected = {
90 "15:62: " + getCheckMessage(MSG_KEY, ":"),
91 "17:21: " + getCheckMessage(MSG_KEY, ":"),
92 "19:21: " + getCheckMessage(MSG_KEY, ":"),
93 "22:67: " + getCheckMessage(MSG_KEY, ":"),
94 "25:36: " + getCheckMessage(MSG_KEY, ":"),
95 "27:21: " + getCheckMessage(MSG_KEY, ":"),
96 };
97 verifyWithInlineConfigParser(
98 getNonCompilablePath(
99 "InputNoWhitespaceBeforeCaseDefaultColonPatternMatchingForSwitch.java"),
100 expected);
101 }
102
103 }