SPR-8653
+ refactor a bit the internals of CacheAspect to allow invocations that do not throw any exceptions (AspectJ)
This commit is contained in:
@@ -18,6 +18,8 @@ package org.springframework.cache.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.aop.framework.AopProxyUtils;
|
||||
@@ -148,6 +150,27 @@ public abstract class AbstractAnnotationTests {
|
||||
assertNotNull(cache.get(expectedKey));
|
||||
}
|
||||
|
||||
public void testCheckedThrowable(CacheableService service) throws Exception {
|
||||
String arg = UUID.randomUUID().toString();
|
||||
try {
|
||||
service.throwChecked(arg);
|
||||
fail("Excepted exception");
|
||||
} catch (Exception ex) {
|
||||
assertEquals(arg, ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testUncheckedThrowable(CacheableService service) throws Exception {
|
||||
try {
|
||||
service.throwUnchecked(Long.valueOf(1));
|
||||
fail("Excepted exception");
|
||||
} catch (RuntimeException ex) {
|
||||
assertTrue("Excepted different exception type and got " + ex.getClass(),
|
||||
ex instanceof UnsupportedOperationException);
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testNullArg(CacheableService service) {
|
||||
Object r1 = service.cache(null);
|
||||
assertSame(r1, service.cache(null));
|
||||
@@ -241,4 +264,24 @@ public abstract class AbstractAnnotationTests {
|
||||
public void testClassNullArg() throws Exception {
|
||||
testNullArg(ccs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckedException() throws Exception {
|
||||
testCheckedThrowable(cs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassCheckedException() throws Exception {
|
||||
testCheckedThrowable(ccs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUncheckedException() throws Exception {
|
||||
testUncheckedThrowable(cs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassUncheckedException() throws Exception {
|
||||
testUncheckedThrowable(ccs);
|
||||
}
|
||||
}
|
||||
@@ -69,4 +69,12 @@ public class AnnotatedClassCacheableService implements CacheableService {
|
||||
public Number nullInvocations() {
|
||||
return nullInvocations.get();
|
||||
}
|
||||
|
||||
public Long throwChecked(Object arg1) throws Exception {
|
||||
throw new UnsupportedOperationException(arg1.toString());
|
||||
}
|
||||
|
||||
public Long throwUnchecked(Object arg1) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,4 +42,8 @@ public interface CacheableService<T> {
|
||||
|
||||
T rootVars(Object arg1);
|
||||
|
||||
T throwChecked(Object arg1) throws Exception;
|
||||
|
||||
T throwUnchecked(Object arg1);
|
||||
|
||||
}
|
||||
@@ -73,4 +73,14 @@ public class DefaultCacheableService implements CacheableService<Long> {
|
||||
public Number nullInvocations() {
|
||||
return nullInvocations.get();
|
||||
}
|
||||
|
||||
@Cacheable("default")
|
||||
public Long throwChecked(Object arg1) throws Exception {
|
||||
throw new Exception(arg1.toString());
|
||||
}
|
||||
|
||||
@Cacheable("default")
|
||||
public Long throwUnchecked(Object arg1) {
|
||||
throw new UnsupportedOperationException(arg1.toString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user