Polish "Improve AssertJ usage in cache config tests"

See gh-28559
This commit is contained in:
Stephane Nicoll
2022-06-03 10:18:53 +02:00
parent 5ed0c848fe
commit baebf71ed7
4 changed files with 17 additions and 14 deletions

View File

@@ -17,6 +17,7 @@
package org.springframework.cache.config;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.context.support.GenericXmlApplicationContext;
@@ -31,8 +32,9 @@ class CacheAdviceParserTests {
@Test
void keyAndKeyGeneratorCannotBeSetTogether() {
assertThatThrownBy(() -> new GenericXmlApplicationContext("/org/springframework/cache/config/cache-advice-invalid.xml"))
.isInstanceOf(BeanDefinitionStoreException.class);
assertThatThrownBy(() -> new GenericXmlApplicationContext(
"/org/springframework/cache/config/cache-advice-invalid.xml")
).isInstanceOf(BeanDefinitionStoreException.class);
// TODO better exception handling
}

View File

@@ -16,9 +16,13 @@
package org.springframework.cache.config;
import java.io.IOException;
import java.util.Map;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.CacheInterceptor;
@@ -32,9 +36,6 @@ import org.springframework.context.testfixture.cache.CacheTestUtils;
import org.springframework.context.testfixture.cache.beans.CacheableService;
import org.springframework.context.testfixture.cache.beans.DefaultCacheableService;
import java.io.IOException;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -115,7 +116,8 @@ class CustomInterceptorTests {
protected Object invokeOperation(CacheOperationInvoker invoker) {
try {
return super.invokeOperation(invoker);
} catch (CacheOperationInvoker.ThrowableWrapper e) {
}
catch (CacheOperationInvoker.ThrowableWrapper e) {
Throwable original = e.getOriginal();
if (original.getClass() == UnsupportedOperationException.class) {
return 55L;

View File

@@ -16,8 +16,11 @@
package org.springframework.cache.config;
import java.util.concurrent.atomic.AtomicLong;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
@@ -34,8 +37,6 @@ import org.springframework.context.testfixture.cache.CacheTestUtils;
import org.springframework.core.env.Environment;
import org.springframework.mock.env.MockEnvironment;
import java.util.concurrent.atomic.AtomicLong;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.context.testfixture.cache.CacheTestUtils.assertCacheHit;
import static org.springframework.context.testfixture.cache.CacheTestUtils.assertCacheMiss;

View File

@@ -17,6 +17,7 @@
package org.springframework.cache.config;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
import org.springframework.cache.CacheManager;
@@ -55,9 +56,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
*/
class EnableCachingTests extends AbstractCacheAnnotationTests {
/**
* hook into superclass suite of tests
*/
/** hook into superclass suite of tests */
@Override
protected ConfigurableApplicationContext getApplicationContext() {
return new AnnotationConfigApplicationContext(EnableCachingConfig.class);
@@ -126,9 +125,8 @@ class EnableCachingTests extends AbstractCacheAnnotationTests {
void emptyConfigSupport() {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(EmptyConfigSupportConfig.class);
CacheInterceptor ci = context.getBean(CacheInterceptor.class);
assertThat(ci.getCacheResolver()).isInstanceOfSatisfying(SimpleCacheResolver.class, cacheResolver -> {
assertThat(cacheResolver.getCacheManager()).isSameAs(context.getBean(CacheManager.class));
});
assertThat(ci.getCacheResolver()).isInstanceOfSatisfying(SimpleCacheResolver.class, cacheResolver ->
assertThat(cacheResolver.getCacheManager()).isSameAs(context.getBean(CacheManager.class)));
context.close();
}