pull/9965/head
Andy Wilkinson 7 years ago
parent e9aeb9ad63
commit abf39915e8

@ -417,12 +417,10 @@ public class HealthIndicatorAutoConfigurationTests {
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

@ -40,10 +40,10 @@ public class WebClientCodecCustomizer implements WebClientCustomizer {
@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());
}
}

@ -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
@ -151,21 +146,19 @@ public class CacheAutoConfigurationTests {
@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
@ -206,13 +199,11 @@ public class CacheAutoConfigurationTests {
@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
@ -339,13 +330,11 @@ public class CacheAutoConfigurationTests {
@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
@ -416,11 +405,9 @@ public class CacheAutoConfigurationTests {
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
@ -448,12 +435,10 @@ public class CacheAutoConfigurationTests {
.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
@ -692,10 +677,9 @@ public class CacheAutoConfigurationTests {
.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
@ -719,10 +703,9 @@ public class CacheAutoConfigurationTests {
"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
@ -751,11 +734,10 @@ public class CacheAutoConfigurationTests {
"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();

@ -70,11 +70,9 @@ public class HazelcastAutoConfigurationClientTests {
.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
@ -83,11 +81,9 @@ public class HazelcastAutoConfigurationClientTests {
.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
@ -95,32 +91,26 @@ public class HazelcastAutoConfigurationClientTests {
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) {

@ -99,11 +99,9 @@ public class HazelcastAutoConfigurationServerTests {
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

@ -85,10 +85,8 @@ public class DataSourceAutoConfigurationTests {
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;
@ -100,11 +98,9 @@ public class DataSourceAutoConfigurationTests {
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
@ -217,10 +213,8 @@ public class DataSourceAutoConfigurationTests {
@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

@ -414,13 +414,11 @@ public class JmsAutoConfigurationTests {
@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

@ -56,9 +56,7 @@ public class HttpHandlerAutoConfigurationTests {
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

@ -55,12 +55,9 @@ public class WebServicesAutoConfigurationTests {
@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

@ -446,10 +446,9 @@ public class SysVinitLaunchScriptIT {
extends DockerCmdExecFactoryImpl {
private SpringBootDockerCmdExecFactory() {
withClientRequestFilters((requestContext) -> {
// Workaround for https://go-review.googlesource.com/#/c/3821/
requestContext.getHeaders().add("Connection", "close");
});
withClientRequestFilters((requestContext) ->
// Workaround for https://go-review.googlesource.com/#/c/3821/
requestContext.getHeaders().add("Connection", "close"));
}
private CopyToContainerCmdExec createCopyToContainerCmdExec() {

@ -138,11 +138,10 @@ class WebTestClientContextCustomizer implements ContextCustomizer {
Collection<CodecCustomizer> codecCustomizers = context
.getBeansOfType(CodecCustomizer.class).values();
if (!CollectionUtils.isEmpty(codecCustomizers)) {
clientBuilder.exchangeStrategies(
ExchangeStrategies.builder().codecs((codecs) -> {
codecCustomizers.forEach((codecCustomizer) -> codecCustomizer
.customize(codecs));
}).build());
clientBuilder.exchangeStrategies(ExchangeStrategies.builder()
.codecs((codecs) -> codecCustomizers.forEach(
(codecCustomizer) -> codecCustomizer.customize(codecs)))
.build());
}
}

@ -54,9 +54,9 @@ public abstract class AbstractApplicationContextRunnerTests<T extends AbstractAp
public void runWithSystemPropertiesShouldSetAndRemoveProperties() {
String key = "test." + UUID.randomUUID().toString();
assertThat(System.getProperties().containsKey(key)).isFalse();
get().withSystemProperties(key + "=value").run((context) -> {
assertThat(System.getProperties()).containsEntry(key, "value");
});
get().withSystemProperties(key + "=value")
.run((context) -> assertThat(System.getProperties()).containsEntry(key,
"value"));
assertThat(System.getProperties().containsKey(key)).isFalse();
}
@ -66,9 +66,8 @@ public abstract class AbstractApplicationContextRunnerTests<T extends AbstractAp
String key = "test." + UUID.randomUUID().toString();
assertThat(System.getProperties().containsKey(key)).isFalse();
get().withSystemProperties(key + "=value")
.withUserConfiguration(FailingConfig.class).run((context) -> {
assertThat(context).hasFailed();
});
.withUserConfiguration(FailingConfig.class)
.run((context) -> assertThat(context).hasFailed());
assertThat(System.getProperties().containsKey(key)).isFalse();
}
@ -79,9 +78,9 @@ public abstract class AbstractApplicationContextRunnerTests<T extends AbstractAp
System.setProperty(key, "value");
try {
assertThat(System.getProperties().getProperty(key)).isEqualTo("value");
get().withSystemProperties(key + "=newValue").run((context) -> {
assertThat(System.getProperties()).containsEntry(key, "newValue");
});
get().withSystemProperties(key + "=newValue")
.run((context) -> assertThat(System.getProperties())
.containsEntry(key, "newValue"));
assertThat(System.getProperties().getProperty(key)).isEqualTo("value");
}
finally {
@ -96,9 +95,9 @@ public abstract class AbstractApplicationContextRunnerTests<T extends AbstractAp
System.setProperty(key, "value");
try {
assertThat(System.getProperties().getProperty(key)).isEqualTo("value");
get().withSystemProperties(key + "=").run((context) -> {
assertThat(System.getProperties()).doesNotContainKey(key);
});
get().withSystemProperties(key + "=")
.run((context) -> assertThat(System.getProperties())
.doesNotContainKey(key));
assertThat(System.getProperties().getProperty(key)).isEqualTo("value");
}
finally {

Loading…
Cancel
Save