Skip to content

Commit c94858f

Browse files
ellebrechtmichael-simons
authored andcommitted
Support ResultSummaries with Notifications with no InputPosition reported by the driver. (#2822)
1 parent 9ae8466 commit c94858f

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
@@ -111,13 +111,14 @@ private static LogAccessor getLogAccessor(NotificationCategory category) {
111111
static String format(Notification notification, String forQuery) {
112112

113113
InputPosition position = notification.position();
114+
boolean hasPosition = position != null;
114115

115116
StringBuilder queryHint = new StringBuilder();
116117
String[] lines = forQuery.split("(\r\n|\n)");
117118
for (int i = 0; i < lines.length; i++) {
118119
String line = lines[i];
119120
queryHint.append("\t").append(line).append(LINE_SEPARATOR);
120-
if (i + 1 == position.line()) {
121+
if (hasPosition && i + 1 == position.line()) {
121122
queryHint.append("\t").append(Stream.generate(() -> " ").limit(position.column() - 1)
122123
.collect(Collectors.joining())).append("^").append(System.lineSeparator());
123124
}

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)