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

Commit 9b3c2af

Browse files
committed
Code review: clean up
1 parent a18bcd6 commit 9b3c2af

File tree

2 files changed

+40
-41
lines changed

2 files changed

+40
-41
lines changed

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

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -183,53 +183,54 @@ public void allowUserToUpdateExpiredPasswordInteractivelyWithoutBeingPrompted()
183183
//given a user that require a password change
184184
int majorVersion = getVersionAndCreateUserWithPasswordChangeRequired();
185185

186-
//in 4.0 and later when the user attempts a non-interactive password update
187-
if (majorVersion >= 4 ) {
188-
baos.reset();
189-
assertEquals( EXIT_SUCCESS, main.runShell( args( SYSTEM_DB_NAME, "foo", "pass",
190-
"ALTER CURRENT USER SET PASSWORD from \"pass\" to \"pass2\";" ), shell, mock(Logger.class) ) );
191-
//we shouldn't ask for a new password
192-
assertEquals("", baos.toString());
193-
194-
//then the new user should be able to successfully connect, and run a command
195-
assertEquals( format( "n%n42%n" ),
196-
executeNonInteractively( args( DEFAULT_DEFAULT_DB_NAME,
197-
"foo", "pass2", "RETURN 42 AS n" ) ) );
198-
}
186+
//when the user attempts a non-interactive password update
187+
assumeTrue(majorVersion >= 4 );
188+
baos.reset();
189+
assertEquals( EXIT_SUCCESS, main.runShell( args( SYSTEM_DB_NAME, "foo", "pass",
190+
"ALTER CURRENT USER SET PASSWORD from \"pass\" to \"pass2\";" ), shell, mock( Logger.class ) ) );
191+
//we shouldn't ask for a new password
192+
assertEquals( "", baos.toString() );
193+
194+
//then the new user should be able to successfully connect, and run a command
195+
assertEquals( format( "n%n42%n" ),
196+
executeNonInteractively( args( DEFAULT_DEFAULT_DB_NAME,
197+
"foo", "pass2", "RETURN 42 AS n" ) ) );
199198
}
200199

201200
@Test
202201
public void shouldFailIfNonInteractivelySettingPasswordOnNonSystemDb() throws Exception {
203202
//given a user that require a password change
204203
int majorVersion = getVersionAndCreateUserWithPasswordChangeRequired();
205204

206-
//in 4.0 and later when the user attempts a non-interactive password update
207-
if (majorVersion >= 4 ) {
208-
assertEquals(EXIT_FAILURE, main.runShell( args( DEFAULT_DEFAULT_DB_NAME, "foo", "pass",
209-
"ALTER CURRENT USER SET PASSWORD from \"pass\" to \"pass2\";"), shell, mock(Logger.class) ) );
210-
}
205+
//when
206+
assumeTrue( majorVersion >= 4 );
207+
208+
//then
209+
assertEquals( EXIT_FAILURE, main.runShell( args( DEFAULT_DEFAULT_DB_NAME, "foo", "pass",
210+
"ALTER CURRENT USER SET PASSWORD from \"pass\" to \"pass2\";" ), shell, mock( Logger.class ) ) );
211211
}
212212

213213
@Test
214214
public void shouldBePromptedIfRunningNonInteractiveCypherThatDoesntUpdatePassword() throws Exception {
215215
//given a user that require a password change
216216
int majorVersion = getVersionAndCreateUserWithPasswordChangeRequired();
217217

218-
//in 4.0 and later when the user attempts a non-interactive password update
219-
if (majorVersion >= 4 ) {
220-
//when asked for a password use this
221-
inputBuffer.put(String.format("pass2%n").getBytes());
222-
baos.reset();
223-
assertEquals( EXIT_SUCCESS, main.runShell( args( DEFAULT_DEFAULT_DB_NAME, "foo", "pass",
224-
"MATCH (n) RETURN n" ), shell, mock(Logger.class) ) );
225-
//we should ask for a new password
226-
assertEquals( format( "Password change required%nnew password: *****%n" ), baos.toString());
227-
228-
//then the new user should be able to successfully connect, and run a command
229-
assertEquals( format( "n%n42%n" ),
230-
executeNonInteractively( args( DEFAULT_DEFAULT_DB_NAME,
231-
"foo", "pass2", "RETURN 42 AS n" ) ) );
232-
}
218+
//when
219+
assumeTrue( majorVersion >= 4 );
220+
221+
//when interactively asked for a password use this
222+
inputBuffer.put( String.format( "pass2%n" ).getBytes() );
223+
baos.reset();
224+
assertEquals( EXIT_SUCCESS, main.runShell( args( DEFAULT_DEFAULT_DB_NAME, "foo", "pass",
225+
"MATCH (n) RETURN n" ), shell, mock( Logger.class ) ) );
226+
227+
//then should ask for a new password
228+
assertEquals( format( "Password change required%nnew password: *****%n" ), baos.toString() );
229+
230+
//then the new user should be able to successfully connect, and run a command
231+
assertEquals( format( "n%n42%n" ),
232+
executeNonInteractively( args( DEFAULT_DEFAULT_DB_NAME,
233+
"foo", "pass2", "RETURN 42 AS n" ) ) );
233234
}
234235

235236
@Test
@@ -602,12 +603,11 @@ public void switchingToUnavailableDefaultDatabaseIfInteractive() throws Exceptio
602603
}
603604
}
604605

605-
private String executeFileNonInteractively(String filename) throws Exception {
606+
private String executeFileNonInteractively(String filename) {
606607
return executeFileNonInteractively(filename, mock(Logger.class));
607608
}
608609

609-
private String executeFileNonInteractively(String filename, Logger logger) throws Exception
610-
{
610+
private String executeFileNonInteractively(String filename, Logger logger) {
611611
CliArgs cliArgs = new CliArgs();
612612
cliArgs.setUsername( USER, "" );
613613
cliArgs.setPassword( PASSWORD, "" );
@@ -616,18 +616,16 @@ private String executeFileNonInteractively(String filename, Logger logger) throw
616616
return executeNonInteractively( cliArgs, logger );
617617
}
618618

619-
private String executeNonInteractively(CliArgs cliArgs) throws Exception {
619+
private String executeNonInteractively(CliArgs cliArgs) {
620620
return executeNonInteractively(cliArgs, mock(Logger.class));
621621
}
622622

623-
private String executeNonInteractively(CliArgs cliArgs, Logger logger) throws Exception
623+
private String executeNonInteractively(CliArgs cliArgs, Logger logger)
624624
{
625625
ToStringLinePrinter linePrinter = new ToStringLinePrinter();
626626
ShellAndConnection sac = getShell( cliArgs, linePrinter );
627627
CypherShell shell = sac.shell;
628628
main.runShell(cliArgs, shell, logger);
629-
// ConnectionConfig connectionConfig = sac.connectionConfig;
630-
// main.connectMaybeInteractively( shell, connectionConfig, false, false );
631629
return linePrinter.result();
632630
}
633631

cypher-shell/src/main/java/org/neo4j/shell/Main.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ void startShell(@Nonnull CliArgs cliArgs) {
8383

8484
CypherShell shell = new CypherShell( logger, prettyConfig, ShellRunner.shouldBeInteractive( cliArgs ),
8585
cliArgs.getParameters() );
86-
System.exit( runShell( cliArgs, shell, logger ) );
86+
int exitCode = runShell( cliArgs, shell, logger );
87+
System.exit( exitCode );
8788
}
8889

8990
int runShell(@Nonnull CliArgs cliArgs, @Nonnull CypherShell shell, Logger logger )

0 commit comments

Comments
 (0)