Skip to content

Commit 0169af2

Browse files
ellebrechtmichael-simons
authored andcommitted
Support ResultSummaries with Notifications with no InputPosition reported by the driver. (#2822)
1 parent 43eed88 commit 0169af2

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/main/java/org/springframework/data/neo4j/core/ResultSummaries.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,14 @@ private static void logNotifications(ResultSummary resultSummary) {
7676
static String format(Notification notification, String forQuery) {
7777

7878
InputPosition position = notification.position();
79+
boolean hasPosition = position != null;
7980

8081
StringBuilder queryHint = new StringBuilder();
8182
String[] lines = forQuery.split("(\r\n|\n)");
8283
for (int i = 0; i < lines.length; i++) {
8384
String line = lines[i];
8485
queryHint.append("\t").append(line).append(LINE_SEPARATOR);
85-
if (i + 1 == position.line()) {
86+
if (hasPosition && i + 1 == position.line()) {
8687
queryHint.append("\t").append(Stream.generate(() -> " ").limit(position.column() - 1)
8788
.collect(Collectors.joining())).append("^").append(System.lineSeparator());
8889
}

src/test/java/org/springframework/data/neo4j/core/ResultSummariesTest.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,24 @@ private static Stream<Arguments> params() {
5454
+ "\tmatch (n) " + LINE_SEPARATOR
5555
+ "\t- [r:FOO*] -> (m) " + LINE_SEPARATOR
5656
+ "\t^" + LINE_SEPARATOR
57-
+ "\tRETURN r" + LINE_SEPARATOR)
57+
+ "\tRETURN r" + LINE_SEPARATOR),
58+
Arguments.of("match (n) - [r] -> (m) RETURN r", null, null, ""
59+
+ "\tmatch (n) - [r] -> (m) RETURN r" + LINE_SEPARATOR)
5860
);
5961
}
6062

6163
@ParameterizedTest(name = "{index}: Notifications for \"{0}\"")
6264
@MethodSource("params")
63-
void shouldFormatNotifications(String query, int line, int column, String expected) {
65+
void shouldFormatNotifications(String query, Integer line, Integer column, String expected) {
6466

65-
InputPosition inputPosition = mock(InputPosition.class);
66-
when(inputPosition.line()).thenReturn(line);
67-
when(inputPosition.column()).thenReturn(column);
67+
InputPosition inputPosition;
68+
if (line == null || column == null) {
69+
inputPosition = null;
70+
} else {
71+
inputPosition = mock(InputPosition.class);
72+
when(inputPosition.line()).thenReturn(line);
73+
when(inputPosition.column()).thenReturn(column);
74+
}
6875

6976
Notification notification = mock(Notification.class);
7077
when(notification.severity()).thenReturn("WARNING");

0 commit comments

Comments
 (0)