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