1
2
3
4
5 package com.qulice.maven;
6
7 import java.io.File;
8 import java.util.Arrays;
9 import java.util.Collections;
10 import org.hamcrest.MatcherAssert;
11 import org.hamcrest.Matchers;
12 import org.junit.jupiter.api.Test;
13
14
15
16
17
18
19 final class SummaryTest {
20
21 @Test
22 void countsJavaFilesAndRulesOfEveryValidator() {
23 MatcherAssert.assertThat(
24 "Summary must count the Java files checked and the rules applied",
25 new Summary(
26 Arrays.asList(
27 new File("Broken.java"),
28 new File("pom.xml"),
29 new File("Fixed.JAVA")
30 ),
31 Arrays.asList(
32 new FakeResourceValidator("Alpha", 41),
33 new FakeResourceValidator("Beta", 7)
34 )
35 ).toString(),
36 Matchers.equalTo(
37 "checked 2 .java files against 48 rules (41 Alpha, 7 Beta)"
38 )
39 );
40 }
41
42 @Test
43 void skipsValidatorThatCountsNoRules() {
44 MatcherAssert.assertThat(
45 "Validator without rules cannot show up in the summary",
46 new Summary(
47 Collections.singleton(new File("Main.java")),
48 Arrays.asList(
49 new FakeResourceValidator("Gamma", 3),
50 new FakeResourceValidator("Delta", 0)
51 )
52 ).toString(),
53 Matchers.equalTo("checked 1 .java file against 3 rules (3 Gamma)")
54 );
55 }
56
57 @Test
58 void mentionsNoRulesWhenNobodyCounts() {
59 MatcherAssert.assertThat(
60 "Summary without rules cannot carry an empty pair of brackets",
61 new Summary(
62 Collections.singleton(new File("pom.xml")),
63 Collections.singleton(new FakeResourceValidator("Zeta", 0))
64 ).toString(),
65 Matchers.equalTo("checked 0 .java files against 0 rules")
66 );
67 }
68
69 @Test
70 void countsNoRulesWhenNothingReachedValidators() {
71 MatcherAssert.assertThat(
72 "Rules cannot be counted when no file went to the validators",
73 new Summary(
74 Collections.emptyList(),
75 Collections.singleton(new FakeResourceValidator("Eta", 12))
76 ).toString(),
77 Matchers.equalTo("checked 0 .java files against 0 rules")
78 );
79 }
80 }