Browse Source

Polish

pull/1106/head
Stephane Nicoll 8 years ago
parent
commit
11ed26584d
  1. 7
      spring-context/src/test/java/org/springframework/cache/CacheReproTests.java
  2. 8
      spring-context/src/test/java/org/springframework/cache/annotation/AnnotationCacheOperationSourceTests.java
  3. 214
      spring-context/src/test/java/org/springframework/cache/config/AbstractCacheAnnotationTests.java
  4. 32
      spring-context/src/test/java/org/springframework/cache/config/AnnotatedClassCacheableService.java
  5. 10
      spring-context/src/test/java/org/springframework/cache/config/AnnotationNamespaceDrivenTests.java
  6. 6
      spring-context/src/test/java/org/springframework/cache/config/CacheAdviceNamespaceTests.java
  7. 15
      spring-context/src/test/java/org/springframework/cache/config/CustomInterceptorTests.java
  8. 40
      spring-context/src/test/java/org/springframework/cache/config/DefaultCacheableService.java
  9. 8
      spring-context/src/test/java/org/springframework/cache/config/EnableCachingIntegrationTests.java
  10. 13
      spring-context/src/test/java/org/springframework/cache/config/EnableCachingTests.java
  11. 9
      spring-context/src/test/java/org/springframework/cache/config/ExpressionCachingIntegrationTests.java
  12. 61
      spring-context/src/test/java/org/springframework/cache/interceptor/CacheErrorHandlerTests.java
  13. 30
      spring-context/src/test/java/org/springframework/cache/interceptor/CachePutEvaluationTests.java
  14. 44
      spring-context/src/test/java/org/springframework/cache/interceptor/CacheResolverCustomizationTests.java
  15. 22
      spring-context/src/test/java/org/springframework/cache/interceptor/CacheSyncFailureTests.java
  16. 10
      spring-context/src/test/java/org/springframework/cache/interceptor/ExpressionEvaluatorTests.java
  17. 4
      spring-context/src/test/java/org/springframework/cache/interceptor/SimpleKeyGeneratorTests.java

7
spring-context/src/test/java/org/springframework/cache/CacheReproTests.java vendored

