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.puppycrawl.tools.checkstyle.checks.coding.UnusedLocalVariableCheck.MSG_UNUSED_LOCAL_VARIABLE;
23 import static com.puppycrawl.tools.checkstyle.checks.coding.UnusedLocalVariableCheck.MSG_UNUSED_NAMED_LOCAL_VARIABLE;
24
25 import org.junit.jupiter.api.Test;
26
27 import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport;
28
29 public class UnusedLocalVariableCheckExamplesTest extends AbstractExamplesModuleTestSupport {
30 @Override
31 protected String getPackageLocation() {
32 return "com/puppycrawl/tools/checkstyle/checks/coding/unusedlocalvariable";
33 }
34
35 @Test
36 public void testExample1() throws Exception {
37 final String[] expected = {
38 "16:5: " + getCheckMessage(MSG_UNUSED_NAMED_LOCAL_VARIABLE, "k"),
39 "26:5: " + getCheckMessage(MSG_UNUSED_NAMED_LOCAL_VARIABLE, "arr"),
40 "32:5: " + getCheckMessage(MSG_UNUSED_NAMED_LOCAL_VARIABLE, "s"),
41 "39:5: " + getCheckMessage(MSG_UNUSED_NAMED_LOCAL_VARIABLE, "s"),
42 "49:10: " + getCheckMessage(MSG_UNUSED_NAMED_LOCAL_VARIABLE, "i"),
43 };
44
45 verifyWithInlineConfigParser(
46 getNonCompilablePath("Example1.java"), expected);
47 }
48
49 @Test
50 public void testExample2() throws Exception {
51 final String[] expected = {
52 "17:5: " + getCheckMessage(MSG_UNUSED_LOCAL_VARIABLE, "k"),
53 "27:5: " + getCheckMessage(MSG_UNUSED_LOCAL_VARIABLE, "arr"),
54 "33:5: " + getCheckMessage(MSG_UNUSED_LOCAL_VARIABLE, "s"),
55 "34:5: " + getCheckMessage(MSG_UNUSED_LOCAL_VARIABLE, "_"),
56 "40:5: " + getCheckMessage(MSG_UNUSED_LOCAL_VARIABLE, "s"),
57 "50:10: " + getCheckMessage(MSG_UNUSED_LOCAL_VARIABLE, "i"),
58 "52:10: " + getCheckMessage(MSG_UNUSED_LOCAL_VARIABLE, "_"),
59 };
60
61 verifyWithInlineConfigParser(
62 getNonCompilablePath("Example2.java"), expected);
63 }
64 }