Skip to content

Commit abf3991

Browse files
committed
Polish
1 parent e9aeb9a commit abf3991

File tree

12 files changed

+104
-152
lines changed

12 files changed

+104
-152
lines changed

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/HealthIndicatorAutoConfigurationTests.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -417,12 +417,10 @@ public void notNeo4jHealthIndicator() throws Exception {
417417

418418
private ContextConsumer<AssertableApplicationContext> hasSingleHealthIndicator(
419419
Class<? extends HealthIndicator> type) {
420-
return (context) -> {
421-
assertThat(context).getBeans(HealthIndicator.class).hasSize(1)
422-
.hasValueSatisfying(new Condition<>(
423-
(indicator) -> indicator.getClass().equals(type),
424-
"Wrong indicator type"));
425-
};
420+
return (context) -> assertThat(context).getBeans(HealthIndicator.class).hasSize(1)
421+
.hasValueSatisfying(
422+
new Condition<>((indicator) -> indicator.getClass().equals(type),
423+
"Wrong indicator type"));
426424
}
427425

428426
@Configuration

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/function/client/WebClientCodecCustomizer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public WebClientCodecCustomizer(List<CodecCustomizer> codecCustomizers) {
4040
@Override
4141
public void customize(WebClient.Builder webClientBuilder) {
4242
webClientBuilder
43-
.exchangeStrategies(ExchangeStrategies.builder().codecs((codecs) -> {
44-
this.codecCustomizers
45-
.forEach((customizer) -> customizer.customize(codecs));
46-
}).build());
43+
.exchangeStrategies(ExchangeStrategies.builder()
44+
.codecs((codecs) -> this.codecCustomizers
45+
.forEach((customizer) -> customizer.customize(codecs)))
46+
.build());
4747
}
4848

4949
}

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java

Lines changed: 45 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -105,38 +105,33 @@ public class CacheAutoConfigurationTests {
105105

106106
@Test
107107
public void noEnableCaching() {
108-
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
109-
.run((context) -> {
110-
assertThat(context).doesNotHaveBean(CacheManager.class);
111-
});
108+
this.contextRunner.withUserConfiguration(EmptyConfiguration.class).run(
109+
(context) -> assertThat(context).doesNotHaveBean(CacheManager.class));
112110
}
113111

114112
@Test
115113
public void cacheManagerBackOff() {
116114
this.contextRunner.withUserConfiguration(CustomCacheManagerConfiguration.class)
117-
.run((context) -> {
118-
assertThat(getCacheManager(context, ConcurrentMapCacheManager.class)
119-
.getCacheNames()).containsOnly("custom1");
120-
});
115+
.run((context) -> assertThat(
116+
getCacheManager(context, ConcurrentMapCacheManager.class)
117+
.getCacheNames()).containsOnly("custom1"));
121118
}
122119

123120
@Test
124121
public void cacheManagerFromSupportBackOff() {
125122
this.contextRunner
126123
.withUserConfiguration(CustomCacheManagerFromSupportConfiguration.class)
127-
.run((context) -> {
128-
assertThat(getCacheManager(context, ConcurrentMapCacheManager.class)
129-
.getCacheNames()).containsOnly("custom1");
130-
});
124+
.run((context) -> assertThat(
125+
getCacheManager(context, ConcurrentMapCacheManager.class)
126+
.getCacheNames()).containsOnly("custom1"));
131127
}
132128

133129
@Test
134130
public void cacheResolverFromSupportBackOff() throws Exception {
135131
this.contextRunner
136132
.withUserConfiguration(CustomCacheResolverFromSupportConfiguration.class)
137-
.run((context) -> {
138-
assertThat(context).doesNotHaveBean(CacheManager.class);
139-
});
133+
.run((context) -> assertThat(context)
134+
.doesNotHaveBean(CacheManager.class));
140135
}
141136

142137
@Test
@@ -151,21 +146,19 @@ public void customCacheResolverCanBeDefined() throws Exception {
151146
@Test
152147
public void notSupportedCachingMode() {
153148
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
154-
.withPropertyValues("spring.cache.type=foobar").run((context) -> {
155-
assertThat(context).getFailure()
156-
.isInstanceOf(BeanCreationException.class)
157-
.hasMessageContaining(
158-
"Failed to bind properties under 'spring.cache.type'");
159-
});
149+
.withPropertyValues("spring.cache.type=foobar")
150+
.run((context) -> assertThat(context).getFailure()
151+
.isInstanceOf(BeanCreationException.class).hasMessageContaining(
152+
"Failed to bind properties under 'spring.cache.type'"));
160153
}
161154

162155
@Test
163156
public void simpleCacheExplicit() {
164157
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
165-
.withPropertyValues("spring.cache.type=simple").run((context) -> {
166-
assertThat(getCacheManager(context, ConcurrentMapCacheManager.class)
167-
.getCacheNames()).isEmpty();
168-
});
158+
.withPropertyValues("spring.cache.type=simple")
159+
.run((context) -> assertThat(
160+
getCacheManager(context, ConcurrentMapCacheManager.class)
161+
.getCacheNames()).isEmpty());
169162
}
170163

171164
@Test
@@ -206,13 +199,11 @@ public void genericCacheWithCaches() {
206199
@Test
207200
public void genericCacheExplicit() {
208201
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
209-
.withPropertyValues("spring.cache.type=generic").run((context) -> {
210-
assertThat(context).getFailure()
211-
.isInstanceOf(BeanCreationException.class)
212-
.hasMessageContaining(
213-
"No cache manager could be auto-configured")
214-
.hasMessageContaining("GENERIC");
215-
});
202+
.withPropertyValues("spring.cache.type=generic")
203+
.run((context) -> assertThat(context).getFailure()
204+
.isInstanceOf(BeanCreationException.class)
205+
.hasMessageContaining("No cache manager could be auto-configured")
206+
.hasMessageContaining("GENERIC"));
216207
}
217208

218209
@Test
@@ -339,13 +330,11 @@ public void noOpCacheExplicit() {
339330
@Test
340331
public void jCacheCacheNoProviderExplicit() {
341332
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
342-
.withPropertyValues("spring.cache.type=jcache").run((context) -> {
343-
assertThat(context).getFailure()
344-
.isInstanceOf(BeanCreationException.class)
345-
.hasMessageContaining(
346-
"No cache manager could be auto-configured")
347-
.hasMessageContaining("JCACHE");
348-
});
333+
.withPropertyValues("spring.cache.type=jcache")
334+
.run((context) -> assertThat(context).getFailure()
335+
.isInstanceOf(BeanCreationException.class)
336+
.hasMessageContaining("No cache manager could be auto-configured")
337+
.hasMessageContaining("JCACHE"));
349338
}
350339

351340
@Test
@@ -416,11 +405,9 @@ public void jCacheCacheWithUnknownProvider() {
416405
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
417406
.withPropertyValues("spring.cache.type=jcache",
418407
"spring.cache.jcache.provider=" + wrongCachingProviderClassName)
419-
.run((context) -> {
420-
assertThat(context).getFailure()
421-
.isInstanceOf(BeanCreationException.class)
422-
.hasMessageContaining(wrongCachingProviderClassName);
423-
});
408+
.run((context) -> assertThat(context).getFailure()
409+
.isInstanceOf(BeanCreationException.class)
410+
.hasMessageContaining(wrongCachingProviderClassName));
424411
}
425412

426413
@Test
@@ -448,12 +435,10 @@ public void jCacheCacheWithWrongConfig() {
448435
.withPropertyValues("spring.cache.type=jcache",
449436
"spring.cache.jcache.provider=" + cachingProviderFqn,
450437
"spring.cache.jcache.config=" + configLocation)
451-
.run((context) -> {
452-
assertThat(context).getFailure()
453-
.isInstanceOf(BeanCreationException.class)
454-
.hasMessageContaining("does not exist")
455-
.hasMessageContaining(configLocation);
456-
});
438+
.run((context) -> assertThat(context).getFailure()
439+
.isInstanceOf(BeanCreationException.class)
440+
.hasMessageContaining("does not exist")
441+
.hasMessageContaining(configLocation));
457442
}
458443

459444
@Test
@@ -692,10 +677,9 @@ public void infinispanCacheWithCaches() {
692677
.withPropertyValues("spring.cache.type=infinispan",
693678
"spring.cache.cacheNames[0]=foo",
694679
"spring.cache.cacheNames[1]=bar")
695-
.run((context) -> {
696-
assertThat(getCacheManager(context, SpringEmbeddedCacheManager.class)
697-
.getCacheNames()).containsOnly("foo", "bar");
698-
});
680+
.run((context) -> assertThat(
681+
getCacheManager(context, SpringEmbeddedCacheManager.class)
682+
.getCacheNames()).containsOnly("foo", "bar"));
699683
}
700684

701685
@Test
@@ -719,10 +703,9 @@ public void infinispanAsJCacheWithCaches() {
719703
"spring.cache.jcache.provider=" + cachingProviderClassName,
720704
"spring.cache.cacheNames[0]=foo",
721705
"spring.cache.cacheNames[1]=bar")
722-
.run((context) -> {
723-
assertThat(getCacheManager(context, JCacheCacheManager.class)
724-
.getCacheNames()).containsOnly("foo", "bar");
725-
});
706+
.run((context) -> assertThat(
707+
getCacheManager(context, JCacheCacheManager.class)
708+
.getCacheNames()).containsOnly("foo", "bar"));
726709
}
727710

728711
@Test
@@ -751,11 +734,10 @@ public void jCacheCacheWithCachesAndCustomizer() {
751734
"spring.cache.jcache.provider=" + cachingProviderClassName,
752735
"spring.cache.cacheNames[0]=foo",
753736
"spring.cache.cacheNames[1]=bar")
754-
.run((context) -> {
755-
// see customizer
756-
assertThat(getCacheManager(context, JCacheCacheManager.class)
757-
.getCacheNames()).containsOnly("foo", "custom1");
758-
});
737+
.run((context) ->
738+
// see customizer
739+
assertThat(getCacheManager(context, JCacheCacheManager.class)
740+
.getCacheNames()).containsOnly("foo", "custom1"));
759741
}
760742
finally {
761743
Caching.getCachingProvider(cachingProviderClassName).close();

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationClientTests.java

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,9 @@ public void systemProperty() throws IOException {
7070
.withSystemProperties(HazelcastClientConfiguration.CONFIG_SYSTEM_PROPERTY
7171
+ "=classpath:org/springframework/boot/autoconfigure/hazelcast/"
7272
+ "hazelcast-client-specific.xml")
73-
.run((context) -> {
74-
assertThat(context).getBean(HazelcastInstance.class)
75-
.isInstanceOf(HazelcastInstance.class)
76-
.has(nameStartingWith("hz.client_"));
77-
});
73+
.run((context) -> assertThat(context).getBean(HazelcastInstance.class)
74+
.isInstanceOf(HazelcastInstance.class)
75+
.has(nameStartingWith("hz.client_")));
7876
}
7977

8078
@Test
@@ -83,44 +81,36 @@ public void explicitConfigFile() throws IOException {
8381
.withPropertyValues(
8482
"spring.hazelcast.config=org/springframework/boot/autoconfigure/"
8583
+ "hazelcast/hazelcast-client-specific.xml")
86-
.run((context) -> {
87-
assertThat(context).getBean(HazelcastInstance.class)
88-
.isInstanceOf(HazelcastClientProxy.class)
89-
.has(nameStartingWith("hz.client_"));
90-
});
84+
.run((context) -> assertThat(context).getBean(HazelcastInstance.class)
85+
.isInstanceOf(HazelcastClientProxy.class)
86+
.has(nameStartingWith("hz.client_")));
9187
}
9288

9389
@Test
9490
public void explicitConfigUrl() throws IOException {
9591
this.contextRunner
9692
.withPropertyValues(
9793
"spring.hazelcast.config=hazelcast-client-default.xml")
98-
.run((context) -> {
99-
assertThat(context).getBean(HazelcastInstance.class)
100-
.isInstanceOf(HazelcastClientProxy.class)
101-
.has(nameStartingWith("hz.client_"));
102-
});
94+
.run((context) -> assertThat(context).getBean(HazelcastInstance.class)
95+
.isInstanceOf(HazelcastClientProxy.class)
96+
.has(nameStartingWith("hz.client_")));
10397
}
10498

10599
@Test
106100
public void unknownConfigFile() {
107101
this.contextRunner
108102
.withPropertyValues("spring.hazelcast.config=foo/bar/unknown.xml")
109-
.run((context) -> {
110-
assertThat(context).getFailure()
111-
.isInstanceOf(BeanCreationException.class)
112-
.hasMessageContaining("foo/bar/unknown.xml");
113-
});
103+
.run((context) -> assertThat(context).getFailure()
104+
.isInstanceOf(BeanCreationException.class)
105+
.hasMessageContaining("foo/bar/unknown.xml"));
114106
}
115107

116108
@Test
117109
public void clientConfigTakesPrecedence() {
118110
this.contextRunner.withUserConfiguration(HazelcastServerAndClientConfig.class)
119111
.withPropertyValues("spring.hazelcast.config=this-is-ignored.xml")
120-
.run((context) -> {
121-
assertThat(context).getBean(HazelcastInstance.class)
122-
.isInstanceOf(HazelcastClientProxy.class);
123-
});
112+
.run((context) -> assertThat(context).getBean(HazelcastInstance.class)
113+
.isInstanceOf(HazelcastClientProxy.class));
124114
}
125115

126116
private Condition<HazelcastInstance> nameStartingWith(String prefix) {

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationServerTests.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,9 @@ public void explicitConfigUrl() throws IOException {
9999
public void unknownConfigFile() {
100100
this.contextRunner
101101
.withPropertyValues("spring.hazelcast.config=foo/bar/unknown.xml")
102-
.run((context) -> {
103-
assertThat(context).getFailure()
104-
.isInstanceOf(BeanCreationException.class)
105-
.hasMessageContaining("foo/bar/unknown.xml");
106-
});
102+
.run((context) -> assertThat(context).getFailure()
103+
.isInstanceOf(BeanCreationException.class)
104+
.hasMessageContaining("foo/bar/unknown.xml"));
107105
}
108106

109107
@Test

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfigurationTests.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,8 @@ public void testBadUrl() throws Exception {
8585
EmbeddedDatabaseConnection.override = EmbeddedDatabaseConnection.NONE;
8686
this.contextRunner
8787
.withPropertyValues("spring.datasource.url:jdbc:not-going-to-work")
88-
.run((context) -> {
89-
assertThat(context).getFailure()
90-
.isInstanceOf(BeanCreationException.class);
91-
});
88+
.run((context) -> assertThat(context).getFailure()
89+
.isInstanceOf(BeanCreationException.class));
9290
}
9391
finally {
9492
EmbeddedDatabaseConnection.override = null;
@@ -100,11 +98,9 @@ public void testBadDriverClass() throws Exception {
10098
this.contextRunner
10199
.withPropertyValues(
102100
"spring.datasource.driverClassName:org.none.jdbcDriver")
103-
.run((context) -> {
104-
assertThat(context).getFailure()
105-
.isInstanceOf(BeanCreationException.class)
106-
.hasMessageContaining("org.none.jdbcDriver");
107-
});
101+
.run((context) -> assertThat(context).getFailure()
102+
.isInstanceOf(BeanCreationException.class)
103+
.hasMessageContaining("org.none.jdbcDriver"));
108104
}
109105

110106
@Test
@@ -217,10 +213,8 @@ public void testExplicitDriverClassClearsUsername() throws Exception {
217213
@Test
218214
public void testDefaultDataSourceCanBeOverridden() throws Exception {
219215
this.contextRunner.withUserConfiguration(TestDataSourceConfiguration.class)
220-
.run((context) -> {
221-
assertThat(context).getBean(DataSource.class)
222-
.isInstanceOf(BasicDataSource.class);
223-
});
216+
.run((context) -> assertThat(context).getBean(DataSource.class)
217+
.isInstanceOf(BasicDataSource.class));
224218
}
225219

226220
@Test

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/JmsAutoConfigurationTests.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -414,13 +414,11 @@ public void testActiveMQOverriddenPoolAndRemoteServer() {
414414
@Test
415415
public void enableJmsAutomatically() throws Exception {
416416
this.contextRunner.withUserConfiguration(NoEnableJmsConfiguration.class)
417-
.run((context) -> {
418-
assertThat(context)
419-
.hasBean(
420-
JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME)
421-
.hasBean(
422-
JmsListenerConfigUtils.JMS_LISTENER_ENDPOINT_REGISTRY_BEAN_NAME);
423-
});
417+
.run((context) -> assertThat(context)
418+
.hasBean(
419+
JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME)
420+
.hasBean(
421+
JmsListenerConfigUtils.JMS_LISTENER_ENDPOINT_REGISTRY_BEAN_NAME));
424422
}
425423

426424
@Configuration

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfigurationTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ public void shouldNotProcessIfExistingHttpHandler() {
5656
public void shouldConfigureHttpHandlerAnnotation() {
5757
this.contextRunner
5858
.withConfiguration(AutoConfigurations.of(WebFluxAutoConfiguration.class))
59-
.run((context) -> {
60-
assertThat(context).hasSingleBean(HttpHandler.class);
61-
});
59+
.run((context) -> assertThat(context).hasSingleBean(HttpHandler.class));
6260
}
6361

6462
@Configuration

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfigurationTests.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,9 @@ public void defaultConfiguration() {
5555
@Test
5656
public void customPathMustBeginWithASlash() {
5757
this.contextRunner.withPropertyValues("spring.webservices.path=invalid")
58-
.run((context) -> {
59-
assertThat(context).getFailure()
60-
.isInstanceOf(BeanCreationException.class)
61-
.hasMessageContaining(
62-
"Failed to bind properties under 'spring.webservices'");
63-
});
58+
.run((context) -> assertThat(context).getFailure()
59+
.isInstanceOf(BeanCreationException.class).hasMessageContaining(
60+
"Failed to bind properties under 'spring.webservices'"));
6461
}
6562

6663
@Test

0 commit comments

Comments
 (0)