diff --git a/spring-aspects/src/test/java/org/springframework/cache/aspectj/AspectJAnnotationTests.java b/spring-aspects/src/test/java/org/springframework/cache/aspectj/AspectJCacheAnnotationTests.java similarity index 80% rename from spring-aspects/src/test/java/org/springframework/cache/aspectj/AspectJAnnotationTests.java rename to spring-aspects/src/test/java/org/springframework/cache/aspectj/AspectJCacheAnnotationTests.java index 70036f6fc40..df81ab51267 100644 --- a/spring-aspects/src/test/java/org/springframework/cache/aspectj/AspectJAnnotationTests.java +++ b/spring-aspects/src/test/java/org/springframework/cache/aspectj/AspectJCacheAnnotationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ import org.junit.Assert; import org.junit.Test; import org.springframework.cache.Cache; -import org.springframework.cache.config.AbstractAnnotationTests; +import org.springframework.cache.config.AbstractCacheAnnotationTests; import org.springframework.cache.config.CacheableService; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.GenericXmlApplicationContext; @@ -30,17 +30,18 @@ import static org.junit.Assert.*; /** * @author Costin Leau */ -public class AspectJAnnotationTests extends AbstractAnnotationTests { - +public class AspectJCacheAnnotationTests extends AbstractCacheAnnotationTests { @Override protected ConfigurableApplicationContext getApplicationContext() { - return new GenericXmlApplicationContext("/org/springframework/cache/config/annotation-cache-aspectj.xml"); + return new GenericXmlApplicationContext( + "/org/springframework/cache/config/annotation-cache-aspectj.xml"); } @Test public void testKeyStrategy() throws Exception { - AnnotationCacheAspect aspect = ctx.getBean("org.springframework.cache.config.internalCacheAspect", AnnotationCacheAspect.class); + AnnotationCacheAspect aspect = ctx.getBean( + "org.springframework.cache.config.internalCacheAspect", AnnotationCacheAspect.class); Assert.assertSame(ctx.getBean("keyGenerator"), aspect.getKeyGenerator()); } diff --git a/spring-context-support/src/test/java/org/springframework/cache/AbstractCacheTests.java b/spring-context-support/src/test/java/org/springframework/cache/AbstractCacheTests.java index cf550a9bd82..97e33a010a1 100644 --- a/spring-context-support/src/test/java/org/springframework/cache/AbstractCacheTests.java +++ b/spring-context-support/src/test/java/org/springframework/cache/AbstractCacheTests.java @@ -33,6 +33,7 @@ public abstract class AbstractCacheTests { protected abstract Object getNativeCache(); + @Test public void testCacheName() throws Exception { assertEquals(CACHE_NAME, getCache().getName()); @@ -105,6 +106,7 @@ public abstract class AbstractCacheTests { assertNull(cache.get("enescu")); } + private String createRandomKey() { return UUID.randomUUID().toString(); } diff --git a/spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheAnnotationTests.java b/spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheAnnotationTests.java index f08a357ff19..8b207f0262f 100644 --- a/spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheAnnotationTests.java +++ b/spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheAnnotationTests.java @@ -28,7 +28,7 @@ import org.junit.Test; import org.springframework.cache.annotation.CachingConfigurerSupport; import org.springframework.cache.annotation.EnableCaching; -import org.springframework.cache.config.AbstractAnnotationTests; +import org.springframework.cache.config.AbstractCacheAnnotationTests; import org.springframework.cache.config.AnnotatedClassCacheableService; import org.springframework.cache.config.CacheableService; import org.springframework.cache.config.DefaultCacheableService; @@ -43,7 +43,7 @@ import org.springframework.context.annotation.Configuration; /** * @author Stephane Nicoll */ -public class JCacheEhCacheAnnotationTests extends AbstractAnnotationTests { +public class JCacheEhCacheAnnotationTests extends AbstractCacheAnnotationTests { private CacheManager jCacheManager; @@ -58,6 +58,10 @@ public class JCacheEhCacheAnnotationTests extends AbstractAnnotationTests { return context; } + protected CachingProvider getCachingProvider() { + return Caching.getCachingProvider(); + } + @After public void shutdown() { if (jCacheManager != null) { @@ -73,11 +77,6 @@ public class JCacheEhCacheAnnotationTests extends AbstractAnnotationTests { } - protected CachingProvider getCachingProvider() { - return Caching.getCachingProvider(); - } - - @Configuration @EnableCaching static class EnableCachingConfig extends CachingConfigurerSupport { diff --git a/spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheTests.java b/spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheApiTests.java similarity index 89% rename from spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheTests.java rename to spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheApiTests.java index d5ee79c9cf1..bfb5bce39f7 100644 --- a/spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheTests.java +++ b/spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheApiTests.java @@ -30,7 +30,7 @@ import org.springframework.cache.AbstractCacheTests; /** * @author Stephane Nicoll */ -public class JCacheEhCacheTests extends AbstractCacheTests { +public class JCacheEhCacheApiTests extends AbstractCacheTests { private CacheManager cacheManager; @@ -38,19 +38,27 @@ public class JCacheEhCacheTests extends AbstractCacheTests { private JCacheCache cache; + @Before - public void setUp() { + public void setup() { this.cacheManager = getCachingProvider().getCacheManager(); this.cacheManager.createCache(CACHE_NAME, new MutableConfiguration<>()); this.nativeCache = this.cacheManager.getCache(CACHE_NAME); this.cache = new JCacheCache(this.nativeCache); } - @After - public void shutdownCacheManager() { - this.cacheManager.close(); + protected CachingProvider getCachingProvider() { + return Caching.getCachingProvider(); } + @After + public void shutdown() { + if (this.cacheManager != null) { + this.cacheManager.close(); + } + } + + @Override protected JCacheCache getCache() { return this.cache; @@ -61,8 +69,4 @@ public class JCacheEhCacheTests extends AbstractCacheTests { return this.nativeCache; } - protected CachingProvider getCachingProvider() { - return Caching.getCachingProvider(); - } - } diff --git a/spring-context/src/test/java/org/springframework/cache/config/AbstractAnnotationTests.java b/spring-context/src/test/java/org/springframework/cache/config/AbstractCacheAnnotationTests.java similarity index 97% rename from spring-context/src/test/java/org/springframework/cache/config/AbstractAnnotationTests.java rename to spring-context/src/test/java/org/springframework/cache/config/AbstractCacheAnnotationTests.java index e130596ec26..73b9d4d69a2 100644 --- a/spring-context/src/test/java/org/springframework/cache/config/AbstractAnnotationTests.java +++ b/spring-context/src/test/java/org/springframework/cache/config/AbstractCacheAnnotationTests.java @@ -34,14 +34,14 @@ import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; /** - * Abstract annotation test (containing several reusable methods). + * Abstract cache annotation tests (containing several reusable methods). * * @author Costin Leau * @author Chris Beams * @author Phillip Webb * @author Stephane Nicoll */ -public abstract class AbstractAnnotationTests { +public abstract class AbstractCacheAnnotationTests { protected ConfigurableApplicationContext ctx; @@ -72,7 +72,7 @@ public abstract class AbstractAnnotationTests { } @After - public void tearDown() { + public void close() { if (ctx != null) { ctx.close(); } @@ -128,7 +128,8 @@ public abstract class AbstractAnnotationTests { assertSame(r1, r2); try { service.evictEarly(o1); - } catch (RuntimeException ex) { + } + catch (RuntimeException ex) { // expected } @@ -147,7 +148,8 @@ public abstract class AbstractAnnotationTests { assertSame(r1, r2); try { service.evictWithException(o1); - } catch (RuntimeException ex) { + } + catch (RuntimeException ex) { // expected } // exception occurred, eviction skipped, data should still be in the cache @@ -179,7 +181,8 @@ public abstract class AbstractAnnotationTests { try { service.invalidateEarly(o1, null); - } catch (Exception ex) { + } + catch (Exception ex) { // expected } Object r3 = service.cache(o1); @@ -290,7 +293,8 @@ public abstract class AbstractAnnotationTests { try { service.throwChecked(arg); fail("Excepted exception"); - } catch (Exception ex) { + } + catch (Exception ex) { assertEquals("Wrong exception type", IOException.class, ex.getClass()); assertEquals(arg, ex.getMessage()); } @@ -300,7 +304,8 @@ public abstract class AbstractAnnotationTests { try { service.throwUnchecked(Long.valueOf(1)); fail("Excepted exception"); - } catch (RuntimeException ex) { + } + catch (RuntimeException ex) { assertEquals("Wrong exception type", UnsupportedOperationException.class, ex.getClass()); assertEquals("1", ex.getMessage()); } @@ -623,7 +628,8 @@ public abstract class AbstractAnnotationTests { Object param = new Object(); cs.unknownCustomKeyGenerator(param); fail("should have failed with NoSuchBeanDefinitionException"); - } catch (NoSuchBeanDefinitionException e) { + } + catch (NoSuchBeanDefinitionException ex) { // expected } } @@ -645,7 +651,8 @@ public abstract class AbstractAnnotationTests { Object param = new Object(); cs.unknownCustomCacheManager(param); fail("should have failed with NoSuchBeanDefinitionException"); - } catch (NoSuchBeanDefinitionException e) { + } + catch (NoSuchBeanDefinitionException ex) { // expected } } diff --git a/spring-context/src/test/java/org/springframework/cache/config/AnnotationTests.java b/spring-context/src/test/java/org/springframework/cache/config/AnnotationDrivenCacheConfigTests.java similarity index 92% rename from spring-context/src/test/java/org/springframework/cache/config/AnnotationTests.java rename to spring-context/src/test/java/org/springframework/cache/config/AnnotationDrivenCacheConfigTests.java index 8514c3ded2f..4d4137fd1be 100644 --- a/spring-context/src/test/java/org/springframework/cache/config/AnnotationTests.java +++ b/spring-context/src/test/java/org/springframework/cache/config/AnnotationDrivenCacheConfigTests.java @@ -23,7 +23,7 @@ import org.springframework.context.support.GenericXmlApplicationContext; * @author Costin Leau * @author Chris Beams */ -public class AnnotationTests extends AbstractAnnotationTests { +public class AnnotationDrivenCacheConfigTests extends AbstractCacheAnnotationTests { @Override protected ConfigurableApplicationContext getApplicationContext() { diff --git a/spring-context/src/test/java/org/springframework/cache/config/AnnotationNamespaceDrivenTests.java b/spring-context/src/test/java/org/springframework/cache/config/AnnotationNamespaceDrivenTests.java index 6e853507de3..ee78edcfb38 100644 --- a/spring-context/src/test/java/org/springframework/cache/config/AnnotationNamespaceDrivenTests.java +++ b/spring-context/src/test/java/org/springframework/cache/config/AnnotationNamespaceDrivenTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,7 @@ import static org.junit.Assert.*; * @author Chris Beams * @author Stephane Nicoll */ -public class AnnotationNamespaceDrivenTests extends AbstractAnnotationTests { +public class AnnotationNamespaceDrivenTests extends AbstractCacheAnnotationTests { @Override protected ConfigurableApplicationContext getApplicationContext() { @@ -40,8 +40,8 @@ public class AnnotationNamespaceDrivenTests extends AbstractAnnotationTests { @Test public void testKeyStrategy() { - CacheInterceptor ci = ctx.getBean("org.springframework.cache.interceptor.CacheInterceptor#0", - CacheInterceptor.class); + CacheInterceptor ci = ctx.getBean( + "org.springframework.cache.interceptor.CacheInterceptor#0", CacheInterceptor.class); assertSame(ctx.getBean("keyGenerator"), ci.getKeyGenerator()); } @@ -67,8 +67,9 @@ public class AnnotationNamespaceDrivenTests extends AbstractAnnotationTests { @Test public void testCacheErrorHandler() { - CacheInterceptor ci = ctx.getBean("org.springframework.cache.interceptor.CacheInterceptor#0", - CacheInterceptor.class); + CacheInterceptor ci = ctx.getBean( + "org.springframework.cache.interceptor.CacheInterceptor#0", CacheInterceptor.class); assertSame(ctx.getBean("errorHandler", CacheErrorHandler.class), ci.getErrorHandler()); } + } diff --git a/spring-context/src/test/java/org/springframework/cache/config/CacheAdviceNamespaceTests.java b/spring-context/src/test/java/org/springframework/cache/config/CacheAdviceNamespaceTests.java index 1c2746d653a..183db521f24 100644 --- a/spring-context/src/test/java/org/springframework/cache/config/CacheAdviceNamespaceTests.java +++ b/spring-context/src/test/java/org/springframework/cache/config/CacheAdviceNamespaceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ import org.springframework.context.support.GenericXmlApplicationContext; * @author Costin Leau * @author Chris Beams */ -public class CacheAdviceNamespaceTests extends AbstractAnnotationTests { +public class CacheAdviceNamespaceTests extends AbstractCacheAnnotationTests { @Override protected ConfigurableApplicationContext getApplicationContext() { diff --git a/spring-context/src/test/java/org/springframework/cache/config/EnableCachingTests.java b/spring-context/src/test/java/org/springframework/cache/config/EnableCachingTests.java index d14ac0cedaa..4fcd044444f 100644 --- a/spring-context/src/test/java/org/springframework/cache/config/EnableCachingTests.java +++ b/spring-context/src/test/java/org/springframework/cache/config/EnableCachingTests.java @@ -44,7 +44,7 @@ import static org.junit.Assert.*; * @author Chris Beams * @author Stephane Nicoll */ -public class EnableCachingTests extends AbstractAnnotationTests { +public class EnableCachingTests extends AbstractCacheAnnotationTests { /** hook into superclass suite of tests */ @Override diff --git a/spring-test/src/test/java/org/springframework/cache/jcache/JCacheEhCache3AnnotationTests.java b/spring-test/src/test/java/org/springframework/cache/jcache/JCacheEhCache3AnnotationTests.java index 895df982a0e..86f0f76d0e3 100644 --- a/spring-test/src/test/java/org/springframework/cache/jcache/JCacheEhCache3AnnotationTests.java +++ b/spring-test/src/test/java/org/springframework/cache/jcache/JCacheEhCache3AnnotationTests.java @@ -24,7 +24,6 @@ import javax.cache.spi.CachingProvider; * runs against EhCache 2.x with the EhCache-JCache add-on. * * @author Juergen Hoeller - * @since 4.2.1 */ public class JCacheEhCache3AnnotationTests extends JCacheEhCacheAnnotationTests { diff --git a/spring-test/src/test/java/org/springframework/cache/jcache/JCacheEhcache3Tests.java b/spring-test/src/test/java/org/springframework/cache/jcache/JCacheEhCache3ApiTests.java similarity index 94% rename from spring-test/src/test/java/org/springframework/cache/jcache/JCacheEhcache3Tests.java rename to spring-test/src/test/java/org/springframework/cache/jcache/JCacheEhCache3ApiTests.java index df7d587e31c..0e724344f29 100644 --- a/spring-test/src/test/java/org/springframework/cache/jcache/JCacheEhcache3Tests.java +++ b/spring-test/src/test/java/org/springframework/cache/jcache/JCacheEhCache3ApiTests.java @@ -25,7 +25,7 @@ import javax.cache.spi.CachingProvider; * * @author Stephane Nicoll */ -public class JCacheEhcache3Tests extends JCacheEhCacheTests { +public class JCacheEhCache3ApiTests extends JCacheEhCacheApiTests { @Override protected CachingProvider getCachingProvider() {