66import org .junit .Rule ;
77import org .junit .Test ;
88import org .junit .rules .ExpectedException ;
9- import org .mockito .ArgumentCaptor ;
109import org .neo4j .shell .ConnectionConfig ;
1110import org .neo4j .shell .CypherShell ;
11+ import org .neo4j .shell .StringLinePrinter ;
1212import org .neo4j .shell .cli .Format ;
1313import org .neo4j .shell .exception .CommandException ;
14- import org .neo4j .shell .log .Logger ;
15-
16- import java .util .List ;
14+ import org .neo4j .shell .prettyprint .PrettyConfig ;
1715
1816import static org .hamcrest .CoreMatchers .containsString ;
1917import static org .hamcrest .MatcherAssert .assertThat ;
20- import static org .mockito .Mockito .doReturn ;
21- import static org .mockito .Mockito .mock ;
22- import static org .mockito .Mockito .times ;
23- import static org .mockito .Mockito .verify ;
18+ import static org .neo4j .shell .prettyprint .OutputFormatter .NEWLINE ;
2419
2520public class CypherShellPlainIntegrationTest {
2621 @ Rule
2722 public final ExpectedException thrown = ExpectedException .none ();
2823
29- private Logger logger = mock ( Logger . class );
24+ private StringLinePrinter linePrinter = new StringLinePrinter ( );
3025 private CypherShell shell ;
3126
3227 @ Before
3328 public void setUp () throws Exception {
34- doReturn ( Format . PLAIN ). when ( logger ). getFormat ();
35- shell = new CypherShell (logger );
29+ linePrinter . clear ();
30+ shell = new CypherShell (linePrinter , new PrettyConfig ( Format . PLAIN , true , 1000 ) );
3631 shell .connect (new ConnectionConfig ("bolt://" , "localhost" , 7687 , "neo4j" , "neo" , true ));
3732 }
3833
@@ -46,14 +41,11 @@ public void periodicCommitWorks() throws CommandException {
4641 shell .execute ("USING PERIODIC COMMIT\n " +
4742 "LOAD CSV FROM 'https://neo4j.com/docs/cypher-refcard/3.2/csv/artists.csv' AS line\n " +
4843 "CREATE (:Artist {name: line[1], year: toInt(line[2])});" );
44+ linePrinter .clear ();
4945
5046 shell .execute ("MATCH (a:Artist) WHERE a.name = 'Europe' RETURN a.name" );
5147
52- ArgumentCaptor <String > captor = ArgumentCaptor .forClass (String .class );
53- verify (logger , times (2 )).printOut (captor .capture ());
54-
55- List <String > queryResult = captor .getAllValues ();
56- assertThat (queryResult .get (1 ), containsString ("Europe" ));
48+ assertThat (linePrinter .output (), containsString ("a.name" + NEWLINE +"\" Europe\" " ));
5749 }
5850
5951 @ Test
@@ -62,11 +54,7 @@ public void cypherWithProfileStatements() throws CommandException {
6254 shell .execute ("CYPHER RUNTIME=INTERPRETED PROFILE RETURN null" );
6355
6456 //then
65- ArgumentCaptor <String > captor = ArgumentCaptor .forClass (String .class );
66- verify (logger , times (1 )).printOut (captor .capture ());
67-
68- List <String > result = captor .getAllValues ();
69- String actual = result .get (0 );
57+ String actual = linePrinter .output ();
7058 // This assertion checks everything except for time and cypher
7159 assertThat (actual , containsString ("Plan: \" PROFILE\" " ));
7260 assertThat (actual , containsString ("Statement: \" READ_ONLY\" " ));
@@ -84,11 +72,7 @@ public void cypherWithExplainStatements() throws CommandException {
8472 shell .execute ("CYPHER RUNTIME=INTERPRETED EXPLAIN RETURN null" );
8573
8674 //then
87- ArgumentCaptor <String > captor = ArgumentCaptor .forClass (String .class );
88- verify (logger , times (1 )).printOut (captor .capture ());
89-
90- List <String > result = captor .getAllValues ();
91- String actual = result .get (0 );
75+ String actual = linePrinter .output ();
9276 // This assertion checks everything except for time and cypher
9377 assertThat (actual , containsString ("Plan: \" EXPLAIN\" " ));
9478 assertThat (actual , containsString ("Statement: \" READ_ONLY\" " ));
0 commit comments