diff --git a/spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/JCacheErrorHandlerTests.java b/spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/JCacheErrorHandlerTests.java index 97978a3c167..96768a32109 100644 --- a/spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/JCacheErrorHandlerTests.java +++ b/spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/JCacheErrorHandlerTests.java @@ -36,16 +36,15 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.interceptor.CacheErrorHandler; +import org.springframework.cache.jcache.config.JCacheConfigurerSupport; import org.springframework.cache.support.SimpleCacheManager; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Role; /** * @@ -112,42 +111,27 @@ public class JCacheErrorHandlerTests { @Configuration @EnableCaching - static class Config { + static class Config extends JCacheConfigurerSupport { - @Bean(name = "jCacheInterceptor") - @Role(BeanDefinition.ROLE_INFRASTRUCTURE) - public JCacheInterceptor cacheInterceptor() { - JCacheInterceptor interceptor = new JCacheInterceptor(); - interceptor.setCacheOperationSource(cacheOperationSource()); - interceptor.setErrorHandler(errorHandler()); - return interceptor; + @Bean + @Override + public CacheManager cacheManager() { + SimpleCacheManager cacheManager = new SimpleCacheManager(); + cacheManager.setCaches(Arrays.asList(mockCache())); + return cacheManager; } @Bean + @Override public CacheErrorHandler errorHandler() { return mock(CacheErrorHandler.class); } - @Bean(name = "jCacheOperationSource") - @Role(BeanDefinition.ROLE_INFRASTRUCTURE) - public JCacheOperationSource cacheOperationSource() { - DefaultJCacheOperationSource source = new DefaultJCacheOperationSource(); - source.setCacheManager(cacheManager()); - return source; - } - @Bean public SimpleService simpleService() { return new SimpleService(); } - @Bean - public CacheManager cacheManager() { - SimpleCacheManager cacheManager = new SimpleCacheManager(); - cacheManager.setCaches(Arrays.asList(mockCache())); - return cacheManager; - } - @Bean public Cache mockCache() { Cache cache = mock(Cache.class); diff --git a/spring-context/src/test/java/org/springframework/cache/interceptor/CacheErrorHandlerTests.java b/spring-context/src/test/java/org/springframework/cache/interceptor/CacheErrorHandlerTests.java index b69990d43b7..15ec2e504a9 100644 --- a/spring-context/src/test/java/org/springframework/cache/interceptor/CacheErrorHandlerTests.java +++ b/spring-context/src/test/java/org/springframework/cache/interceptor/CacheErrorHandlerTests.java @@ -34,11 +34,11 @@ import org.junit.rules.ExpectedException; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; -import org.springframework.cache.annotation.AnnotationCacheOperationSource; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CachePut; import org.springframework.cache.annotation.Cacheable; +import org.springframework.cache.annotation.CachingConfigurerSupport; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.support.SimpleCacheManager; import org.springframework.cache.support.SimpleValueWrapper; @@ -172,28 +172,14 @@ public class CacheErrorHandlerTests { @Configuration @EnableCaching - static class Config { - - @Bean - public CacheInterceptor cacheInterceptor() { - CacheInterceptor cacheInterceptor = new CacheInterceptor(); - cacheInterceptor.setCacheManager(cacheManager()); - cacheInterceptor.setCacheOperationSources(cacheOperationSource()); - cacheInterceptor.setErrorHandler(errorHandler()); - return cacheInterceptor; - } + static class Config extends CachingConfigurerSupport { @Bean + @Override public CacheErrorHandler errorHandler() { return mock(CacheErrorHandler.class); } - @Bean - public CacheOperationSource cacheOperationSource() { - return new AnnotationCacheOperationSource(); - - } - @Bean public SimpleService simpleService() { return new SimpleService();