Skip to content

Commit

Permalink
Merge pull request #295 from openmainframeproject/throw-an-exception-…
Browse files Browse the repository at this point in the history
…no-argument

Throw an exception no argument
  • Loading branch information
issacto authored Jun 28, 2023
2 parents 0b17618 + 82c37af commit c7ed8cc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ private void processCommandLineArgumentArray(String[] args) {

public void loadArgProgramPaths(){
String applicationSourceDirectory = Config.getApplicationSourceDirectoryPathString();
boolean isProgramSpecified = false;
for (OptionKey optionKey : options.keySet()) {
if (optionKey.shortKey.equals(Constants.PROGRAMS_OPTION) || optionKey.longKey.equals(Constants.PROGRAMS_OPTION)) {
String programArgs = options.get(optionKey).argumentValue;
Expand All @@ -152,8 +153,13 @@ public void loadArgProgramPaths(){
newValue += "|";
}
options.get(optionKey).argumentValue = newValue.substring(0, newValue.length()-1);
if(!programArgs.equals("")) isProgramSpecified = true;
}
}
if(!isProgramSpecified){
// return error when no program is passed
throw new CommandLineArgumentException(Messages.get("ERR030"));
}
}

private OptionValue lookupOption(String requestedOption) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ ERR027 = ERR027: NumericFields.dataTypeOf() was called with empty fieldName.
ERR028 = ERR028: NumericFields.setDataTypeOf() was called with empty fieldName.
ERR029 = ERR029: NumericFields.setDataTypeOf() was called with null dataType.

ERR030 = ERR030: Command line missing program argument '-p programName' .


WRN001 = WRN001: No test suite directory for program %1$s was found under directory %2$s.
WRN002 = WRN002: No test suite files were found under directory %1$s.
WRN003 = WRN003: DirectoryNameMatcher caught IOException on file %1$s.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,26 @@ public void it_throws_when_no_value_is_passed_for_the_last_argument_and_it_requi
});
}

@Test
public void it_throws_when_program_argument_is_not_present() {
Throwable ex = assertThrows(CommandLineArgumentException.class, () -> {
ArgumentHandler argumentHandler = new ArgumentHandler(new String[] { },
optionSpec);
argumentHandler.loadArgProgramPaths();
});
assertEquals("ERR030: Command line missing program argument '-p programName' .",
ex.getMessage());
}

@Test
public void it_throws_when_program_argument_is_not_presen_and_has_other_argument() {
Throwable ex = assertThrows(CommandLineArgumentException.class, () -> {
ArgumentHandler argumentHandler = new ArgumentHandler(new String[] {"-c", "config.properties" },
optionSpec);
argumentHandler.loadArgProgramPaths();
});
assertEquals("ERR030: Command line missing program argument '-p programName' .",
ex.getMessage());
}

}

0 comments on commit c7ed8cc

Please sign in to comment.