Browse Source

Polish "Improve AssertJ usage in cache config tests"

See gh-28559
pull/28569/head
Stephane Nicoll 4 years ago
parent
commit
baebf71ed7
  1. 6
      spring-context/src/test/java/org/springframework/cache/config/CacheAdviceParserTests.java
  2. 10
      spring-context/src/test/java/org/springframework/cache/config/CustomInterceptorTests.java
  3. 5
      spring-context/src/test/java/org/springframework/cache/config/EnableCachingIntegrationTests.java
  4. 10
      spring-context/src/test/java/org/springframework/cache/config/EnableCachingTests.java

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

@ -17,6 +17,7 @@ @@ -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 { @@ -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
}

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

@ -16,9 +16,13 @@ @@ -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; @@ -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 { @@ -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;

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

@ -16,8 +16,11 @@ @@ -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; @@ -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;

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

@ -17,6 +17,7 @@ @@ -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; @@ -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 { @@ -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();
}

Loading…
Cancel
Save