-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViolationsReporterApiTest.java
152 lines (126 loc) · 4.5 KB
/
ViolationsReporterApiTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package se.bjurr.violations.git;
import static org.assertj.core.api.Assertions.assertThat;
import static se.bjurr.violations.git.ViolationsReporterApi.violationsReporterApi;
import static se.bjurr.violations.git.ViolationsReporterDetailLevel.COMPACT;
import static se.bjurr.violations.git.ViolationsReporterDetailLevel.PER_FILE_COMPACT;
import static se.bjurr.violations.git.ViolationsReporterDetailLevel.VERBOSE;
import static se.bjurr.violations.lib.ViolationsApi.violationsApi;
import static se.bjurr.violations.lib.reports.Parser.FINDBUGS;
import static se.bjurr.violations.lib.reports.Parser.PERLCRITIC;
import static se.bjurr.violations.lib.reports.Parser.PMD;
import java.io.File;
import java.util.Set;
import java.util.TreeSet;
import java.util.logging.Logger;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import se.bjurr.violations.lib.model.Violation;
public class ViolationsReporterApiTest {
private static Logger LOG = Logger.getLogger(ViolationsReporterApiTest.class.getName());
private Set<Violation> findbugsViolations;
private Set<Violation> pmdViolations;
private final Set<Violation> accumulatedViolations = new TreeSet<>();
private Set<Violation> perlCriticViolations;
public static String getRootFolder() {
return new File(
ViolationsReporterApiTest.class.getClassLoader().getResource("root.txt").getFile())
.getParent();
}
@Rule public TestName name = new TestName();
@Before
public void before() {
final String rootFolder = getRootFolder();
this.findbugsViolations =
violationsApi() //
.withPattern(".*/findbugs/main\\.xml$") //
.inFolder(rootFolder) //
.findAll(FINDBUGS) //
.violations();
this.accumulatedViolations.addAll(this.findbugsViolations);
this.pmdViolations =
violationsApi() //
.withPattern(".*/pmd/main\\.xml$") //
.inFolder(rootFolder) //
.findAll(PMD) //
.violations();
this.pmdViolations =
violationsApi() //
.withPattern(".*/pmd/main\\.xml$") //
.inFolder(rootFolder) //
.findAll(PMD) //
.violations();
this.accumulatedViolations.addAll(this.pmdViolations);
this.perlCriticViolations =
violationsApi() //
.withPattern(".*/perlcritic/.*\\.txt$") //
.inFolder(rootFolder) //
.findAll(PERLCRITIC) //
.violations();
this.accumulatedViolations.addAll(this.perlCriticViolations);
assertThat(this.accumulatedViolations).isNotEmpty();
LOG.info("\n\n\n " + this.name.getMethodName() + " \n\n\n");
}
@Test
public void testCompact() {
final String report =
violationsReporterApi() //
.withViolations(this.accumulatedViolations) //
.getReport(COMPACT);
LOG.info("\n" + report);
}
@Test
public void testPerFileCompact() {
final String report =
violationsReporterApi() //
.withViolations(this.accumulatedViolations) //
.getReport(PER_FILE_COMPACT);
LOG.info("\n" + report);
}
@Test
public void testVerbose() {
final String report =
violationsReporterApi() //
.withViolations(this.accumulatedViolations) //
.getReport(VERBOSE);
LOG.info("\n" + report);
}
@Test
public void testVerboseLimitations() {
final String report =
violationsReporterApi() //
.withViolations(this.accumulatedViolations) //
.withMaxReporterColumnWidth(20) //
.withMaxRuleColumnWidth(50) //
.withMaxSeverityColumnWidth(20) //
.withMaxLineColumnWidth(10) //
.withMaxMessageColumnWidth(50) //
.getReport(VERBOSE);
LOG.info("\n" + report);
}
@Test
public void testCompactWithZeroViolations() {
final String report =
violationsReporterApi() //
.withViolations(new TreeSet<Violation>()) //
.getReport(COMPACT);
LOG.info("\n" + report);
}
@Test
public void testPerFileCompactWithZeroViolations() {
final String report =
violationsReporterApi() //
.withViolations(new TreeSet<Violation>()) //
.getReport(PER_FILE_COMPACT);
LOG.info("\n" + report);
}
@Test
public void testVerboseWithZeroViolations() {
final String report =
violationsReporterApi() //
.withViolations(new TreeSet<Violation>()) //
.getReport(VERBOSE);
LOG.info("\n" + report);
}
}