Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Aug 4, 2017
1 parent e9aeb9a commit abf3991
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,10 @@ public void notNeo4jHealthIndicator() throws Exception {

private ContextConsumer<AssertableApplicationContext> hasSingleHealthIndicator(
Class<? extends HealthIndicator> type) {
return (context) -> {
assertThat(context).getBeans(HealthIndicator.class).hasSize(1)
.hasValueSatisfying(new Condition<>(
(indicator) -> indicator.getClass().equals(type),
"Wrong indicator type"));
};
return (context) -> assertThat(context).getBeans(HealthIndicator.class).hasSize(1)
.hasValueSatisfying(
new Condition<>((indicator) -> indicator.getClass().equals(type),
"Wrong indicator type"));
}

@Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public WebClientCodecCustomizer(List<CodecCustomizer> codecCustomizers) {
@Override
public void customize(WebClient.Builder webClientBuilder) {
webClientBuilder
.exchangeStrategies(ExchangeStrategies.builder().codecs((codecs) -> {
this.codecCustomizers
.forEach((customizer) -> customizer.customize(codecs));
}).build());
.exchangeStrategies(ExchangeStrategies.builder()
.codecs((codecs) -> this.codecCustomizers
.forEach((customizer) -> customizer.customize(codecs)))
.build());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -105,38 +105,33 @@ public class CacheAutoConfigurationTests {

@Test
public void noEnableCaching() {
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
.run((context) -> {
assertThat(context).doesNotHaveBean(CacheManager.class);
});
this.contextRunner.withUserConfiguration(EmptyConfiguration.class).run(
(context) -> assertThat(context).doesNotHaveBean(CacheManager.class));
}

@Test
public void cacheManagerBackOff() {
this.contextRunner.withUserConfiguration(CustomCacheManagerConfiguration.class)
.run((context) -> {
assertThat(getCacheManager(context, ConcurrentMapCacheManager.class)
.getCacheNames()).containsOnly("custom1");
});
.run((context) -> assertThat(
getCacheManager(context, ConcurrentMapCacheManager.class)
.getCacheNames()).containsOnly("custom1"));
}

@Test
public void cacheManagerFromSupportBackOff() {
this.contextRunner
.withUserConfiguration(CustomCacheManagerFromSupportConfiguration.class)
.run((context) -> {
assertThat(getCacheManager(context, ConcurrentMapCacheManager.class)
.getCacheNames()).containsOnly("custom1");
});
.run((context) -> assertThat(
getCacheManager(context, ConcurrentMapCacheManager.class)
.getCacheNames()).containsOnly("custom1"));
}

@Test
public void cacheResolverFromSupportBackOff() throws Exception {
this.contextRunner
.withUserConfiguration(CustomCacheResolverFromSupportConfiguration.class)
.run((context) -> {
assertThat(context).doesNotHaveBean(CacheManager.class);
});
.run((context) -> assertThat(context)
.doesNotHaveBean(CacheManager.class));
}

@Test
Expand All @@ -151,21 +146,19 @@ public void customCacheResolverCanBeDefined() throws Exception {
@Test
public void notSupportedCachingMode() {
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
.withPropertyValues("spring.cache.type=foobar").run((context) -> {
assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class)
.hasMessageContaining(
"Failed to bind properties under 'spring.cache.type'");
});
.withPropertyValues("spring.cache.type=foobar")
.run((context) -> assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class).hasMessageContaining(
"Failed to bind properties under 'spring.cache.type'"));
}

@Test
public void simpleCacheExplicit() {
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
.withPropertyValues("spring.cache.type=simple").run((context) -> {
assertThat(getCacheManager(context, ConcurrentMapCacheManager.class)
.getCacheNames()).isEmpty();
});
.withPropertyValues("spring.cache.type=simple")
.run((context) -> assertThat(
getCacheManager(context, ConcurrentMapCacheManager.class)
.getCacheNames()).isEmpty());
}

@Test
Expand Down Expand Up @@ -206,13 +199,11 @@ public void genericCacheWithCaches() {
@Test
public void genericCacheExplicit() {
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
.withPropertyValues("spring.cache.type=generic").run((context) -> {
assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class)
.hasMessageContaining(
"No cache manager could be auto-configured")
.hasMessageContaining("GENERIC");
});
.withPropertyValues("spring.cache.type=generic")
.run((context) -> assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class)
.hasMessageContaining("No cache manager could be auto-configured")
.hasMessageContaining("GENERIC"));
}

@Test
Expand Down Expand Up @@ -339,13 +330,11 @@ public void noOpCacheExplicit() {
@Test
public void jCacheCacheNoProviderExplicit() {
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
.withPropertyValues("spring.cache.type=jcache").run((context) -> {
assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class)
.hasMessageContaining(
"No cache manager could be auto-configured")
.hasMessageContaining("JCACHE");
});
.withPropertyValues("spring.cache.type=jcache")
.run((context) -> assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class)
.hasMessageContaining("No cache manager could be auto-configured")
.hasMessageContaining("JCACHE"));
}

@Test
Expand Down Expand Up @@ -416,11 +405,9 @@ public void jCacheCacheWithUnknownProvider() {
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
.withPropertyValues("spring.cache.type=jcache",
"spring.cache.jcache.provider=" + wrongCachingProviderClassName)
.run((context) -> {
assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class)
.hasMessageContaining(wrongCachingProviderClassName);
});
.run((context) -> assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class)
.hasMessageContaining(wrongCachingProviderClassName));
}

