Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6717057
Failing test to catch and reproduce #143
pesse Jun 4, 2019
038981f
Merge branch 'develop' into feature/new_cli_library
pesse Jun 7, 2019
b21f651
Unit-Test to simulate passing all parameters that should be known
pesse Jun 7, 2019
ce849fc
Initial implementation of Picocli usage
pesse Jun 11, 2019
5520562
Some more tests around FileMapping
pesse Jun 12, 2019
f9c4cf7
New RunAction which does the logic based on RunCommandConfig
pesse Jun 12, 2019
d8cbce2
RunAction tested and functional so far
pesse Jun 12, 2019
3b5e168
Include RunAction into RunCommand
pesse Jun 12, 2019
60997d7
New entry point for Picocli
pesse Jun 12, 2019
d13ae5b
Extract functionality to interface
pesse Jun 12, 2019
5e86b01
Adapt tests to IRunCommand and implement necessary functionality
pesse Jun 12, 2019
00f3f5f
Change VersionCommand to Picocli
pesse Jun 12, 2019
2ce4e91
Change ReportersCommand to Picocli
pesse Jun 13, 2019
b88d5c5
Fix arity for mapping options and prevent NPE
pesse Jun 13, 2019
c80dc8c
Refactor RunCommandTest to cover new approach
pesse Jun 13, 2019
8eec2cb
Implement rules for printToScreen Reporters: Only one can go to screen
pesse Jun 13, 2019
ded39d3
Implemented new Picocli help
pesse Jun 13, 2019
6922e52
Removed some now unnecessary stuff
pesse Jun 13, 2019
5aa4c1d
We don't need the old RunCommand anymore, time to get rid of it
pesse Jun 13, 2019
60fcfaf
Improve help and help-tests
pesse Jun 13, 2019
a3608b5
Refactor: Remove unnecessary logic
pesse Jun 13, 2019
09bf357
Refactor: extract ReporterConfig -> ReporterOption conversion
pesse Jun 13, 2019
1b65b51
Refactor: getCommand() no longer needed
pesse Jun 13, 2019
77fd752
Refactor: Include only left check-functionality
pesse Jun 13, 2019
e443e3c
Refactor: Cleanup ReporterManager a bit
pesse Jun 13, 2019
0bdca7d
Get rid of JCommander dependency
pesse Jun 13, 2019
ae0e9c4
Move ConnectionString description to main Utplsql-Command
pesse Jun 18, 2019
f47c0de
Fix Typo
pesse Jun 18, 2019
bb18ea1
Some Refactorings and make things final
pesse Jun 18, 2019
1a984ff
Merge branch 'develop' into feature/new_cli_library
pesse Jun 18, 2019
81e0953
Reformatting
pesse Jun 18, 2019
a8acbb9
Add `-h` option to all commands and cover it with tests
pesse Jun 18, 2019
10bef7b
Adjust documentation to reflect parameter changes
pesse Jun 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement rules for printToScreen Reporters: Only one can go to screen
  • Loading branch information
