@Test public void promptsForNewPasswordIfPasswordChangeRequiredCannotBeEmpty() throws Exception { ConnectionConfig connectionConfig = new ConnectionConfig("", "", 0, "", "", Encryption.DEFAULT, ""); doThrow(authException).doThrow(passwordChangeRequiredException).doNothing().when(shell).connect(connectionConfig, null); String inputString = "bob\nsecret\n\nnewsecret\n"; InputStream inputStream = new ByteArrayInputStream(inputString.getBytes()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); Main main = new Main(inputStream, ps); main.connectMaybeInteractively(shell, connectionConfig, true, true, true); String out = new String(baos.toByteArray(), StandardCharsets.UTF_8); assertEquals(String.format("username: bob%npassword: ******%nPassword change required%nnew password: %nnew password cannot be empty%n%nnew password: *********%n" ), out); assertEquals("bob", connectionConfig.username()); assertEquals("secret", connectionConfig.password()); assertEquals("newsecret", connectionConfig.newPassword()); verify(shell, times(3)).connect(connectionConfig, null); verify(shell).changePassword(connectionConfig); }
void connectMaybeInteractively(@Nonnull CypherShell shell, @Nonnull ConnectionConfig connectionConfig, boolean inputInteractive, boolean outputInteractive, boolean shouldPromptForPassword) throws Exception { connectMaybeInteractively( shell, connectionConfig, inputInteractive, outputInteractive, shouldPromptForPassword, null ); }
Main { void connectMaybeInteractively(@Nonnull CypherShell shell, @Nonnull ConnectionConfig connectionConfig, boolean inputInteractive, boolean outputInteractive, boolean shouldPromptForPassword) throws Exception { connectMaybeInteractively( shell, connectionConfig, inputInteractive, outputInteractive, shouldPromptForPassword, null ); } }
Main { void connectMaybeInteractively(@Nonnull CypherShell shell, @Nonnull ConnectionConfig connectionConfig, boolean inputInteractive, boolean outputInteractive, boolean shouldPromptForPassword) throws Exception { connectMaybeInteractively( shell, connectionConfig, inputInteractive, outputInteractive, shouldPromptForPassword, null ); } Main();   Main(final InputStream in, final PrintStream out); private  Main(final InputStream in, final PrintStream out, final boolean hasSpecialInteractiveOutputStream ); }
Main { void connectMaybeInteractively(@Nonnull CypherShell shell, @Nonnull ConnectionConfig connectionConfig, boolean inputInteractive, boolean outputInteractive, boolean shouldPromptForPassword) throws Exception { connectMaybeInteractively( shell, connectionConfig, inputInteractive, outputInteractive, shouldPromptForPassword, null ); } Main();   Main(final InputStream in, final PrintStream out); private  Main(final InputStream in, final PrintStream out, final boolean hasSpecialInteractiveOutputStream ); static void main(String[] args); }
Main { void connectMaybeInteractively(@Nonnull CypherShell shell, @Nonnull ConnectionConfig connectionConfig, boolean inputInteractive, boolean outputInteractive, boolean shouldPromptForPassword) throws Exception { connectMaybeInteractively( shell, connectionConfig, inputInteractive, outputInteractive, shouldPromptForPassword, null ); } Main();   Main(final InputStream in, final PrintStream out); private  Main(final InputStream in, final PrintStream out, final boolean hasSpecialInteractiveOutputStream ); static void main(String[] args); static final int EXIT_FAILURE; static final int EXIT_SUCCESS; }