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;
21  
22  import static com.google.common.truth.Truth.assertWithMessage;
23  import static com.puppycrawl.tools.checkstyle.checks.coding.UnusedLocalVariableCheck.MSG_UNUSED_LOCAL_VARIABLE;
24  import static com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck.MSG_KEY;
25  import static com.puppycrawl.tools.checkstyle.internal.utils.TestUtil.getExpectedThrowable;
26  
27  import java.io.File;
28  import java.util.List;
29  import java.util.Map;
30  import java.util.Optional;
31  
32  import org.junit.jupiter.api.AfterEach;
33  import org.junit.jupiter.api.Test;
34  
35  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
36  import com.puppycrawl.tools.checkstyle.Checker;
37  import com.puppycrawl.tools.checkstyle.DetailAstImpl;
38  import com.puppycrawl.tools.checkstyle.JavaParser;
39  import com.puppycrawl.tools.checkstyle.api.AuditEvent;
40  import com.puppycrawl.tools.checkstyle.api.DetailAST;
41  import com.puppycrawl.tools.checkstyle.api.TokenTypes;
42  import com.puppycrawl.tools.checkstyle.api.Violation;
43  import com.puppycrawl.tools.checkstyle.checks.coding.UnusedLocalVariableCheck;
44  import com.puppycrawl.tools.checkstyle.checks.naming.AbstractNameCheck;
45  import com.puppycrawl.tools.checkstyle.checks.naming.ConstantNameCheck;
46  import com.puppycrawl.tools.checkstyle.checks.naming.MemberNameCheck;
47  import com.puppycrawl.tools.checkstyle.checks.naming.MethodNameCheck;
48  import com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck;
49  import com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck;
50  import com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck;
51  import com.puppycrawl.tools.checkstyle.checks.whitespace.TypecastParenPadCheck;
52  import com.puppycrawl.tools.checkstyle.internal.utils.TestUtil;
53  import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
54  
55  public class SuppressWarningsHolderTest extends AbstractModuleTestSupport {
56  
57      @Override
58      public String getPackageLocation() {
59          return "com/puppycrawl/tools/checkstyle/checks/suppresswarningsholder";
60      }
61  
62      @AfterEach
63      public void cleanUp() {
64          // clear cache that may have been set by tests
65  
66          new SuppressWarningsHolder().beginTree(null);
67  
68          final Map<String, String> map = TestUtil.getInternalStaticStateMap(
69                  SuppressWarningsHolder.class, "CHECK_ALIAS_MAP");
70          map.clear();
71      }
72  
73      @Test
74      public void testGet() {
75          final SuppressWarningsHolder checkObj = new SuppressWarningsHolder();
76          final int[] expected = {TokenTypes.ANNOTATION};
77          assertWithMessage("Required token array differs from expected")
78              .that(checkObj.getRequiredTokens())
79              .isEqualTo(expected);
80          assertWithMessage("Required token array differs from expected")
81              .that(checkObj.getAcceptableTokens())
82              .isEqualTo(expected);
83      }
84  
85      @Test
86      public void testOnComplexAnnotations() throws Exception {
87          final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
88  
89          verifyWithInlineConfigParser(getPath("InputSuppressWarningsHolder.java"), expected);
90      }
91  
92      @Test
93      public void testOnComplexAnnotationsNonConstant() throws Exception {
94          final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
95  
96          verifyWithInlineConfigParser(
97                  getNonCompilablePath("InputSuppressWarningsHolderNonConstant.java"), expected);
98      }
99  
100     @Test
101     public void testCustomAnnotation() throws Exception {
102         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
103 
104         verifyWithInlineConfigParser(getPath("InputSuppressWarningsHolder5.java"), expected);
105     }
106 
107     @Test
108     public void testAll() throws Exception {
109         final String[] expected = {
110             "21:23: "
111                     + getCheckMessage(TypecastParenPadCheck.class,
112                             AbstractParenPadCheck.MSG_WS_NOT_PRECEDED, ")"),
113         };
114 
115         verifyWithInlineConfigParser(getPath("InputSuppressWarningsHolder6.java"), expected);
116     }
117 
118     @Test
119     public void testGetDefaultAlias() {
120         assertWithMessage("Default alias differs from expected")
121             .that(SuppressWarningsHolder.getDefaultAlias("TestName"))
122             .isEqualTo("testname");
123         assertWithMessage("Default alias differs from expected")
124             .that(SuppressWarningsHolder.getDefaultAlias("TestNameCheck"))
125             .isEqualTo("testname");
126     }
127 
128     @Test
129     public void testSetAliasListEmpty() {
130         final SuppressWarningsHolder holder = new SuppressWarningsHolder();
131         holder.setAliasList("");
132         assertWithMessage("Empty alias list should not be set")
133             .that(SuppressWarningsHolder.getAlias(""))
134             .isEqualTo("");
135     }
136 
137     @Test
138     public void testSetAliasListCorrect() {
139         final SuppressWarningsHolder holder = new SuppressWarningsHolder();
140         holder.setAliasList("alias=value");
141         assertWithMessage("Alias differs from expected")
142             .that(SuppressWarningsHolder.getAlias("alias"))
143             .isEqualTo("value");
144     }
145 
146     @Test
147     public void testSetAliasListWrong() {
148         final SuppressWarningsHolder holder = new SuppressWarningsHolder();
149 
150         final IllegalArgumentException exc = getExpectedThrowable(
151                 IllegalArgumentException.class,
152                 () -> holder.setAliasList("=SomeAlias"));
153         assertWithMessage("Error message is unexpected")
154             .that(exc.getMessage())
155             .isEqualTo("'=' expected in alias list item: =SomeAlias");
156     }
157 
158     @Test
159     public void testAliasCombo() throws Exception {
160         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
161 
162         verifyWithInlineXmlConfig(getPath("InputSuppressWarningsHolderAlias3.java"), expected);
163     }
164 
165     @Test
166     public void testIsSuppressed() throws Exception {
167         populateHolder("MockEntry", 100, 100, 350, 350);
168         final AuditEvent event = createAuditEvent("check", 100, 10);
169 
170         assertWithMessage("Event is not suppressed")
171                 .that(SuppressWarningsHolder.isSuppressed(event))
172                 .isFalse();
173     }
174 
175     @Test
176     public void testIsSuppressedByName() throws Exception {
177         populateHolder("check", 100, 100, 350, 350);
178         final SuppressWarningsHolder holder = new SuppressWarningsHolder();
179         final AuditEvent event = createAuditEvent("id", 110, 10);
180         holder.setAliasList(MemberNameCheck.class.getName() + "=check");
181 
182         assertWithMessage("Event is not suppressed")
183                 .that(SuppressWarningsHolder.isSuppressed(event))
184                 .isTrue();
185     }
186 
187     @Test
188     public void testIsSuppressedByModuleId() throws Exception {
189         populateHolder("check", 100, 100, 350, 350);
190         final AuditEvent event = createAuditEvent("check", 350, 350);
191 
192         assertWithMessage("Event is not suppressed")
193                 .that(SuppressWarningsHolder.isSuppressed(event))
194                 .isTrue();
195     }
196 
197     @Test
198     public void testIsSuppressedAfterEventEnd() throws Exception {
199         populateHolder("check", 100, 100, 350, 350);
200         final AuditEvent event = createAuditEvent("check", 350, 352);
201 
202         assertWithMessage("Event is not suppressed")
203                 .that(SuppressWarningsHolder.isSuppressed(event))
204                 .isFalse();
205     }
206 
207     @Test
208     public void testIsSuppressedAfterEventEnd2() throws Exception {
209         populateHolder("check", 100, 100, 350, 350);
210         final AuditEvent event = createAuditEvent("check", 400, 10);
211 
212         assertWithMessage("Event is not suppressed")
213                 .that(SuppressWarningsHolder.isSuppressed(event))
214                 .isFalse();
215     }
216 
217     @Test
218     public void testIsSuppressedAfterEventStart() throws Exception {
219         populateHolder("check", 100, 100, 350, 350);
220         final AuditEvent event = createAuditEvent("check", 100, 100);
221 
222         assertWithMessage("Event is not suppressed")
223                 .that(SuppressWarningsHolder.isSuppressed(event))
224                 .isTrue();
225     }
226 
227     @Test
228     public void testIsSuppressedAfterEventStart2() throws Exception {
229         populateHolder("check", 100, 100, 350, 350);
230         final AuditEvent event = createAuditEvent("check", 100, 0);
231 
232         assertWithMessage("Event is not suppressed")
233                 .that(SuppressWarningsHolder.isSuppressed(event))
234                 .isTrue();
235     }
236 
237     @Test
238     public void testIsSuppressedWithAllArgument() throws Exception {
239         populateHolder("all", 100, 100, 350, 350);
240 
241         final Checker source = new Checker();
242         final Violation firstViolationForTest =
243             new Violation(100, 10, null, null, null, "id", MemberNameCheck.class, "msg");
244         final AuditEvent firstEventForTest =
245             new AuditEvent(source, "fileName", firstViolationForTest);
246         assertWithMessage("Event is suppressed")
247                 .that(SuppressWarningsHolder.isSuppressed(firstEventForTest))
248                 .isFalse();
249 
250         final Violation secondViolationForTest =
251             new Violation(100, 150, null, null, null, "id", MemberNameCheck.class, "msg");
252         final AuditEvent secondEventForTest =
253             new AuditEvent(source, "fileName", secondViolationForTest);
254         assertWithMessage("Event is not suppressed")
255                 .that(SuppressWarningsHolder.isSuppressed(secondEventForTest))
256                 .isTrue();
257 
258         final Violation thirdViolationForTest =
259             new Violation(200, 1, null, null, null, "id", MemberNameCheck.class, "msg");
260         final AuditEvent thirdEventForTest =
261             new AuditEvent(source, "fileName", thirdViolationForTest);
262         assertWithMessage("Event is not suppressed")
263                 .that(SuppressWarningsHolder.isSuppressed(thirdEventForTest))
264                 .isTrue();
265     }
266 
267     @Test
268     public void testAnnotationInTry() throws Exception {
269         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
270 
271         verifyWithInlineConfigParser(getPath("InputSuppressWarningsHolder2.java"), expected);
272     }
273 
274     @Test
275     public void testEmptyAnnotation() throws Exception {
276         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
277 
278         verifyWithInlineConfigParser(getPath("InputSuppressWarningsHolder3.java"), expected);
279     }
280 
281     @Test
282     public void testGetAllAnnotationValuesWrongArg() {
283         final SuppressWarningsHolder holder = new SuppressWarningsHolder();
284 
285         final DetailAstImpl methodDef = new DetailAstImpl();
286         methodDef.setType(TokenTypes.METHOD_DEF);
287         methodDef.setText("Method Def");
288         methodDef.setLineNo(0);
289         methodDef.setColumnNo(0);
290 
291         final DetailAstImpl lparen = new DetailAstImpl();
292         lparen.setType(TokenTypes.LPAREN);
293 
294         final DetailAstImpl parent = new DetailAstImpl();
295         parent.addChild(lparen);
296         parent.addChild(methodDef);
297 
298         final ReflectiveOperationException exc1 = getExpectedThrowable(
299                 ReflectiveOperationException.class,
300                 () -> TestUtil.invokeVoidMethod(holder, "getAllAnnotationValues", parent));
301         assertWithMessage("Error type is unexpected")
302                 .that(exc1)
303                 .hasCauseThat()
304                 .isInstanceOf(IllegalArgumentException.class);
305         assertWithMessage("Error message is unexpected")
306             .that(exc1)
307             .hasCauseThat()
308             .hasMessageThat()
309             .isEqualTo("Unexpected AST: Method Def[0x0]");
310     }
311 
312     @Test
313     public void testGetAnnotationValuesWrongArg() {
314         final SuppressWarningsHolder holder = new SuppressWarningsHolder();
315 
316         final DetailAstImpl methodDef = new DetailAstImpl();
317         methodDef.setType(TokenTypes.METHOD_DEF);
318         methodDef.setText("Method Def");
319         methodDef.setLineNo(0);
320         methodDef.setColumnNo(0);
321 
322         final ReflectiveOperationException exc2 = getExpectedThrowable(
323                 ReflectiveOperationException.class,
324                 () -> TestUtil.invokeVoidMethod(holder, "getAnnotationValues", methodDef));
325         assertWithMessage("Error type is unexpected")
326                 .that(exc2)
327                 .hasCauseThat()
328                 .isInstanceOf(IllegalArgumentException.class);
329         assertWithMessage("Error message is unexpected")
330             .that(exc2)
331             .hasCauseThat()
332             .hasMessageThat()
333             .isEqualTo("Expression or annotation array initializer AST expected: "
334                     + "Method Def[0x0]");
335     }
336 
337     @Test
338     public void testGetAnnotationTargetWrongArg() {
339         final SuppressWarningsHolder holder = new SuppressWarningsHolder();
340 
341         final DetailAstImpl methodDef = new DetailAstImpl();
342         methodDef.setType(TokenTypes.METHOD_DEF);
343         methodDef.setText("Method Def");
344 
345         final DetailAstImpl parent = new DetailAstImpl();
346         parent.setType(TokenTypes.ASSIGN);
347         parent.setText("Parent ast");
348         parent.addChild(methodDef);
349         parent.setLineNo(0);
350         parent.setColumnNo(0);
351 
352         final ReflectiveOperationException exc3 = getExpectedThrowable(
353                 ReflectiveOperationException.class,
354                 () -> TestUtil.invokeVoidMethod(holder, "getAnnotationTarget", methodDef));
355         assertWithMessage("Error type is unexpected")
356                 .that(exc3)
357                 .hasCauseThat()
358                 .isInstanceOf(IllegalArgumentException.class);
359         assertWithMessage("Error message is unexpected")
360             .that(exc3)
361             .hasCauseThat()
362             .hasMessageThat()
363             .isEqualTo("Unexpected container AST: Parent ast[0x0]");
364     }
365 
366     @Test
367     public void testAstWithoutChildren() {
368         final SuppressWarningsHolder holder = new SuppressWarningsHolder();
369         final DetailAstImpl methodDef = new DetailAstImpl();
370         methodDef.setType(TokenTypes.METHOD_DEF);
371 
372         final IllegalArgumentException exc4 = getExpectedThrowable(
373                 IllegalArgumentException.class,
374                 () -> holder.visitToken(methodDef));
375         assertWithMessage("Error message is unexpected")
376             .that(exc4.getMessage())
377             .isEqualTo("Identifier AST expected, but get null.");
378     }
379 
380     @Test
381     public void testAnnotationWithFullName() throws Exception {
382         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
383 
384         verifyWithInlineConfigParser(getPath("InputSuppressWarningsHolder4.java"), expected);
385     }
386 
387     @Test
388     public void testSuppressWarningsAsAnnotationProperty() throws Exception {
389         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
390 
391         verifyWithInlineConfigParser(getPath("InputSuppressWarningsHolder7.java"), expected);
392     }
393 
394     @SuppressWarnings("unchecked")
395     @Test
396     public void testClearState() throws Exception {
397         final SuppressWarningsHolder check = new SuppressWarningsHolder();
398 
399         final Optional<DetailAST> annotationDef = TestUtil.findTokenInAstByPredicate(
400                 JavaParser.parseFile(
401                     new File(getPath("InputSuppressWarningsHolder.java")),
402                     JavaParser.Options.WITHOUT_COMMENTS),
403             ast -> ast.getType() == TokenTypes.ANNOTATION);
404 
405         assertWithMessage("Ast should contain ANNOTATION")
406                 .that(annotationDef.isPresent())
407                 .isTrue();
408         assertWithMessage("State is not cleared on beginTree")
409                 .that(TestUtil.isStatefulFieldClearedDuringBeginTree(check,
410                         annotationDef.orElseThrow(), "ENTRIES",
411                         entries -> ((ThreadLocal<List<Object>>) entries).get().isEmpty()))
412                 .isTrue();
413     }
414 
415     private static void populateHolder(String checkName, int firstLine,
416                                                          int firstColumn, int lastLine,
417                                                          int lastColumn) throws Exception {
418         final Class<?> entry = Class
419                 .forName("com.puppycrawl.tools.checkstyle.checks.SuppressWarningsHolder$Entry");
420 
421         final Object entryInstance = TestUtil.instantiate(entry, checkName, firstLine,
422                 firstColumn, lastLine, lastColumn);
423 
424         final ThreadLocal<List<Object>> entries = TestUtil
425                 .getInternalStaticStateThreadLocal(SuppressWarningsHolder.class,
426                         "ENTRIES");
427         entries.get().add(entryInstance);
428     }
429 
430     private static AuditEvent createAuditEvent(String moduleId, int line, int column) {
431         final Checker source = new Checker();
432         final Violation violation = new Violation(line, column, null, null, null,
433                 moduleId, MemberNameCheck.class, "violation");
434         return new AuditEvent(source, "filename", violation);
435     }
436 
437     @Test
438     public void testSuppressWarningsTextBlocks() throws Exception {
439         final String pattern = "^[a-z][a-zA-Z0-9]*$";
440 
441         final String[] expected = {
442             "31:12: " + getCheckMessage(MemberNameCheck.class,
443                 AbstractNameCheck.MSG_INVALID_PATTERN, "STRING3", pattern),
444             "33:12: " + getCheckMessage(MemberNameCheck.class,
445                 AbstractNameCheck.MSG_INVALID_PATTERN, "STRING4", pattern),
446             "61:12: " + getCheckMessage(MemberNameCheck.class,
447                 AbstractNameCheck.MSG_INVALID_PATTERN, "STRING8", pattern),
448             };
449 
450         verifyWithInlineConfigParser(
451                 getPath("InputSuppressWarningsHolderTextBlocks.java"), expected);
452 
453     }
454 
455     @Test
456     public void testWithAndWithoutCheckSuffixDifferentCases() throws Exception {
457         final String pattern = "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$";
458         final String[] expected = {
459             "20:30: " + getCheckMessage(ConstantNameCheck.class,
460                 AbstractNameCheck.MSG_INVALID_PATTERN, "a", pattern),
461         };
462 
463         verifyWithInlineConfigParser(
464                 getPath("InputSuppressWarningsHolderWithAndWithoutCheckSuffixDifferentCases.java"),
465                 expected);
466     }
467 
468     @Test
469     public void testAliasList() throws Exception {
470         final String[] expected = {
471             "19:17: " + getCheckMessage(ParameterNumberCheck.class,
472                     ParameterNumberCheck.MSG_KEY, 7, 8),
473             "31:17: " + getCheckMessage(ParameterNumberCheck.class,
474                     ParameterNumberCheck.MSG_KEY, 7, 8),
475         };
476         verifyWithInlineConfigParser(
477                 getPath("InputSuppressWarningsHolderAlias.java"),
478                 expected);
479     }
480 
481     @Test
482     public void testAliasList2() throws Exception {
483         final String pattern = "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$";
484         final String[] expected = {
485             "20:29: " + getCheckMessage(ConstantNameCheck.class,
486                 AbstractNameCheck.MSG_INVALID_PATTERN, "a", pattern),
487             "23:30: " + getCheckMessage(ConstantNameCheck.class,
488                 AbstractNameCheck.MSG_INVALID_PATTERN, "b", pattern),
489         };
490 
491         verifyWithInlineConfigParser(
492                 getPath("InputSuppressWarningsHolderAlias2.java"),
493                 expected);
494     }
495 
496     @Test
497     public void testAliasList3() throws Exception {
498         final String[] expected = {
499             "18:17: " + getCheckMessage(ParameterNumberCheck.class,
500                     ParameterNumberCheck.MSG_KEY, 7, 8),
501             "30:17: " + getCheckMessage(ParameterNumberCheck.class,
502                     ParameterNumberCheck.MSG_KEY, 7, 8),
503         };
504 
505         verifyWithInlineConfigParser(
506                 getPath("InputSuppressWarningsHolderAlias5.java"),
507                 expected);
508     }
509 
510     @Test
511     public void testAliasList4() throws Exception {
512         final String pattern = "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$";
513         final String[] expected = {
514             "20:30: " + getCheckMessage(ConstantNameCheck.class,
515                 AbstractNameCheck.MSG_INVALID_PATTERN, "a", pattern),
516             "23:30: " + getCheckMessage(ConstantNameCheck.class,
517                 AbstractNameCheck.MSG_INVALID_PATTERN, "b", pattern),
518         };
519 
520         verifyWithInlineConfigParser(
521                 getPath("InputSuppressWarningsHolderAlias4.java"),
522                 expected);
523     }
524 
525     @Test
526     public void testAliasList5() throws Exception {
527         final String[] expected = {
528             "23: " + getCheckMessage(LineLengthCheck.class, MSG_KEY, 80, 83),
529             "33: " + getCheckMessage(LineLengthCheck.class, MSG_KEY, 75, 96),
530             "33: " + getCheckMessage(LineLengthCheck.class, MSG_KEY, 80, 96),
531             "63: " + getCheckMessage(LineLengthCheck.class, MSG_KEY, 75, 76),
532             "70: " + getCheckMessage(LineLengthCheck.class, MSG_KEY, 75, 87),
533         };
534 
535         verifyWithInlineConfigParser(
536                 getPath("InputSuppressWarningsHolderAlias6.java"),
537                 expected);
538     }
539 
540     @Test
541     public void testAliasList6() throws Exception {
542         final String pattern1 = "^[a-z][a-zA-Z0-9]*$";
543         final String pattern2 = "^[A-Z][a-zA-Z0-9]*$";
544 
545         final String[] expected = {
546             "35:18: " + getCheckMessage(MethodNameCheck.class,
547                     AbstractNameCheck.MSG_INVALID_PATTERN, "Method3", pattern1),
548             "40:20: " + getCheckMessage(MethodNameCheck.class,
549                     AbstractNameCheck.MSG_INVALID_PATTERN, "Method5", pattern1),
550             "45:17: " + getCheckMessage(MethodNameCheck.class,
551                     AbstractNameCheck.MSG_INVALID_PATTERN, "method7", pattern2),
552             "50:18: " + getCheckMessage(MethodNameCheck.class,
553                     AbstractNameCheck.MSG_INVALID_PATTERN, "method9", pattern2),
554             "55:20: " + getCheckMessage(MethodNameCheck.class,
555                     AbstractNameCheck.MSG_INVALID_PATTERN, "method11", pattern2),
556             "57:17: " + getCheckMessage(MethodNameCheck.class,
557                     AbstractNameCheck.MSG_INVALID_PATTERN, "_methodCheck1", pattern2),
558             "63:18: " + getCheckMessage(MethodNameCheck.class,
559                     AbstractNameCheck.MSG_INVALID_PATTERN, "_methodCheck3", pattern2),
560             "63:18: " + getCheckMessage(MethodNameCheck.class,
561                     AbstractNameCheck.MSG_INVALID_PATTERN, "_methodCheck3", pattern1),
562             "71:20: " + getCheckMessage(MethodNameCheck.class,
563                     AbstractNameCheck.MSG_INVALID_PATTERN, "_methodCheck5", pattern2),
564             "71:20: " + getCheckMessage(MethodNameCheck.class,
565                     AbstractNameCheck.MSG_INVALID_PATTERN, "_methodCheck5", pattern1),
566         };
567 
568         verifyWithInlineConfigParser(
569                 getPath("InputSuppressWarningsHolderAlias7.java"),
570                 expected);
571     }
572 
573     @Test
574     public void testIdent() throws Exception {
575         final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
576         verifyWithInlineConfigParser(
577                 getNonCompilablePath("InputSuppressWarningsHolder1.java"),
578                 expected);
579     }
580 
581     @Test
582     public void testIdent2() throws Exception {
583         final String[] expected = {
584             "40:9: " + getCheckMessage(UnusedLocalVariableCheck.class,
585                     MSG_UNUSED_LOCAL_VARIABLE, "a"),
586             "45:9: " + getCheckMessage(UnusedLocalVariableCheck.class,
587                     MSG_UNUSED_LOCAL_VARIABLE, "a"),
588         };
589         verifyWithInlineConfigParser(
590                 getNonCompilablePath("InputSuppressWarningsHolder2.java"),
591                 expected);
592     }
593 
594     @Test
595     public void test3() throws Exception {
596         final String pattern = "^[a-z][a-zA-Z0-9]*$";
597 
598         final String[] expected = {
599             "22:16: " + getCheckMessage(MemberNameCheck.class,
600                     AbstractNameCheck.MSG_INVALID_PATTERN, "K", pattern),
601         };
602         verifyWithInlineConfigParser(
603                 getPath("InputSuppressWarningsHolder8.java"),
604                 expected);
605     }
606 }