UserInputProperty { public String promptForAcceptableValue(Gfsh gfsh) { if (gfsh.isQuietMode() || gfsh.isHeadlessMode()) { return defaultValue == null ? "" : defaultValue; } String value = promptForUserInput(gfsh); if (value.length() > 0) { return value; } if (value.length() == 0 && defaultValue != null) { return defaultValue; } while (value.length() == 0) { value = promptForUserInput(gfsh); } return value; } UserInputProperty(String key, String prompt, boolean isMasked);   UserInputProperty(String key, String prompt, String defaultValue, boolean isMasked); String promptForAcceptableValue(Gfsh gfsh); String getKey(); @Immutable
  static final UserInputProperty USERNAME; @Immutable
  static final UserInputProperty PASSWORD; @Immutable
  static final UserInputProperty KEYSTORE; @Immutable
  static final UserInputProperty KEYSTORE_PASSWORD; @Immutable
  static final UserInputProperty KEYSTORE_TYPE; @Immutable
  static final UserInputProperty TRUSTSTORE; @Immutable
  static final UserInputProperty TRUSTSTORE_PASSWORD; @Immutable
  static final UserInputProperty TRUSTSTORE_TYPE; @Immutable
  static final UserInputProperty CIPHERS; @Immutable
  static final UserInputProperty PROTOCOL; @Immutable
  static final UserInputProperty COMPONENT; }
@Test public void propertyWithNoDefaultVaueWillPromptTillAValueIsSupplied_interactive() throws Exception { userInputProperty = new UserInputProperty("key", "prompt", false); when(gfsh.readText(any())).thenReturn("").thenReturn("").thenReturn("value"); String input = userInputProperty.promptForAcceptableValue(gfsh); assertThat(input).isEqualTo("value"); verify(gfsh, times(0)).readPassword(any()); verify(gfsh, times(3)).readText(any()); }
@Test public void propertyWithNoDefaultValue_quietMode() throws Exception { when(gfsh.isQuietMode()).thenReturn(true); userInputProperty = new UserInputProperty("key", "prompt", false); String input = userInputProperty.promptForAcceptableValue(gfsh); assertThat(input).isEqualTo(""); verify(gfsh, times(0)).readPassword(any()); verify(gfsh, times(0)).readText(any()); }
@Test public void propertyWithDefaultValue_Interactive() throws Exception { userInputProperty = new UserInputProperty("key", "prompt", "value", false); String input = userInputProperty.promptForAcceptableValue(gfsh); assertThat(input).isEqualTo("value"); verify(gfsh, times(0)).readPassword(any()); verify(gfsh).readText(any()); }
@Test public void propertyWithEmptyDefaultValue_Interactive() throws Exception { userInputProperty = new UserInputProperty("key", "prompt", "", false); String input = userInputProperty.promptForAcceptableValue(gfsh); assertThat(input).isEqualTo(""); verify(gfsh, times(0)).readPassword(any()); verify(gfsh).readText(any()); }
@Test public void propertyWithDefaultValue_Interactive_masked() throws Exception { userInputProperty = new UserInputProperty("key", "prompt", "value", true); String input = userInputProperty.promptForAcceptableValue(gfsh); assertThat(input).isEqualTo("value"); verify(gfsh).readPassword(any()); verify(gfsh, times(0)).readText(any()); }
@Test public void propertyWithDefaultValue_Quiet() throws Exception { when(gfsh.isQuietMode()).thenReturn(true); userInputProperty = new UserInputProperty("key", "prompt", "value", false); String input = userInputProperty.promptForAcceptableValue(gfsh); assertThat(input).isEqualTo("value"); verify(gfsh, times(0)).readPassword(any()); verify(gfsh, times(0)).readText(any()); }