Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.

Commit 1677827

Browse files
committed
Fix build failures
1 parent 63e57dd commit 1677827

File tree

2 files changed

+57
-114
lines changed

2 files changed

+57
-114
lines changed

cypher-shell/src/integration-test/java/org/neo4j/shell/MainIntegrationTest.java

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -98,36 +98,25 @@ public void promptsOnWrongAuthenticationIfInteractive() throws Exception {
9898
}
9999

100100
@Test
101-
public void doesNotPromptToStdOutOnWrongAuthenticationIfOutputRedirected() throws Exception {
101+
public void doesNotPromptToStdOutOnWrongAuthenticationIfOutputRedirected() throws Exception
102+
{
102103
// when
103-
assertEquals("", connectionConfig.username());
104-
assertEquals("", connectionConfig.password());
105-
106-
// Redirect System.in and System.out
107-
InputStream stdIn = System.in;
108-
PrintStream stdOut = System.out;
109-
System.setIn(inputStream);
110-
System.setOut(printStream);
104+
assertEquals( "", connectionConfig.username() );
105+
assertEquals( "", connectionConfig.password() );
111106

112107
// Create a Main with the standard in and out
113-
try {
114-
Main realMain = new Main(stdIn, stdOut);
115-
realMain.connectMaybeInteractively(shell, connectionConfig, true, false);
116-
117-
// then
118-
// should be connected
119-
assertTrue(shell.isConnected());
120-
// should have prompted silently and set the username and password
121-
assertEquals("neo4j", connectionConfig.username());
122-
assertEquals("neo", connectionConfig.password());
123-
124-
String out = baos.toString();
125-
assertEquals("", out);
126-
} finally {
127-
// Restore in and out
128-
System.setIn(stdIn);
129-
System.setOut(stdOut);
130-
}
108+
Main realMain = new Main( inputStream, printStream );
109+
realMain.connectMaybeInteractively( shell, connectionConfig, true, false );
110+
111+
// then
112+
// should be connected
113+
assertTrue( shell.isConnected() );
114+
// should have prompted silently and set the username and password
115+
assertEquals( "neo4j", connectionConfig.username() );
116+
assertEquals( "neo", connectionConfig.password() );
117+
118+
String out = baos.toString();
119+
assertEquals( "", out );
131120
}
132121

133122
@Test

cypher-shell/src/test/java/org/neo4j/shell/MainTest.java

Lines changed: 41 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
import org.junit.Test;
66
import org.junit.rules.ExpectedException;
77
import org.mockito.ArgumentCaptor;
8-
import org.neo4j.driver.exceptions.AuthenticationException;
9-
import org.neo4j.driver.exceptions.Neo4jException;
10-
import org.neo4j.shell.cli.CliArgs;
11-
import org.neo4j.shell.system.Utils;
128

139
import java.io.ByteArrayInputStream;
1410
import java.io.ByteArrayOutputStream;
1511
import java.io.InputStream;
1612
import java.io.PrintStream;
1713
import java.nio.charset.StandardCharsets;
1814

15+
import org.neo4j.driver.exceptions.AuthenticationException;
16+
import org.neo4j.driver.exceptions.Neo4jException;
17+
import org.neo4j.shell.cli.CliArgs;
18+
import org.neo4j.shell.system.Utils;
19+
1920
import static org.junit.Assert.assertEquals;
2021
import static org.junit.Assert.assertTrue;
2122
import static org.junit.Assert.fail;
@@ -108,28 +109,17 @@ public void promptsSilentlyForUsernameAndPasswordIfNoneGivenIfOutputRedirected()
108109
InputStream inputStream = new ByteArrayInputStream(inputString.getBytes());
109110

110111
ByteArrayOutputStream baos = new ByteArrayOutputStream();
111-
PrintStream ps = new PrintStream(baos);
112+
PrintStream ps = new PrintStream( baos );
112113

113-
// Redirect stdin and stdout
114-
InputStream stdIn = System.in;
115-
PrintStream stdOut = System.out;
116-
System.setIn(inputStream);
117-
System.setOut(ps);
114+
Main main = new Main( inputStream, ps );
115+
main.connectMaybeInteractively( shell, connectionConfig, true, false );
118116

119-
try {
120-
Main main = new Main();
121-
main.connectMaybeInteractively(shell, connectionConfig, true, false);
122-
123-
String out = new String(baos.toByteArray(), StandardCharsets.UTF_8);
124-
125-
assertEquals("", out);
126-
verify(connectionConfig).setUsername("bob");
127-
verify(connectionConfig).setPassword("secret");
128-
verify(shell, times(2)).connect(connectionConfig);
129-
} finally {
130-
System.setIn(stdIn);
131-
System.setOut(stdOut);
132-
}
117+
String out = new String( baos.toByteArray(), StandardCharsets.UTF_8 );
118+
119+
assertEquals( "", out );
120+
verify( connectionConfig ).setUsername( "bob" );
121+
verify( connectionConfig ).setPassword( "secret" );
122+
verify( shell, times( 2 ) ).connect( connectionConfig );
133123
}
134124

135125
@Test
@@ -184,30 +174,19 @@ public void promptsSilentlyForUserIfPassExistsIfOutputRedirected() throws Except
184174
doReturn("secret").when(connectionConfig).password();
185175

