View Javadoc
1   ////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code for adherence to a set of rules.
3   // Copyright (C) 2001-2018 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.filters;
21  
22  import static com.puppycrawl.tools.checkstyle.checks.naming.AbstractNameCheck.MSG_INVALID_PATTERN;
23  import static org.junit.Assert.assertEquals;
24  import static org.junit.Assert.assertTrue;
25  import static org.junit.Assert.fail;
26  
27  import java.util.Arrays;
28  import java.util.Collection;
29  import java.util.List;
30  import java.util.stream.Collectors;
31  
32  import org.junit.Test;
33  import org.powermock.reflect.Whitebox;
34  
35  import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
36  import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
37  import com.puppycrawl.tools.checkstyle.TreeWalker;
38  import com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent;
39  import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
40  import com.puppycrawl.tools.checkstyle.api.Configuration;
41  import com.puppycrawl.tools.checkstyle.api.FileContents;
42  import com.puppycrawl.tools.checkstyle.api.LocalizedMessage;
43  import com.puppycrawl.tools.checkstyle.checks.coding.IllegalCatchCheck;
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.utils.CommonUtils;
48  import nl.jqno.equalsverifier.EqualsVerifier;
49  
50  public class SuppressWithNearbyCommentFilterTest
51      extends AbstractModuleTestSupport {
52  
53      private static final String[] ALL_MESSAGES = {
54          "14:17: "
55              + getCheckMessage(AbstractNameCheck.class,
56                  MSG_INVALID_PATTERN, "A1", "^[a-z][a-zA-Z0-9]*$"),
57          "15:17: "
58              + getCheckMessage(AbstractNameCheck.class,
59                  MSG_INVALID_PATTERN, "A2", "^[a-z][a-zA-Z0-9]*$"),
60          "16:59: "
61              + getCheckMessage(AbstractNameCheck.class,
62                  MSG_INVALID_PATTERN, "A3", "^[a-z][a-zA-Z0-9]*$"),
63          "18:17: "
64              + getCheckMessage(AbstractNameCheck.class,
65                  MSG_INVALID_PATTERN, "B1", "^[a-z][a-zA-Z0-9]*$"),
66          "19:17: "
67              + getCheckMessage(AbstractNameCheck.class,
68                  MSG_INVALID_PATTERN, "B2", "^[a-z][a-zA-Z0-9]*$"),
69          "20:59: "
70              + getCheckMessage(AbstractNameCheck.class,
71                  MSG_INVALID_PATTERN, "B3", "^[a-z][a-zA-Z0-9]*$"),
72          "22:17: "
73              + getCheckMessage(AbstractNameCheck.class,
74                  MSG_INVALID_PATTERN, "C1", "^[a-z][a-zA-Z0-9]*$"),
75          "24:17: "
76              + getCheckMessage(AbstractNameCheck.class,
77                  MSG_INVALID_PATTERN, "C2", "^[a-z][a-zA-Z0-9]*$"),
78          "25:17: "
79              + getCheckMessage(AbstractNameCheck.class,
80                  MSG_INVALID_PATTERN, "C3", "^[a-z][a-zA-Z0-9]*$"),
81          "27:17: "
82              + getCheckMessage(AbstractNameCheck.class,
83                  MSG_INVALID_PATTERN, "D1", "^[a-z][a-zA-Z0-9]*$"),
84          "28:17: "
85              + getCheckMessage(AbstractNameCheck.class,
86                  MSG_INVALID_PATTERN, "D2", "^[a-z][a-zA-Z0-9]*$"),
87          "30:17: "
88              + getCheckMessage(AbstractNameCheck.class,
89                  MSG_INVALID_PATTERN, "D3", "^[a-z][a-zA-Z0-9]*$"),
90          "32:30: "
91              + getCheckMessage(AbstractNameCheck.class,
92                  MSG_INVALID_PATTERN, "e1", "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"),
93          "33:17: "
94              + getCheckMessage(AbstractNameCheck.class,
95                  MSG_INVALID_PATTERN, "E2", "^[a-z][a-zA-Z0-9]*$"),
96          "34:17: "
97              + getCheckMessage(AbstractNameCheck.class,
98                  MSG_INVALID_PATTERN, "E3", "^[a-z][a-zA-Z0-9]*$"),
99          "35:30: "
100             + getCheckMessage(AbstractNameCheck.class,
101                 MSG_INVALID_PATTERN, "e4", "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"),
102         "36:17: "
103             + getCheckMessage(AbstractNameCheck.class,
104                 MSG_INVALID_PATTERN, "E5", "^[a-z][a-zA-Z0-9]*$"),
105         "37:30: "
106             + getCheckMessage(AbstractNameCheck.class,
107                 MSG_INVALID_PATTERN, "e6", "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"),
108         "38:17: "
109             + getCheckMessage(AbstractNameCheck.class,
110                 MSG_INVALID_PATTERN, "E7", "^[a-z][a-zA-Z0-9]*$"),
111         "39:17: "
112             + getCheckMessage(AbstractNameCheck.class,
113                 MSG_INVALID_PATTERN, "E8", "^[a-z][a-zA-Z0-9]*$"),
114         "40:30: "
115             + getCheckMessage(AbstractNameCheck.class,
116                 MSG_INVALID_PATTERN, "e9", "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"),
117         "64:23: "
118             + getCheckMessage(IllegalCatchCheck.class, IllegalCatchCheck.MSG_KEY, "Exception"),
119         "66:23: "
120             + getCheckMessage(IllegalCatchCheck.class, IllegalCatchCheck.MSG_KEY, "Throwable"),
121         "73:11: "
122             + getCheckMessage(IllegalCatchCheck.class, IllegalCatchCheck.MSG_KEY, "Exception"),
123         "80:59: "
124             + getCheckMessage(AbstractNameCheck.class,
125                 MSG_INVALID_PATTERN, "A2", "^[a-z][a-zA-Z0-9]*$"),
126         "81:17: "
127             + getCheckMessage(AbstractNameCheck.class,
128                 MSG_INVALID_PATTERN, "A1", "^[a-z][a-zA-Z0-9]*$"),
129     };
130 
131     @Override
132     protected String getPackageLocation() {
133         return "com/puppycrawl/tools/checkstyle/filters/suppresswithnearbycommentfilter";
134     }
135 
136     @Test
137     public void testNone() throws Exception {
138         final DefaultConfiguration filterConfig = null;
139         final String[] suppressed = CommonUtils.EMPTY_STRING_ARRAY;
140         verifySuppressed(filterConfig, suppressed);
141     }
142 
143     @Test
144     public void testDefault() throws Exception {
145         final DefaultConfiguration filterConfig =
146             createModuleConfig(SuppressWithNearbyCommentFilter.class);
147         final String[] suppressed = {
148             "14:17: "
149                 + getCheckMessage(AbstractNameCheck.class,
150                     MSG_INVALID_PATTERN, "A1", "^[a-z][a-zA-Z0-9]*$"),
151             "15:17: "
152                 + getCheckMessage(AbstractNameCheck.class,
153                     MSG_INVALID_PATTERN, "A2", "^[a-z][a-zA-Z0-9]*$"),
154             "16:59: "
155                 + getCheckMessage(AbstractNameCheck.class,
156                     MSG_INVALID_PATTERN, "A3", "^[a-z][a-zA-Z0-9]*$"),
157             "18:17: "
158                 + getCheckMessage(AbstractNameCheck.class,
159                     MSG_INVALID_PATTERN, "B1", "^[a-z][a-zA-Z0-9]*$"),
160             "19:17: "
161                 + getCheckMessage(AbstractNameCheck.class,
162                     MSG_INVALID_PATTERN, "B2", "^[a-z][a-zA-Z0-9]*$"),
163             "20:59: "
164                 + getCheckMessage(AbstractNameCheck.class,
165                     MSG_INVALID_PATTERN, "B3", "^[a-z][a-zA-Z0-9]*$"),
166             "80:59: "
167                 + getCheckMessage(AbstractNameCheck.class,
168                     MSG_INVALID_PATTERN, "A2", "^[a-z][a-zA-Z0-9]*$"),
169         };
170         verifySuppressed(filterConfig, suppressed);
171     }
172 
173     @Test
174     public void testCheckC() throws Exception {
175         final DefaultConfiguration filterConfig =
176             createModuleConfig(SuppressWithNearbyCommentFilter.class);
177         filterConfig.addAttribute("checkC", "false");
178         final String[] suppressed = {
179             "14:17: "
180                 + getCheckMessage(AbstractNameCheck.class,
181                     MSG_INVALID_PATTERN, "A1", "^[a-z][a-zA-Z0-9]*$"),
182             "18:17: "
183                 + getCheckMessage(AbstractNameCheck.class,
184                     MSG_INVALID_PATTERN, "B1", "^[a-z][a-zA-Z0-9]*$"),
185         };
186         verifySuppressed(filterConfig, suppressed);
187     }
188 
189     @Test
190     public void testCheckCpp() throws Exception {
191         final DefaultConfiguration filterConfig =
192             createModuleConfig(SuppressWithNearbyCommentFilter.class);
193         filterConfig.addAttribute("checkCPP", "false");
194         final String[] suppressed = {
195             "15:17: "
196                 + getCheckMessage(AbstractNameCheck.class,
197                     MSG_INVALID_PATTERN, "A2", "^[a-z][a-zA-Z0-9]*$"),
198             "16:59: "
199                 + getCheckMessage(AbstractNameCheck.class,
200                     MSG_INVALID_PATTERN, "A3", "^[a-z][a-zA-Z0-9]*$"),
201             "19:17: "
202                 + getCheckMessage(AbstractNameCheck.class,
203                     MSG_INVALID_PATTERN, "B2", "^[a-z][a-zA-Z0-9]*$"),
204             "20:59: "
205                 + getCheckMessage(AbstractNameCheck.class,
206                     MSG_INVALID_PATTERN, "B3", "^[a-z][a-zA-Z0-9]*$"),
207             "80:59: "
208                 + getCheckMessage(AbstractNameCheck.class,
209                     MSG_INVALID_PATTERN, "A2", "^[a-z][a-zA-Z0-9]*$"),
210         };
211         verifySuppressed(filterConfig, suppressed);
212     }
213 
214     @Test
215     public void testUsingVariableMessage() throws Exception {
216         final DefaultConfiguration filterConfig =
217             createModuleConfig(SuppressWithNearbyCommentFilter.class);
218         filterConfig.addAttribute("commentFormat", "ALLOW CATCH (\\w+) BECAUSE");
219         filterConfig.addAttribute("checkFormat", "IllegalCatchCheck");
220         filterConfig.addAttribute("messageFormat", "$1");
221         filterConfig.addAttribute("influenceFormat", "-1");
222         final String[] suppressed = {
223             "66:23: "
224                 + getCheckMessage(IllegalCatchCheck.class,
225                     IllegalCatchCheck.MSG_KEY, "Throwable"),
226             "73:11: "
227                 + getCheckMessage(IllegalCatchCheck.class,
228                     IllegalCatchCheck.MSG_KEY, "Exception"),
229         };
230         verifySuppressed(filterConfig, suppressed);
231     }
232 
233     @Test
234     public void testUsingVariableCheckOnNextLine() throws Exception {
235         final DefaultConfiguration filterConfig =
236             createModuleConfig(SuppressWithNearbyCommentFilter.class);
237         filterConfig.addAttribute("commentFormat", "ALLOW (\\w+) ON NEXT LINE");
238         filterConfig.addAttribute("checkFormat", "$1");
239         filterConfig.addAttribute("influenceFormat", "1");
240         final String[] suppressed = {
241             "24:17: "
242                 + getCheckMessage(AbstractNameCheck.class,
243                     MSG_INVALID_PATTERN, "C2", "^[a-z][a-zA-Z0-9]*$"),
244         };
245         verifySuppressed(filterConfig, suppressed);
246     }
247 
248     @Test
249     public void testUsingVariableCheckOnPreviousLine() throws Exception {
250         final DefaultConfiguration filterConfig =
251             createModuleConfig(SuppressWithNearbyCommentFilter.class);
252         filterConfig.addAttribute("commentFormat", "ALLOW (\\w+) ON PREVIOUS LINE");
253         filterConfig.addAttribute("checkFormat", "$1");
254         filterConfig.addAttribute("influenceFormat", "-1");
255         final String[] suppressed = {
256             "28:17: "
257                 + getCheckMessage(AbstractNameCheck.class,
258                     MSG_INVALID_PATTERN, "D2", "^[a-z][a-zA-Z0-9]*$"),
259         };
260         verifySuppressed(filterConfig, suppressed);
261     }
262 
263     @Test
264     public void testVariableCheckOnVariableNumberOfLines() throws Exception {
265         final DefaultConfiguration filterConfig =
266             createModuleConfig(SuppressWithNearbyCommentFilter.class);
267         filterConfig.addAttribute("commentFormat", "ALLOW (\\w+) UNTIL THIS LINE([+-]\\d+)");
268         filterConfig.addAttribute("checkFormat", "$1");
269         filterConfig.addAttribute("influenceFormat", "$2");
270         final String[] suppressed = {
271             "35:30: "
272                 + getCheckMessage(AbstractNameCheck.class,
273                     MSG_INVALID_PATTERN, "e4", "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"),
274             "36:17: "
275                 + getCheckMessage(AbstractNameCheck.class,
276                     MSG_INVALID_PATTERN, "E5", "^[a-z][a-zA-Z0-9]*$"),
277             "38:17: "
278                 + getCheckMessage(AbstractNameCheck.class,
279                     MSG_INVALID_PATTERN, "E7", "^[a-z][a-zA-Z0-9]*$"),
280             "39:17: "
281                 + getCheckMessage(AbstractNameCheck.class,
282                     MSG_INVALID_PATTERN, "E8", "^[a-z][a-zA-Z0-9]*$"),
283         };
284         verifySuppressed(filterConfig, suppressed);
285     }
286 
287     @Test
288     public void testEqualsAndHashCodeOfTagClass() {
289         EqualsVerifier.forClass(SuppressWithNearbyCommentFilter.Tag.class).usingGetClass().verify();
290     }
291 
292     private void verifySuppressed(Configuration moduleConfig,
293             String... aSuppressed)
294             throws Exception {
295         verifySuppressed(moduleConfig, getPath("InputSuppressWithNearbyCommentFilter.java"),
296                ALL_MESSAGES, aSuppressed);
297     }
298 
299     private void verifySuppressed(Configuration moduleConfig, String fileName,
300             String[] expectedViolations, String... suppressedViolations) throws Exception {
301         final DefaultConfiguration memberNameCheckConfig =
302                 createModuleConfig(MemberNameCheck.class);
303         memberNameCheckConfig.addAttribute("id", "ignore");
304 
305         final DefaultConfiguration constantNameCheckConfig =
306             createModuleConfig(ConstantNameCheck.class);
307         constantNameCheckConfig.addAttribute("id", null);
308 
309         final DefaultConfiguration treewalkerConfig = createModuleConfig(TreeWalker.class);
310         treewalkerConfig.addChild(memberNameCheckConfig);
311         treewalkerConfig.addChild(constantNameCheckConfig);
312         treewalkerConfig.addChild(createModuleConfig(IllegalCatchCheck.class));
313 
314         if (moduleConfig != null) {
315             treewalkerConfig.addChild(moduleConfig);
316         }
317 
318         final DefaultConfiguration checkerConfig = createRootConfig(treewalkerConfig);
319 
320         verify(checkerConfig,
321                 fileName,
322                 removeSuppressed(expectedViolations, suppressedViolations));
323     }
324 
325     private static String[] removeSuppressed(String[] from, String... remove) {
326         final Collection<String> coll = Arrays.stream(from).collect(Collectors.toList());
327         coll.removeAll(Arrays.asList(remove));
328         return coll.toArray(new String[coll.size()]);
329     }
330 
331     @Test
332     public void testInvalidInfluenceFormat() throws Exception {
333         final DefaultConfiguration filterConfig =
334             createModuleConfig(SuppressWithNearbyCommentFilter.class);
335         filterConfig.addAttribute("influenceFormat", "a");
336 
337         try {
338             final String[] suppressed = CommonUtils.EMPTY_STRING_ARRAY;
339             verifySuppressed(filterConfig, suppressed);
340             fail("Exception is expected");
341         }
342         catch (CheckstyleException ex) {
343             final IllegalArgumentException cause = (IllegalArgumentException) ex.getCause();
344             assertEquals("Invalid exception message", "unable to parse influence"
345                 + " from 'SUPPRESS CHECKSTYLE MemberNameCheck' using a", cause.getMessage());
346         }
347     }
348 
349     @Test
350     public void testInfluenceFormat() throws Exception {
351         final DefaultConfiguration filterConfig =
352                 createModuleConfig(SuppressWithNearbyCommentFilter.class);
353         filterConfig.addAttribute("influenceFormat", "1");
354 
355         final String[] suppressed = {
356             "14:17: "
357                 + getCheckMessage(AbstractNameCheck.class,
358                     MSG_INVALID_PATTERN, "A1", "^[a-z][a-zA-Z0-9]*$"),
359             "15:17: "
360                 + getCheckMessage(AbstractNameCheck.class,
361                     MSG_INVALID_PATTERN, "A2", "^[a-z][a-zA-Z0-9]*$"),
362             "16:59: "
363                 + getCheckMessage(AbstractNameCheck.class,
364                     MSG_INVALID_PATTERN, "A3", "^[a-z][a-zA-Z0-9]*$"),
365             "18:17: "
366                 + getCheckMessage(AbstractNameCheck.class,
367                     MSG_INVALID_PATTERN, "B1", "^[a-z][a-zA-Z0-9]*$"),
368             "19:17: "
369                 + getCheckMessage(AbstractNameCheck.class,
370                     MSG_INVALID_PATTERN, "B2", "^[a-z][a-zA-Z0-9]*$"),
371             "20:59: "
372                 + getCheckMessage(AbstractNameCheck.class,
373                     MSG_INVALID_PATTERN, "B3", "^[a-z][a-zA-Z0-9]*$"),
374             "80:59: "
375                 + getCheckMessage(AbstractNameCheck.class,
376                     MSG_INVALID_PATTERN, "A2", "^[a-z][a-zA-Z0-9]*$"),
377             "81:17: "
378                 + getCheckMessage(AbstractNameCheck.class,
379                     MSG_INVALID_PATTERN, "A1", "^[a-z][a-zA-Z0-9]*$"),
380         };
381         verifySuppressed(filterConfig, suppressed);
382     }
383 
384     @Test
385     public void testInvalidCheckFormat() throws Exception {
386         final DefaultConfiguration filterConfig =
387             createModuleConfig(SuppressWithNearbyCommentFilter.class);
388         filterConfig.addAttribute("checkFormat", "a[l");
389 
390         try {
391             final String[] suppressed = CommonUtils.EMPTY_STRING_ARRAY;
392             verifySuppressed(filterConfig, suppressed);
393             fail("Exception is expected");
394         }
395         catch (CheckstyleException ex) {
396             final IllegalArgumentException cause = (IllegalArgumentException) ex.getCause();
397             assertEquals("Invalid exception message",
398                 "unable to parse expanded comment a[l", cause.getMessage());
399         }
400     }
401 
402     @Test
403     public void testAcceptNullLocalizedMessage() {
404         final SuppressWithNearbyCommentFilter filter = new SuppressWithNearbyCommentFilter();
405         final TreeWalkerAuditEvent auditEvent = new TreeWalkerAuditEvent(null, null, null, null);
406         assertTrue("Filter should accept null localized message", filter.accept(auditEvent));
407     }
408 
409     @Test
410     public void testToStringOfTagClass() {
411         final SuppressWithNearbyCommentFilter.Tag tag = new SuppressWithNearbyCommentFilter.Tag(
412                 "text", 7, new SuppressWithNearbyCommentFilter()
413         );
414         assertEquals("Invalid toString result",
415             "Tag[text='text', firstLine=7, lastLine=7, "
416                     + "tagCheckRegexp=.*, tagMessageRegexp=null]", tag.toString());
417     }
418 
419     @Test
420     public void testUsingTagMessageRegexp() throws Exception {
421         final DefaultConfiguration filterConfig =
422             createModuleConfig(SuppressWithNearbyCommentFilter.class);
423         filterConfig.addAttribute("commentFormat", "SUPPRESS CHECKSTYLE (\\w+)");
424         filterConfig.addAttribute("checkFormat", "IllegalCatchCheck");
425         filterConfig.addAttribute("messageFormat", "^$1 ololo*$");
426         final String[] suppressed = CommonUtils.EMPTY_STRING_ARRAY;
427         verifySuppressed(filterConfig, suppressed);
428     }
429 
430     @Test
431     public void testSuppressById() throws Exception {
432         final DefaultConfiguration filterConfig =
433             createModuleConfig(SuppressWithNearbyCommentFilter.class);
434         filterConfig.addAttribute("commentFormat", "@cs-: (\\w+) \\(\\w+\\)");
435         filterConfig.addAttribute("checkFormat", "$1");
436         filterConfig.addAttribute("influenceFormat", "0");
437         final String[] suppressedViolationMessages = {
438             "5:17: "
439                 + getCheckMessage(AbstractNameCheck.class,
440                     MSG_INVALID_PATTERN, "A1", "^[a-z][a-zA-Z0-9]*$"),
441             "9:9: "
442                 + getCheckMessage(AbstractNameCheck.class,
443                     MSG_INVALID_PATTERN, "line_length", "^[a-z][a-zA-Z0-9]*$"),
444         };
445         final String[] expectedViolationMessages = {
446             "5:17: "
447                 + getCheckMessage(AbstractNameCheck.class,
448                     MSG_INVALID_PATTERN, "A1", "^[a-z][a-zA-Z0-9]*$"),
449             "7:30: "
450                 + getCheckMessage(AbstractNameCheck.class,
451                     MSG_INVALID_PATTERN, "abc", "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"),
452             "9:9: "
453                 + getCheckMessage(AbstractNameCheck.class,
454                     MSG_INVALID_PATTERN, "line_length", "^[a-z][a-zA-Z0-9]*$"),
455             "11:18: "
456                 + getCheckMessage(AbstractNameCheck.class,
457                     MSG_INVALID_PATTERN, "ID", "^[a-z][a-zA-Z0-9]*$"),
458         };
459 
460         verifySuppressed(filterConfig,
461             getPath("InputSuppressWithNearbyCommentFilterById.java"),
462             expectedViolationMessages, suppressedViolationMessages);
463     }
464 
465     @Test
466     public void testTagsAreClearedEachRun() {
467         final SuppressWithNearbyCommentFilter suppressionCommentFilter =
468                 new SuppressWithNearbyCommentFilter();
469         final FileContents contents =
470                 new FileContents("filename", "//SUPPRESS CHECKSTYLE ignore", "line2");
471         contents.reportSingleLineComment(1, 0);
472         final TreeWalkerAuditEvent dummyEvent = new TreeWalkerAuditEvent(contents, "filename",
473                 new LocalizedMessage(1, null, null, null, null, Object.class, null), null);
474         suppressionCommentFilter.accept(dummyEvent);
475         final FileContents contents2 =
476                 new FileContents("filename2", "some line", "//SUPPRESS CHECKSTYLE ignore");
477         contents2.reportSingleLineComment(2, 0);
478         final TreeWalkerAuditEvent dummyEvent2 = new TreeWalkerAuditEvent(contents2, "filename",
479                 new LocalizedMessage(1, null, null, null, null, Object.class, null), null);
480         suppressionCommentFilter.accept(dummyEvent2);
481         final List<SuppressionCommentFilter.Tag> tags =
482                 Whitebox.getInternalState(suppressionCommentFilter, "tags");
483         assertEquals("Invalid tags size", 1, tags.size());
484     }
485 
486 }