Update after review and add a test

This commit is contained in:
David Pilato 2017-01-13 12:51:35 +01:00
parent 726c05b7c5
commit 815c4ac4c8
2 changed files with 9 additions and 1 deletions

View File

@ -65,7 +65,7 @@ class AddStringKeyStoreCommand extends EnvironmentAwareCommand {
String setting = arguments.value(options); String setting = arguments.value(options);
if (setting == null) { if (setting == null) {
throw new UserException(ExitCodes.DATA_ERROR, "the setting name can not be null."); throw new UserException(ExitCodes.USAGE, "The setting name can not be null");
} }
if (keystore.getSettings().contains(setting) && options.has(forceOption) == false) { if (keystore.getSettings().contains(setting) && options.has(forceOption) == false) {
if (terminal.promptYesNo("Setting " + setting + " already exists. Overwrite?", false) == false) { if (terminal.promptYesNo("Setting " + setting + " already exists. Overwrite?", false) == false) {

View File

@ -127,6 +127,14 @@ public class AddStringKeyStoreCommandTests extends KeyStoreCommandTestCase {
assertEquals("String value must contain only ASCII", e.getMessage()); assertEquals("String value must contain only ASCII", e.getMessage());
} }
public void testNpe() throws Exception {
createKeystore("");
terminal.addTextInput("");
UserException e = expectThrows(UserException.class, this::execute);
assertEquals(ExitCodes.USAGE, e.exitCode);
assertThat(e.getMessage(), containsString("The setting name can not be null"));
}
void setInput(String inputStr) { void setInput(String inputStr) {
input = new ByteArrayInputStream(inputStr.getBytes(StandardCharsets.UTF_8)); input = new ByteArrayInputStream(inputStr.getBytes(StandardCharsets.UTF_8));
} }