1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.puppycrawl.tools.checkstyle;
21
22 import static com.google.common.truth.Truth.assertWithMessage;
23
24 import java.io.ByteArrayInputStream;
25 import java.io.ByteArrayOutputStream;
26 import java.io.File;
27 import java.io.IOException;
28 import java.io.InputStreamReader;
29 import java.io.LineNumberReader;
30 import java.nio.charset.StandardCharsets;
31 import java.nio.file.Path;
32 import java.text.MessageFormat;
33 import java.util.ArrayList;
34 import java.util.Arrays;
35 import java.util.Collections;
36 import java.util.HashMap;
37 import java.util.List;
38 import java.util.Locale;
39 import java.util.Map;
40 import java.util.ResourceBundle;
41 import java.util.stream.Collectors;
42
43 import com.google.common.collect.ImmutableMap;
44 import com.google.common.collect.Maps;
45 import com.puppycrawl.tools.checkstyle.LocalizedMessage.Utf8Control;
46 import com.puppycrawl.tools.checkstyle.api.AuditListener;
47 import com.puppycrawl.tools.checkstyle.api.Configuration;
48 import com.puppycrawl.tools.checkstyle.api.DetailAST;
49 import com.puppycrawl.tools.checkstyle.bdd.InlineConfigParser;
50 import com.puppycrawl.tools.checkstyle.bdd.TestInputConfiguration;
51 import com.puppycrawl.tools.checkstyle.bdd.TestInputViolation;
52 import com.puppycrawl.tools.checkstyle.internal.utils.BriefUtLogger;
53 import com.puppycrawl.tools.checkstyle.internal.utils.TestUtil;
54 import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
55 import com.puppycrawl.tools.checkstyle.utils.ModuleReflectionUtil;
56 import com.puppycrawl.tools.checkstyle.xpath.RootNode;
57
58 public abstract class AbstractModuleTestSupport extends AbstractPathTestSupport {
59
60 protected static final String ROOT_MODULE_NAME = Checker.class.getSimpleName();
61
62 private final ByteArrayOutputStream stream = new ByteArrayOutputStream();
63
64
65
66
67
68
69 protected final ByteArrayOutputStream getStream() {
70 return stream;
71 }
72
73
74
75
76
77
78 protected final BriefUtLogger getBriefUtLogger() {
79 return new BriefUtLogger(stream);
80 }
81
82
83
84
85
86
87
88
89 protected static DefaultConfiguration createModuleConfig(Class<?> clazz) {
90 return new DefaultConfiguration(clazz.getName());
91 }
92
93
94
95
96
97
98
99
100 protected final Checker createChecker(Configuration moduleConfig)
101 throws Exception {
102 final String moduleName = moduleConfig.getName();
103 final Checker checker = new Checker();
104 checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
105
106 if (ROOT_MODULE_NAME.equals(moduleName)) {
107 checker.configure(moduleConfig);
108 }
109 else {
110 configureChecker(checker, moduleConfig);
111 }
112
113 checker.addListener(getBriefUtLogger());
114 return checker;
115 }
116
117
118
119
120
121
122
123
124 protected void configureChecker(Checker checker, Configuration moduleConfig) throws Exception {
125 final Class<?> moduleClass = Class.forName(moduleConfig.getName());
126
127 final Configuration config;
128 if (ModuleReflectionUtil.isCheckstyleTreeWalkerCheck(moduleClass)
129 || ModuleReflectionUtil.isTreeWalkerFilterModule(moduleClass)) {
130 config = createTreeWalkerConfig(moduleConfig);
131 }
132 else {
133 config = createRootConfig(moduleConfig);
134 }
135 checker.configure(config);
136 }
137
138
139
140
141
142
143
144
145
146 protected static DefaultConfiguration createTreeWalkerConfig(Configuration config) {
147 final DefaultConfiguration rootConfig =
148 new DefaultConfiguration(ROOT_MODULE_NAME);
149 final DefaultConfiguration twConf = createModuleConfig(TreeWalker.class);
150
151 rootConfig.addProperty("charset", StandardCharsets.UTF_8.name());
152 rootConfig.addChild(twConf);
153 twConf.addChild(config);
154 return rootConfig;
155 }
156
157
158
159
160
161
162
163 protected static DefaultConfiguration createRootConfig(Configuration config) {
164 final DefaultConfiguration rootConfig = new DefaultConfiguration(ROOT_MODULE_NAME);
165 if (config != null) {
166 rootConfig.addChild(config);
167 }
168 return rootConfig;
169 }
170
171
172
173
174
175
176
177
178
179 protected final String getNonCompilablePath(String filename) throws IOException {
180 return new File("src/" + getResourceLocation()
181 + "/resources-noncompilable/" + getPackageLocation() + "/"
182 + filename).getCanonicalPath();
183 }
184
185
186
187
188
189
190
191
192 protected RootNode getRootNodeForNonCompilable(String fileName) throws Exception {
193 final File file = new File(getNonCompilablePath(fileName));
194 final DetailAST rootAst = JavaParser.parseFile(file, JavaParser.Options.WITHOUT_COMMENTS);
195 return new RootNode(rootAst);
196 }
197
198
199
200
201
202
203
204
205 protected final String getUriString(String filename) {
206 return new File("src/test/resources/" + getPackageLocation() + "/" + filename).toURI()
207 .toString();
208 }
209
210
211
212
213
214
215
216
217
218
219
220 protected final void verifyFilterWithInlineConfigParser(String filePath,
221 String[] expectedUnfiltered,
222 String... expectedFiltered)
223 throws Exception {
224 final TestInputConfiguration testInputConfiguration =
225 InlineConfigParser.parseWithFilteredViolations(filePath);
226 final DefaultConfiguration configWithoutFilters =
227 testInputConfiguration.createConfigurationWithoutFilters();
228 final List<TestInputViolation> violationsWithoutFilters =
229 new ArrayList<>(testInputConfiguration.getViolations());
230 violationsWithoutFilters.addAll(testInputConfiguration.getFilteredViolations());
231 Collections.sort(violationsWithoutFilters);
232 verifyViolations(configWithoutFilters, filePath, violationsWithoutFilters);
233 verify(configWithoutFilters, filePath, expectedUnfiltered);
234 final DefaultConfiguration configWithFilters =
235 testInputConfiguration.createConfiguration();
236 verifyViolations(configWithFilters, filePath, testInputConfiguration.getViolations());
237 verify(configWithFilters, filePath, expectedFiltered);
238 }
239
240
241
242
243
244
245
246
247
248
249 protected final void verifyWithInlineXmlConfig(String filePath, String... expected)
250 throws Exception {
251 final TestInputConfiguration testInputConfiguration =
252 InlineConfigParser.parseWithXmlHeader(filePath);
253 final Configuration xmlConfig =
254 testInputConfiguration.getXmlConfiguration();
255 verifyViolations(xmlConfig, filePath, testInputConfiguration.getViolations());
256 verify(xmlConfig, filePath, expected);
257 }
258
259
260
261
262
263
264
265
266
267
268 protected final void verifyWithInlineConfigParser(String filePath, String... expected)
269 throws Exception {
270 final TestInputConfiguration testInputConfiguration =
271 InlineConfigParser.parse(filePath);
272 final DefaultConfiguration parsedConfig =
273 testInputConfiguration.createConfiguration();
274 final List<String> actualViolations = getActualViolationsForFile(parsedConfig, filePath);
275 verifyViolations(filePath, testInputConfiguration.getViolations(), actualViolations);
276 assertWithMessage("Violations for %s differ.", filePath)
277 .that(actualViolations)
278 .containsExactlyElementsIn(expected);
279 }
280
281
282
283
284
285
286
287
288
289
290
291
292 protected final void verifyWithInlineConfigParser(String filePath1,
293 String filePath2,
294 String... expected)
295 throws Exception {
296 final TestInputConfiguration testInputConfiguration1 =
297 InlineConfigParser.parse(filePath1);
298 final DefaultConfiguration parsedConfig =
299 testInputConfiguration1.createConfiguration();
300 final TestInputConfiguration testInputConfiguration2 =
301 InlineConfigParser.parse(filePath2);
302 verifyViolations(parsedConfig, filePath1, testInputConfiguration1.getViolations());
303 verifyViolations(parsedConfig, filePath2, testInputConfiguration2.getViolations());
304 verify(createChecker(parsedConfig),
305 new File[] {new File(filePath1), new File(filePath2)},
306 filePath1,
307 expected);
308 }
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323 protected final void verifyWithInlineConfigParser(String filePath1,
324 String filePath2,
325 List<String> expectedFromFile1,
326 List<String> expectedFromFile2)
327 throws Exception {
328 final TestInputConfiguration testInputConfiguration = InlineConfigParser.parse(filePath1);
329 final DefaultConfiguration parsedConfig = testInputConfiguration.createConfiguration();
330 final TestInputConfiguration testInputConfiguration2 = InlineConfigParser.parse(filePath2);
331 final DefaultConfiguration parsedConfig2 = testInputConfiguration.createConfiguration();
332 final File[] inputs = {new File(filePath1), new File(filePath2)};
333 verifyViolations(parsedConfig, filePath1, testInputConfiguration.getViolations());
334 verifyViolations(parsedConfig2, filePath2, testInputConfiguration2.getViolations());
335 verify(createChecker(parsedConfig), inputs, ImmutableMap.of(
336 filePath1, expectedFromFile1,
337 filePath2, expectedFromFile2));
338 }
339
340
341
342
343
344
345
346
347
348
349
350
351 protected final void verifyWithInlineConfigParserSeparateConfigAndTarget(String fileWithConfig,
352 String targetFile,
353 String... expected)
354 throws Exception {
355 final TestInputConfiguration testInputConfiguration1 =
356 InlineConfigParser.parse(fileWithConfig);
357 final DefaultConfiguration parsedConfig =
358 testInputConfiguration1.createConfiguration();
359 final List<TestInputViolation> inputViolations =
360 InlineConfigParser.getViolationsFromInputFile(targetFile);
361 final List<String> actualViolations = getActualViolationsForFile(parsedConfig, targetFile);
362 verifyViolations(targetFile, inputViolations, actualViolations);
363 assertWithMessage("Violations for %s differ.", targetFile)
364 .that(actualViolations)
365 .containsExactlyElementsIn(expected);
366 }
367
368
369
370
371
372
373
374
375
376
377
378
379 protected final void verifyFilterWithInlineConfigParserSeparateConfigAndTarget(
380 String fileWithConfig,
381 String targetFilePath,
382 String[] expectedUnfiltered,
383 String... expectedFiltered)
384 throws Exception {
385 final TestInputConfiguration testInputConfiguration =
386 InlineConfigParser.parseWithFilteredViolations(fileWithConfig);
387 final DefaultConfiguration configWithoutFilters =
388 testInputConfiguration.createConfigurationWithoutFilters();
389 final List<TestInputViolation> violationsWithoutFilters = new ArrayList<>(
390 InlineConfigParser.getFilteredViolationsFromInputFile(targetFilePath));
391 violationsWithoutFilters.addAll(
392 InlineConfigParser.getViolationsFromInputFile(targetFilePath));
393 Collections.sort(violationsWithoutFilters);
394 verifyViolations(configWithoutFilters, targetFilePath, violationsWithoutFilters);
395 verify(configWithoutFilters, targetFilePath, expectedUnfiltered);
396 final DefaultConfiguration configWithFilters =
397 testInputConfiguration.createConfiguration();
398 final List<TestInputViolation> violationsWithFilters =
399 InlineConfigParser.getViolationsFromInputFile(targetFilePath);
400 verifyViolations(configWithFilters, targetFilePath, violationsWithFilters);
401 verify(configWithFilters, targetFilePath, expectedFiltered);
402 }
403
404
405
406
407
408
409
410
411
412
413 protected void verifyWithInlineConfigParserTwice(String filePath, String... expected)
414 throws Exception {
415 final TestInputConfiguration testInputConfiguration =
416 InlineConfigParser.parse(filePath);
417 final DefaultConfiguration parsedConfig =
418 testInputConfiguration.createConfiguration();
419 verifyViolations(parsedConfig, filePath, testInputConfiguration.getViolations());
420 verify(parsedConfig, filePath, expected);
421 }
422
423
424
425
426
427
428
429
430
431
432
433
434 protected void verifyWithInlineConfigParserAndLogger(String inputFile,
435 String expectedReportFile,
436 AuditListener logger,
437 ByteArrayOutputStream outputStream)
438 throws Exception {
439 final TestInputConfiguration testInputConfiguration =
440 InlineConfigParser.parse(inputFile);
441 final DefaultConfiguration parsedConfig =
442 testInputConfiguration.createConfiguration();
443 final List<File> filesToCheck = Collections.singletonList(new File(inputFile));
444 final String basePath = Path.of("").toAbsolutePath().toString();
445
446 final Checker checker = createChecker(parsedConfig);
447 checker.setBasedir(basePath);
448 checker.addListener(logger);
449 checker.process(filesToCheck);
450
451 verifyContent(expectedReportFile, outputStream);
452 }
453
454
455
456
457
458
459
460
461
462
463
464
465 protected final void verifyWithInlineConfigParserAndDefaultLogger(String inputFile,
466 String expectedOutputFile,
467 AuditListener logger,
468 ByteArrayOutputStream outputStream)
469 throws Exception {
470 final TestInputConfiguration testInputConfiguration =
471 InlineConfigParser.parseWithXmlHeader(inputFile);
472 final Configuration parsedConfig =
473 testInputConfiguration.getXmlConfiguration();
474 final List<File> filesToCheck = Collections.singletonList(new File(inputFile));
475 final String basePath = Path.of("").toAbsolutePath().toString();
476
477 final Checker checker = createChecker(parsedConfig);
478 checker.setBasedir(basePath);
479 checker.addListener(logger);
480 checker.process(filesToCheck);
481
482 verifyCleanedMessageContent(expectedOutputFile, outputStream, basePath);
483 }
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502 protected final void verifyWithInlineConfigParserAndDefaultLogger(String inputFile,
503 String expectedInfoFile,
504 String expectedErrorFile,
505 AuditListener logger,
506 ByteArrayOutputStream infoStream,
507 ByteArrayOutputStream errorStream)
508 throws Exception {
509 final TestInputConfiguration testInputConfiguration =
510 InlineConfigParser.parseWithXmlHeader(inputFile);
511 final Configuration parsedConfig =
512 testInputConfiguration.getXmlConfiguration();
513 final List<File> filesToCheck = Collections.singletonList(new File(inputFile));
514 final String basePath = Path.of("").toAbsolutePath().toString();
515
516 final Checker checker = createChecker(parsedConfig);
517 checker.setBasedir(basePath);
518 checker.addListener(logger);
519 checker.process(filesToCheck);
520
521 verifyContent(expectedInfoFile, infoStream);
522 verifyCleanedMessageContent(expectedErrorFile, errorStream, basePath);
523 }
524
525
526
527
528
529
530
531
532
533
534
535
536 protected final void verify(Configuration config, String fileName, String... expected)
537 throws Exception {
538 verify(createChecker(config), fileName, fileName, expected);
539 }
540
541
542
543
544
545
546
547
548
549
550
551
552
553 protected void verify(Checker checker, String fileName, String... expected)
554 throws Exception {
555 verify(checker, fileName, fileName, expected);
556 }
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571 protected final void verify(Checker checker,
572 String processedFilename,
573 String messageFileName,
574 String... expected)
575 throws Exception {
576 verify(checker,
577 new File[] {new File(processedFilename)},
578 messageFileName, expected);
579 }
580
581
582
583
584
585
586
587
588
589
590
591 protected void verify(Checker checker,
592 File[] processedFiles,
593 String messageFileName,
594 String... expected)
595 throws Exception {
596 final Map<String, List<String>> expectedViolations = new HashMap<>();
597 expectedViolations.put(messageFileName, Arrays.asList(expected));
598 verify(checker, processedFiles, expectedViolations);
599 }
600
601
602
603
604
605
606
607
608
609 protected final void verify(Checker checker,
610 File[] processedFiles,
611 Map<String, List<String>> expectedViolations)
612 throws Exception {
613 stream.flush();
614 stream.reset();
615 final List<File> theFiles = new ArrayList<>();
616 Collections.addAll(theFiles, processedFiles);
617 checker.process(theFiles);
618
619
620 final Map<String, List<String>> actualViolations = getActualViolations();
621 final Map<String, List<String>> realExpectedViolations =
622 Maps.filterValues(expectedViolations, input -> !input.isEmpty());
623
624 assertWithMessage("Files with expected violations and actual violations differ.")
625 .that(actualViolations.keySet())
626 .isEqualTo(realExpectedViolations.keySet());
627
628 realExpectedViolations.forEach((fileName, violationList) -> {
629 assertWithMessage("Violations for %s differ.", fileName)
630 .that(actualViolations.get(fileName))
631 .containsExactlyElementsIn(violationList);
632 });
633
634 checker.destroy();
635 }
636
637
638
639
640
641
642
643
644 protected final void verifyWithLimitedResources(String fileName, String... expected)
645 throws Exception {
646
647 final Void result = TestUtil.getResultWithLimitedResources(() -> {
648 verifyWithInlineConfigParser(fileName, expected);
649 return null;
650 });
651 assertWithMessage("Verify should complete successfully.")
652 .that(result)
653 .isNull();
654 }
655
656
657
658
659
660
661
662
663 protected final void execute(Configuration config, String... filenames) throws Exception {
664 final Checker checker = createChecker(config);
665 final List<File> files = Arrays.stream(filenames)
666 .map(File::new)
667 .toList();
668 checker.process(files);
669 checker.destroy();
670 }
671
672
673
674
675
676
677
678
679 protected static void execute(Checker checker, String... filenames) throws Exception {
680 final List<File> files = Arrays.stream(filenames)
681 .map(File::new)
682 .toList();
683 checker.process(files);
684 checker.destroy();
685 }
686
687
688
689
690
691
692
693
694
695 private void verifyViolations(Configuration config,
696 String file,
697 List<TestInputViolation> testInputViolations)
698 throws Exception {
699 final List<String> actualViolations = getActualViolationsForFile(config, file);
700 final List<Integer> actualViolationLines = actualViolations.stream()
701 .map(violation -> violation.substring(0, violation.indexOf(':')))
702 .map(Integer::valueOf)
703 .toList();
704 final List<Integer> expectedViolationLines = testInputViolations.stream()
705 .map(TestInputViolation::getLineNo)
706 .toList();
707 assertWithMessage("Violation lines for %s differ.", file)
708 .that(actualViolationLines)
709 .isEqualTo(expectedViolationLines);
710 for (int index = 0; index < actualViolations.size(); index++) {
711 assertWithMessage("Actual and expected violations differ.")
712 .that(actualViolations.get(index))
713 .matches(testInputViolations.get(index).toRegex());
714 }
715 }
716
717
718
719
720
721
722
723
724 private static void verifyViolations(String file,
725 List<TestInputViolation> testInputViolations,
726 List<String> actualViolations) {
727 final List<Integer> actualViolationLines = actualViolations.stream()
728 .map(violation -> violation.substring(0, violation.indexOf(':')))
729 .map(Integer::valueOf)
730 .toList();
731 final List<Integer> expectedViolationLines = testInputViolations.stream()
732 .map(TestInputViolation::getLineNo)
733 .toList();
734 assertWithMessage("Violation lines for %s differ.", file)
735 .that(actualViolationLines)
736 .isEqualTo(expectedViolationLines);
737 for (int index = 0; index < actualViolations.size(); index++) {
738 assertWithMessage("Actual and expected violations differ.")
739 .that(actualViolations.get(index))
740 .matches(testInputViolations.get(index).toRegex());
741 }
742 }
743
744
745
746
747
748
749
750
751 private static void verifyContent(
752 String expectedOutputFile,
753 ByteArrayOutputStream outputStream) throws IOException {
754 final String expectedContent = readFile(expectedOutputFile);
755 final String actualContent =
756 toLfLineEnding(outputStream.toString(StandardCharsets.UTF_8));
757 assertWithMessage("Content should match")
758 .that(actualContent)
759 .isEqualTo(expectedContent);
760 }
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781 private static void verifyCleanedMessageContent(
782 String expectedOutputFile,
783 ByteArrayOutputStream outputStream,
784 String basePath) throws IOException {
785 final String expectedContent = readFile(expectedOutputFile);
786 final String rawActualContent =
787 toLfLineEnding(outputStream.toString(StandardCharsets.UTF_8));
788
789 final String cleanedActualContent = rawActualContent.lines()
790 .filter(line -> {
791 return line.startsWith("[")
792 || line.contains("Starting audit...")
793 || line.contains("Audit done.");
794 })
795 .map(line -> line.replace(basePath, ""))
796 .map(line -> line.replace('\\', '/'))
797 .collect(Collectors.joining("\n", "", "\n"));
798
799 assertWithMessage("Content should match")
800 .that(cleanedActualContent)
801 .isEqualTo(expectedContent);
802 }
803
804
805
806
807
808
809
810
811
812 private List<String> getActualViolationsForFile(Configuration config,
813 String file) throws Exception {
814 stream.flush();
815 stream.reset();
816 final List<File> files = Collections.singletonList(new File(file));
817 final Checker checker = createChecker(config);
818 checker.process(files);
819 final Map<String, List<String>> actualViolations =
820 getActualViolations();
821 checker.destroy();
822 return actualViolations.getOrDefault(file, new ArrayList<>());
823 }
824
825
826
827
828
829
830
831
832
833 private Map<String, List<String>> getActualViolations() throws IOException {
834
835 try (ByteArrayInputStream inputStream =
836 new ByteArrayInputStream(stream.toByteArray());
837 LineNumberReader lnr = new LineNumberReader(
838 new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
839 final Map<String, List<String>> actualViolations = new HashMap<>();
840 for (String line = lnr.readLine(); line != null;
841 line = lnr.readLine()) {
842 if ("Audit done.".equals(line) || line.contains("at com")) {
843 break;
844 }
845
846
847 final String[] actualViolation = line.split("(?<=.{2}):", 2);
848 final String actualViolationFileName = actualViolation[0];
849 final String actualViolationMessage = actualViolation[1];
850
851 actualViolations
852 .computeIfAbsent(actualViolationFileName, key -> new ArrayList<>())
853 .add(actualViolationMessage);
854 }
855
856 return actualViolations;
857 }
858 }
859
860
861
862
863
864
865
866
867
868 protected final String getCheckMessage(String messageKey, Object... arguments) {
869 return internalGetCheckMessage(getMessageBundle(), messageKey, arguments);
870 }
871
872
873
874
875
876
877
878
879
880
881 protected static String getCheckMessage(
882 Class<?> clazz, String messageKey, Object... arguments) {
883 return internalGetCheckMessage(getMessageBundle(clazz.getName()), messageKey, arguments);
884 }
885
886
887
888
889
890
891
892
893
894
895 private static String internalGetCheckMessage(
896 String messageBundle, String messageKey, Object... arguments) {
897 final ResourceBundle resourceBundle = ResourceBundle.getBundle(
898 messageBundle,
899 Locale.ROOT,
900 Thread.currentThread().getContextClassLoader(),
901 new Utf8Control());
902 final String pattern = resourceBundle.getString(messageKey);
903 final MessageFormat formatter = new MessageFormat(pattern, Locale.ROOT);
904 return formatter.format(arguments);
905 }
906
907
908
909
910
911
912 private String getMessageBundle() {
913 final String className = getClass().getName();
914 return getMessageBundle(className);
915 }
916
917
918
919
920
921
922
923 private static String getMessageBundle(String className) {
924 final String messageBundle;
925 final String messages = "messages";
926 final int endIndex = className.lastIndexOf('.');
927 final Map<String, String> messageBundleMappings = new HashMap<>();
928 messageBundleMappings.put("SeverityMatchFilterExamplesTest",
929 "com.puppycrawl.tools.checkstyle.checks.naming.messages");
930
931 if (endIndex < 0) {
932 messageBundle = messages;
933 }
934 else {
935 final String packageName = className.substring(0, endIndex);
936 if ("com.puppycrawl.tools.checkstyle.filters".equals(packageName)) {
937 messageBundle = messageBundleMappings.get(className.substring(endIndex + 1));
938 }
939 else {
940 messageBundle = packageName + "." + messages;
941 }
942 }
943 return messageBundle;
944 }
945
946
947
948
949
950
951
952
953 protected static String[] removeSuppressed(String[] actualViolations,
954 String... suppressedViolations) {
955 final List<String> actualViolationsList =
956 Arrays.stream(actualViolations).collect(Collectors.toCollection(ArrayList::new));
957 actualViolationsList.removeAll(Arrays.asList(suppressedViolations));
958 return actualViolationsList.toArray(CommonUtil.EMPTY_STRING_ARRAY);
959 }
960
961 }