DATACMNS-714 - Improved test cases for CompletableFuture support.
We now make sure the converter for CompletableFuture is only registered if Spring 4.2 or better is on the classpath. Adapted test cases to only run tests for CompletableFuture support in the very same scenario.
This commit is contained in:
@@ -21,11 +21,13 @@ import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.springframework.core.SpringVersion;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.converter.GenericConverter;
|
||||
import org.springframework.core.convert.support.ConfigurableConversionService;
|
||||
import org.springframework.data.util.Version;
|
||||
import org.springframework.scheduling.annotation.AsyncResult;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
@@ -42,6 +44,9 @@ import com.google.common.base.Optional;
|
||||
*/
|
||||
public abstract class QueryExecutionConverters {
|
||||
|
||||
private static final Version SPRING_VERSION = Version.parse(SpringVersion.getVersion());
|
||||
private static final Version FOUR_DOT_TWO = new Version(4, 2);
|
||||
|
||||
private static final boolean GUAVA_PRESENT = ClassUtils.isPresent("com.google.common.base.Optional",
|
||||
QueryExecutionConverters.class.getClassLoader());
|
||||
private static final boolean JDK_8_PRESENT = ClassUtils.isPresent("java.util.Optional",
|
||||
@@ -60,6 +65,9 @@ public abstract class QueryExecutionConverters {
|
||||
|
||||
if (JDK_8_PRESENT) {
|
||||
WRAPPER_TYPES.add(NullableWrapperToJdk8OptionalConverter.getWrapperType());
|
||||
}
|
||||
|
||||
if (JDK_8_PRESENT && SPRING_VERSION.isGreaterThanOrEqualTo(FOUR_DOT_TWO)) {
|
||||
WRAPPER_TYPES.add(NullableWrapperToCompletableFutureConverter.getWrapperType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.core.SpringVersion;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -52,6 +53,7 @@ import org.springframework.data.repository.core.NamedQueries;
|
||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.data.repository.query.RepositoryQuery;
|
||||
import org.springframework.data.repository.sample.User;
|
||||
import org.springframework.data.util.Version;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
@@ -66,6 +68,9 @@ import org.springframework.util.concurrent.ListenableFuture;
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RepositoryFactorySupportUnitTests {
|
||||
|
||||
static final Version SPRING_VERSION = Version.parse(SpringVersion.getVersion());
|
||||
static final Version FOUR_DOT_TWO = new Version(4, 2);
|
||||
|
||||
public @Rule ExpectedException exception = ExpectedException.none();
|
||||
|
||||
DummyRepositoryFactory factory;
|
||||
@@ -252,7 +257,7 @@ public class RepositoryFactorySupportUnitTests {
|
||||
@Test
|
||||
public void wrapsExecutionResultIntoCompletableFutureIfConfigured() throws Exception {
|
||||
|
||||
assumeThat(ClassUtils.isPresent("org.springframework.transaction.interceptor.TransactionalProxy", null), is(true));
|
||||
assumeThat(SPRING_VERSION.isGreaterThanOrEqualTo(FOUR_DOT_TWO), is(true));
|
||||
|
||||
User reference = new User();
|
||||
|
||||
@@ -265,7 +270,7 @@ public class RepositoryFactorySupportUnitTests {
|
||||
@Test
|
||||
public void wrapsExecutionResultIntoListenableFutureIfConfigured() throws Exception {
|
||||
|
||||
assumeThat(ClassUtils.isPresent("org.springframework.transaction.interceptor.TransactionalProxy", null), is(true));
|
||||
assumeThat(SPRING_VERSION.isGreaterThanOrEqualTo(FOUR_DOT_TWO), is(true));
|
||||
|
||||
User reference = new User();
|
||||
|
||||
@@ -278,7 +283,7 @@ public class RepositoryFactorySupportUnitTests {
|
||||
@Test
|
||||
public void wrapsExecutionResultIntoCompletableFutureWithEntityCollectionIfConfigured() throws Exception {
|
||||
|
||||
assumeThat(ClassUtils.isPresent("org.springframework.transaction.interceptor.TransactionalProxy", null), is(true));
|
||||
assumeThat(SPRING_VERSION.isGreaterThanOrEqualTo(FOUR_DOT_TWO), is(true));
|
||||
|
||||
List<User> reference = Arrays.asList(new User());
|
||||
|
||||
@@ -291,7 +296,7 @@ public class RepositoryFactorySupportUnitTests {
|
||||
@Test
|
||||
public void wrapsExecutionResultIntoListenableFutureWithEntityCollectionIfConfigured() throws Exception {
|
||||
|
||||
assumeThat(ClassUtils.isPresent("org.springframework.transaction.interceptor.TransactionalProxy", null), is(true));
|
||||
assumeThat(SPRING_VERSION.isGreaterThanOrEqualTo(FOUR_DOT_TWO), is(true));
|
||||
|
||||
List<User> reference = Arrays.asList(new User());
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.data.repository.query;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -26,12 +27,14 @@ import java.util.concurrent.Future;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.SpringVersion;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
|
||||
import org.springframework.data.util.Version;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link QueryMethod}.
|
||||
@@ -41,6 +44,9 @@ import org.springframework.data.repository.core.support.DefaultRepositoryMetadat
|
||||
*/
|
||||
public class QueryMethodUnitTests {
|
||||
|
||||
private static final Version SPRING_VERSION = Version.parse(SpringVersion.getVersion());
|
||||
private static final Version FOUR_DOT_TWO = new Version(4, 2);
|
||||
|
||||
RepositoryMetadata metadata = new DefaultRepositoryMetadata(SampleRepository.class);
|
||||
|
||||
/**
|
||||
@@ -185,6 +191,8 @@ public class QueryMethodUnitTests {
|
||||
@Test
|
||||
public void doesNotRejectCompletableFutureQueryForEntityCollection() throws Exception {
|
||||
|
||||
assumeThat(SPRING_VERSION.isGreaterThanOrEqualTo(FOUR_DOT_TWO), is(true));
|
||||
|
||||
RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(SampleRepository.class);
|
||||
Method method = SampleRepository.class.getMethod("returnsCompletableFutureForEntityCollection");
|
||||
|
||||
|
||||
@@ -17,13 +17,16 @@ package org.springframework.data.repository.util;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.SpringVersion;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.data.util.Version;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
@@ -35,6 +38,9 @@ import com.google.common.base.Optional;
|
||||
*/
|
||||
public class QueryExecutionConvertersUnitTests {
|
||||
|
||||
private static final Version SPRING_VERSION = Version.parse(SpringVersion.getVersion());
|
||||
private static final Version FOUR_DOT_TWO = new Version(4, 2);
|
||||
|
||||
DefaultConversionService conversionService;
|
||||
|
||||
@Before
|
||||
@@ -54,6 +60,16 @@ public class QueryExecutionConvertersUnitTests {
|
||||
assertThat(QueryExecutionConverters.supports(java.util.Optional.class), is(true));
|
||||
assertThat(QueryExecutionConverters.supports(Future.class), is(true));
|
||||
assertThat(QueryExecutionConverters.supports(ListenableFuture.class), is(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-714
|
||||
*/
|
||||
@Test
|
||||
public void registersCompletableFutureAsWrapperTypeOnSpring42OrBetter() {
|
||||
|
||||
assumeThat(SPRING_VERSION.isGreaterThanOrEqualTo(FOUR_DOT_TWO), is(true));
|
||||
|
||||
assertThat(QueryExecutionConverters.supports(CompletableFuture.class), is(true));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user