|
1 | 1 | package org.utplsql.cli; |
2 | 2 |
|
| 3 | +import org.junit.jupiter.api.Nested; |
3 | 4 | import org.junit.jupiter.api.Test; |
4 | 5 | import org.utplsql.api.TestRunnerOptions; |
5 | 6 | import org.utplsql.api.reporter.CoreReporters; |
6 | 7 |
|
7 | 8 | import java.util.ArrayList; |
| 9 | +import java.util.Arrays; |
8 | 10 | import java.util.List; |
9 | 11 |
|
10 | 12 | import static org.hamcrest.CoreMatchers.equalTo; |
|
17 | 19 | */ |
18 | 20 | class RunCommandTest { |
19 | 21 |
|
20 | | - @Test |
21 | | - void reporterOptions_Default() { |
22 | | - IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString()); |
23 | | - |
24 | | - List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList(); |
25 | | - |
26 | | - ReporterOptions reporterOptions1 = reporterOptionsList.get(0); |
27 | | - assertEquals(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), reporterOptions1.getReporterName()); |
28 | | - assertNull(reporterOptions1.getOutputFileName()); |
29 | | - assertFalse(reporterOptions1.outputToFile()); |
30 | | - assertTrue(reporterOptions1.outputToScreen()); |
31 | | - } |
32 | | - |
33 | | - @Test |
34 | | - void reporterOptions_OneReporter() { |
35 | | - IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(), "-f=ut_documentation_reporter", "-o=output.txt"); |
36 | | - |
37 | | - List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList(); |
38 | | - |
39 | | - ReporterOptions reporterOptions1 = reporterOptionsList.get(0); |
40 | | - assertEquals(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), reporterOptions1.getReporterName()); |
41 | | - assertEquals(reporterOptions1.getOutputFileName(), "output.txt"); |
42 | | - assertTrue(reporterOptions1.outputToFile()); |
43 | | - assertFalse(reporterOptions1.outputToScreen()); |
44 | | - } |
45 | | - |
46 | | - @Test |
47 | | - void reporterOptions_OneReporterForceScreen() { |
48 | | - IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(), "-f=ut_documentation_reporter", "-o=output.txt", "-s"); |
49 | | - |
50 | | - List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList(); |
51 | | - |
52 | | - ReporterOptions reporterOptions1 = reporterOptionsList.get(0); |
53 | | - assertEquals(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), reporterOptions1.getReporterName()); |
54 | | - assertEquals(reporterOptions1.getOutputFileName(), "output.txt"); |
55 | | - assertTrue(reporterOptions1.outputToFile()); |
56 | | - assertTrue(reporterOptions1.outputToScreen()); |
57 | | - } |
58 | | - |
59 | | - @Test |
60 | | - void reporterOptions_OneReporterForceScreenInverse() { |
61 | | - IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(), "-f=ut_documentation_reporter", "-s", "-o=output.txt"); |
62 | | - |
63 | | - List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList(); |
64 | | - |
65 | | - ReporterOptions reporterOptions1 = reporterOptionsList.get(0); |
66 | | - assertEquals(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), reporterOptions1.getReporterName()); |
67 | | - assertEquals(reporterOptions1.getOutputFileName(), "output.txt"); |
68 | | - assertTrue(reporterOptions1.outputToFile()); |
69 | | - assertTrue(reporterOptions1.outputToScreen()); |
70 | | - } |
71 | | - |
72 | | - @Test |
73 | | - void reporterOptions_TwoReporters() { |
74 | | - IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(), |
75 | | - "-f=ut_documentation_reporter", |
76 | | - "-f=ut_coverage_html_reporter", "-o=coverage.html", "-s"); |
77 | | - |
78 | | - List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList(); |
79 | | - |
80 | | - ReporterOptions reporterOptions1 = reporterOptionsList.get(0); |
81 | | - assertEquals(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), reporterOptions1.getReporterName()); |
82 | | - assertNull(reporterOptions1.getOutputFileName()); |
83 | | - assertFalse(reporterOptions1.outputToFile()); |
84 | | - assertFalse(reporterOptions1.outputToScreen()); |
85 | | - |
86 | | - ReporterOptions reporterOptions2 = reporterOptionsList.get(1); |
87 | | - assertEquals(CoreReporters.UT_COVERAGE_HTML_REPORTER.name(), reporterOptions2.getReporterName()); |
88 | | - assertEquals(reporterOptions2.getOutputFileName(), "coverage.html"); |
89 | | - assertTrue(reporterOptions2.outputToFile()); |
90 | | - assertTrue(reporterOptions2.outputToScreen()); |
| 22 | + @Nested |
| 23 | + class A_reporter { |
| 24 | + |
| 25 | + List<ReporterOptions> getReporterOptionsWithArgs(String... args) { |
| 26 | + ArrayList<String> newArgs = new ArrayList<>(args.length + 1); |
| 27 | + newArgs.add(TestHelper.getConnectionString()); |
| 28 | + newArgs.addAll(Arrays.asList(args)); |
| 29 | + IRunCommand cmd = TestHelper.createRunCommand(newArgs.toArray(new String[0])); |
| 30 | + return cmd.getReporterOptionsList(); |
| 31 | + } |
| 32 | + |
| 33 | + @Nested |
| 34 | + class Is_output_to_screen { |
| 35 | + |
| 36 | + @Test |
| 37 | + void by_default() { |
| 38 | + List<ReporterOptions> options = getReporterOptionsWithArgs(); |
| 39 | + |
| 40 | + assertTrue(options.get(0).outputToScreen()); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + void when_only_reporter_without_output_specified() { |
| 45 | + List<ReporterOptions> options = getReporterOptionsWithArgs("-f=ut_documentation_reporter"); |
| 46 | + |
| 47 | + assertTrue(options.get(0).outputToScreen()); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + void when_without_output_and_no_other_reporter_has_forceToScreen_flag() { |
| 52 | + List<ReporterOptions> options = getReporterOptionsWithArgs( |
| 53 | + "-f=ut_coverage_sonar_reporter", "-o=output.txt", |
| 54 | + "-f=ut_coverage_html_reporter"); |
| 55 | + |
| 56 | + assertTrue(options.get(1).outputToScreen()); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + void when_only_reporter_with_forceToScreen_flag() { |
| 61 | + List<ReporterOptions> options = getReporterOptionsWithArgs( |
| 62 | + "-f=ut_coverage_sonar_reporter", "-o=output.txt", |
| 63 | + "-f=ut_coverage_html_reporter", "-o=output.html", "-s", |
| 64 | + "-f=ut_coverage_cobertura_reporter", "-o=cobertura.html"); |
| 65 | + |
| 66 | + assertTrue(options.get(1).outputToScreen()); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + @Nested |
| 71 | + class Is_not_output_to_screen { |
| 72 | + |
| 73 | + @Test |
| 74 | + void when_it_has_output_specified_but_no_forceToScreen() { |
| 75 | + List<ReporterOptions> options = getReporterOptionsWithArgs( |
| 76 | + "-f=ut_documentation_reporter", "-o=output.txt", |
| 77 | + "-f=ut_coverage_html_reporter", "-o=output.html" |
| 78 | + ); |
| 79 | + |
| 80 | + assertFalse(options.get(0).outputToScreen()); |
| 81 | + assertFalse(options.get(1).outputToScreen()); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + @Nested |
| 86 | + class Cannot_be_run { |
| 87 | + |
| 88 | + @Test |
| 89 | + void when_more_than_one_forceToScreen_flags() { |
| 90 | + assertThrows(IllegalArgumentException.class, () -> { |
| 91 | + getReporterOptionsWithArgs( |
| 92 | + "-f=ut_coverage_sonar_reporter", "-o=output.txt", "-s", |
| 93 | + "-f=ut_coverage_html_reporter", "-o=output.html", "-s"); |
| 94 | + }); |
| 95 | + } |
| 96 | + |
| 97 | + @Test |
| 98 | + void when_more_than_one_reporters_without_output() { |
| 99 | + assertThrows(IllegalArgumentException.class, () -> { |
| 100 | + getReporterOptionsWithArgs( |
| 101 | + "-f=ut_coverage_sonar_reporter", |
| 102 | + "-f=ut_coverage_html_reporter"); |
| 103 | + }); |
| 104 | + } |
| 105 | + @Test |
| 106 | + void when_one_reporter_without_output_and_one_with_forceToScreen() { |
| 107 | + assertThrows(IllegalArgumentException.class, () -> { |
| 108 | + getReporterOptionsWithArgs( |
| 109 | + "-f=ut_coverage_sonar_reporter", |
| 110 | + "-f=ut_coverage_html_reporter", "-o=output.html", "-s"); |
| 111 | + }); |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + @Test |
| 116 | + void reporterOptions_Default() { |
| 117 | + IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString()); |
| 118 | + |
| 119 | + List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList(); |
| 120 | + |
| 121 | + ReporterOptions reporterOptions1 = reporterOptionsList.get(0); |
| 122 | + assertEquals(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), reporterOptions1.getReporterName()); |
| 123 | + assertNull(reporterOptions1.getOutputFileName()); |
| 124 | + assertFalse(reporterOptions1.outputToFile()); |
| 125 | + assertTrue(reporterOptions1.outputToScreen()); |
| 126 | + } |
| 127 | + |
| 128 | + @Test |
| 129 | + void reporterOptions_OneReporter() { |
| 130 | + IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(), "-f=ut_documentation_reporter", "-o=output.txt"); |
| 131 | + |
| 132 | + List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList(); |
| 133 | + |
| 134 | + ReporterOptions reporterOptions1 = reporterOptionsList.get(0); |
| 135 | + assertEquals(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), reporterOptions1.getReporterName()); |
| 136 | + assertEquals("output.txt", reporterOptions1.getOutputFileName()); |
| 137 | + assertTrue(reporterOptions1.outputToFile()); |
| 138 | + assertFalse(reporterOptions1.outputToScreen()); |
| 139 | + } |
| 140 | + |
| 141 | + @Test |
| 142 | + void reporterOptions_OneReporter_DefaultToScreen() { |
| 143 | + IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(), "-f=ut_documentation_reporter"); |
| 144 | + |
| 145 | + List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList(); |
| 146 | + |
| 147 | + ReporterOptions reporterOptions1 = reporterOptionsList.get(0); |
| 148 | + assertEquals(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), reporterOptions1.getReporterName()); |
| 149 | + assertNull(reporterOptions1.getOutputFileName()); |
| 150 | + assertFalse(reporterOptions1.outputToFile()); |
| 151 | + assertTrue(reporterOptions1.outputToScreen()); |
| 152 | + } |
| 153 | + |
| 154 | + @Test |
| 155 | + void reporterOptions_OneReporterForceScreen() { |
| 156 | + IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(), "-f=ut_documentation_reporter", "-o=output.txt", "-s"); |
| 157 | + |
| 158 | + List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList(); |
| 159 | + |
| 160 | + ReporterOptions reporterOptions1 = reporterOptionsList.get(0); |
| 161 | + assertEquals(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), reporterOptions1.getReporterName()); |
| 162 | + assertEquals("output.txt", reporterOptions1.getOutputFileName()); |
| 163 | + assertTrue(reporterOptions1.outputToFile()); |
| 164 | + assertTrue(reporterOptions1.outputToScreen()); |
| 165 | + } |
| 166 | + |
| 167 | + @Test |
| 168 | + void reporterOptions_OneReporterForceScreenInverse() { |
| 169 | + IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(), "-f=ut_documentation_reporter", "-s", "-o=output.txt"); |
| 170 | + |
| 171 | + List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList(); |
| 172 | + |
| 173 | + ReporterOptions reporterOptions1 = reporterOptionsList.get(0); |
| 174 | + assertEquals(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), reporterOptions1.getReporterName()); |
| 175 | + assertEquals("output.txt", reporterOptions1.getOutputFileName()); |
| 176 | + assertTrue(reporterOptions1.outputToFile()); |
| 177 | + assertTrue(reporterOptions1.outputToScreen()); |
| 178 | + } |
| 179 | + |
| 180 | + @Test |
| 181 | + void reporterOptions_TwoReporters() { |
| 182 | + IRunCommand runCmd = TestHelper.createRunCommand(TestHelper.getConnectionString(), |
| 183 | + "-f=ut_documentation_reporter", "-o=output.txt", |
| 184 | + "-f=ut_coverage_html_reporter", "-o=coverage.html", "-s"); |
| 185 | + |
| 186 | + List<ReporterOptions> reporterOptionsList = runCmd.getReporterOptionsList(); |
| 187 | + |
| 188 | + ReporterOptions reporterOptions1 = reporterOptionsList.get(0); |
| 189 | + assertEquals(CoreReporters.UT_DOCUMENTATION_REPORTER.name(), reporterOptions1.getReporterName()); |
| 190 | + assertEquals("output.txt", reporterOptions1.getOutputFileName()); |
| 191 | + assertTrue(reporterOptions1.outputToFile()); |
| 192 | + assertFalse(reporterOptions1.outputToScreen()); |
| 193 | + |
| 194 | + ReporterOptions reporterOptions2 = reporterOptionsList.get(1); |
| 195 | + assertEquals(CoreReporters.UT_COVERAGE_HTML_REPORTER.name(), reporterOptions2.getReporterName()); |
| 196 | + assertEquals("coverage.html", reporterOptions2.getOutputFileName()); |
| 197 | + assertTrue(reporterOptions2.outputToFile()); |
| 198 | + assertTrue(reporterOptions2.outputToScreen()); |
| 199 | + } |
91 | 200 | } |
92 | 201 |
|
93 | 202 | @Test |
|
0 commit comments