Update after review and add a test
This commit is contained in:
parent
726c05b7c5
commit
815c4ac4c8
|
@ -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) {
|
||||||
|
|
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue