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.coding;
21
22 import static com.google.common.truth.Truth.assertWithMessage;
23 import static com.puppycrawl.tools.checkstyle.checks.coding.NestedForDepthCheck.MSG_KEY;
24
25 import org.junit.jupiter.api.Test;
26
27 import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
28 import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
29
30 public class NestedForDepthCheckTest extends AbstractModuleTestSupport {
31
32 @Override
33 protected String getPackageLocation() {
34 return "com/puppycrawl/tools/checkstyle/checks/coding/nestedfordepth";
35 }
36
37
38
39
40
41
42
43
44
45
46 @Test
47 public void testNestedForDepthCheckCustomMaxLevelTwo() throws Exception {
48
49 final String[] expected = {
50 "32:11: " + getCheckMessage(MSG_KEY, 3, 2),
51 "33:13: " + getCheckMessage(MSG_KEY, 4, 2),
52 "36:13: " + getCheckMessage(MSG_KEY, 4, 2),
53 };
54
55 verifyWithInlineConfigParser(
56 getPath("InputNestedForDepthCheckCustomMaxLevelTwo.java"),
57 expected);
58 }
59
60
61
62
63
64
65
66
67
68
69
70 @Test
71 public void testNestedForDepthCheckCustomMaxLevelFour() throws Exception {
72
73 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
74
75 verifyWithInlineConfigParser(
76 getPath("InputNestedForDepthCheckCustomMaxLevelFour.java"),
77 expected);
78 }
79
80 @Test
81 public void testTokensNotNull() {
82 final NestedForDepthCheck check = new NestedForDepthCheck();
83 assertWithMessage("Acceptable tokens should not be null")
84 .that(check.getAcceptableTokens())
85 .isNotNull();
86 assertWithMessage("Default tokens should not be null")
87 .that(check.getDefaultTokens())
88 .isNotNull();
89 assertWithMessage("Required tokens should not be null")
90 .that(check.getRequiredTokens())
91 .isNotNull();
92 }
93
94 @Test
95 public void testNestedForDepthCheckDefaultMaxLevel() throws Exception {
96 final String[] expected = {
97 "27:9: " + getCheckMessage(MSG_KEY, 2, 1),
98 };
99
100 verifyWithInlineConfigParser(
101 getPath("InputNestedForDepthCheckDefaultMaxLevel.java"),
102 expected);
103 }
104 }