@Test
Expand Down Expand Up @@ -448,12 +435,10 @@ public void jCacheCacheWithWrongConfig() {
.withPropertyValues("spring.cache.type=jcache",
"spring.cache.jcache.provider=" + cachingProviderFqn,
"spring.cache.jcache.config=" + configLocation)
.run((context) -> {
assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class)
.hasMessageContaining("does not exist")
.hasMessageContaining(configLocation);
});
.run((context) -> assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class)
.hasMessageContaining("does not exist")
.hasMessageContaining(configLocation));
}

@Test
Expand Down Expand Up @@ -692,10 +677,9 @@ public void infinispanCacheWithCaches() {
.withPropertyValues("spring.cache.type=infinispan",
"spring.cache.cacheNames[0]=foo",
"spring.cache.cacheNames[1]=bar")
.run((context) -> {
assertThat(getCacheManager(context, SpringEmbeddedCacheManager.class)
.getCacheNames()).containsOnly("foo", "bar");
});
.run((context) -> assertThat(
getCacheManager(context, SpringEmbeddedCacheManager.class)
.getCacheNames()).containsOnly("foo", "bar"));
}

@Test
Expand All @@ -719,10 +703,9 @@ public void infinispanAsJCacheWithCaches() {
"spring.cache.jcache.provider=" + cachingProviderClassName,
"spring.cache.cacheNames[0]=foo",
"spring.cache.cacheNames[1]=bar")
.run((context) -> {
assertThat(getCacheManager(context, JCacheCacheManager.class)
.getCacheNames()).containsOnly("foo", "bar");
});
.run((context) -> assertThat(
getCacheManager(context, JCacheCacheManager.class)
.getCacheNames()).containsOnly("foo", "bar"));
}

@Test
Expand Down Expand Up @@ -751,11 +734,10 @@ public void jCacheCacheWithCachesAndCustomizer() {
"spring.cache.jcache.provider=" + cachingProviderClassName,
"spring.cache.cacheNames[0]=foo",
"spring.cache.cacheNames[1]=bar")
.run((context) -> {
// see customizer
assertThat(getCacheManager(context, JCacheCacheManager.class)
.getCacheNames()).containsOnly("foo", "custom1");
});
.run((context) ->
// see customizer
assertThat(getCacheManager(context, JCacheCacheManager.class)
.getCacheNames()).containsOnly("foo", "custom1"));
}
finally {
Caching.getCachingProvider(cachingProviderClassName).close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,9 @@ public void systemProperty() throws IOException {
.withSystemProperties(HazelcastClientConfiguration.CONFIG_SYSTEM_PROPERTY
+ "=classpath:org/springframework/boot/autoconfigure/hazelcast/"
+ "hazelcast-client-specific.xml")
.run((context) -> {
assertThat(context).getBean(HazelcastInstance.class)
.isInstanceOf(HazelcastInstance.class)
.has(nameStartingWith("hz.client_"));
});
.run((context) -> assertThat(context).getBean(HazelcastInstance.class)
.isInstanceOf(HazelcastInstance.class)
.has(nameStartingWith("hz.client_")));
}

@Test
Expand All @@ -83,44 +81,36 @@ public void explicitConfigFile() throws IOException {
.withPropertyValues(
"spring.hazelcast.config=org/springframework/boot/autoconfigure/"
+ "hazelcast/hazelcast-client-specific.xml")
.run((context) -> {
assertThat(context).getBean(HazelcastInstance.class)
.isInstanceOf(HazelcastClientProxy.class)
.has(nameStartingWith("hz.client_"));
});
.run((context) -> assertThat(context).getBean(HazelcastInstance.class)
.isInstanceOf(HazelcastClientProxy.class)
.has(nameStartingWith("hz.client_")));
}

@Test
public void explicitConfigUrl() throws IOException {
this.contextRunner
.withPropertyValues(
"spring.hazelcast.config=hazelcast-client-default.xml")
.run((context) -> {
assertThat(context).getBean(HazelcastInstance.class)
.isInstanceOf(HazelcastClientProxy.class)
.has(nameStartingWith("hz.client_"));
});
.run((context) -> assertThat(context).getBean(HazelcastInstance.class)
.isInstanceOf(HazelcastClientProxy.class)
.has(nameStartingWith("hz.client_")));
}

@Test
public void unknownConfigFile() {
this.contextRunner
.withPropertyValues("spring.hazelcast.config=foo/bar/unknown.xml")
.run((context) -> {
assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class)
.hasMessageContaining("foo/bar/unknown.xml");
});
.run((context) -> assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class)
.hasMessageContaining("foo/bar/unknown.xml"));
}