pesse committed Jun 13, 2019
commit 8eec2cbdf50597f0f5cf0bc3dfc75a84a5444e39
6 changes: 3 additions & 3 deletions src/main/java/org/utplsql/cli/ReporterOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ public class ReporterOptions {

private Reporter reporterObj = null;

public ReporterOptions(String reporterName, String outputFileName, boolean outputToScreen) {
public ReporterOptions(String reporterName, String outputFileName ) {
setReporterName(reporterName);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two fields should be final and set directly, not through the setters.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And check what fields can also be final, seems like first three.

setOutputFileName(outputFileName);
this.outputToScreen = outputToScreen;
this.outputToScreen = (outputFileName == null); // If outputFileName is null we assume it should be sent to screen
this.forceOutputToScreen = false;
}

public ReporterOptions(String reporterName) {
this(reporterName, null, true);
this(reporterName, null);
}

public Reporter getReporterObj() {
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/org/utplsql/cli/RunAction.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.utplsql.cli;

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.zaxxer.hikari.HikariDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -23,7 +21,6 @@
import org.utplsql.cli.log.StringBlockFormatter;

import javax.sql.DataSource;
import javax.xml.crypto.dsig.keyinfo.KeyValue;
import java.io.File;
import java.sql.Connection;
import java.sql.SQLException;
Expand Down Expand Up @@ -280,11 +277,18 @@ private ReporterManager getReporterManager() {
ReporterConfig[] reporterConfigs = config.getReporters();
if ( reporterConfigs != null ) {
ReporterOptions[] options = new ReporterOptions[reporterConfigs.length];
boolean printToScreen = false;
for (int i = 0; i<reporterConfigs.length; i++ ) {
options[i] = new ReporterOptions(
reporterConfigs[i].getName(),
reporterConfigs[i].getOutput(),
reporterConfigs[i].isScreen());
reporterConfigs[i].getOutput());

options[i].forceOutputToScreen(reporterConfigs[i].isForceToScreen());

// Check printToScreen validity
if ( options[i].outputToScreen() && printToScreen )
throw new IllegalArgumentException("You cannot configure more than one reporter to output to screen");
printToScreen = options[i].outputToScreen();
}
reporterManager = new ReporterManager(options);
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/utplsql/cli/config/ReporterConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ public class ReporterConfig {

private final String name;
private final String output;
private boolean screen = false;
private boolean forceToScreen = false;

@ConstructorProperties({"name", "output", "screen"})
public ReporterConfig( String name, String output, Boolean screen ) {
@ConstructorProperties({"name", "output", "forceToScreen"})
public ReporterConfig( String name, String output, Boolean forceToScreen) {
this.name = name;
this.output = output;
if ( screen != null ) this.screen = screen;
if ( forceToScreen != null ) this.forceToScreen = forceToScreen;
}

public String getName() {
Expand All @@ -23,7 +23,7 @@ public String getOutput() {
return output;
}

public boolean isScreen() {
return screen;
public boolean isForceToScreen() {
return forceToScreen;
}
}
10 changes: 3 additions & 7 deletions src/test/java/org/utplsql/cli/PicocliRunCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package org.utplsql.cli;

import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.utplsql.cli.config.FileMapperConfig;
import org.utplsql.cli.config.ReporterConfig;
import org.utplsql.cli.config.RunCommandConfig;
import picocli.CommandLine;

import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
Expand Down Expand Up @@ -139,7 +135,7 @@ void singleReporter() throws Exception {
ReporterConfig reporterConfig = config.getReporters()[0];
assertEquals("ut_documentation_reporter", reporterConfig.getName());
assertNull(reporterConfig.getOutput());
assertFalse(reporterConfig.isScreen());
assertFalse(reporterConfig.isForceToScreen());
}

@Test
Expand All @@ -157,12 +153,12 @@ void multipleReporters() throws Exception {
ReporterConfig reporterConfig = config.getReporters()[0];
assertEquals("ut_documentation_reporter", reporterConfig.getName());
assertEquals("output1.txt", reporterConfig.getOutput());
assertFalse(reporterConfig.isScreen());
assertFalse(reporterConfig.isForceToScreen());

reporterConfig = config.getReporters()[1];
assertEquals("ut_coverage_html", reporterConfig.getName());
assertEquals("output2.html", reporterConfig.getOutput());
assertTrue(reporterConfig.isScreen());
assertTrue(reporterConfig.isForceToScreen());
}

@Test
Expand Down
251 changes: 180 additions & 71 deletions src/test/java/org/utplsql/cli/RunCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.utplsql.cli;

import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.utplsql.api.TestRunnerOptions;
import org.utplsql.api.reporter.CoreReporters;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static org.hamcrest.CoreMatchers.equalTo;
Expand All @@ -17,77 +19,184 @@
*/
class RunCommandTest {

@Test
void reporterOptions_Default() {
IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString());

List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList();

ReporterOptions reporterOptions1 = reporterOptionsList.get(0);
assertEquals(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), reporterOptions1.getReporterName());
assertNull(reporterOptions1.getOutputFileName());
assertFalse(reporterOptions1.outputToFile());
assertTrue(reporterOptions1.outputToScreen());
}

@Test
void reporterOptions_OneReporter() {
IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(), "-f=ut_documentation_reporter", "-o=output.txt");

List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList();

ReporterOptions reporterOptions1 = reporterOptionsList.get(0);
assertEquals(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), reporterOptions1.getReporterName());
assertEquals(reporterOptions1.getOutputFileName(), "output.txt");
assertTrue(reporterOptions1.outputToFile());
assertFalse(reporterOptions1.outputToScreen());
}

@Test
void reporterOptions_OneReporterForceScreen() {
IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(), "-f=ut_documentation_reporter", "-o=output.txt", "-s");

List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList();

ReporterOptions reporterOptions1 = reporterOptionsList.get(0);
assertEquals(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), reporterOptions1.getReporterName());
assertEquals(reporterOptions1.getOutputFileName(), "output.txt");
assertTrue(reporterOptions1.outputToFile());
assertTrue(reporterOptions1.outputToScreen());
}

@Test
void reporterOptions_OneReporterForceScreenInverse() {
IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(), "-f=ut_documentation_reporter", "-s", "-o=output.txt");

List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList();

ReporterOptions reporterOptions1 = reporterOptionsList.get(0);
assertEquals(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), reporterOptions1.getReporterName());
assertEquals(reporterOptions1.getOutputFileName(), "output.txt");
assertTrue(reporterOptions1.outputToFile());
assertTrue(reporterOptions1.outputToScreen());
}

