Skip to content

Commit 17b37f1

Browse files
GH-902 - Add more tests.
1 parent f60bf48 commit 17b37f1

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

core/src/main/java/org/neo4j/ogm/context/RestModelMapper.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@
1818
*/
1919
package org.neo4j.ogm.context;
2020

21-
import static java.util.stream.Collectors.*;
22-
2321
import java.lang.reflect.Array;
2422
import java.util.*;
2523
import java.util.concurrent.ThreadLocalRandom;
2624
import java.util.function.BiFunction;
2725
import java.util.function.Function;
2826
import java.util.function.Predicate;
27+
import java.util.stream.Collectors;
2928

3029
import org.neo4j.ogm.metadata.MetaData;
3130
import org.neo4j.ogm.model.GraphModel;
@@ -93,7 +92,7 @@ public String[] columns() {
9392
// Recreate the original structure
9493
RestStatisticsModel restStatisticsModel = new RestStatisticsModel();
9594
response.getStatistics().ifPresent(restStatisticsModel::setStatistics);
96-
restStatisticsModel.setResult(resultRowBuilders.stream().map(ResultRowBuilder::finish).collect(toList()));
95+
restStatisticsModel.setResult(resultRowBuilders.stream().map(ResultRowBuilder::finish).collect(Collectors.toList()));
9796
return restStatisticsModel;
9897
}
9998

@@ -268,7 +267,8 @@ Map<String, Object> finish() {
268267
Object entity = resolveNodeId.apply(v.get(0), graphModel);
269268
resultRow.put(k, entity);
270269
} else {
271-
List<Object> entities = v.stream().map(id -> resolveNodeId.apply(id, graphModel)).collect(toList());
270+
List<Object> entities = v.stream().map(id -> resolveNodeId.apply(id, graphModel)).collect(
271+
Collectors.toList());
272272
List<Object> entityList = (List<Object>) resultRow.computeIfAbsent(k, key -> new ArrayList<>());
273273
entityList.addAll(entities);
274274
}
@@ -278,7 +278,7 @@ Map<String, Object> finish() {
278278
Object entity = resolveRelationshipId.apply(v.get(0));
279279
resultRow.put(k, entity);
280280
} else {
281-
List<Object> entities = v.stream().map(resolveRelationshipId).collect(toList());
281+
List<Object> entities = v.stream().map(resolveRelationshipId).collect(Collectors.toList());
282282
List<Object> entityList = (List<Object>) resultRow.computeIfAbsent(k, key -> new ArrayList<>());
283283
entityList.addAll(entities);
284284
}

neo4j-ogm-tests/neo4j-ogm-integration-tests/src/test/java/org/neo4j/ogm/persistence/model/EntityGraphMapperTest.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,4 +982,50 @@ public void collectedListOfNodesFromPathsShouldNotCollapse() {
982982
});
983983
});
984984
}
985+
986+
@Test
987+
public void emptyArray1Level() {
988+
989+
Result result = session.query("RETURN [] as x", Collections.emptyMap());
990+
assertThat(result).hasSize(1).first().satisfies(row -> {
991+
Object x = row.get("x");
992+
assertThat(x).isInstanceOf(Void[].class);
993+
assertThat(((Void[]) x)).isEmpty();
994+
});
995+
}
996+
997+
@Test
998+
public void emptyArray2Level() {
999+
1000+
Result result = session.query("RETURN [[]] as x", Collections.emptyMap());
1001+
assertThat(result).hasSize(1).first().satisfies(row -> {
1002+
Object x = row.get("x");
1003+
assertThat(x).isInstanceOf(Void[].class);
1004+
assertThat(((Void[]) x)).isEmpty();
1005+
});
1006+
}
1007+
1008+
@Test
1009+
public void empty2Dim1Level() {
1010+
1011+
Result result = session.query("RETURN [[], []] as x", Collections.emptyMap());
1012+
assertThat(result).hasSize(1).first().satisfies(row -> {
1013+
Object x = row.get("x");
1014+
assertThat(x).isInstanceOf(Void[].class);
1015+
assertThat(((Void[]) x)).isEmpty();
1016+
});
1017+
}
1018+
1019+
@Test // GH-902
1020+
@SuppressWarnings("unchecked")
1021+
public void emptyCollectedNodeList() {
1022+
1023+
Result result = session.query("MATCH p=(:AAA)-[*]->(:BBB) RETURN COLLECT (DISTINCT nodes(p)) AS paths",
1024+
Collections.emptyMap());
1025+
assertThat(result).hasSize(1).first().satisfies(row -> {
1026+
Object nestedLists = row.get("paths");
1027+
assertThat(nestedLists).isInstanceOf(Void[].class);
1028+
assertThat(((Void[]) nestedLists)).isEmpty();
1029+
});
1030+
}
9851031
}

0 commit comments

Comments
 (0)