Skip to content

Commit baebf71

Browse files
committed
Polish "Improve AssertJ usage in cache config tests"
See gh-28559
1 parent 5ed0c84 commit baebf71

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

spring-context/src/test/java/org/springframework/cache/config/CacheAdviceParserTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.cache.config;
1818

1919
import org.junit.jupiter.api.Test;
20+
2021
import org.springframework.beans.factory.BeanDefinitionStoreException;
2122
import org.springframework.context.support.GenericXmlApplicationContext;
2223

@@ -31,8 +32,9 @@ class CacheAdviceParserTests {
3132

3233
@Test
3334
void keyAndKeyGeneratorCannotBeSetTogether() {
34-
assertThatThrownBy(() -> new GenericXmlApplicationContext("/org/springframework/cache/config/cache-advice-invalid.xml"))
35-
.isInstanceOf(BeanDefinitionStoreException.class);
35+
assertThatThrownBy(() -> new GenericXmlApplicationContext(
36+
"/org/springframework/cache/config/cache-advice-invalid.xml")
37+
).isInstanceOf(BeanDefinitionStoreException.class);
3638
// TODO better exception handling
3739
}
3840

spring-context/src/test/java/org/springframework/cache/config/CustomInterceptorTests.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616

1717
package org.springframework.cache.config;
1818

19+
import java.io.IOException;
20+
import java.util.Map;
21+
1922
import org.junit.jupiter.api.AfterEach;
2023
import org.junit.jupiter.api.BeforeEach;
2124
import org.junit.jupiter.api.Test;
25+
2226
import org.springframework.cache.CacheManager;
2327
import org.springframework.cache.annotation.EnableCaching;
2428
import org.springframework.cache.interceptor.CacheInterceptor;
@@ -32,9 +36,6 @@
3236
import org.springframework.context.testfixture.cache.beans.CacheableService;
3337
import org.springframework.context.testfixture.cache.beans.DefaultCacheableService;
3438

35-
import java.io.IOException;
36-
import java.util.Map;
37-
3839
import static org.assertj.core.api.Assertions.assertThat;
3940
import static org.assertj.core.api.Assertions.assertThatThrownBy;
4041

@@ -115,7 +116,8 @@ static class TestCacheInterceptor extends CacheInterceptor {
115116
protected Object invokeOperation(CacheOperationInvoker invoker) {
116117
try {
117118
return super.invokeOperation(invoker);
118-
} catch (CacheOperationInvoker.ThrowableWrapper e) {
119+
}
120+
catch (CacheOperationInvoker.ThrowableWrapper e) {
119121
Throwable original = e.getOriginal();
120122
if (original.getClass() == UnsupportedOperationException.class) {
121123
return 55L;

spring-context/src/test/java/org/springframework/cache/config/EnableCachingIntegrationTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616

1717
package org.springframework.cache.config;
1818

19+
import java.util.concurrent.atomic.AtomicLong;
20+
1921
import org.junit.jupiter.api.AfterEach;
2022
import org.junit.jupiter.api.Test;
23+
2124
import org.springframework.beans.factory.annotation.Autowired;
2225
import org.springframework.cache.Cache;
2326
import org.springframework.cache.CacheManager;
@@ -34,8 +37,6 @@
3437
import org.springframework.core.env.Environment;
3538
import org.springframework.mock.env.MockEnvironment;
3639

37-
import java.util.concurrent.atomic.AtomicLong;
38-
3940
import static org.assertj.core.api.Assertions.assertThat;
4041
import static org.springframework.context.testfixture.cache.CacheTestUtils.assertCacheHit;
4142
import static org.springframework.context.testfixture.cache.CacheTestUtils.assertCacheMiss;

spring-context/src/test/java/org/springframework/cache/config/EnableCachingTests.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.cache.config;
1818

1919
import org.junit.jupiter.api.Test;
20+
2021
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
2122
import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
2223
import org.springframework.cache.CacheManager;
@@ -55,9 +56,7 @@
5556
*/
5657
class EnableCachingTests extends AbstractCacheAnnotationTests {
5758

58-
/**
59-
* hook into superclass suite of tests
60-
*/
59+
/** hook into superclass suite of tests */
6160
@Override
6261
protected ConfigurableApplicationContext getApplicationContext() {
6362
return new AnnotationConfigApplicationContext(EnableCachingConfig.class);
@@ -126,9 +125,8 @@ void noCacheManagerBeans() {
126125
void emptyConfigSupport() {
127126
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(EmptyConfigSupportConfig.class);
128127
CacheInterceptor ci = context.getBean(CacheInterceptor.class);
129-
assertThat(ci.getCacheResolver()).isInstanceOfSatisfying(SimpleCacheResolver.class, cacheResolver -> {
130-
assertThat(cacheResolver.getCacheManager()).isSameAs(context.getBean(CacheManager.class));
131-
});
128+
assertThat(ci.getCacheResolver()).isInstanceOfSatisfying(SimpleCacheResolver.class, cacheResolver ->
129+
assertThat(cacheResolver.getCacheManager()).isSameAs(context.getBean(CacheManager.class)));
132130
context.close();
133131
}
134132

0 commit comments

Comments
 (0)