@Test
void reporterOptions_TwoReporters() {
IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(),
"-f=ut_documentation_reporter",
"-f=ut_coverage_html_reporter", "-o=coverage.html", "-s");

List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList();

ReporterOptions reporterOptions1 = reporterOptionsList.get(0);
assertEquals(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), reporterOptions1.getReporterName());
assertNull(reporterOptions1.getOutputFileName());
assertFalse(reporterOptions1.outputToFile());
assertFalse(reporterOptions1.outputToScreen());

ReporterOptions reporterOptions2 = reporterOptionsList.get(1);
assertEquals(CoreReporters.UT_COVERAGE_HTML_REPORTER.name(), reporterOptions2.getReporterName());
assertEquals(reporterOptions2.getOutputFileName(), "coverage.html");
assertTrue(reporterOptions2.outputToFile());
assertTrue(reporterOptions2.outputToScreen());
@Nested
class A_reporter {

List<ReporterOptions> getReporterOptionsWithArgs(String... args) {
ArrayList<String> newArgs = new ArrayList<>(args.length + 1);
newArgs.add(TestHelper.getConnectionString());
newArgs.addAll(Arrays.asList(args));
IRunCommand cmd = TestHelper.createRunCommand(newArgs.toArray(new String[0]));
return cmd.getReporterOptionsList();
}

@Nested
class Is_output_to_screen {

@Test
void by_default() {
List<ReporterOptions> options = getReporterOptionsWithArgs();

assertTrue(options.get(0).outputToScreen());
}

@Test
void when_only_reporter_without_output_specified() {
List<ReporterOptions> options = getReporterOptionsWithArgs("-f=ut_documentation_reporter");

assertTrue(options.get(0).outputToScreen());
}

@Test
void when_without_output_and_no_other_reporter_has_forceToScreen_flag() {
List<ReporterOptions> options = getReporterOptionsWithArgs(
"-f=ut_coverage_sonar_reporter", "-o=output.txt",
"-f=ut_coverage_html_reporter");

assertTrue(options.get(1).outputToScreen());
}

@Test
void when_only_reporter_with_forceToScreen_flag() {
List<ReporterOptions> options = getReporterOptionsWithArgs(
"-f=ut_coverage_sonar_reporter", "-o=output.txt",
"-f=ut_coverage_html_reporter", "-o=output.html", "-s",
"-f=ut_coverage_cobertura_reporter", "-o=cobertura.html");

assertTrue(options.get(1).outputToScreen());
}
}

@Nested
class Is_not_output_to_screen {

@Test
void when_it_has_output_specified_but_no_forceToScreen() {
List<ReporterOptions> options = getReporterOptionsWithArgs(
"-f=ut_documentation_reporter", "-o=output.txt",
"-f=ut_coverage_html_reporter", "-o=output.html"
);

assertFalse(options.get(0).outputToScreen());
assertFalse(options.get(1).outputToScreen());
}
}

@Nested
class Cannot_be_run {

@Test
void when_more_than_one_forceToScreen_flags() {
assertThrows(IllegalArgumentException.class, () -> {
getReporterOptionsWithArgs(
"-f=ut_coverage_sonar_reporter", "-o=output.txt", "-s",
"-f=ut_coverage_html_reporter", "-o=output.html", "-s");
});
}

@Test
void when_more_than_one_reporters_without_output() {
assertThrows(IllegalArgumentException.class, () -> {
getReporterOptionsWithArgs(
"-f=ut_coverage_sonar_reporter",
"-f=ut_coverage_html_reporter");
});
}
@Test
void when_one_reporter_without_output_and_one_with_forceToScreen() {
assertThrows(IllegalArgumentException.class, () -> {
getReporterOptionsWithArgs(
"-f=ut_coverage_sonar_reporter",
"-f=ut_coverage_html_reporter", "-o=output.html", "-s");
});
}
}

@Test
void reporterOptions_Default() {
IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString());

List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList();

ReporterOptions reporterOptions1 = reporterOptionsList.get(0);
assertEquals(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), reporterOptions1.getReporterName());
assertNull(reporterOptions1.getOutputFileName());
assertFalse(reporterOptions1.outputToFile());
assertTrue(reporterOptions1.outputToScreen());
}

