Skip to content

Commit b88d5c5

Browse files
committed
Fix arity for mapping options and prevent NPE
1 parent 2ce4e91 commit b88d5c5

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ static class Format {
108108

109109
static class FileMappingComposite {
110110

111+
@ArgGroup(exclusive = true, multiplicity = "1")
112+
TestOrSourcePath testOrSourcePath;
113+
114+
@ArgGroup(exclusive = false, multiplicity = "0..1")
115+
FileMapping mapping;
116+
111117
static class TestOrSourcePath {
112118
@Option(names="-source_path", required = true)
113119
String sourcePath;
@@ -138,14 +144,10 @@ static class FileMapping {
138144
Integer nameSubExpression;
139145
}
140146

141-
@ArgGroup(exclusive = true, multiplicity = "1")
142-
TestOrSourcePath testOrSourcePath;
143-
144-
@ArgGroup(exclusive = false, multiplicity = "1")
145-
FileMapping mapping;
146-
147-
148147
FileMapperConfig toFileMapperConfig() {
148+
if ( mapping == null )
149+
mapping = new FileMapping();
150+
149151
Map<String, String> typeMap = new HashMap<>();
150152

151153
if ( mapping.typeMapping != null && !mapping.typeMapping.isEmpty()) {

src/test/java/org/utplsql/cli/PicocliRunCommandTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.utplsql.cli;
22

3+
import org.hamcrest.Matchers;
34
import org.junit.jupiter.api.Test;
45
import org.utplsql.cli.config.FileMapperConfig;
56
import org.utplsql.cli.config.ReporterConfig;
@@ -192,6 +193,7 @@ void sourceFileMapping() throws Exception {
192193
assertEquals( 1, sourceMapperConfig.getTypeSubexpression());
193194
assertEquals( 3, sourceMapperConfig.getNameSubexpression());
194195
}
196+
195197
@Test
196198
void testFileMapping() throws Exception {
197199
RunCommandConfig config = parseForConfig("run",
@@ -214,4 +216,20 @@ void testFileMapping() throws Exception {
214216
assertEquals( 5, testMapperConfig.getTypeSubexpression());
215217
assertEquals( 6, testMapperConfig.getNameSubexpression());
216218
}
219+
220+
@Test
221+
void testFileMappingWithoutDetails() throws Exception {
222+
RunCommandConfig config = parseForConfig("run",
223+
TestHelper.getConnectionString(),
224+
"-test_path=src/test/resources/plsql/test");
225+
226+
FileMapperConfig testMapperConfig = config.getTestMapping();
227+
assertEquals( "src/test/resources/plsql/test", testMapperConfig.getPath());
228+
assertNull( testMapperConfig.getOwner());
229+
assertNull( testMapperConfig.getRegexExpression());
230+
assertThat( testMapperConfig.getTypeMapping(), anEmptyMap());
231+
assertNull( testMapperConfig.getOwnerSubexpression());
232+
assertNull( testMapperConfig.getTypeSubexpression());
233+
assertNull( testMapperConfig.getNameSubexpression());
234+
}
217235
}

0 commit comments

Comments
 (0)