Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw an exception no argument #295

Merged
merged 5 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi Issac,

please add another unit test, where it throws the error when you have given arguments, but -p is not there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hey David, I just added the new test case!

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());
}

}