@Test
void reporterOptions_OneReporter() {
IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(), "-f=ut_documentation_reporter", "-o=output.txt");

List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList();

ReporterOptions reporterOptions1 = reporterOptionsList.get(0);
assertEquals(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), reporterOptions1.getReporterName());
assertEquals("output.txt", reporterOptions1.getOutputFileName());
assertTrue(reporterOptions1.outputToFile());
assertFalse(reporterOptions1.outputToScreen());
}

@Test
void reporterOptions_OneReporter_DefaultToScreen() {
IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(), "-f=ut_documentation_reporter");

List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList();

ReporterOptions reporterOptions1 = reporterOptionsList.get(0);
assertEquals(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), reporterOptions1.getReporterName());
assertNull(reporterOptions1.getOutputFileName());
assertFalse(reporterOptions1.outputToFile());
assertTrue(reporterOptions1.outputToScreen());
}

@Test
void reporterOptions_OneReporterForceScreen() {
IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(), "-f=ut_documentation_reporter", "-o=output.txt", "-s");

List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList();

ReporterOptions reporterOptions1 = reporterOptionsList.get(0);
assertEquals(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), reporterOptions1.getReporterName());
assertEquals("output.txt", reporterOptions1.getOutputFileName());
assertTrue(reporterOptions1.outputToFile());
assertTrue(reporterOptions1.outputToScreen());
}

@Test
void reporterOptions_OneReporterForceScreenInverse() {
IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(), "-f=ut_documentation_reporter", "-s", "-o=output.txt");

List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList();

ReporterOptions reporterOptions1 = reporterOptionsList.get(0);
assertEquals(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), reporterOptions1.getReporterName());
assertEquals("output.txt", reporterOptions1.getOutputFileName());
assertTrue(reporterOptions1.outputToFile());
assertTrue(reporterOptions1.outputToScreen());
}

@Test
void reporterOptions_TwoReporters() {
IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(),
"-f=ut_documentation_reporter", "-o=output.txt",
"-f=ut_coverage_html_reporter", "-o=coverage.html", "-s");

List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList();

ReporterOptions reporterOptions1 = reporterOptionsList.get(0);
assertEquals(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), reporterOptions1.getReporterName());
assertEquals("output.txt", reporterOptions1.getOutputFileName());
assertTrue(reporterOptions1.outputToFile());
assertFalse(reporterOptions1.outputToScreen());

ReporterOptions reporterOptions2 = reporterOptionsList.get(1);
assertEquals(CoreReporters.UT_COVERAGE_HTML_REPORTER.name(), reporterOptions2.getReporterName());
assertEquals("coverage.html", reporterOptions2.getOutputFileName());
assertTrue(reporterOptions2.outputToFile());
assertTrue(reporterOptions2.outputToScreen());
}
}

@Test
Expand Down