Skip to content

Commit 09bf357

Browse files
committed
Refactor: extract ReporterConfig -> ReporterOption conversion
1 parent a3608b5 commit 09bf357

File tree

2 files changed

+23
-29
lines changed

2 files changed

+23
-29
lines changed

src/main/java/org/utplsql/cli/ReporterManager.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.utplsql.api.reporter.CoreReporters;
55
import org.utplsql.api.reporter.Reporter;
66
import org.utplsql.api.reporter.ReporterFactory;
7+
import org.utplsql.cli.config.ReporterConfig;
78
import org.utplsql.cli.reporters.ReporterOptionsAware;
89

910
import javax.sql.DataSource;
@@ -13,7 +14,6 @@
1314
import java.sql.Connection;
1415
import java.sql.SQLException;
1516
import java.util.ArrayList;
16-
import java.util.Arrays;
1717
import java.util.List;
1818
import java.util.concurrent.ExecutorService;
1919

@@ -23,17 +23,30 @@ class ReporterManager {
2323
private List<Throwable> reporterGatherErrors;
2424
private ExecutorService executorService;
2525

26-
ReporterManager( ReporterOptions[] reporterOptions ) {
27-
this.reporterOptionsList = Arrays.asList(reporterOptions);
28-
initReporterOptionsList();
26+
ReporterManager(ReporterConfig[] reporterConfigs ) {
27+
reporterOptionsList = new ArrayList<>();
28+
if ( reporterConfigs != null && reporterConfigs.length > 0 ) {
29+
loadOptionsFromConfigs( reporterConfigs );
30+
}
31+
else {
32+
reporterOptionsList.add(getDefaultReporterOption());
33+
}
2934
}
3035

31-
private void initReporterOptionsList( ) {
36+
private void loadOptionsFromConfigs( ReporterConfig[] reporterConfigs ) {
37+
boolean printToScreen = false;
38+
for (ReporterConfig reporterConfig : reporterConfigs) {
39+
ReporterOptions option = new ReporterOptions(
40+
reporterConfig.getName(),
41+
reporterConfig.getOutput());
3242

33-
// If no reporter parameters were passed, use default reporter.
34-
if (reporterOptionsList.isEmpty()) {
35-
reporterOptionsList = new ArrayList<>();
36-
reporterOptionsList.add(getDefaultReporterOption());
43+
option.forceOutputToScreen(reporterConfig.isForceToScreen());
44+
reporterOptionsList.add(option);
45+
46+
// Check printToScreen validity
47+
if (option.outputToScreen() && printToScreen)
48+
throw new IllegalArgumentException("You cannot configure more than one reporter to output to screen");
49+
printToScreen = option.outputToScreen();
3750
}
3851
}
3952

src/main/java/org/utplsql/cli/RunAction.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.utplsql.api.reporter.Reporter;
1515
import org.utplsql.api.reporter.ReporterFactory;
1616
import org.utplsql.cli.config.FileMapperConfig;
17-
import org.utplsql.cli.config.ReporterConfig;
1817
import org.utplsql.cli.config.RunCommandConfig;
1918
import org.utplsql.cli.exception.DatabaseConnectionFailed;
2019
import org.utplsql.cli.exception.ReporterTimeoutException;
@@ -273,25 +272,7 @@ private CompatibilityProxy checkFrameworkCompatibility(Connection conn) throws S
273272

274273
private ReporterManager getReporterManager() {
275274
if ( reporterManager == null ) {
276-
277-
ReporterConfig[] reporterConfigs = config.getReporters();
278-
if ( reporterConfigs != null ) {
279-
ReporterOptions[] options = new ReporterOptions[reporterConfigs.length];
280-
boolean printToScreen = false;
281-
for (int i = 0; i<reporterConfigs.length; i++ ) {
282-
options[i] = new ReporterOptions(
283-
reporterConfigs[i].getName(),
284-
reporterConfigs[i].getOutput());
285-
286-
options[i].forceOutputToScreen(reporterConfigs[i].isForceToScreen());
287-
288-
// Check printToScreen validity
289-
if ( options[i].outputToScreen() && printToScreen )
290-
throw new IllegalArgumentException("You cannot configure more than one reporter to output to screen");
291-
printToScreen = options[i].outputToScreen();
292-
}
293-
reporterManager = new ReporterManager(options);
294-
}
275+
reporterManager = new ReporterManager(config.getReporters());
295276
}
296277

297278
return reporterManager;

0 commit comments

Comments
 (0)