View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2026 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.coding;
21  
22  import static com.google.common.truth.Truth.assertWithMessage;
23  import static com.puppycrawl.tools.checkstyle.checks.coding.VariableDeclarationUsageDistanceCheck.MSG_KEY;
24  import static com.puppycrawl.tools.checkstyle.checks.coding.VariableDeclarationUsageDistanceCheck.MSG_KEY_EXT;
25  
26  import org.junit.jupiter.api.Test;
27  
28  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
29  import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
30  
31  public class VariableDeclarationUsageDistanceCheckTest extends
32          AbstractModuleTestSupport {
33  
34      @Override
35      public String getPackageLocation() {
36          return "com/puppycrawl/tools/checkstyle/checks/coding/variabledeclarationusagedistance";
37      }
38  
39      @Test
40      public void testGeneralLogic() throws Exception {
41          final String[] expected = {
42              "42:9: " + getCheckMessage(MSG_KEY, "a", 2, 1),
43              "50:9: " + getCheckMessage(MSG_KEY, "temp", 2, 1),
44              "56:9: " + getCheckMessage(MSG_KEY, "temp", 2, 1),
45              "69:9: " + getCheckMessage(MSG_KEY, "count", 2, 1),
46              "83:9: " + getCheckMessage(MSG_KEY, "count", 4, 1),
47              "108:9: " + getCheckMessage(MSG_KEY, "arg", 2, 1),
48              "156:9: " + getCheckMessage(MSG_KEY, "m", 3, 1),
49              "157:9: " + getCheckMessage(MSG_KEY, "n", 2, 1),
50              "196:9: " + getCheckMessage(MSG_KEY, "result", 2, 1),
51              "231:9: " + getCheckMessage(MSG_KEY, "t", 5, 1),
52              "234:9: " + getCheckMessage(MSG_KEY, "c", 3, 1),
53              "235:9: " + getCheckMessage(MSG_KEY, "d2", 3, 1),
54              "272:9: " + getCheckMessage(MSG_KEY, "sel", 2, 1),
55              "273:9: " + getCheckMessage(MSG_KEY, "model", 2, 1),
56              "299:9: " + getCheckMessage(MSG_KEY, "sw", 2, 1),
57              "312:9: " + getCheckMessage(MSG_KEY, "wh", 2, 1),
58              "355:9: " + getCheckMessage(MSG_KEY, "green", 2, 1),
59              "356:9: " + getCheckMessage(MSG_KEY, "blue", 3, 1),
60              "379:9: " + getCheckMessage(MSG_KEY, "intervalMs", 2, 1),
61              "466:9: " + getCheckMessage(MSG_KEY, "aOpt", 3, 1),
62              "467:9: " + getCheckMessage(MSG_KEY, "bOpt", 2, 1),
63              "483:9: " + getCheckMessage(MSG_KEY, "l1", 3, 1),
64              "483:9: " + getCheckMessage(MSG_KEY, "l2", 2, 1),
65              "491:9: " + getCheckMessage(MSG_KEY, "myOption", 7, 1),
66              "503:9: " + getCheckMessage(MSG_KEY, "myOption", 6, 1),
67              "516:9: " + getCheckMessage(MSG_KEY, "count", 4, 1),
68              "517:9: " + getCheckMessage(MSG_KEY, "files", 2, 1),
69              "552:13: " + getCheckMessage(MSG_KEY, "id", 2, 1),
70              "554:13: " + getCheckMessage(MSG_KEY, "parentId", 3, 1),
71              "903:9: " + getCheckMessage(MSG_KEY, "a", 4, 1),
72              "913:9: " + getCheckMessage(MSG_KEY, "a", 4, 1),
73              "979:9: " + getCheckMessage(MSG_KEY, "a", 4, 1),
74              "990:9: " + getCheckMessage(MSG_KEY, "a", 2, 1),
75              "1001:9: " + getCheckMessage(MSG_KEY, "a", 3, 1),
76              "1036:9: " + getCheckMessage(MSG_KEY, "c", 3, 1),
77              "1066:9: " + getCheckMessage(MSG_KEY, "a", 4, 1),
78          };
79          verifyWithInlineConfigParser(
80                  getPath("InputVariableDeclarationUsageDistanceGeneral.java"), expected);
81      }
82  
83      @Test
84      public void testGeneralLogic2() throws Exception {
85          final String[] expected = {
86              "17:9: " + getCheckMessage(MSG_KEY, "first", 5, 1),
87              "29:9: " + getCheckMessage(MSG_KEY, "allInvariants", 2, 1),
88          };
89          verifyWithInlineConfigParser(
90                  getPath("InputVariableDeclarationUsageDistanceGeneral2.java"), expected);
91      }
92  
93      @Test
94      public void testIfStatements() throws Exception {
95          final String[] expected = {
96              "18:9: " + getCheckMessage(MSG_KEY, "a", 4, 1),
97              "28:9: " + getCheckMessage(MSG_KEY, "a", 2, 1),
98              "32:9: " + getCheckMessage(MSG_KEY, "b", 2, 1),
99              "38:9: " + getCheckMessage(MSG_KEY, "c", 3, 1),
100             "49:9: " + getCheckMessage(MSG_KEY, "b", 2, 1),
101             "50:9: " + getCheckMessage(MSG_KEY, "c", 3, 1),
102             "51:9: " + getCheckMessage(MSG_KEY, "d", 4, 1),
103             "63:9: " + getCheckMessage(MSG_KEY, "a", 4, 1),
104 
105         };
106         verifyWithInlineConfigParser(
107             getPath("InputVariableDeclarationUsageDistanceIfStatements.java"), expected);
108     }
109 
110     @Test
111     public void testDistance() throws Exception {
112         final String[] expected = {
113             "83:9: " + getCheckMessage(MSG_KEY, "count", 4, 3),
114             "231:9: " + getCheckMessage(MSG_KEY, "t", 5, 3),
115             "491:9: " + getCheckMessage(MSG_KEY, "myOption", 7, 3),
116             "503:9: " + getCheckMessage(MSG_KEY, "myOption", 6, 3),
117             "516:9: " + getCheckMessage(MSG_KEY, "count", 4, 3),
118             "903:9: " + getCheckMessage(MSG_KEY, "a", 4, 3),
119             "913:9: " + getCheckMessage(MSG_KEY, "a", 4, 3),
120             "979:9: " + getCheckMessage(MSG_KEY, "a", 4, 3),
121             "1066:9: " + getCheckMessage(MSG_KEY, "a", 4, 3),
122         };
123         verifyWithInlineConfigParser(
124                 getPath("InputVariableDeclarationUsageDistance.java"), expected);
125     }
126 
127     @Test
128     public void testVariableRegExp() throws Exception {
129         final String[] expected = {
130             "50:9: " + getCheckMessage(MSG_KEY, "temp", 2, 1),
131             "56:9: " + getCheckMessage(MSG_KEY, "temp", 2, 1),
132             "69:9: " + getCheckMessage(MSG_KEY, "count", 2, 1),
133             "83:9: " + getCheckMessage(MSG_KEY, "count", 4, 1),
134             "108:9: " + getCheckMessage(MSG_KEY, "arg", 2, 1),
135             "157:9: " + getCheckMessage(MSG_KEY, "n", 2, 1),
136             "196:9: " + getCheckMessage(MSG_KEY, "result", 2, 1),
137             "235:9: " + getCheckMessage(MSG_KEY, "d2", 3, 1),
138             "272:9: " + getCheckMessage(MSG_KEY, "sel", 2, 1),
139             "273:9: " + getCheckMessage(MSG_KEY, "model", 2, 1),
140             "299:9: " + getCheckMessage(MSG_KEY, "sw", 2, 1),
141             "312:9: " + getCheckMessage(MSG_KEY, "wh", 2, 1),
142             "355:9: " + getCheckMessage(MSG_KEY, "green", 2, 1),
143             "356:9: " + getCheckMessage(MSG_KEY, "blue", 3, 1),
144             "379:9: " + getCheckMessage(MSG_KEY, "intervalMs", 2, 1),
145             "466:9: " + getCheckMessage(MSG_KEY, "aOpt", 3, 1),
146             "467:9: " + getCheckMessage(MSG_KEY, "bOpt", 2, 1),
147             "483:9: " + getCheckMessage(MSG_KEY, "l1", 3, 1),
148             "483:9: " + getCheckMessage(MSG_KEY, "l2", 2, 1),
149             "491:9: " + getCheckMessage(MSG_KEY, "myOption", 7, 1),
150             "503:9: " + getCheckMessage(MSG_KEY, "myOption", 6, 1),
151             "516:9: " + getCheckMessage(MSG_KEY, "count", 4, 1),
152             "517:9: " + getCheckMessage(MSG_KEY, "files", 2, 1),
153             "552:13: " + getCheckMessage(MSG_KEY, "id", 2, 1),
154             "554:13: " + getCheckMessage(MSG_KEY, "parentId", 3, 1),
155         };
156         verifyWithInlineConfigParser(
157                 getPath("InputVariableDeclarationUsageDistanceRegExp.java"), expected);
158     }
159 
160     @Test
161     public void testValidateBetweenScopesOption() throws Exception {
162         final String[] expected = {
163             "42:9: " + getCheckMessage(MSG_KEY, "a", 2, 1),
164             "50:9: " + getCheckMessage(MSG_KEY, "temp", 2, 1),
165             "56:9: " + getCheckMessage(MSG_KEY, "temp", 2, 1),
166             "83:9: " + getCheckMessage(MSG_KEY, "count", 4, 1),
167             "108:9: " + getCheckMessage(MSG_KEY, "arg", 2, 1),
168             "231:9: " + getCheckMessage(MSG_KEY, "t", 5, 1),
169             "234:9: " + getCheckMessage(MSG_KEY, "c", 3, 1),
170             "235:9: " + getCheckMessage(MSG_KEY, "d2", 3, 1),
171             "272:9: " + getCheckMessage(MSG_KEY, "sel", 2, 1),
172             "273:9: " + getCheckMessage(MSG_KEY, "model", 2, 1),
173             "312:9: " + getCheckMessage(MSG_KEY, "wh", 2, 1),
174             "355:9: " + getCheckMessage(MSG_KEY, "green", 2, 1),
175             "356:9: " + getCheckMessage(MSG_KEY, "blue", 3, 1),
176             "379:9: " + getCheckMessage(MSG_KEY, "intervalMs", 2, 1),
177             "466:9: " + getCheckMessage(MSG_KEY, "aOpt", 3, 1),
178             "467:9: " + getCheckMessage(MSG_KEY, "bOpt", 2, 1),
179             "483:9: " + getCheckMessage(MSG_KEY, "l1", 3, 1),
180             "483:9: " + getCheckMessage(MSG_KEY, "l2", 2, 1),
181             "491:9: " + getCheckMessage(MSG_KEY, "myOption", 7, 1),
182             "503:9: " + getCheckMessage(MSG_KEY, "myOption", 6, 1),
183             "516:9: " + getCheckMessage(MSG_KEY, "count", 4, 1),
184             "517:9: " + getCheckMessage(MSG_KEY, "files", 2, 1),
185             "552:13: " + getCheckMessage(MSG_KEY, "id", 2, 1),
186             "554:13: " + getCheckMessage(MSG_KEY, "parentId", 4, 1),
187             "855:9: " + getCheckMessage(MSG_KEY, "a", 5, 1),
188             "867:9: " + getCheckMessage(MSG_KEY, "a", 5, 1),
189             "879:9: " + getCheckMessage(MSG_KEY, "a", 5, 1),
190             "891:9: " + getCheckMessage(MSG_KEY, "a", 5, 1),
191             "903:9: " + getCheckMessage(MSG_KEY, "a", 5, 1),
192             "913:9: " + getCheckMessage(MSG_KEY, "a", 5, 1),
193             "924:9: " + getCheckMessage(MSG_KEY, "a", 2, 1),
194             "945:9: " + getCheckMessage(MSG_KEY, "a", 5, 1),
195             "979:9: " + getCheckMessage(MSG_KEY, "a", 4, 1),
196             "990:9: " + getCheckMessage(MSG_KEY, "a", 2, 1),
197             "1001:9: " + getCheckMessage(MSG_KEY, "a", 4, 1),
198             "1036:9: " + getCheckMessage(MSG_KEY, "c", 4, 1),
199             "1066:9: " + getCheckMessage(MSG_KEY, "a", 4, 1),
200         };
201         verifyWithInlineConfigParser(
202                 getPath("InputVariableDeclarationUsageDistanceScopes.java"), expected);
203     }
204 
205     @Test
206     public void testIgnoreFinalOption() throws Exception {
207         final String[] expected = {
208             "42:9: " + getCheckMessage(MSG_KEY_EXT, "a", 2, 1),
209             "50:9: " + getCheckMessage(MSG_KEY_EXT, "temp", 2, 1),
210             "56:9: " + getCheckMessage(MSG_KEY_EXT, "temp", 2, 1),
211             "69:9: " + getCheckMessage(MSG_KEY_EXT, "count", 2, 1),
212             "83:9: " + getCheckMessage(MSG_KEY_EXT, "count", 4, 1),
213             "108:9: " + getCheckMessage(MSG_KEY_EXT, "arg", 2, 1),
214             "156:9: " + getCheckMessage(MSG_KEY_EXT, "m", 3, 1),
215             "157:9: " + getCheckMessage(MSG_KEY_EXT, "n", 2, 1),
216             "196:9: " + getCheckMessage(MSG_KEY_EXT, "result", 2, 1),
217             "231:9: " + getCheckMessage(MSG_KEY_EXT, "t", 5, 1),
218             "234:9: " + getCheckMessage(MSG_KEY_EXT, "c", 3, 1),
219             "235:9: " + getCheckMessage(MSG_KEY_EXT, "d2", 3, 1),
220             "272:9: " + getCheckMessage(MSG_KEY_EXT, "sel", 2, 1),
221             "273:9: " + getCheckMessage(MSG_KEY_EXT, "model", 2, 1),
222             "299:9: " + getCheckMessage(MSG_KEY_EXT, "sw", 2, 1),
223             "312:9: " + getCheckMessage(MSG_KEY_EXT, "wh", 2, 1),
224             "355:9: " + getCheckMessage(MSG_KEY_EXT, "green", 2, 1),
225             "356:9: " + getCheckMessage(MSG_KEY_EXT, "blue", 3, 1),
226             "466:9: " + getCheckMessage(MSG_KEY_EXT, "aOpt", 3, 1),
227             "467:9: " + getCheckMessage(MSG_KEY_EXT, "bOpt", 2, 1),
228             "483:9: " + getCheckMessage(MSG_KEY_EXT, "l1", 3, 1),
229             "483:9: " + getCheckMessage(MSG_KEY_EXT, "l2", 2, 1),
230             "491:9: " + getCheckMessage(MSG_KEY_EXT, "myOption", 7, 1),
231             "503:9: " + getCheckMessage(MSG_KEY_EXT, "myOption", 6, 1),
232             "516:9: " + getCheckMessage(MSG_KEY_EXT, "count", 4, 1),
233             "517:9: " + getCheckMessage(MSG_KEY_EXT, "files", 2, 1),
234             "552:13: " + getCheckMessage(MSG_KEY_EXT, "id", 2, 1),
235             "554:13: " + getCheckMessage(MSG_KEY_EXT, "parentId", 3, 1),
236             "903:9: " + getCheckMessage(MSG_KEY_EXT, "a", 4, 1),
237             "913:9: " + getCheckMessage(MSG_KEY_EXT, "a", 4, 1),
238             "979:9: " + getCheckMessage(MSG_KEY_EXT, "a", 4, 1),
239             "1001:9: " + getCheckMessage(MSG_KEY_EXT, "a", 3, 1),
240             "1036:9: " + getCheckMessage(MSG_KEY_EXT, "c", 3, 1),
241             "1066:9: " + getCheckMessage(MSG_KEY_EXT, "a", 4, 1),
242         };
243         verifyWithInlineConfigParser(
244                 getPath("InputVariableDeclarationUsageDistanceFinal.java"), expected);
245     }
246 
247     @Test
248     public void testTokensNotNull() {
249         final VariableDeclarationUsageDistanceCheck check =
250             new VariableDeclarationUsageDistanceCheck();
251         assertWithMessage("Acceptable tokens should not be null")
252             .that(check.getAcceptableTokens())
253             .isNotNull();
254         assertWithMessage("Default tokens should not be null")
255             .that(check.getDefaultTokens())
256             .isNotNull();
257         assertWithMessage("Required tokens should not be null")
258             .that(check.getRequiredTokens())
259             .isNotNull();
260     }
261 
262     @Test
263     public void testDefaultConfiguration() throws Exception {
264         final String[] expected = {
265             "83:9: " + getCheckMessage(MSG_KEY_EXT, "count", 4, 3),
266             "231:9: " + getCheckMessage(MSG_KEY_EXT, "t", 5, 3),
267             "491:9: " + getCheckMessage(MSG_KEY_EXT, "myOption", 7, 3),
268             "503:9: " + getCheckMessage(MSG_KEY_EXT, "myOption", 6, 3),
269             "516:9: " + getCheckMessage(MSG_KEY_EXT, "count", 4, 3),
270             "554:13: " + getCheckMessage(MSG_KEY_EXT, "parentId", 4, 3),
271             "855:9: " + getCheckMessage(MSG_KEY_EXT, "a", 5, 3),
272             "867:9: " + getCheckMessage(MSG_KEY_EXT, "a", 5, 3),
273             "879:9: " + getCheckMessage(MSG_KEY_EXT, "a", 5, 3),
274             "891:9: " + getCheckMessage(MSG_KEY_EXT, "a", 5, 3),
275             "903:9: " + getCheckMessage(MSG_KEY_EXT, "a", 5, 3),
276             "913:9: " + getCheckMessage(MSG_KEY_EXT, "a", 5, 3),
277             "945:9: " + getCheckMessage(MSG_KEY_EXT, "a", 5, 3),
278             "1036:9: " + getCheckMessage(MSG_KEY_EXT, "c", 4, 3),
279             "979:9: " + getCheckMessage(MSG_KEY_EXT, "a", 4, 3),
280             "1001:9: " + getCheckMessage(MSG_KEY_EXT, "a", 4, 3),
281             "1066:9: " + getCheckMessage(MSG_KEY_EXT, "a", 4, 3),
282         };
283         verifyWithInlineConfigParser(
284                 getPath("InputVariableDeclarationUsageDistanceDefault.java"), expected);
285     }
286 
287     @Test
288     public void testDefaultConfiguration2() throws Exception {
289         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
290 
291         verifyWithInlineConfigParser(
292             getPath("InputVariableDeclarationUsageDistanceDefault2.java"), expected);
293     }
294 
295     @Test
296     public void testAnonymousClass() throws Exception {
297         final String[] expected = {
298             "19:9: " + getCheckMessage(MSG_KEY_EXT, "prefs", 4, 3),
299         };
300 
301         verifyWithInlineConfigParser(
302                 getPath("InputVariableDeclarationUsageDistanceAnonymous.java"),
303                 expected);
304     }
305 
306     @Test
307     public void testLabels() throws Exception {
308         final String[] expected = {
309             "15:9: " + getCheckMessage(MSG_KEY_EXT, "eol", 5, 3),
310         };
311         verifyWithInlineConfigParser(
312                 getPath("InputVariableDeclarationUsageDistanceLabels.java"), expected);
313     }
314 
315     @Test
316     public void testVariableDeclarationUsageDistanceSwitchExpressions() throws Exception {
317 
318         final int maxDistance = 1;
319         final String[] expected = {
320             "33:17: " + getCheckMessage(MSG_KEY, "arg", 2, maxDistance),
321             "50:17: " + getCheckMessage(MSG_KEY, "m", 3, maxDistance),
322             "51:17: " + getCheckMessage(MSG_KEY, "n", 2, maxDistance),
323             "83:17: " + getCheckMessage(MSG_KEY, "arg", 2, maxDistance),
324             "100:17: " + getCheckMessage(MSG_KEY, "m", 3, maxDistance),
325             "101:17: " + getCheckMessage(MSG_KEY, "n", 2, maxDistance),
326         };
327 
328         final String filename = "InputVariableDeclarationUsageDistanceCheckSwitchExpressions.java";
329         verifyWithInlineConfigParser(getPath(filename), expected);
330     }
331 
332     @Test
333     public void testVariableDeclarationUsageDistanceSwitchExpressions2() throws Exception {
334         final int maxDistance = 1;
335         final String[] expected = {
336             "16:9: " + getCheckMessage(MSG_KEY, "i", 2, maxDistance),
337         };
338 
339         final String filename = "InputVariableDeclarationUsageDistanceCheckSwitchExpressions2.java";
340         verifyWithInlineConfigParser(getPath(filename), expected);
341     }
342 
343     @Test
344     public void testGeneralClass3() throws Exception {
345         final String[] expected = {
346             "46:9: " + getCheckMessage(MSG_KEY, "a", 2, 1),
347         };
348 
349         verifyWithInlineConfigParser(
350                 getPath("InputVariableDeclarationUsageDistanceGeneral3.java"), expected);
351     }
352 
353     @Test
354     public void testGeneralClass4() throws Exception {
355         final String[] expected = {
356             "25:9: " + getCheckMessage(MSG_KEY, "z", 2, 1),
357         };
358 
359         verifyWithInlineConfigParser(
360                 getPath("InputVariableDeclarationUsageDistanceGeneral4.java"), expected);
361     }
362 
363     @Test
364     public void testVariableDeclarationUsageDistanceTryResources() throws Exception {
365         final String[] expected = {
366             "19:9: " + getCheckMessage(MSG_KEY, "a", 2, 1),
367             "20:9: " + getCheckMessage(MSG_KEY, "b", 2, 1),
368         };
369 
370         verifyWithInlineConfigParser(
371                 getPath("InputVariableDeclarationUsageDistanceTryResources.java"), expected);
372     }
373 
374     @Test
375     public void testVariableDeclarationUsageDistanceTryBlock() throws Exception {
376         final String[] expected = {
377             "16:9: " + getCheckMessage(MSG_KEY_EXT, "a", 4, 3),
378             "28:9: " + getCheckMessage(MSG_KEY_EXT, "a", 4, 3),
379             "40:9: " + getCheckMessage(MSG_KEY_EXT, "a", 4, 3),
380             "76:9: " + getCheckMessage(MSG_KEY_EXT, "a", 4, 3),
381             "88:9: " + getCheckMessage(MSG_KEY_EXT, "a", 4, 3),
382         };
383 
384         verifyWithInlineConfigParser(
385                 getPath("InputVariableDeclarationUsageDistanceTryBlock.java"), expected);
386     }
387 
388     @Test
389     public void testVariableDeclarationUsageDistance4() throws Exception {
390         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
391 
392         verifyWithInlineConfigParser(
393                 getPath("InputVariableDeclarationUsageDistance3.java"), expected);
394     }
395 
396     @Test
397     public void testVariableDeclarationUsageDistanceScope2() throws Exception {
398         final String[] expected = {
399             "16:9: " + getCheckMessage(MSG_KEY, "i", 5, 1),
400         };
401 
402         verifyWithInlineConfigParser(
403                 getPath("InputVariableDeclarationUsageDistanceScope2.java"), expected);
404     }
405 
406     @Test
407     public void testVariableDeclarationUsageDistance1() throws Exception {
408         final String[] expected = {
409             "15:9: " + getCheckMessage(MSG_KEY, "i", 2, 1),
410         };
411 
412         verifyWithInlineConfigParser(
413                 getPath("InputVariableDeclarationUsageDistance1.java"), expected);
414     }
415 
416     @Test
417     public void testVariableDeclarationUsageDistanceCloseToBlock() throws Exception {
418         final String[] expected = {
419             "15:9: " + getCheckMessage(MSG_KEY, "a", 13, 1),
420             "16:9: " + getCheckMessage(MSG_KEY, "b", 13, 1),
421         };
422         verifyWithInlineConfigParser(
423                 getPath("InputVariableDeclarationUsageDistanceCloseToBlock.java"), expected);
424     }
425 
426     @Test
427     public void testVariableDeclarationUsageDistancePatternVariables() throws Exception {
428         final String[] expected = {
429             "35:9: " + getCheckMessage(MSG_KEY, "b", 5, 1),
430         };
431         verifyWithInlineConfigParser(
432                 getNonCompilablePath("InputVariableDeclarationUsageDistancePatternVariables.java"),
433                 expected);
434     }
435 
436     @Test
437     public void testVariableDeclarationUsageDistanceMethodDef() throws Exception {
438         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
439         verifyWithInlineConfigParser(
440                 getPath("InputVariableDeclarationUsageDistanceMethodDef.java"), expected);
441     }
442 }