From f4531305691cbc635dfafe4abe07195c8c197bdd Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 13 Feb 2017 09:56:22 +0100 Subject: [PATCH] DATACMNS-987 - Polishing. Remove unused Querydsl tests. Add author. Reformat code. Extend Javadoc. --- .../config/SpringDataWebConfiguration.java | 9 ++- ...gDataWebConfigurationIntegrationTests.java | 76 ++++--------------- 2 files changed, 21 insertions(+), 64 deletions(-) diff --git a/src/main/java/org/springframework/data/web/config/SpringDataWebConfiguration.java b/src/main/java/org/springframework/data/web/config/SpringDataWebConfiguration.java index 4c3ab0566..e739c0502 100644 --- a/src/main/java/org/springframework/data/web/config/SpringDataWebConfiguration.java +++ b/src/main/java/org/springframework/data/web/config/SpringDataWebConfiguration.java @@ -44,9 +44,10 @@ import com.fasterxml.jackson.databind.ObjectMapper; /** * Configuration class to register {@link PageableHandlerMethodArgumentResolver}, * {@link SortHandlerMethodArgumentResolver} and {@link DomainClassConverter}. - * + * * @since 1.6 * @author Oliver Gierke + * @author Jens Schauder */ @Configuration public class SpringDataWebConfiguration extends WebMvcConfigurerAdapter { @@ -72,7 +73,7 @@ public class SpringDataWebConfiguration extends WebMvcConfigurerAdapter { return new SortHandlerMethodArgumentResolver(); } - /* + /* * (non-Javadoc) * @see org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter#addFormatters(org.springframework.format.FormatterRegistry) */ @@ -93,7 +94,7 @@ public class SpringDataWebConfiguration extends WebMvcConfigurerAdapter { converter.setApplicationContext(context); } - /* + /* * (non-Javadoc) * @see org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter#addArgumentResolvers(java.util.List) */ @@ -111,7 +112,7 @@ public class SpringDataWebConfiguration extends WebMvcConfigurerAdapter { argumentResolvers.add(resolver); } - /* + /* * (non-Javadoc) * @see org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter#extendMessageConverters(java.util.List) */ diff --git a/src/test/java/org/springframework/data/web/config/SpringDataWebConfigurationIntegrationTests.java b/src/test/java/org/springframework/data/web/config/SpringDataWebConfigurationIntegrationTests.java index 56488c1d5..97c973d83 100644 --- a/src/test/java/org/springframework/data/web/config/SpringDataWebConfigurationIntegrationTests.java +++ b/src/test/java/org/springframework/data/web/config/SpringDataWebConfigurationIntegrationTests.java @@ -22,8 +22,8 @@ import static org.springframework.test.util.ReflectionTestUtils.*; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.List; + import org.hamcrest.Matcher; -import org.junit.Ignore; import org.junit.Test; import org.springframework.beans.BeansException; import org.springframework.beans.factory.ObjectFactory; @@ -31,61 +31,18 @@ import org.springframework.context.support.GenericApplicationContext; import org.springframework.core.convert.ConversionService; import org.springframework.data.web.ProjectingJackson2HttpMessageConverter; import org.springframework.data.web.XmlBeamHttpMessageConverter; -import org.springframework.data.web.querydsl.QuerydslPredicateArgumentResolver; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.instrument.classloading.ShadowingClassLoader; -import org.springframework.web.context.support.GenericWebApplicationContext; -import org.springframework.web.method.support.HandlerMethodArgumentResolver; /** + * Integration test for {@link SpringDataWebConfiguration}. + * * @author Christoph Strobl * @author Jens Schauder */ public class SpringDataWebConfigurationIntegrationTests { - @Test // DATACMNS-669 - public void shouldNotAddQuerydslPredicateArgumentResolverWhenQuerydslNotPresent() throws ClassNotFoundException, - InstantiationException, IllegalAccessException { - - ClassLoader classLoader = initClassLoader("com.mysema"); - - Object config = classLoader.loadClass(SpringDataWebConfiguration.class.getName()) - .newInstance(); - - setField(config, "context", classLoader.loadClass(GenericWebApplicationContext.class.getName()).newInstance() - ); - setField(config, "conversionService", classLoader.loadClass(ObjectFactoryImpl.class.getName()).newInstance()); - - List argumentResolvers = new ArrayList(); - - invokeMethod(config, "addArgumentResolvers", argumentResolvers); - - assertThat(argumentResolvers, - not(hasItem((Matcher) instanceWithClassName(QuerydslPredicateArgumentResolver.class)))); - } - - @Test // DATACMNS-669 - @Ignore("currently fails because he setup is not sufficient to trigger loading of the QuerydslArgumentResolver. See DATACMNS-993") - public void shouldAddQuerydslPredicateArgumentResolverWhenQuerydslPresent() throws ClassNotFoundException, - InstantiationException, IllegalAccessException { - - ClassLoader classLoader = initClassLoader("load.everything"); - - Object config = classLoader.loadClass(SpringDataWebConfiguration.class.getName()) - .newInstance(); - - setField(config, "context", classLoader.loadClass(GenericWebApplicationContext.class.getName()).newInstance()); - setField(config, "conversionService", classLoader.loadClass(ObjectFactoryImpl.class.getName()).newInstance()); - - List argumentResolvers = new ArrayList(); - - invokeMethod(config, "addArgumentResolvers", argumentResolvers); - - assertThat(argumentResolvers, - hasItem((Matcher) instanceWithClassName(QuerydslPredicateArgumentResolver.class))); - } - - @Test // DATACOMNS-987 + @Test // DATACMNS-987 public void shouldNotLoadJacksonConverterWhenJacksonNotPresent() { SpringDataWebConfiguration config = createConfigWithClassLoaderExcluding("com.fasterxml.jackson"); @@ -98,7 +55,7 @@ public class SpringDataWebConfigurationIntegrationTests { instanceWithClassName(ProjectingJackson2HttpMessageConverter.class)))); } - @Test // DATACOMNS-987 + @Test // DATACMNS-987 public void shouldNotLoadJacksonConverterWhenJaywayNotPresent() { SpringDataWebConfiguration config = createConfigWithClassLoaderExcluding("com.jayway"); @@ -111,8 +68,8 @@ public class SpringDataWebConfigurationIntegrationTests { instanceWithClassName(ProjectingJackson2HttpMessageConverter.class)))); } - @Test // DATACOMNS-987 - public void shouldNotLoadXBeamConverterWhenXBeamNotPresent() throws ClassNotFoundException, IllegalAccessException, InstantiationException { + @Test // DATACMNS-987 + public void shouldNotLoadXBeamConverterWhenXBeamNotPresent() throws Exception { SpringDataWebConfiguration config = createConfigWithClassLoaderExcluding("org.xmlbeam"); @@ -124,10 +81,8 @@ public class SpringDataWebConfigurationIntegrationTests { instanceWithClassName(XmlBeamHttpMessageConverter.class)))); } - - @Test // DATACOMNS-987 - public void shouldLoadAllConvertersWhenDependenciesArePresent() throws ClassNotFoundException, - IllegalAccessException, InstantiationException { + @Test // DATACMNS-987 + public void shouldLoadAllConvertersWhenDependenciesArePresent() throws Exception { SpringDataWebConfiguration config = createConfigWithClassLoaderExcluding("load.everything"); @@ -135,12 +90,14 @@ public class SpringDataWebConfigurationIntegrationTests { config.extendMessageConverters(converters); - assertThat(converters, containsInAnyOrder( // - instanceWithClassName(XmlBeamHttpMessageConverter.class), // - instanceWithClassName(ProjectingJackson2HttpMessageConverter.class))); + assertThat(converters, + containsInAnyOrder( // + instanceWithClassName(XmlBeamHttpMessageConverter.class), // + instanceWithClassName(ProjectingJackson2HttpMessageConverter.class))); } private SpringDataWebConfiguration createConfigWithClassLoaderExcluding(String excludedClassNamePrefix) { + ClassLoader classLoader = initClassLoader(excludedClassNamePrefix); SpringDataWebConfiguration config = new SpringDataWebConfiguration(); @@ -153,9 +110,8 @@ public class SpringDataWebConfigurationIntegrationTests { } /** - * creates a Matcher that check if an object is an instance of a class with the same name as the provided class. - * This is necessary since we are dealing with multiple classloaders which would make a simple instanceof fail all - * the time + * creates a Matcher that check if an object is an instance of a class with the same name as the provided class. This + * is necessary since we are dealing with multiple classloaders which would make a simple instanceof fail all the time * * @param expectedClass the class that is expected (possibly loaded by a different classloader). * @return a Matcher