From 9b077890b4f9429a494658cc60cc9a6d94f7ea1c Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Thu, 31 Oct 2013 12:18:54 +0100 Subject: [PATCH] DATACMNS-391 - Mitigate changes between Spring 3 and 4' GenericTypeResolver. As of Spring 4, the GenericTypeResolver is more consistent in detecting raw types. It now returns null for both resolveTypeArguments(Set.class, Set.class) as well as resolveTypeArguments(Set.class, Iterable.class). The latter returns an array of Object.class in 3.x. As this shouldn't make a pratical difference to actual clients (as they need to check for null anyway, we loosen the test case to be able to build Spring Data Commons against both Spring 3 and Spring 4. Some polishing in the version detection in integration tests. Moved the Servlet 3.0 dependency into the Spring 4 profile. --- pom.xml | 21 ++++++++++++------- ...rBeanDefinitionParserIntegrationTests.java | 19 +++++++++-------- .../util/ClassTypeInformationUnitTests.java | 11 +++++++++- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/pom.xml b/pom.xml index 4adeda446..64f7fc515 100644 --- a/pom.xml +++ b/pom.xml @@ -23,6 +23,20 @@ DATACMNS + + + spring4 + + + javax.servlet + javax.servlet-api + 3.0.1 + test + + + + + org.springframework @@ -132,13 +146,6 @@ 3.0 true - - - javax.servlet - javax.servlet-api - 3.0.1 - test - diff --git a/src/test/java/org/springframework/data/repository/config/ResourceReaderRepositoryPopulatorBeanDefinitionParserIntegrationTests.java b/src/test/java/org/springframework/data/repository/config/ResourceReaderRepositoryPopulatorBeanDefinitionParserIntegrationTests.java index 971e7870c..43271dc31 100644 --- a/src/test/java/org/springframework/data/repository/config/ResourceReaderRepositoryPopulatorBeanDefinitionParserIntegrationTests.java +++ b/src/test/java/org/springframework/data/repository/config/ResourceReaderRepositoryPopulatorBeanDefinitionParserIntegrationTests.java @@ -41,14 +41,6 @@ import org.springframework.test.util.ReflectionTestUtils; */ public class ResourceReaderRepositoryPopulatorBeanDefinitionParserIntegrationTests { - private ClassPathResource getPopulatorResource() { - String populatorsResourceName = "populators.xml"; - if (SpringVersion.getVersion().startsWith("4.0")) { - populatorsResourceName = "populators-spring-4.0.xml"; - } - return new ClassPathResource(populatorsResourceName, getClass()); - } - /** * @see DATACMNS-58 */ @@ -117,7 +109,7 @@ public class ResourceReaderRepositoryPopulatorBeanDefinitionParserIntegrationTes assertIsListOfClasspathResourcesWithPath(resources, "org/springframework/data/repository/init/data.xml"); } - private void assertIsListOfClasspathResourcesWithPath(Object source, String path) { + private static void assertIsListOfClasspathResourcesWithPath(Object source, String path) { assertThat(source, is(instanceOf(List.class))); List list = (List) source; @@ -127,4 +119,13 @@ public class ResourceReaderRepositoryPopulatorBeanDefinitionParserIntegrationTes ClassPathResource resource = (ClassPathResource) element; assertThat(resource.getPath(), is(path)); } + + private static ClassPathResource getPopulatorResource() { + + String springVersion = SpringVersion.getVersion(); + String populatorsResourceName = springVersion.startsWith("4") ? "populators-spring-4.0.xml" : "populators.xml"; + + return new ClassPathResource(populatorsResourceName, + ResourceReaderRepositoryPopulatorBeanDefinitionParserIntegrationTests.class); + } } diff --git a/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java b/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java index cb57bbcf9..f8ebca1de 100644 --- a/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java +++ b/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java @@ -26,7 +26,9 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.hamcrest.Matchers; import org.junit.Test; +import org.springframework.core.SpringVersion; import org.springframework.data.mapping.Person; /** @@ -104,7 +106,14 @@ public class ClassTypeInformationUnitTests { property = information.getProperty("rawSet"); assertEquals(Set.class, property.getType()); - assertEquals(Object.class, property.getComponentType().getType()); + + // Spring 4 returns null for component types of raw types + if (SpringVersion.getVersion().startsWith("4")) { + assertThat(property.getComponentType(), nullValue()); + } else { + assertThat(property.getComponentType().getType(), is(Matchers.> equalTo(Object.class))); + } + assertNull(property.getMapValueType()); }