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

Commit b052602

Browse files
committed
Fix CypherShellTest and unify LinePrinter + Logger
1 parent 29867d8 commit b052602

File tree

10 files changed

+30
-36
lines changed

10 files changed

+30
-36
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class StringLinePrinter implements LinePrinter {
88
private StringBuilder sb = new StringBuilder();
99

1010
@Override
11-
public void println(String line) {
11+
public void printOut(String line) {
1212
sb.append(line).append(OutputFormatter.NEWLINE);
1313
}
1414

cypher-shell/src/main/java/org/neo4j/shell/log/AnsiLogger.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,6 @@ public void printOut(@Nonnull final String msg) {
109109
out.println(Ansi.ansi().render(msg).toString());
110110
}
111111

112-
@Override
113-
public void println(String line) {
114-
printOut(line);
115-
}
116-
117112
/**
118113
* Interpret the cause of a Bolt exception and translate it into a sensible error message.
119114
*/

cypher-shell/src/main/java/org/neo4j/shell/log/Logger.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@ public interface Logger extends LinePrinter {
3434
*/
3535
void printError(@Nonnull String text);
3636

37-
/**
38-
* Print the designated text to configured output stream.
39-
*
40-
* @param text to print to the output stream
41-
*/
42-
void printOut(@Nonnull String text);
43-
4437
/**
4538
* @return the current format of the logger
4639
*/

cypher-shell/src/main/java/org/neo4j/shell/prettyprint/LinePrinter.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,11 @@
55
*/
66
@FunctionalInterface
77
public interface LinePrinter {
8-
void println( String line );
8+
9+
/**
10+
* Print the designated line to configured output stream.
11+
*
12+
* @param line to print to the output stream
13+
*/
14+
void printOut(String line );
915
}

cypher-shell/src/main/java/org/neo4j/shell/prettyprint/PrettyPrinter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ public void format(@Nonnull final BoltResult result, LinePrinter linePrinter) {
2424

2525
if (capabilities.contains(OutputFormatter.Capablities.result)) outputFormatter.format(result, linePrinter);
2626

27-
if (capabilities.contains(OutputFormatter.Capablities.info)) linePrinter.println(outputFormatter.formatInfo(result.getSummary()));
28-
if (capabilities.contains(OutputFormatter.Capablities.plan)) linePrinter.println(outputFormatter.formatPlan(result.getSummary()));
29-
if (capabilities.contains(OutputFormatter.Capablities.footer)) linePrinter.println(outputFormatter.formatFooter(result));
30-
if (capabilities.contains(OutputFormatter.Capablities.statistics)) linePrinter.println(statisticsCollector.collect(result.getSummary()));
27+
if (capabilities.contains(OutputFormatter.Capablities.info)) linePrinter.printOut(outputFormatter.formatInfo(result.getSummary()));
28+
if (capabilities.contains(OutputFormatter.Capablities.plan)) linePrinter.printOut(outputFormatter.formatPlan(result.getSummary()));
29+
if (capabilities.contains(OutputFormatter.Capablities.footer)) linePrinter.printOut(outputFormatter.formatFooter(result));
30+
if (capabilities.contains(OutputFormatter.Capablities.statistics)) linePrinter.printOut(statisticsCollector.collect(result.getSummary()));
3131
}
3232

3333
// Helper for testing

cypher-shell/src/main/java/org/neo4j/shell/prettyprint/SimpleOutputFormatter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ public void format(@Nonnull BoltResult result, @Nonnull LinePrinter output) {
1919
Iterator<Record> records = result.iterate();
2020
if (records.hasNext()) {
2121
Record firstRow = records.next();
22-
output.println(String.join(COMMA_SEPARATOR, firstRow.keys()));
23-
output.println(formatRecord(firstRow));
22+
output.printOut(String.join(COMMA_SEPARATOR, firstRow.keys()));
23+
output.printOut(formatRecord(firstRow));
2424
while (records.hasNext()) {
25-
output.println(formatRecord(records.next()));
25+
output.printOut(formatRecord(records.next()));
2626
}
2727
}
2828
}

cypher-shell/src/main/java/org/neo4j/shell/prettyprint/TableOutputFormatter.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ private void formatResult(String[] columns,
5959
int lineWidth = totalWidth - 2;
6060
String dashes = "+" + OutputFormatter.repeat('-', lineWidth) + "+";
6161

62-
output.println(dashes);
63-
output.println(headerLine);
64-
output.println(dashes);
62+
output.printOut(dashes);
63+
output.printOut(headerLine);
64+
output.printOut(dashes);
6565

6666
for (Record record : topRecords) {
67-
output.println(formatRecord(builder, columnSizes, record));
67+
output.printOut(formatRecord(builder, columnSizes, record));
6868
}
6969
while (records.hasNext()) {
70-
output.println(formatRecord(builder, columnSizes, records.next()));
70+
output.printOut(formatRecord(builder, columnSizes, records.next()));
7171
}
72-
output.println(dashes);
72+
output.printOut(dashes);
7373
}
7474

7575
private int[] calculateColumnSizes(@Nonnull String[] columns, @Nonnull List<Record> data) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public void executeShouldPrintResult() throws CommandException {
176176

177177
when(boltStateHandler.isConnected()).thenReturn(true);
178178
when(boltStateHandler.runCypher(anyString(), anyMap())).thenReturn(Optional.of(result));
179-
doAnswer((a) -> { ((LinePrinter)a.getArguments()[1]).println("999"); return null;}).when(mockedPrettyPrinter).format(any(BoltResult.class), anyObject());
179+
doAnswer((a) -> { ((LinePrinter)a.getArguments()[1]).printOut("999"); return null;}).when(mockedPrettyPrinter).format(any(BoltResult.class), anyObject());
180180
when(mockedDriver.session()).thenReturn(session);
181181

182182
OfflineTestShell shell = new OfflineTestShell(logger, boltStateHandler, mockedPrettyPrinter);
@@ -190,7 +190,7 @@ public void commitShouldPrintResult() throws CommandException {
190190

191191
BoltStateHandler boltStateHandler = mock(BoltStateHandler.class);
192192

193-
doAnswer((a) -> { ((LinePrinter)a.getArguments()[1]).println("999"); return null;}).when(mockedPrettyPrinter).format(any(BoltResult.class), anyObject());
193+
doAnswer((a) -> { ((LinePrinter)a.getArguments()[1]).printOut("999"); return null;}).when(mockedPrettyPrinter).format(any(BoltResult.class), anyObject());
194194
when(boltStateHandler.commitTransaction()).thenReturn(Optional.of(asList(result)));
195195

196196
OfflineTestShell shell = new OfflineTestShell(logger, boltStateHandler, mockedPrettyPrinter);

cypher-shell/src/test/java/org/neo4j/shell/prettyprint/TableOutputFormatterTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,9 @@ public void wrapContent()
286286
// GIVEN
287287
StatementResult result = mockResult( asList( "c1"), "a", "bb","ccc","dddd","eeeee" );
288288
// WHEN
289-
StringBuilder sb = new StringBuilder();
290-
new TableOutputFormatter(true, 2).format(new ListBoltResult(result.list(), result.summary()), (s) -> sb.append(s).append("\n"));
291-
String table = sb.toString();
289+
ToStringLinePrinter printer = new ToStringLinePrinter();
290+
new TableOutputFormatter(true, 2).format(new ListBoltResult(result.list(), result.summary()), printer);
291+
String table = printer.result();
292292
// THEN
293293
assertThat(table, is(
294294
"+------+\n" +
@@ -311,9 +311,9 @@ public void truncateContent()
311311
// GIVEN
312312
StatementResult result = mockResult( asList( "c1"), "a", "bb","ccc","dddd","eeeee" );
313313
// WHEN
314-
StringBuilder sb = new StringBuilder();
315-
new TableOutputFormatter(false, 2).format(new ListBoltResult(result.list(), result.summary()), (s) -> sb.append(s).append("\n"));
316-
String table = sb.toString();
314+
ToStringLinePrinter printer = new ToStringLinePrinter();
315+
new TableOutputFormatter(false, 2).format(new ListBoltResult(result.list(), result.summary()), printer);
316+
String table = printer.result();
317317
// THEN
318318
assertThat(table, is(
319319
"+------+\n" +

cypher-shell/src/test/java/org/neo4j/shell/prettyprint/ToStringLinePrinter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public ToStringLinePrinter() {
1111
}
1212

1313
@Override
14-
public void println(String line) {
14+
public void printOut(String line) {
1515
sb.append(line);
1616
sb.append(OutputFormatter.NEWLINE);
1717
}

0 commit comments

Comments
 (0)