@ -16,7 +16,6 @@ @@ -16,7 +16,6 @@
package org.springframework.cache;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@ -128,8 +127,8 @@ public class CacheReproTests { @@ -128,8 +127,8 @@ public class CacheReproTests {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr13081Config.class);
Spr13081Service bean = context.getBean(Spr13081Service.class);
thrown.expect(IllegalStateException.class);
thrown.expectMessage(MyCacheResolver.class.getName());
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage(MyCacheResolver.class.getName());
bean.getSimple(null);
}
@ -235,7 +234,7 @@ public class CacheReproTests { @@ -235,7 +234,7 @@ public class CacheReproTests {
@Bean
public CacheManager cacheManager() {
SimpleCacheManager cacheManager = new SimpleCacheManager();
cacheManager.setCaches(Arrays.asList(cache()));
cacheManager.setCaches(Collections.singletonList(cache()));
return cacheManager;
}

8
spring-context/src/test/java/org/springframework/cache/annotation/AnnotationCacheOperationSourceTests.java vendored

@ -75,7 +75,7 @@ public class AnnotationCacheOperationSourceTests { @@ -75,7 +75,7 @@ public class AnnotationCacheOperationSourceTests {
@Test
public void emptyCaching() throws Exception {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "emptyCaching", 0);
getOps(AnnotatedClass.class, "emptyCaching", 0);
}
@Test
@ -155,7 +155,7 @@ public class AnnotationCacheOperationSourceTests { @@ -155,7 +155,7 @@ public class AnnotationCacheOperationSourceTests {
@Test
public void keyAndKeyGeneratorCannotBeSetTogether() {
exception.expect(IllegalStateException.class);
this.exception.expect(IllegalStateException.class);
getOps(AnnotatedClass.class, "invalidKeyAndKeyGeneratorSet");
}
@ -189,7 +189,7 @@ public class AnnotationCacheOperationSourceTests { @@ -189,7 +189,7 @@ public class AnnotationCacheOperationSourceTests {
@Test
public void cacheResolverAndCacheManagerCannotBeSetTogether() {
exception.expect(IllegalStateException.class);
this.exception.expect(IllegalStateException.class);
getOps(AnnotatedClass.class, "invalidCacheResolverAndCacheManagerSet");
}
@ -275,7 +275,7 @@ public class AnnotationCacheOperationSourceTests { @@ -275,7 +275,7 @@ public class AnnotationCacheOperationSourceTests {
private Collection<CacheOperation> getOps(Class<?> target, String name) {
try {
Method method = target.getMethod(name);
return source.getCacheOperations(method, target);
return this.source.getCacheOperations(method, target);
}
catch (NoSuchMethodException ex) {
throw new IllegalStateException(ex);

214
spring-context/src/test/java/org/springframework/cache/config/AbstractCacheAnnotationTests.java vendored

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@ -60,12 +60,12 @@ public abstract class AbstractCacheAnnotationTests { @@ -60,12 +60,12 @@ public abstract class AbstractCacheAnnotationTests {
@Before
public void setup() {
ctx = getApplicationContext();
cs = ctx.getBean("service", CacheableService.class);
ccs = ctx.getBean("classService", CacheableService.class);
cm = ctx.getBean("cacheManager", CacheManager.class);
this.ctx = getApplicationContext();
this.cs = ctx.getBean("service", CacheableService.class);
this.ccs = ctx.getBean("classService", CacheableService.class);
this.cm = ctx.getBean("cacheManager", CacheManager.class);
Collection<String> cn = cm.getCacheNames();
Collection<String> cn = this.cm.getCacheNames();
assertTrue(cn.contains("testCache"));
assertTrue(cn.contains("secondary"));
assertTrue(cn.contains("primary"));
@ -73,8 +73,8 @@ public abstract class AbstractCacheAnnotationTests { @@ -73,8 +73,8 @@ public abstract class AbstractCacheAnnotationTests {
@After
public void close() {
if (ctx != null) {
ctx.close();
if (this.ctx != null) {
this.ctx.close();
}
}
@ -92,7 +92,7 @@ public abstract class AbstractCacheAnnotationTests { @@ -92,7 +92,7 @@ public abstract class AbstractCacheAnnotationTests {
public void testCacheableNull(CacheableService<?> service) throws Exception {
Object o1 = new Object();
assertNull(cm.getCache("testCache").get(o1));
assertNull(this.cm.getCache("testCache").get(o1));
Object r1 = service.cacheNull(o1);
Object r2 = service.cacheNull(o1);
@ -101,7 +101,7 @@ public abstract class AbstractCacheAnnotationTests { @@ -101,7 +101,7 @@ public abstract class AbstractCacheAnnotationTests {
assertSame(r1, r2);
assertSame(r1, r3);
assertEquals(r3, cm.getCache("testCache").get(o1).get());
assertEquals(r3, this.cm.getCache("testCache").get(o1).get());
assertNull("Cached value should be null", r3);
}
@ -118,7 +118,7 @@ public abstract class AbstractCacheAnnotationTests { @@ -118,7 +118,7 @@ public abstract class AbstractCacheAnnotationTests {
public void testCacheableSyncNull(CacheableService<?> service) throws Exception {
Object o1 = new Object();
assertNull(cm.getCache("testCache").get(o1));
assertNull(this.cm.getCache("testCache").get(o1));
Object r1 = service.cacheSyncNull(o1);
Object r2 = service.cacheSyncNull(o1);
@ -127,7 +127,7 @@ public abstract class AbstractCacheAnnotationTests { @@ -127,7 +127,7 @@ public abstract class AbstractCacheAnnotationTests {
assertSame(r1, r2);
assertSame(r1, r3);
assertEquals(r3, cm.getCache("testCache").get(o1).get());
assertEquals(r3, this.cm.getCache("testCache").get(o1).get());
assertNull("Cached value should be null", r3);
}
@ -229,7 +229,7 @@ public abstract class AbstractCacheAnnotationTests { @@ -229,7 +229,7 @@ public abstract class AbstractCacheAnnotationTests {
assertSame(r1, r2);
assertNotSame(r1, r10);
service.evictAll(new Object());
Cache cache = cm.getCache("testCache");
Cache cache = this.cm.getCache("testCache");
assertNull(cache.get(o1));
assertNull(cache.get(o2));
@ -264,11 +264,11 @@ public abstract class AbstractCacheAnnotationTests { @@ -264,11 +264,11 @@ public abstract class AbstractCacheAnnotationTests {
}
public void testUnlessExpression(CacheableService<?> service) throws Exception {
Cache cache = cm.getCache("testCache");
Cache cache = this.cm.getCache("testCache");
cache.clear();
service.unless(10);
service.unless(11);
assertThat(cache.get(10).get(), equalTo((Object) 10L));
assertThat(cache.get(10).get(), equalTo(10L));
assertThat(cache.get(11), nullValue());
}
@ -311,7 +311,7 @@ public abstract class AbstractCacheAnnotationTests { @@ -311,7 +311,7 @@ public abstract class AbstractCacheAnnotationTests {
Object key = new Object();
Object r1 = service.name(key);
assertSame(r1, service.name(key));
Cache cache = cm.getCache("testCache");
Cache cache = this.cm.getCache("testCache");
// assert the method name is used
assertNotNull(cache.get(keyName));
}
@ -320,7 +320,7 @@ public abstract class AbstractCacheAnnotationTests { @@ -320,7 +320,7 @@ public abstract class AbstractCacheAnnotationTests {
Object key = new Object();
Object r1 = service.rootVars(key);
assertSame(r1, service.rootVars(key));
Cache cache = cm.getCache("testCache");
Cache cache = this.cm.getCache("testCache");
// assert the method name is used
String expectedKey = "rootVarsrootVars" + AopProxyUtils.ultimateTargetClass(service) + service;
assertNotNull(cache.get(expectedKey));
@ -340,7 +340,7 @@ public abstract class AbstractCacheAnnotationTests { @@ -340,7 +340,7 @@ public abstract class AbstractCacheAnnotationTests {
public void testUncheckedThrowable(CacheableService<?> service) throws Exception {
try {
service.throwUnchecked(Long.valueOf(1));
service.throwUnchecked(1L);
fail("Excepted exception");
}
catch (RuntimeException ex) {
@ -364,7 +364,7 @@ public abstract class AbstractCacheAnnotationTests { @@ -364,7 +364,7 @@ public abstract class AbstractCacheAnnotationTests {
public void testUncheckedThrowableSync(CacheableService<?> service) throws Exception {
try {
service.throwUncheckedSync(Long.valueOf(1));
service.throwUncheckedSync(1L);
fail("Excepted exception");
}
catch (RuntimeException ex) {
@ -380,7 +380,7 @@ public abstract class AbstractCacheAnnotationTests { @@ -380,7 +380,7 @@ public abstract class AbstractCacheAnnotationTests {
public void testCacheUpdate(CacheableService<?> service) {
Object o = new Object();
Cache cache = cm.getCache("testCache");
Cache cache = this.cm.getCache("testCache");
assertNull(cache.get(o));
Object r1 = service.update(o);
assertSame(r1, cache.get(o).get());
@ -392,10 +392,10 @@ public abstract class AbstractCacheAnnotationTests { @@ -392,10 +392,10 @@ public abstract class AbstractCacheAnnotationTests {
}
public void testConditionalCacheUpdate(CacheableService<?> service) {
Integer one = Integer.valueOf(1);
Integer three = Integer.valueOf(3);
Integer one = 1;
Integer three = 3;
Cache cache = cm.getCache("testCache");
Cache cache = this.cm.getCache("testCache");
assertEquals(one, Integer.valueOf(service.conditionalUpdate(one).toString()));
assertNull(cache.get(one));
@ -407,8 +407,8 @@ public abstract class AbstractCacheAnnotationTests { @@ -407,8 +407,8 @@ public abstract class AbstractCacheAnnotationTests {
Object o1 = new Object();
Object o2 = new Object();
Cache primary = cm.getCache("primary");
Cache secondary = cm.getCache("secondary");
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
assertNull(primary.get(o1));
assertNull(secondary.get(o1));
@ -437,8 +437,8 @@ public abstract class AbstractCacheAnnotationTests { @@ -437,8 +437,8 @@ public abstract class AbstractCacheAnnotationTests {
Object r1 = service.multiCache(o1);
Object r2 = service.multiCache(o1);
Cache primary = cm.getCache("primary");
Cache secondary = cm.getCache("secondary");
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
primary.put(o2, o2);
assertSame(r1, r2);
@ -460,10 +460,10 @@ public abstract class AbstractCacheAnnotationTests { @@ -460,10 +460,10 @@ public abstract class AbstractCacheAnnotationTests {
}
public void testMultiPut(CacheableService<?> service) {
Object o = Integer.valueOf(1);
Object o = 1;
Cache primary = cm.getCache("primary");
Cache secondary = cm.getCache("secondary");
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
assertNull(primary.get(o));
assertNull(secondary.get(o));
@ -471,7 +471,7 @@ public abstract class AbstractCacheAnnotationTests { @@ -471,7 +471,7 @@ public abstract class AbstractCacheAnnotationTests {
assertSame(r1, primary.get(o).get());
assertSame(r1, secondary.get(o).get());
o = Integer.valueOf(2);
o = 2;
assertNull(primary.get(o));
assertNull(secondary.get(o));
Object r2 = service.multiUpdate(o);
@ -482,7 +482,7 @@ public abstract class AbstractCacheAnnotationTests { @@ -482,7 +482,7 @@ public abstract class AbstractCacheAnnotationTests {
public void testPutRefersToResult(CacheableService<?> service) throws Exception {
Long id = Long.MIN_VALUE;
TestEntity entity = new TestEntity();
Cache primary = cm.getCache("primary");
Cache primary = this.cm.getCache("primary");
assertNull(primary.get(id));
assertNull(entity.getId());
service.putRefersToResult(entity);
@ -492,9 +492,9 @@ public abstract class AbstractCacheAnnotationTests { @@ -492,9 +492,9 @@ public abstract class AbstractCacheAnnotationTests {
public void testMultiCacheAndEvict(CacheableService<?> service) {
String methodName = "multiCacheAndEvict";
Cache primary = cm.getCache("primary");
Cache secondary = cm.getCache("secondary");
Object key = Integer.valueOf(1);
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
Object key = 1;
secondary.put(key, key);
@ -511,9 +511,9 @@ public abstract class AbstractCacheAnnotationTests { @@ -511,9 +511,9 @@ public abstract class AbstractCacheAnnotationTests {
}
public void testMultiConditionalCacheAndEvict(CacheableService<?> service) {
Cache primary = cm.getCache("primary");
Cache secondary = cm.getCache("secondary");
Object key = Integer.valueOf(1);
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
Object key = 1;
secondary.put(key, key);
@ -526,7 +526,7 @@ public abstract class AbstractCacheAnnotationTests { @@ -526,7 +526,7 @@ public abstract class AbstractCacheAnnotationTests {
assertTrue(!r1.equals(r3));
assertNull(primary.get(key));
Object key2 = Integer.valueOf(3);
Object key2 = 3;
Object r2 = service.multiConditionalCacheAndEvict(key2);
assertSame(r2, service.multiConditionalCacheAndEvict(key2));
@ -537,163 +537,163 @@ public abstract class AbstractCacheAnnotationTests { @@ -537,163 +537,163 @@ public abstract class AbstractCacheAnnotationTests {
@Test
public void testCacheable() throws Exception {
testCacheable(cs);
testCacheable(this.cs);
}
@Test
public void testCacheableNull() throws Exception {
testCacheableNull(cs);
testCacheableNull(this.cs);
}
@Test
public void testCacheableSync() throws Exception {
testCacheableSync(cs);
testCacheableSync(this.cs);
}
@Test
public void testCacheableSyncNull() throws Exception {
testCacheableSyncNull(cs);
testCacheableSyncNull(this.cs);
}
@Test
public void testInvalidate() throws Exception {
testEvict(cs);
testEvict(this.cs);
}
@Test
public void testEarlyInvalidate() throws Exception {
testEvictEarly(cs);
testEvictEarly(this.cs);
}
@Test
public void testEvictWithException() throws Exception {
testEvictException(cs);
testEvictException(this.cs);
}
@Test
public void testEvictAll() throws Exception {
testEvictAll(cs);
testEvictAll(this.cs);
}
@Test
public void testInvalidateWithKey() throws Exception {
testEvictWKey(cs);
testEvictWKey(this.cs);
}
@Test
public void testEarlyInvalidateWithKey() throws Exception {
testEvictWKeyEarly(cs);
testEvictWKeyEarly(this.cs);
}
@Test
public void testConditionalExpression() throws Exception {
testConditionalExpression(cs);
testConditionalExpression(this.cs);
}
@Test
public void testConditionalExpressionSync() throws Exception {
testConditionalExpressionSync(cs);
testConditionalExpressionSync(this.cs);
}
@Test
public void testUnlessExpression() throws Exception {
testUnlessExpression(cs);
testUnlessExpression(this.cs);
}
@Test
public void testClassCacheUnlessExpression() throws Exception {
testUnlessExpression(cs);
testUnlessExpression(this.cs);
}
@Test
public void testKeyExpression() throws Exception {
testKeyExpression(cs);
testKeyExpression(this.cs);
}
@Test
public void testVarArgsKey() throws Exception {
testVarArgsKey(cs);
testVarArgsKey(this.cs);
}
@Test
public void testClassCacheCacheable() throws Exception {
testCacheable(ccs);
testCacheable(this.ccs);
}
@Test
public void testClassCacheInvalidate() throws Exception {
testEvict(ccs);
testEvict(this.ccs);
}
@Test
public void testClassEarlyInvalidate() throws Exception {
testEvictEarly(ccs);
testEvictEarly(this.ccs);
}
@Test
public void testClassEvictAll() throws Exception {
testEvictAll(ccs);
testEvictAll(this.ccs);
}
@Test
public void testClassEvictWithException() throws Exception {
testEvictException(ccs);
testEvictException(this.ccs);
}
@Test
public void testClassCacheInvalidateWKey() throws Exception {
testEvictWKey(ccs);
testEvictWKey(this.ccs);
}
@Test
public void testClassEarlyInvalidateWithKey() throws Exception {
testEvictWKeyEarly(ccs);
testEvictWKeyEarly(this.ccs);
}
@Test
public void testNullValue() throws Exception {
testNullValue(cs);
testNullValue(this.cs);
}
@Test
public void testClassNullValue() throws Exception {
Object key = new Object();
assertNull(ccs.nullValue(key));
int nr = ccs.nullInvocations().intValue();
assertNull(ccs.nullValue(key));
assertEquals(nr, ccs.nullInvocations().intValue());
assertNull(ccs.nullValue(new Object()));
assertNull(this.ccs.nullValue(key));
int nr = this.ccs.nullInvocations().intValue();
assertNull(this.ccs.nullValue(key));
assertEquals(nr, this.ccs.nullInvocations().intValue());
assertNull(this.ccs.nullValue(new Object()));
// the check method is also cached
assertEquals(nr, ccs.nullInvocations().intValue());
assertEquals(nr, this.ccs.nullInvocations().intValue());
assertEquals(nr + 1, AnnotatedClassCacheableService.nullInvocations.intValue());
}
@Test
public void testMethodName() throws Exception {
testMethodName(cs, "name");
testMethodName(this.cs, "name");
}
@Test
public void testClassMethodName() throws Exception {
testMethodName(ccs, "nametestCache");
testMethodName(this.ccs, "nametestCache");
}
@Test
public void testRootVars() throws Exception {
testRootVars(cs);
testRootVars(this.cs);
}
@Test
public void testClassRootVars() throws Exception {
testRootVars(ccs);
testRootVars(this.ccs);
}
@Test
public void testCustomKeyGenerator() {
Object param = new Object();
Object r1 = cs.customKeyGenerator(param);
assertSame(r1, cs.customKeyGenerator(param));
Cache cache = cm.getCache("testCache");
Object r1 = this.cs.customKeyGenerator(param);
assertSame(r1, this.cs.customKeyGenerator(param));
Cache cache = this.cm.getCache("testCache");
// Checks that the custom keyGenerator was used
Object expectedKey = SomeCustomKeyGenerator.generateKey("customKeyGenerator", param);
assertNotNull(cache.get(expectedKey));
@ -703,7 +703,7 @@ public abstract class AbstractCacheAnnotationTests { @@ -703,7 +703,7 @@ public abstract class AbstractCacheAnnotationTests {
public void testUnknownCustomKeyGenerator() {
try {
Object param = new Object();
cs.unknownCustomKeyGenerator(param);
this.cs.unknownCustomKeyGenerator(param);
fail("should have failed with NoSuchBeanDefinitionException");
}
catch (NoSuchBeanDefinitionException ex) {
@ -713,10 +713,10 @@ public abstract class AbstractCacheAnnotationTests { @@ -713,10 +713,10 @@ public abstract class AbstractCacheAnnotationTests {
@Test
public void testCustomCacheManager() {
CacheManager customCm = ctx.getBean("customCacheManager", CacheManager.class);
CacheManager customCm = this.ctx.getBean("customCacheManager", CacheManager.class);
Object key = new Object();
Object r1 = cs.customCacheManager(key);
assertSame(r1, cs.customCacheManager(key));
Object r1 = this.cs.customCacheManager(key);
assertSame(r1, this.cs.customCacheManager(key));
Cache cache = customCm.getCache("testCache");
assertNotNull(cache.get(key));
@ -726,7 +726,7 @@ public abstract class AbstractCacheAnnotationTests { @@ -726,7 +726,7 @@ public abstract class AbstractCacheAnnotationTests {
public void testUnknownCustomCacheManager() {
try {
Object param = new Object();
cs.unknownCustomCacheManager(param);
this.cs.unknownCustomCacheManager(param);
fail("should have failed with NoSuchBeanDefinitionException");
}
catch (NoSuchBeanDefinitionException ex) {
@ -736,132 +736,132 @@ public abstract class AbstractCacheAnnotationTests { @@ -736,132 +736,132 @@ public abstract class AbstractCacheAnnotationTests {
@Test
public void testNullArg() throws Exception {
testNullArg(cs);
testNullArg(this.cs);
}
@Test
public void testClassNullArg() throws Exception {
testNullArg(ccs);
testNullArg(this.ccs);
}
@Test
public void testCheckedException() throws Exception {
testCheckedThrowable(cs);
testCheckedThrowable(this.cs);
}
@Test
public void testClassCheckedException() throws Exception {
testCheckedThrowable(ccs);
testCheckedThrowable(this.ccs);
}
@Test
public void testCheckedExceptionSync() throws Exception {
testCheckedThrowableSync(cs);
testCheckedThrowableSync(this.cs);
}
@Test
public void testClassCheckedExceptionSync() throws Exception {
testCheckedThrowableSync(ccs);
testCheckedThrowableSync(this.ccs);
}
@Test
public void testUncheckedException() throws Exception {
testUncheckedThrowable(cs);
testUncheckedThrowable(this.cs);
}
@Test
public void testClassUncheckedException() throws Exception {
testUncheckedThrowable(ccs);
testUncheckedThrowable(this.ccs);
}
@Test
public void testUncheckedExceptionSync() throws Exception {
testUncheckedThrowableSync(cs);
testUncheckedThrowableSync(this.cs);
}
@Test
public void testClassUncheckedExceptionSync() throws Exception {
testUncheckedThrowableSync(ccs);
testUncheckedThrowableSync(this.ccs);
}
@Test
public void testUpdate() {
testCacheUpdate(cs);
testCacheUpdate(this.cs);
}
@Test
public void testClassUpdate() {
testCacheUpdate(ccs);
testCacheUpdate(this.ccs);
}
@Test
public void testConditionalUpdate() {
testConditionalCacheUpdate(cs);
testConditionalCacheUpdate(this.cs);
}
@Test
public void testClassConditionalUpdate() {
testConditionalCacheUpdate(ccs);
testConditionalCacheUpdate(this.ccs);
}
@Test
public void testMultiCache() {
testMultiCache(cs);
testMultiCache(this.cs);
}
@Test
public void testClassMultiCache() {
testMultiCache(ccs);
testMultiCache(this.ccs);
}
@Test
public void testMultiEvict() {
testMultiEvict(cs);
testMultiEvict(this.cs);
}
@Test
public void testClassMultiEvict() {
testMultiEvict(ccs);
testMultiEvict(this.ccs);
}
@Test
public void testMultiPut() {
testMultiPut(cs);
testMultiPut(this.cs);
}
@Test
public void testClassMultiPut() {
testMultiPut(ccs);
testMultiPut(this.ccs);
}
@Test
public void testPutRefersToResult() throws Exception {
testPutRefersToResult(cs);
testPutRefersToResult(this.cs);
}
@Test
public void testClassPutRefersToResult() throws Exception {
testPutRefersToResult(ccs);
testPutRefersToResult(this.ccs);
}
@Test
public void testMultiCacheAndEvict() {
testMultiCacheAndEvict(cs);
testMultiCacheAndEvict(this.cs);
}
@Test
public void testClassMultiCacheAndEvict() {
testMultiCacheAndEvict(ccs);
testMultiCacheAndEvict(this.ccs);
}
@Test
public void testMultiConditionalCacheAndEvict() {
testMultiConditionalCacheAndEvict(cs);
testMultiConditionalCacheAndEvict(this.cs);
}
@Test
public void testClassMultiConditionalCacheAndEvict() {
testMultiConditionalCacheAndEvict(ccs);
testMultiConditionalCacheAndEvict(this.ccs);
}
}

32
spring-context/src/test/java/org/springframework/cache/config/AnnotatedClassCacheableService.java vendored

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@ -38,7 +38,7 @@ public class AnnotatedClassCacheableService implements CacheableService<Object> @@ -38,7 +38,7 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
@Override
public Object cache(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@ -49,7 +49,7 @@ public class AnnotatedClassCacheableService implements CacheableService<Object> @@ -49,7 +49,7 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
@Override
@Cacheable(cacheNames = "testCache", sync = true)
public Object cacheSync(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@ -110,55 +110,55 @@ public class AnnotatedClassCacheableService implements CacheableService<Object> @@ -110,55 +110,55 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
@Override
@Cacheable(cacheNames = "testCache", key = "#p0")
public Object key(Object arg1, Object arg2) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Cacheable("testCache")
public Object varArgsKey(Object... args) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", key = "#root.methodName + #root.caches[0].name")
public Object name(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", key = "#root.methodName + #root.method.name + #root.targetClass + #root.target")
public Object rootVars(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", keyGenerator = "customKyeGenerator")
public Object customKeyGenerator(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", keyGenerator = "unknownBeanName")
public Object unknownCustomKeyGenerator(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", cacheManager = "customCacheManager")
public Object customCacheManager(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", cacheManager = "unknownBeanName")
public Object unknownCustomCacheManager(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@CachePut("testCache")
public Object update(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@ -205,25 +205,25 @@ public class AnnotatedClassCacheableService implements CacheableService<Object> @@ -205,25 +205,25 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
@Override
@Caching(cacheable = { @Cacheable("primary"), @Cacheable("secondary") })
public Object multiCache(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Caching(evict = { @CacheEvict("primary"), @CacheEvict(cacheNames = "secondary", key = "#a0"), @CacheEvict(cacheNames = "primary", key = "#p0 + 'A'") })
public Object multiEvict(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Caching(cacheable = { @Cacheable(cacheNames = "primary", key = "#root.methodName") }, evict = { @CacheEvict("secondary") })
public Object multiCacheAndEvict(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Caching(cacheable = { @Cacheable(cacheNames = "primary", condition = "#a0 == 3") }, evict = { @CacheEvict("secondary") })
public Object multiConditionalCacheAndEvict(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@ -40,9 +40,9 @@ public class AnnotationNamespaceDrivenTests extends AbstractCacheAnnotationTests @@ -40,9 +40,9 @@ public class AnnotationNamespaceDrivenTests extends AbstractCacheAnnotationTests
@Test
public void testKeyStrategy() {
CacheInterceptor ci = ctx.getBean(
CacheInterceptor ci = this.ctx.getBean(
"org.springframework.cache.interceptor.CacheInterceptor#0", CacheInterceptor.class);
assertSame(ctx.getBean("keyGenerator"), ci.getKeyGenerator());
assertSame(this.ctx.getBean("keyGenerator"), ci.getKeyGenerator());
}
@Test
@ -67,9 +67,9 @@ public class AnnotationNamespaceDrivenTests extends AbstractCacheAnnotationTests @@ -67,9 +67,9 @@ public class AnnotationNamespaceDrivenTests extends AbstractCacheAnnotationTests
@Test
public void testCacheErrorHandler() {
CacheInterceptor ci = ctx.getBean(
CacheInterceptor ci = this.ctx.getBean(
"org.springframework.cache.interceptor.CacheInterceptor#0", CacheInterceptor.class);
assertSame(ctx.getBean("errorHandler", CacheErrorHandler.class), ci.getErrorHandler());
assertSame(this.ctx.getBean("errorHandler", CacheErrorHandler.class), ci.getErrorHandler());
}
}

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@ -37,8 +37,8 @@ public class CacheAdviceNamespaceTests extends AbstractCacheAnnotationTests { @@ -37,8 +37,8 @@ public class CacheAdviceNamespaceTests extends AbstractCacheAnnotationTests {
@Test
public void testKeyStrategy() throws Exception {
CacheInterceptor bean = ctx.getBean("cacheAdviceClass", CacheInterceptor.class);
Assert.assertSame(ctx.getBean("keyGenerator"), bean.getKeyGenerator());
CacheInterceptor bean = this.ctx.getBean("cacheAdviceClass", CacheInterceptor.class);
Assert.assertSame(this.ctx.getBean("keyGenerator"), bean.getKeyGenerator());
}
}

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 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.
@ -37,7 +37,6 @@ import org.springframework.context.annotation.Configuration; @@ -37,7 +37,6 @@ import org.springframework.context.annotation.Configuration;
import static org.junit.Assert.*;
/**
*
* @author Stephane Nicoll
*/
public class CustomInterceptorTests {
@ -48,18 +47,18 @@ public class CustomInterceptorTests { @@ -48,18 +47,18 @@ public class CustomInterceptorTests {
@Before
public void setup() {
ctx = new AnnotationConfigApplicationContext(EnableCachingConfig.class);
cs = ctx.getBean("service", CacheableService.class);
this.ctx = new AnnotationConfigApplicationContext(EnableCachingConfig.class);
this.cs = ctx.getBean("service", CacheableService.class);
}
@After
public void tearDown() {
ctx.close();
this.ctx.close();
}
@Test
public void onlyOneInterceptorIsAvailable() {
Map<String, CacheInterceptor> interceptors = ctx.getBeansOfType(CacheInterceptor.class);
Map<String, CacheInterceptor> interceptors = this.ctx.getBeansOfType(CacheInterceptor.class);
assertEquals("Only one interceptor should be defined", 1, interceptors.size());
CacheInterceptor interceptor = interceptors.values().iterator().next();
assertEquals("Custom interceptor not defined", TestCacheInterceptor.class, interceptor.getClass());
@ -67,14 +66,14 @@ public class CustomInterceptorTests { @@ -67,14 +66,14 @@ public class CustomInterceptorTests {
@Test
public void customInterceptorAppliesWithRuntimeException() {
Object o = cs.throwUnchecked(0L);
Object o = this.cs.throwUnchecked(0L);
assertEquals(55L, o); // See TestCacheInterceptor
}
@Test
public void customInterceptorAppliesWithCheckedException() {
try {
cs.throwChecked(0L);
this.cs.throwChecked(0L);
fail("Should have failed");
}
catch (RuntimeException e) {

40
spring-context/src/test/java/org/springframework/cache/config/DefaultCacheableService.java vendored

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@ -39,7 +39,7 @@ public class DefaultCacheableService implements CacheableService<Long> { @@ -39,7 +39,7 @@ public class DefaultCacheableService implements CacheableService<Long> {
@Override
@Cacheable("testCache")
public Long cache(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@ -51,7 +51,7 @@ public class DefaultCacheableService implements CacheableService<Long> { @@ -51,7 +51,7 @@ public class DefaultCacheableService implements CacheableService<Long> {
@Override
@Cacheable(cacheNames = "testCache", sync = true)
public Long cacheSync(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@ -96,13 +96,13 @@ public class DefaultCacheableService implements CacheableService<Long> { @@ -96,13 +96,13 @@ public class DefaultCacheableService implements CacheableService<Long> {
@Override
@Cacheable(cacheNames = "testCache", condition = "#p0 == 3")
public Long conditional(int classField) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", sync = true, condition = "#p0 == 3")
public Long conditionalSync(int classField) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@ -114,55 +114,55 @@ public class DefaultCacheableService implements CacheableService<Long> { @@ -114,55 +114,55 @@ public class DefaultCacheableService implements CacheableService<Long> {
@Override
@Cacheable(cacheNames = "testCache", key = "#p0")
public Long key(Object arg1, Object arg2) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache")
public Long varArgsKey(Object... args) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", key = "#root.methodName")
public Long name(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", key = "#root.methodName + #root.method.name + #root.targetClass + #root.target")
public Long rootVars(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", keyGenerator = "customKeyGenerator")
public Long customKeyGenerator(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", keyGenerator = "unknownBeanName")
public Long unknownCustomKeyGenerator(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", cacheManager = "customCacheManager")
public Long customCacheManager(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Cacheable(cacheNames = "testCache", cacheManager = "unknownBeanName")
public Long unknownCustomCacheManager(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@CachePut("testCache")
public Long update(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@ -174,13 +174,13 @@ public class DefaultCacheableService implements CacheableService<Long> { @@ -174,13 +174,13 @@ public class DefaultCacheableService implements CacheableService<Long> {
@Override
@Cacheable("testCache")
public Long nullValue(Object arg1) {
nullInvocations.incrementAndGet();
this.nullInvocations.incrementAndGet();
return null;
}
@Override
public Number nullInvocations() {
return nullInvocations.get();
return this.nullInvocations.get();
}
@Override
@ -212,25 +212,25 @@ public class DefaultCacheableService implements CacheableService<Long> { @@ -212,25 +212,25 @@ public class DefaultCacheableService implements CacheableService<Long> {
@Override
@Caching(cacheable = { @Cacheable("primary"), @Cacheable("secondary") })
public Long multiCache(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Caching(evict = { @CacheEvict("primary"), @CacheEvict(cacheNames = "secondary", key = "#p0"), @CacheEvict(cacheNames = "primary", key = "#p0 + 'A'") })
public Long multiEvict(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Caching(cacheable = { @Cacheable(cacheNames = "primary", key = "#root.methodName") }, evict = { @CacheEvict("secondary") })
public Long multiCacheAndEvict(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Caching(cacheable = { @Cacheable(cacheNames = "primary", condition = "#p0 == 3") }, evict = { @CacheEvict("secondary") })
public Long multiConditionalCacheAndEvict(Object arg1) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override

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

@ -80,7 +80,7 @@ public class EnableCachingIntegrationTests { @@ -80,7 +80,7 @@ public class EnableCachingIntegrationTests {
public void beanCondition() {
this.context = new AnnotationConfigApplicationContext(BeanConditionConfig.class);
Cache cache = getCache();
FooService service = context.getBean(FooService.class);
FooService service = this.context.getBean(FooService.class);
Object key = new Object();
service.getWithCondition(key);
@ -133,13 +133,13 @@ public class EnableCachingIntegrationTests { @@ -133,13 +133,13 @@ public class EnableCachingIntegrationTests {
@Override
@Cacheable
public Object getSimple(Object key) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Override
@Cacheable(condition = "@bar.enabled")
public Object getWithCondition(Object key) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
}
@ -161,7 +161,7 @@ public class EnableCachingIntegrationTests { @@ -161,7 +161,7 @@ public class EnableCachingIntegrationTests {
}
public boolean isEnabled() {
return enabled;
return this.enabled;
}
}
}

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 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.
@ -39,7 +39,8 @@ import org.springframework.context.annotation.Configuration; @@ -39,7 +39,8 @@ import org.springframework.context.annotation.Configuration;
import static org.junit.Assert.*;
/**
* Integration tests for @EnableCaching and its related @Configuration classes.
* Integration tests for {@code @EnableCaching} and its related
* {@code @Configuration} classes.
*
* @author Chris Beams
* @author Stephane Nicoll
@ -54,14 +55,14 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests { @@ -54,14 +55,14 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
@Test
public void testKeyStrategy() {
CacheInterceptor ci = ctx.getBean(CacheInterceptor.class);
assertSame(ctx.getBean("keyGenerator", KeyGenerator.class), ci.getKeyGenerator());
CacheInterceptor ci = this.ctx.getBean(CacheInterceptor.class);
assertSame(this.ctx.getBean("keyGenerator", KeyGenerator.class), ci.getKeyGenerator());
}
@Test
public void testCacheErrorHandler() {
CacheInterceptor ci = ctx.getBean(CacheInterceptor.class);
assertSame(ctx.getBean("errorHandler", CacheErrorHandler.class), ci.getErrorHandler());
CacheInterceptor ci = this.ctx.getBean(CacheInterceptor.class);
assertSame(this.ctx.getBean("errorHandler", CacheErrorHandler.class), ci.getErrorHandler());
}
// --- local tests -------

9
spring-context/src/test/java/org/springframework/cache/config/ExpressionCachingIntegrationTests.java vendored

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 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.
@ -29,7 +29,6 @@ import org.springframework.context.annotation.Bean; @@ -29,7 +29,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
*
* @author Stephane Nicoll
*/
public class ExpressionCachingIntegrationTests {
@ -65,7 +64,7 @@ public class ExpressionCachingIntegrationTests { @@ -65,7 +64,7 @@ public class ExpressionCachingIntegrationTests {
}
private static interface BaseDao<T> {
private interface BaseDao<T> {
T persist(T t);
}
@ -94,7 +93,7 @@ public class ExpressionCachingIntegrationTests { @@ -94,7 +93,7 @@ public class ExpressionCachingIntegrationTests {
@SuppressWarnings("unused")
public String getId() {
return id;
return this.id;
}
}
@ -107,7 +106,7 @@ public class ExpressionCachingIntegrationTests { @@ -107,7 +106,7 @@ public class ExpressionCachingIntegrationTests {
@SuppressWarnings("unused")
public String getId() {
return id;
return this.id;
}
}

61
spring-context/src/test/java/org/springframework/cache/interceptor/CacheErrorHandlerTests.java vendored

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 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.
@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
package org.springframework.cache.interceptor;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.atomic.AtomicLong;
import org.junit.Before;
@ -43,7 +43,6 @@ import static org.junit.Assert.*; @@ -43,7 +43,6 @@ import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
/**
*
* @author Stephane Nicoll
*/
public class CacheErrorHandlerTests {
@ -71,23 +70,23 @@ public class CacheErrorHandlerTests { @@ -71,23 +70,23 @@ public class CacheErrorHandlerTests {
@Test
public void getFail() {
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on get");
willThrow(exception).given(cache).get(0L);
willThrow(exception).given(this.cache).get(0L);
Object result = this.simpleService.get(0L);
verify(errorHandler).handleCacheGetError(exception, cache, 0L);
verify(cache).get(0L);
verify(cache).put(0L, result); // result of the invocation
verify(this.errorHandler).handleCacheGetError(exception, cache, 0L);
verify(this.cache).get(0L);
verify(this.cache).put(0L, result); // result of the invocation
}
@Test
public void getAndPutFail() {
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on get");
willThrow(exception).given(cache).get(0L);
willThrow(exception).given(cache).put(0L, 0L); // Update of the cache will fail as well
willThrow(exception).given(this.cache).get(0L);
willThrow(exception).given(this.cache).put(0L, 0L); // Update of the cache will fail as well
Object counter = this.simpleService.get(0L);
willReturn(new SimpleValueWrapper(2L)).given(cache).get(0L);
willReturn(new SimpleValueWrapper(2L)).given(this.cache).get(0L);
Object counter2 = this.simpleService.get(0L);
Object counter3 = this.simpleService.get(0L);
assertNotSame(counter, counter2);
@ -97,71 +96,71 @@ public class CacheErrorHandlerTests { @@ -97,71 +96,71 @@ public class CacheErrorHandlerTests {
@Test
public void getFailProperException() {
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on get");
willThrow(exception).given(cache).get(0L);
willThrow(exception).given(this.cache).get(0L);
cacheInterceptor.setErrorHandler(new SimpleCacheErrorHandler());
this.cacheInterceptor.setErrorHandler(new SimpleCacheErrorHandler());
thrown.expect(is(exception));
this.thrown.expect(is(exception));
this.simpleService.get(0L);
}
@Test
public void putFail() {
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on put");
willThrow(exception).given(cache).put(0L, 0L);
willThrow(exception).given(this.cache).put(0L, 0L);
this.simpleService.put(0L);
verify(errorHandler).handleCachePutError(exception, cache, 0L, 0L);
verify(this.errorHandler).handleCachePutError(exception, cache, 0L, 0L);
}
@Test
public void putFailProperException() {
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on put");
willThrow(exception).given(cache).put(0L, 0L);
willThrow(exception).given(this.cache).put(0L, 0L);
cacheInterceptor.setErrorHandler(new SimpleCacheErrorHandler());
this.cacheInterceptor.setErrorHandler(new SimpleCacheErrorHandler());
thrown.expect(is(exception));
this.thrown.expect(is(exception));
this.simpleService.put(0L);
}
@Test
public void evictFail() {
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict");
willThrow(exception).given(cache).evict(0L);
willThrow(exception).given(this.cache).evict(0L);
this.simpleService.evict(0L);
verify(errorHandler).handleCacheEvictError(exception, cache, 0L);
verify(this.errorHandler).handleCacheEvictError(exception, cache, 0L);
}
@Test
public void evictFailProperException() {
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict");
willThrow(exception).given(cache).evict(0L);
willThrow(exception).given(this.cache).evict(0L);
cacheInterceptor.setErrorHandler(new SimpleCacheErrorHandler());
this.cacheInterceptor.setErrorHandler(new SimpleCacheErrorHandler());
thrown.expect(is(exception));
this.thrown.expect(is(exception));
this.simpleService.evict(0L);
}
@Test
public void clearFail() {
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict");
willThrow(exception).given(cache).clear();
willThrow(exception).given(this.cache).clear();
this.simpleService.clear();
verify(errorHandler).handleCacheClearError(exception, cache);
verify(this.errorHandler).handleCacheClearError(exception, cache);
}
@Test
public void clearFailProperException() {
UnsupportedOperationException exception = new UnsupportedOperationException("Test exception on evict");
willThrow(exception).given(cache).clear();
willThrow(exception).given(this.cache).clear();
cacheInterceptor.setErrorHandler(new SimpleCacheErrorHandler());
this.cacheInterceptor.setErrorHandler(new SimpleCacheErrorHandler());
thrown.expect(is(exception));
this.thrown.expect(is(exception));
this.simpleService.clear();
}
@ -184,7 +183,7 @@ public class CacheErrorHandlerTests { @@ -184,7 +183,7 @@ public class CacheErrorHandlerTests {
@Bean
public CacheManager cacheManager() {
SimpleCacheManager cacheManager = new SimpleCacheManager();
cacheManager.setCaches(Arrays.asList(mockCache()));
cacheManager.setCaches(Collections.singletonList(mockCache()));
return cacheManager;
}
@ -203,12 +202,12 @@ public class CacheErrorHandlerTests { @@ -203,12 +202,12 @@ public class CacheErrorHandlerTests {
@Cacheable
public Object get(long id) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@CachePut
public Object put(long id) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@CacheEvict

30
spring-context/src/test/java/org/springframework/cache/interceptor/CachePutEvaluationTests.java vendored

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 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.
@ -54,8 +54,8 @@ public class CachePutEvaluationTests { @@ -54,8 +54,8 @@ public class CachePutEvaluationTests {
@Before
public void setup() {
this.context = new AnnotationConfigApplicationContext(Config.class);
this.cache = context.getBean(CacheManager.class).getCache("test");
this.service = context.getBean(SimpleService.class);
this.cache = this.context.getBean(CacheManager.class).getCache("test");
this.service = this.context.getBean(SimpleService.class);
}
@After
@ -69,38 +69,38 @@ public class CachePutEvaluationTests { @@ -69,38 +69,38 @@ public class CachePutEvaluationTests {
public void mutualGetPutExclusion() {
String key = "1";
Long first = service.getOrPut(key, true);
Long second = service.getOrPut(key, true);
Long first = this.service.getOrPut(key, true);
Long second = this.service.getOrPut(key, true);
assertSame(first, second);
// This forces the method to be executed again
Long expected = first + 1;
Long third = service.getOrPut(key, false);
Long third = this.service.getOrPut(key, false);
assertEquals(expected, third);
Long fourth = service.getOrPut(key, true);
Long fourth = this.service.getOrPut(key, true);
assertSame(third, fourth);
}
@Test
public void getAndPut() {
cache.clear();
this.cache.clear();
long key = 1;
Long value = service.getAndPut(key);
Long value = this.service.getAndPut(key);
assertEquals("Wrong value for @Cacheable key", value, cache.get(key).get());
assertEquals("Wrong value for @CachePut key", value, cache.get(value + 100).get()); // See @CachePut
assertEquals("Wrong value for @Cacheable key", value, this.cache.get(key).get());
assertEquals("Wrong value for @CachePut key", value, this.cache.get(value + 100).get()); // See @CachePut
// CachePut forced a method call
Long anotherValue = service.getAndPut(key);
Long anotherValue = this.service.getAndPut(key);
assertNotSame(value, anotherValue);
// NOTE: while you might expect the main key to have been updated, it hasn't. @Cacheable operations
// are only processed in case of a cache miss. This is why combining @Cacheable with @CachePut
// is a very bad idea. We could refine the condition now that we can figure out if we are going
// to invoke the method anyway but that brings a whole new set of potential regressions.
//assertEquals("Wrong value for @Cacheable key", anotherValue, cache.get(key).get());
assertEquals("Wrong value for @CachePut key", anotherValue, cache.get(anotherValue + 100).get());
assertEquals("Wrong value for @CachePut key", anotherValue, this.cache.get(anotherValue + 100).get());
}
@Configuration
@ -130,7 +130,7 @@ public class CachePutEvaluationTests { @@ -130,7 +130,7 @@ public class CachePutEvaluationTests {
@Cacheable(condition = "#p1", key = "#p0")
@CachePut(condition = "!#p1", key = "#p0")
public Long getOrPut(Object id, boolean flag) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
/**
@ -140,7 +140,7 @@ public class CachePutEvaluationTests { @@ -140,7 +140,7 @@ public class CachePutEvaluationTests {
@Cacheable
@CachePut(key = "#result + 100", condition = "#result != null")
public Long getAndPut(long id) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
}
}

44
spring-context/src/test/java/org/springframework/cache/interceptor/CacheResolverCustomizationTests.java vendored

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 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.
@ -67,63 +67,63 @@ public class CacheResolverCustomizationTests { @@ -67,63 +67,63 @@ public class CacheResolverCustomizationTests {
@Test
public void noCustomization() {
Cache cache = cacheManager.getCache("default");
Cache cache = this.cacheManager.getCache("default");
Object key = new Object();
assertCacheMiss(key, cache);
Object value = simpleService.getSimple(key);
Object value = this.simpleService.getSimple(key);
assertCacheHit(key, value, cache);
}
@Test
public void customCacheResolver() {
Cache cache = cacheManager.getCache("primary");
Cache cache = this.cacheManager.getCache("primary");
Object key = new Object();
assertCacheMiss(key, cache);
Object value = simpleService.getWithCustomCacheResolver(key);
Object value = this.simpleService.getWithCustomCacheResolver(key);
assertCacheHit(key, value, cache);
}
@Test
public void customCacheManager() {
Cache cache = anotherCacheManager.getCache("default");
Cache cache = this.anotherCacheManager.getCache("default");
Object key = new Object();
assertCacheMiss(key, cache);
Object value = simpleService.getWithCustomCacheManager(key);
Object value = this.simpleService.getWithCustomCacheManager(key);
assertCacheHit(key, value, cache);
}
@Test
public void runtimeResolution() {
Cache defaultCache = cacheManager.getCache("default");
Cache primaryCache = cacheManager.getCache("primary");
Cache defaultCache = this.cacheManager.getCache("default");
Cache primaryCache = this.cacheManager.getCache("primary");
Object key = new Object();
assertCacheMiss(key, defaultCache, primaryCache);
Object value = simpleService.getWithRuntimeCacheResolution(key, "default");
Object value = this.simpleService.getWithRuntimeCacheResolution(key, "default");
assertCacheHit(key, value, defaultCache);
assertCacheMiss(key, primaryCache);
Object key2 = new Object();
assertCacheMiss(key2, defaultCache, primaryCache);
Object value2 = simpleService.getWithRuntimeCacheResolution(key2, "primary");
Object value2 = this.simpleService.getWithRuntimeCacheResolution(key2, "primary");
assertCacheHit(key2, value2, primaryCache);
assertCacheMiss(key2, defaultCache);
}
@Test
public void namedResolution() {
Cache cache = cacheManager.getCache("secondary");
Cache cache = this.cacheManager.getCache("secondary");
Object key = new Object();
assertCacheMiss(key, cache);
Object value = simpleService.getWithNamedCacheResolution(key);
Object value = this.simpleService.getWithNamedCacheResolution(key);
assertCacheHit(key, value, cache);
}
@ -131,7 +131,7 @@ public class CacheResolverCustomizationTests { @@ -131,7 +131,7 @@ public class CacheResolverCustomizationTests {
public void noCacheResolved() {
Method method = ReflectionUtils.findMethod(SimpleService.class, "noCacheResolved", Object.class);
try {
simpleService.noCacheResolved(new Object());
this.simpleService.noCacheResolved(new Object());
fail("Should have failed, no cache resolved");
}
catch (IllegalStateException ex) {
@ -142,7 +142,7 @@ public class CacheResolverCustomizationTests { @@ -142,7 +142,7 @@ public class CacheResolverCustomizationTests {
@Test
public void unknownCacheResolver() {
try {
simpleService.unknownCacheResolver(new Object());
this.simpleService.unknownCacheResolver(new Object());
fail("Should have failed, no cache resolver with that name");
}
catch (NoSuchBeanDefinitionException ex) {
@ -214,37 +214,37 @@ public class CacheResolverCustomizationTests { @@ -214,37 +214,37 @@ public class CacheResolverCustomizationTests {
@Cacheable
public Object getSimple(Object key) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Cacheable(cacheResolver = "primaryCacheResolver")
public Object getWithCustomCacheResolver(Object key) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Cacheable(cacheManager = "anotherCacheManager")
public Object getWithCustomCacheManager(Object key) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Cacheable(cacheResolver = "runtimeCacheResolver", key = "#p0")
public Object getWithRuntimeCacheResolution(Object key, String cacheName) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Cacheable(cacheResolver = "namedCacheResolver")
public Object getWithNamedCacheResolution(Object key) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Cacheable(cacheResolver = "nullCacheResolver") // No cache resolved for the operation
public Object noCacheResolved(Object key) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
@Cacheable(cacheResolver = "unknownCacheResolver") // No such bean defined
public Object unknownCacheResolver(Object key) {
return counter.getAndIncrement();
return this.counter.getAndIncrement();
}
}

22
spring-context/src/test/java/org/springframework/cache/interceptor/CacheSyncFailureTests.java vendored

@ -54,7 +54,7 @@ public class CacheSyncFailureTests { @@ -54,7 +54,7 @@ public class CacheSyncFailureTests {
@Before
public void setUp() {
this.context = new AnnotationConfigApplicationContext(Config.class);
this.simpleService = context.getBean(SimpleService.class);
this.simpleService = this.context.getBean(SimpleService.class);
}
@After
@ -66,36 +66,36 @@ public class CacheSyncFailureTests { @@ -66,36 +66,36 @@ public class CacheSyncFailureTests {
@Test
public void unlessSync() {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("@Cacheable(sync=true) does not support unless attribute");
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("@Cacheable(sync=true) does not support unless attribute");
this.simpleService.unlessSync("key");
}
@Test
public void severalCachesSync() {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("@Cacheable(sync=true) only allows a single cache");
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("@Cacheable(sync=true) only allows a single cache");
this.simpleService.severalCachesSync("key");
}
@Test
public void severalCachesWithResolvedSync() {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("@Cacheable(sync=true) only allows a single cache");
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("@Cacheable(sync=true) only allows a single cache");
this.simpleService.severalCachesWithResolvedSync("key");
}
@Test
public void syncWithAnotherOperation() {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("@Cacheable(sync=true) cannot be combined with other cache operations");
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("@Cacheable(sync=true) cannot be combined with other cache operations");
this.simpleService.syncWithAnotherOperation("key");
}
@Test
public void syncWithTwoGetOperations() {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Only one @Cacheable(sync=true) entry is allowed");
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Only one @Cacheable(sync=true) entry is allowed");
this.simpleService.syncWithTwoGetOperations("key");
}

10
spring-context/src/test/java/org/springframework/cache/interceptor/ExpressionEvaluatorTests.java vendored

@ -81,7 +81,7 @@ public class ExpressionEvaluatorTests { @@ -81,7 +81,7 @@ public class ExpressionEvaluatorTests {
Object[] args = new Object[] { new Object(), new Object() };
Collection<ConcurrentMapCache> caches = Collections.singleton(new ConcurrentMapCache("test"));
EvaluationContext evalCtx = eval.createEvaluationContext(caches, method, args,
EvaluationContext evalCtx = this.eval.createEvaluationContext(caches, method, args,
target, target.getClass(), null);
Collection<CacheOperation> ops = getOps("multipleCaching");
@ -89,8 +89,8 @@ public class ExpressionEvaluatorTests { @@ -89,8 +89,8 @@ public class ExpressionEvaluatorTests {
AnnotatedElementKey key = new AnnotatedElementKey(method, AnnotatedClass.class);
Object keyA = eval.key(it.next().getKey(), key, evalCtx);
Object keyB = eval.key(it.next().getKey(), key, evalCtx);
Object keyA = this.eval.key(it.next().getKey(), key, evalCtx);
Object keyB = this.eval.key(it.next().getKey(), key, evalCtx);
assertEquals(args[0], keyA);
assertEquals(args[1], keyB);
@ -100,7 +100,7 @@ public class ExpressionEvaluatorTests { @@ -100,7 +100,7 @@ public class ExpressionEvaluatorTests {
public void withReturnValue() throws Exception {
EvaluationContext context = createEvaluationContext("theResult");
Object value = new SpelExpressionParser().parseExpression("#result").getValue(context);
assertThat(value, equalTo((Object) "theResult"));
assertThat(value, equalTo("theResult"));
}
@Test
@ -151,7 +151,7 @@ public class ExpressionEvaluatorTests { @@ -151,7 +151,7 @@ public class ExpressionEvaluatorTests {
Object.class);
Object[] args = new Object[] { new Object(), new Object() };
Collection<ConcurrentMapCache> caches = Collections.singleton(new ConcurrentMapCache("test"));
return eval.createEvaluationContext(caches, method, args, target, target.getClass(), result, beanFactory);
return this.eval.createEvaluationContext(caches, method, args, target, target.getClass(), result, beanFactory);
}

4
spring-context/src/test/java/org/springframework/cache/interceptor/SimpleKeyGeneratorTests.java vendored

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 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.
@ -52,7 +52,7 @@ public class SimpleKeyGeneratorTests { @@ -52,7 +52,7 @@ public class SimpleKeyGeneratorTests {
assertThat(k1.hashCode(), not(equalTo(k3.hashCode())));
assertThat(k1, equalTo(k2));
assertThat(k1, not(equalTo(k3)));
assertThat(k1, equalTo((Object) "a"));
assertThat(k1, equalTo("a"));
}
@Test

Loading…
Cancel
Save