@Test public void doesNotRepromptIfUserIsNotProvidedIfOutputRedirected() throws Exception { if (Utils.isWindows()) { return; } doThrow(authException).doNothing().when(shell).connect(connectionConfig, null); String inputString = "\nsecret\n"; InputStream inputStream = new ByteArrayInputStream(inputString.getBytes()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); InputStream stdIn = System.in; PrintStream stdOut = System.out; System.setIn(inputStream); System.setOut(ps); try { Main main = new Main(); main.connectMaybeInteractively(shell, connectionConfig, true, false, true); String out = new String(baos.toByteArray(), StandardCharsets.UTF_8); assertEquals("", out ); verify(connectionConfig).setUsername(""); verify(connectionConfig).setPassword("secret"); verify(shell, times(2)).connect(connectionConfig, null); } finally { System.setIn(stdIn); System.setOut(stdOut); } }
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; }