1+ /*
2+ * Copyright (c) 2002-2020 "Neo4j,"
3+ * Neo4j Sweden AB [http://neo4j.com]
4+ *
5+ * This file is part of Neo4j.
6+ *
7+ * Neo4j is free software: you can redistribute it and/or modify
8+ * it under the terms of the GNU General Public License as published by
9+ * the Free Software Foundation, either version 3 of the License, or
10+ * (at your option) any later version.
11+ *
12+ * This program is distributed in the hope that it will be useful,
13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+ * GNU General Public License for more details.
16+ *
17+ * You should have received a copy of the GNU General Public License
18+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
19+ */
120package org .neo4j .shell ;
221
322import org .junit .Before ;
423import org .junit .Test ;
5- import org .neo4j .shell .cli .CliArgs ;
6- import org .neo4j .shell .log .AnsiLogger ;
7- import org .neo4j .shell .log .Logger ;
8- import org .neo4j .shell .prettyprint .PrettyConfig ;
924
1025import java .io .ByteArrayInputStream ;
1126import java .io .ByteArrayOutputStream ;
1227import java .io .InputStream ;
1328import java .io .PrintStream ;
1429
30+ import org .neo4j .shell .cli .CliArgs ;
31+ import org .neo4j .shell .log .AnsiLogger ;
32+ import org .neo4j .shell .log .Logger ;
33+ import org .neo4j .shell .prettyprint .PrettyConfig ;
34+
1535import static org .junit .Assert .assertEquals ;
1636import static org .junit .Assert .assertTrue ;
1737
18- public class MainIntegrationTest {
38+ public class MainIntegrationTest
39+ {
1940
2041 private String inputString = String .format ( "neo4j%nneo%n" );
2142 private ByteArrayOutputStream baos ;
@@ -26,82 +47,87 @@ public class MainIntegrationTest {
2647 private InputStream inputStream ;
2748
2849 @ Before
29- public void setup () {
50+ public void setup ()
51+ {
3052 // given
31- inputStream = new ByteArrayInputStream (inputString .getBytes ());
53+ inputStream = new ByteArrayInputStream ( inputString .getBytes () );
3254
3355 baos = new ByteArrayOutputStream ();
34- printStream = new PrintStream (baos );
56+ printStream = new PrintStream ( baos );
3557
36- main = new Main (inputStream , printStream );
58+ main = new Main ( inputStream , printStream );
3759
3860 CliArgs cliArgs = new CliArgs ();
39- cliArgs .setUsername ("" , "" );
40- cliArgs .setPassword ("" , "" );
61+ cliArgs .setUsername ( "" , "" );
62+ cliArgs .setPassword ( "" , "" );
4163
42- Logger logger = new AnsiLogger (cliArgs .getDebugMode ());
43- PrettyConfig prettyConfig = new PrettyConfig (cliArgs );
64+ Logger logger = new AnsiLogger ( cliArgs .getDebugMode () );
65+ PrettyConfig prettyConfig = new PrettyConfig ( cliArgs );
4466 connectionConfig = new ConnectionConfig (
4567 cliArgs .getScheme (),
4668 cliArgs .getHost (),
4769 cliArgs .getPort (),
4870 cliArgs .getUsername (),
4971 cliArgs .getPassword (),
50- cliArgs .getEncryption ());
72+ cliArgs .getEncryption () );
5173
52- shell = new CypherShell (logger , prettyConfig );
74+ shell = new CypherShell ( logger , prettyConfig );
5375 }
5476
55-
5677 @ Test
57- public void promptsOnWrongAuthenticationIfInteractive () throws Exception {
78+ public void promptsOnWrongAuthenticationIfInteractive () throws Exception
79+ {
5880 // when
59- assertEquals ("" , connectionConfig .username ());
60- assertEquals ("" , connectionConfig .password ());
81+ assertEquals ( "" , connectionConfig .username () );
82+ assertEquals ( "" , connectionConfig .password () );
6183
62- main .connectMaybeInteractively (shell , connectionConfig , true , true );
84+ main .connectMaybeInteractively ( shell , connectionConfig , true , true );
6385
6486 // then
6587 // should be connected
66- assertTrue (shell .isConnected ());
88+ assertTrue ( shell .isConnected () );
6789 // should have prompted and set the username and password
68- assertEquals ("neo4j" , connectionConfig .username ());
69- assertEquals ("neo" , connectionConfig .password ());
90+ assertEquals ( "neo4j" , connectionConfig .username () );
91+ assertEquals ( "neo" , connectionConfig .password () );
7092
7193 String out = baos .toString ();
72- assertEquals (String .format ( "username: neo4j%npassword: ***%n" ), out );
94+ assertEquals ( String .format ( "username: neo4j%npassword: ***%n" ), out );
7395 }
7496
7597 @ Test
76- public void doesNotPromptToStdOutOnWrongAuthenticationIfOutputRedirected () throws Exception {
98+ public void doesNotPromptToStdOutOnWrongAuthenticationIfOutputRedirected () throws Exception
99+ {
77100 // when
78- assertEquals ("" , connectionConfig .username ());
79- assertEquals ("" , connectionConfig .password ());
101+ assertEquals ( "" , connectionConfig .username () );
102+ assertEquals ( "" , connectionConfig .password () );
80103
81104 // Redirect System.in and System.out
82105 InputStream stdIn = System .in ;
83106 PrintStream stdOut = System .out ;
84- System .setIn (inputStream );
85- System .setOut (printStream );
107+ System .setIn ( inputStream );
108+ System .setOut ( printStream );
86109
87110 // Create a Main with the standard in and out
88- try {
111+ try
112+ {
89113 Main realMain = new Main ();
90- realMain .connectMaybeInteractively (shell , connectionConfig , true , false );
114+ realMain .connectMaybeInteractively ( shell , connectionConfig , true , false );
91115
92116 // then
93117 // should be connected
94- assertTrue (shell .isConnected ());
118+ assertTrue ( shell .isConnected () );
95119 // should have prompted silently and set the username and password
96- assertEquals ("neo4j" , connectionConfig .username ());
97- assertEquals ("neo" , connectionConfig .password ());
120+ assertEquals ( "neo4j" , connectionConfig .username () );
121+ assertEquals ( "neo" , connectionConfig .password () );
98122
99123 String out = baos .toString ();
100- assertEquals ("" , out );
101- } finally {
124+ assertEquals ( "" , out );
125+ }
126+ finally
127+ {
102128 // Restore in and out
103- System .setIn (stdIn );
104- System .setOut (stdOut );
129+ System .setIn ( stdIn );
130+ System .setOut ( stdOut );
105131 }
106132 }
107133}
0 commit comments