Skip to content

Commit aa83de6

Browse files
committed
We want to have description for all our reporters.
Because that's very valuable information. We like valuable information. We gather them. And eat them. And grow.
1 parent 19782c3 commit aa83de6

File tree

3 files changed

+58
-22
lines changed

3 files changed

+58
-22
lines changed

src/main/java/org/utplsql/api/reporter/DefaultReporters.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,32 @@
88
*/
99
public enum DefaultReporters {
1010

11-
UT_COVERAGE_HTML_REPORTER(CoverageHTMLReporter::new),
12-
UT_DOCUMENTATION_REPORTER(DocumentationReporter::new),
13-
UT_TEAMCITY_REPORTER(TeamCityReporter::new),
14-
UT_XUNIT_REPORTER(XUnitReporter::new),
15-
UT_COVERALLS_REPORTER(CoverallsReporter::new),
16-
UT_COVERAGE_SONAR_REPORTER(CoverageSonarReporter::new),
17-
UT_SONAR_TEST_REPORTER(SonarTestReporter::new);
11+
UT_COVERAGE_HTML_REPORTER(CoverageHTMLReporter::new, "Generates a HTML coverage report with summary and line by line information on code coverage.\n" +
12+
"Based on open-source simplecov-html coverage reporter for Ruby.\n" +
13+
"Includes source code in the report."),
14+
UT_DOCUMENTATION_REPORTER(DocumentationReporter::new, "A textual pretty-print of unit test results (usually use for console output)"),
15+
UT_TEAMCITY_REPORTER(TeamCityReporter::new, "For reporting live progress of test execution with Teamcity CI."),
16+
UT_XUNIT_REPORTER(XUnitReporter::new, "Used for reporting test results with CI servers like Jenkins/Hudson/Teamcity."),
17+
UT_COVERALLS_REPORTER(CoverallsReporter::new, "Generates a JSON coverage report providing information on code coverage with line numbers.\n" +
18+
"Designed for [Coveralls](https://coveralls.io/)."),
19+
UT_COVERAGE_SONAR_REPORTER(CoverageSonarReporter::new, "Generates a JSON coverage report providing information on code coverage with line numbers.\n" +
20+
"Designed for [SonarQube](https://about.sonarqube.com/) to report coverage."),
21+
UT_SONAR_TEST_REPORTER(SonarTestReporter::new, "Generates a JSON report providing detailed information on test execution.\n" +
22+
"Designed for [SonarQube](https://about.sonarqube.com/) to report test execution.");
1823

1924
private Supplier<? extends Reporter> factoryMethod;
25+
private String description;
2026

21-
DefaultReporters(Supplier<? extends Reporter> factoryMethod ) {
27+
DefaultReporters(Supplier<? extends Reporter> factoryMethod, String description ) {
2228
this.factoryMethod = factoryMethod;
29+
this.description = description;
2330
}
2431

2532
public Supplier<? extends Reporter> getFactoryMethod() {
2633
return factoryMethod;
2734
}
35+
36+
public String getDescription() {
37+
return description;
38+
}
2839
}

src/main/java/org/utplsql/api/reporter/ReporterFactory.java

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@
1515
*/
1616
public final class ReporterFactory {
1717

18-
private Map<String, Supplier<? extends Reporter>> reportFactoryMethodMap = new HashMap<>();
18+
19+
public static class ReporterInfo {
20+
public ReporterInfo( Supplier<? extends Reporter> factoryMethod, String description) {
21+
this.factoryMethod = factoryMethod;
22+
this.description = description;
23+
}
24+
public Supplier<? extends Reporter> factoryMethod;
25+
public String description;
26+
}
27+
28+
private Map<String, ReporterInfo> reportFactoryMethodMap = new HashMap<>();
1929

2030
private static ReporterFactory instance;
2131

@@ -27,7 +37,7 @@ private ReporterFactory() {
2737
*/
2838
private void registerDefaultReporters() {
2939
Arrays.stream(DefaultReporters.values())
30-
.forEach(r -> registerReporterFactoryMethod(r.name(), r.getFactoryMethod()));
40+
.forEach(r -> registerReporterFactoryMethod(r.name(), r.getFactoryMethod(), r.getDescription()));
3141
}
3242

3343
/** Returns the global instance of the ReporterFactory
@@ -44,18 +54,19 @@ public static ReporterFactory getInstance() {
4454
*
4555
* @param reporterName the reporter's name to register
4656
* @param factoryMethod the method which will return the reporter
47-
* @return the method stored for the registered name
57+
* @param description the description of the reporter
58+
* @return Object with information about the registered reporter
4859
*/
49-
public synchronized Supplier<? extends Reporter> registerReporterFactoryMethod( String reporterName, Supplier<? extends Reporter> factoryMethod) {
50-
return reportFactoryMethodMap.put(reporterName, factoryMethod);
60+
public synchronized ReporterInfo registerReporterFactoryMethod( String reporterName, Supplier<? extends Reporter> factoryMethod, String description) {
61+
return reportFactoryMethodMap.put(reporterName, new ReporterInfo(factoryMethod, description));
5162
}
5263

5364
/** Unregisters a specified reporter name.
5465
*
5566
* @param reporterName the reporter's name to unregister
56-
* @return the method which was previously registered or null
67+
* @return information about the reporter which was previously registered or null
5768
*/
58-
public synchronized Supplier<? extends Reporter> unregisterReporterFactoryMethod( String reporterName ) {
69+
public synchronized ReporterInfo unregisterReporterFactoryMethod( String reporterName ) {
5970
return reportFactoryMethodMap.remove(reporterName);
6071
}
6172

@@ -67,9 +78,17 @@ public synchronized Supplier<? extends Reporter> unregisterReporterFactoryMethod
6778
* @return A reporter
6879
*/
6980
public Reporter createReporter(String reporterName) {
70-
Supplier<? extends Reporter> supplier = reportFactoryMethodMap.get(reporterName);
71-
if ( supplier == null )
81+
82+
if ( !reportFactoryMethodMap.containsKey(reporterName))
7283
throw new RuntimeException("Reporter " + reporterName + " not implemented.");
84+
85+
ReporterInfo ri = reportFactoryMethodMap.get(reporterName);
86+
if ( ri == null )
87+
throw new RuntimeException("ReporterInfo for " + reporterName + " was null");
88+
89+
Supplier<? extends Reporter> supplier = ri.factoryMethod;
90+
if ( supplier == null )
91+
throw new RuntimeException("No factory method for " + reporterName);
7392
else
7493
return supplier.get();
7594
}
@@ -78,7 +97,13 @@ public Reporter createReporter(String reporterName) {
7897
*
7998
* @return Set of reporter names
8099
*/
81-
public Set<String> getRegisteredReporterNames() {
82-
return reportFactoryMethodMap.keySet();
100+
public Map<String, String> getRegisteredReporterInfo() {
101+
Map<String, String> descMap = new HashMap<>(reportFactoryMethodMap.size());
102+
103+
for (Map.Entry<String, ReporterInfo> entry : reportFactoryMethodMap.entrySet()) {
104+
descMap.put(entry.getKey(), entry.getValue().description);
105+
}
106+
return descMap;
83107
}
108+
84109
}

src/test/java/org/utplsql/api/ReporterNameTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import org.utplsql.api.reporter.*;
55

66
import java.sql.SQLException;
7-
import java.util.Set;
7+
import java.util.Map;
88

99
import static org.junit.jupiter.api.Assertions.assertEquals;
1010
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -43,10 +43,10 @@ public void reporterFactory() {
4343

4444
@Test
4545
public void defaultReporterFactoryNamesList() {
46-
Set<String> names = ReporterFactory.getInstance().getRegisteredReporterNames();
46+
Map<String, String> reporterDescriptions = ReporterFactory.getInstance().getRegisteredReporterInfo();
4747

4848
for ( DefaultReporters r : DefaultReporters.values() ) {
49-
assertTrue(names.contains(r.name()));
49+
assertTrue(reporterDescriptions.containsKey(r.name()));
5050
}
5151
}
5252

0 commit comments

Comments
 (0)