@Test
public void clientConfigTakesPrecedence() {
this.contextRunner.withUserConfiguration(HazelcastServerAndClientConfig.class)
.withPropertyValues("spring.hazelcast.config=this-is-ignored.xml")
.run((context) -> {
assertThat(context).getBean(HazelcastInstance.class)
.isInstanceOf(HazelcastClientProxy.class);
});
.run((context) -> assertThat(context).getBean(HazelcastInstance.class)
.isInstanceOf(HazelcastClientProxy.class));
}

private Condition<HazelcastInstance> nameStartingWith(String prefix) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,9 @@ public void explicitConfigUrl() throws IOException {
public void unknownConfigFile() {
this.contextRunner
.withPropertyValues("spring.hazelcast.config=foo/bar/unknown.xml")
.run((context) -> {
assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class)
.hasMessageContaining("foo/bar/unknown.xml");
});
.run((context) -> assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class)
.hasMessageContaining("foo/bar/unknown.xml"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@ public void testBadUrl() throws Exception {
EmbeddedDatabaseConnection.override = EmbeddedDatabaseConnection.NONE;
this.contextRunner
.withPropertyValues("spring.datasource.url:jdbc:not-going-to-work")
.run((context) -> {
assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class);
});
.run((context) -> assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class));
}
finally {
EmbeddedDatabaseConnection.override = null;
Expand All @@ -100,11 +98,9 @@ public void testBadDriverClass() throws Exception {
this.contextRunner
.withPropertyValues(
"spring.datasource.driverClassName:org.none.jdbcDriver")
.run((context) -> {
assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class)
.hasMessageContaining("org.none.jdbcDriver");
});
.run((context) -> assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class)
.hasMessageContaining("org.none.jdbcDriver"));
}

@Test
Expand Down Expand Up @@ -217,10 +213,8 @@ public void testExplicitDriverClassClearsUsername() throws Exception {
@Test
public void testDefaultDataSourceCanBeOverridden() throws Exception {
this.contextRunner.withUserConfiguration(TestDataSourceConfiguration.class)
.run((context) -> {
assertThat(context).getBean(DataSource.class)
.isInstanceOf(BasicDataSource.class);
});
.run((context) -> assertThat(context).getBean(DataSource.class)
.isInstanceOf(BasicDataSource.class));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,13 +414,11 @@ public void testActiveMQOverriddenPoolAndRemoteServer() {
@Test
public void enableJmsAutomatically() throws Exception {
this.contextRunner.withUserConfiguration(NoEnableJmsConfiguration.class)
.run((context) -> {
assertThat(context)
.hasBean(
JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME)
.hasBean(
JmsListenerConfigUtils.JMS_LISTENER_ENDPOINT_REGISTRY_BEAN_NAME);
});
.run((context) -> assertThat(context)
.hasBean(
JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME)
.hasBean(
JmsListenerConfigUtils.JMS_LISTENER_ENDPOINT_REGISTRY_BEAN_NAME));
}

@Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ public void shouldNotProcessIfExistingHttpHandler() {
public void shouldConfigureHttpHandlerAnnotation() {
this.contextRunner
.withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class))
.run((context) -> {
assertThat(context).hasSingleBean(HttpHandler.class);
});
.run((context) -> assertThat(context).hasSingleBean(HttpHandler.class));
}

@Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,9 @@ public void defaultConfiguration() {
@Test
public void customPathMustBeginWithASlash() {
this.contextRunner.withPropertyValues("spring.webservices.path=invalid")
.run((context) -> {
assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class)
.hasMessageContaining(
"Failed to bind properties under 'spring.webservices'");
});
.run((context) -> assertThat(context).getFailure()
.isInstanceOf(BeanCreationException.class).hasMessageContaining(
"Failed to bind properties under 'spring.webservices'"));
}

@Test
Expand Down
Loading

0 comments on commit abf3991

Please sign in to comment.