186176
String inputString = "bob\n";
187-
InputStream inputStream = new ByteArrayInputStream(inputString.getBytes());
177+
InputStream inputStream = new ByteArrayInputStream( inputString.getBytes() );
188178

189179
ByteArrayOutputStream baos = new ByteArrayOutputStream();
190-
PrintStream ps = new PrintStream(baos);
191-
192-
// Redirect stdin and stdout
193-
InputStream stdIn = System.in;
194-
PrintStream stdOut = System.out;
195-
System.setIn(inputStream);
196-
System.setOut(ps);
180+
PrintStream ps = new PrintStream( baos );
197181

198-
try {
199-
Main main = new Main();
200-
main.connectMaybeInteractively(shell, connectionConfig, true, false);
182+
Main main = new Main( inputStream, ps );
183+
main.connectMaybeInteractively( shell, connectionConfig, true, false );
201184

202-
String out = new String(baos.toByteArray(), StandardCharsets.UTF_8);
185+
String out = new String( baos.toByteArray(), StandardCharsets.UTF_8 );
203186

204-
assertEquals(out, "");
205-
verify(connectionConfig).setUsername("bob");
206-
verify(shell, times(2)).connect(connectionConfig);
207-
} finally {
208-
System.setIn(stdIn);
209-
System.setOut(stdOut);
210-
}
187+
assertEquals( out, "" );
188+
verify( connectionConfig ).setUsername( "bob" );
189+
verify( shell, times( 2 ) ).connect( connectionConfig );
211190
}
212191

213192
@Test
@@ -232,42 +211,28 @@ public void promptsForPassBeforeConnectIfUserExistsIfInteractive() throws Except
232211

233212
@Test
234213
public void promptsSilentlyForPassIfUserExistsIfOutputRedirected() throws Exception {
235-
<<<<<<< HEAD
236-
doThrow(authException).doNothing().when(shell).connect(connectionConfig);
237-
=======
238214
if (Utils.isWindows()) {
239215
// Disable this test on Windows due to problem with redirection
240216
return;
241217
}
242218

243-
>>>>>>> upstream/1.1
244-
doReturn("bob").when(connectionConfig).username();
219+
doThrow(authException).doNothing().when(shell).connect(connectionConfig);
245220

246-
String inputString = "secret\n";
221+
String inputString = "bob\nsecret\n";
247222
InputStream inputStream = new ByteArrayInputStream(inputString.getBytes());
248223

249224
ByteArrayOutputStream baos = new ByteArrayOutputStream();
250-
PrintStream ps = new PrintStream(baos);
225+
PrintStream ps = new PrintStream( baos );
251226

252-
// Redirect stdin and stdout
253-
InputStream stdIn = System.in;
254-
PrintStream stdOut = System.out;
255-
System.setIn(inputStream);
256-
System.setOut(ps);
227+
Main main = new Main( inputStream, ps );
228+
main.connectMaybeInteractively( shell, connectionConfig, true, false );
257229

258-
try {
259-
Main main = new Main();
260-
main.connectMaybeInteractively(shell, connectionConfig, true, false);
261-
262-
String out = new String(baos.toByteArray(), StandardCharsets.UTF_8);
230+
String out = new String( baos.toByteArray(), StandardCharsets.UTF_8 );
263231

264-
assertEquals(out, "");
265-
verify(connectionConfig).setPassword("secret");
266-
verify(shell, times(1)).connect(connectionConfig);
267-
} finally {
268-
System.setIn(stdIn);
269-
System.setOut(stdOut);
270-
}
232+
assertEquals( "", out );
233+
verify( connectionConfig ).setUsername( "bob" );
234+
verify( connectionConfig ).setPassword( "secret" );
235+
verify( shell, times( 2 ) ).connect( connectionConfig );
271236
}
272237

273238
@Test
@@ -347,28 +312,17 @@ public void doesNotRepromptIfUserIsNotProvidedIfOutputRedirected() throws Except
347312
InputStream inputStream = new ByteArrayInputStream(inputString.getBytes());
348313

349314
ByteArrayOutputStream baos = new ByteArrayOutputStream();
350-
PrintStream ps = new PrintStream(baos);
315+
PrintStream ps = new PrintStream( baos );
316+
Main main = new Main( inputStream, ps );
317+
main.connectMaybeInteractively( shell, connectionConfig, true, false );
351318

352-
// Redirect stdin and stdout
353-
InputStream stdIn = System.in;
354-
PrintStream stdOut = System.out;
355-
System.setIn(inputStream);
356-
System.setOut(ps);
319+
String out = new String( baos.toByteArray(), StandardCharsets.UTF_8 );
320+
321+
assertEquals( "", out );
322+
verify( connectionConfig ).setUsername( "" );
323+
verify( connectionConfig ).setPassword( "secret" );
324+
verify( shell, times( 2 ) ).connect( connectionConfig );
357325

358-
try {
359-
Main main = new Main();
360-
main.connectMaybeInteractively(shell, connectionConfig, true, false);
361-
362-
String out = new String(baos.toByteArray(), StandardCharsets.UTF_8);
363-
364-
assertEquals("", out );
365-
verify(connectionConfig).setUsername("");
366-
verify(connectionConfig).setPassword("secret");
367-
verify(shell, times(2)).connect(connectionConfig);
368-
} finally {
369-
System.setIn(stdIn);
370-
System.setOut(stdOut);
371-
}
372326
}
373327

374328
@Test

0 commit comments

Comments
 (0)