DATACMNS-917 - Query method execution for Maps now defaults null to an empty Map.

QueryExecutionResultHandler now explicitly handles null values for query methods returning Maps by returning an empty Map. This can be the case if a query is supposed to produce a Map (a single result) but doesn't actually yield any results at all.
This commit is contained in:
Oliver Gierke
2016-09-23 14:46:59 +02:00
parent 8e35c4e41d
commit 3811ce5873
2 changed files with 23 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ import static org.junit.Assert.*;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
@@ -102,6 +103,14 @@ public class QueryExecutionResultHandlerUnitTests {
assertThat(optional, is(com.google.common.base.Optional.of(entity)));
}
/**
* @see DATACMNS-917
*/
@Test
public void defaultsNullToEmptyMap() throws Exception {
assertThat(handler.postProcessInvocationResult(null, getTypeDescriptorFor("map")), is(instanceOf(Map.class)));
}
private static TypeDescriptor getTypeDescriptorFor(String methodName) throws Exception {
Method method = Sample.class.getMethod(methodName);
@@ -117,6 +126,8 @@ public class QueryExecutionResultHandlerUnitTests {
Optional<Entity> jdk8Optional();
com.google.common.base.Optional<Entity> guavaOptional();
Map<Integer, Entity> map();
}
static class Entity {}