From e06198e9cbf49312a7c1b3949a7508354705983a Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Fri, 6 Nov 2015 13:21:53 -0800 Subject: [PATCH] Polish --- ...zelcastJpaDependencyAutoConfiguration.java | 12 +++++---- .../cache/CacheAutoConfigurationTests.java | 11 ++++---- ...stJpaDependencyAutoConfigurationTests.java | 26 +++++++++++++------ 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastJpaDependencyAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastJpaDependencyAutoConfiguration.java index 29251db18d..916042df4d 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastJpaDependencyAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastJpaDependencyAutoConfiguration.java @@ -33,15 +33,16 @@ import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; /** - * Additional configuration to ensure that {@link EntityManagerFactory} beans - * depend-on the {@code hazelcastInstance} bean. + * Additional configuration to ensure that {@link EntityManagerFactory} beans depend-on + * the {@code hazelcastInstance} bean. * * @author Stephane Nicoll - * @since 1.3.0 */ @Configuration -@ConditionalOnClass({ HazelcastInstance.class, LocalContainerEntityManagerFactoryBean.class }) -@AutoConfigureAfter({ HazelcastAutoConfiguration.class, HibernateJpaAutoConfiguration.class }) +@ConditionalOnClass({ HazelcastInstance.class, + LocalContainerEntityManagerFactoryBean.class }) +@AutoConfigureAfter({ HazelcastAutoConfiguration.class, + HibernateJpaAutoConfiguration.class }) class HazelcastJpaDependencyAutoConfiguration { @Bean @@ -56,6 +57,7 @@ class HazelcastJpaDependencyAutoConfiguration { HazelcastInstanceJpaDependencyPostProcessor() { super("hazelcastInstance"); } + } static class OnHazelcastAndJpaCondition extends AllNestedConditions { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java index b8ceb09ba3..79403b0deb 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java @@ -382,8 +382,8 @@ public class CacheAutoConfigurationTests { public void hazelcastCacheWithMainHazelcastAutoConfiguration() throws IOException { String mainConfig = "org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml"; AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); - EnvironmentTestUtils.addEnvironment(applicationContext, "spring.cache.type=hazelcast", - "spring.hazelcast.config=" + mainConfig); + EnvironmentTestUtils.addEnvironment(applicationContext, + "spring.cache.type=hazelcast", "spring.hazelcast.config=" + mainConfig); applicationContext.register(DefaultCacheConfiguration.class); applicationContext.register(HazelcastAndCacheConfiguration.class); applicationContext.refresh(); @@ -404,14 +404,14 @@ public class CacheAutoConfigurationTests { String mainConfig = "org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml"; String cacheConfig = "org/springframework/boot/autoconfigure/cache/hazelcast-specific.xml"; AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); - EnvironmentTestUtils.addEnvironment(applicationContext, "spring.cache.type=hazelcast", + EnvironmentTestUtils.addEnvironment(applicationContext, + "spring.cache.type=hazelcast", "spring.cache.hazelcast.config=" + cacheConfig, "spring.hazelcast.config=" + mainConfig); applicationContext.register(DefaultCacheConfiguration.class); applicationContext.register(HazelcastAndCacheConfiguration.class); applicationContext.refresh(); this.context = applicationContext; - HazelcastInstance hazelcastInstance = this.context .getBean(HazelcastInstance.class); HazelcastCacheManager cacheManager = validateCacheManager( @@ -681,7 +681,8 @@ public class CacheAutoConfigurationTests { } @Configuration - @ImportAutoConfiguration({CacheAutoConfiguration.class, HazelcastAutoConfiguration.class}) + @ImportAutoConfiguration({ CacheAutoConfiguration.class, + HazelcastAutoConfiguration.class }) static class HazelcastAndCacheConfiguration { } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastJpaDependencyAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastJpaDependencyAutoConfigurationTests.java index 95c7837d5c..0ef71cb81a 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastJpaDependencyAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastJpaDependencyAutoConfigurationTests.java @@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.hazelcast; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Map; import com.hazelcast.core.HazelcastInstance; import org.junit.After; @@ -57,7 +58,7 @@ public class HazelcastJpaDependencyAutoConfigurationTests { @Test public void registrationIfHazelcastInstanceHasRegularBeanName() { load(HazelcastConfiguration.class); - assertThat(this.context.getBeansOfType(EntityManagerFactoryDependsOnPostProcessor.class), + assertThat(getPostProcessor(), hasKey("hazelcastInstanceJpaDependencyPostProcessor")); assertThat(getEntityManagerFactoryDependencies(), hasItem("hazelcastInstance")); } @@ -65,16 +66,18 @@ public class HazelcastJpaDependencyAutoConfigurationTests { @Test public void noRegistrationIfHazelcastInstanceHasCustomBeanName() { load(HazelcastCustomNameConfiguration.class); - assertThat(getEntityManagerFactoryDependencies(), not(hasItem("hazelcastInstance"))); - assertThat(this.context.getBeansOfType(EntityManagerFactoryDependsOnPostProcessor.class), + assertThat(getEntityManagerFactoryDependencies(), + not(hasItem("hazelcastInstance"))); + assertThat(getPostProcessor(), not(hasKey("hazelcastInstanceJpaDependencyPostProcessor"))); } @Test public void noRegistrationWithNoHazelcastInstance() { load(null); - assertThat(getEntityManagerFactoryDependencies(), not(hasItem("hazelcastInstance"))); - assertThat(this.context.getBeansOfType(EntityManagerFactoryDependsOnPostProcessor.class), + assertThat(getEntityManagerFactoryDependencies(), + not(hasItem("hazelcastInstance"))); + assertThat(getPostProcessor(), not(hasKey("hazelcastInstanceJpaDependencyPostProcessor"))); } @@ -84,13 +87,20 @@ public class HazelcastJpaDependencyAutoConfigurationTests { this.context.register(HazelcastConfiguration.class, HazelcastJpaDependencyAutoConfiguration.class); this.context.refresh(); - assertThat(this.context.getBeansOfType(EntityManagerFactoryDependsOnPostProcessor.class), + assertThat(getPostProcessor(), not(hasKey("hazelcastInstanceJpaDependencyPostProcessor"))); } + private Map getPostProcessor() { + return this.context + .getBeansOfType(EntityManagerFactoryDependsOnPostProcessor.class); + } + private List getEntityManagerFactoryDependencies() { - String[] dependsOn = this.context.getBeanDefinition("entityManagerFactory").getDependsOn(); - return dependsOn != null ? Arrays.asList(dependsOn) : Collections.emptyList(); + String[] dependsOn = this.context.getBeanDefinition("entityManagerFactory") + .getDependsOn(); + return dependsOn != null ? Arrays.asList(dependsOn) + : Collections.emptyList(); } public void load(Class config) {