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