提交 09b7735b 编写于 作者: J Juergen Hoeller

Polishing

上级 e6ae4370
...@@ -33,7 +33,6 @@ import org.springframework.cache.interceptor.CacheEvictOperation; ...@@ -33,7 +33,6 @@ import org.springframework.cache.interceptor.CacheEvictOperation;
import org.springframework.cache.interceptor.CacheOperation; import org.springframework.cache.interceptor.CacheOperation;
import org.springframework.cache.interceptor.CacheableOperation; import org.springframework.cache.interceptor.CacheableOperation;
import org.springframework.core.annotation.AliasFor; import org.springframework.core.annotation.AliasFor;
import org.springframework.util.ReflectionUtils;
import static org.junit.Assert.*; import static org.junit.Assert.*;
...@@ -50,17 +49,6 @@ public class AnnotationCacheOperationSourceTests { ...@@ -50,17 +49,6 @@ public class AnnotationCacheOperationSourceTests {
private final AnnotationCacheOperationSource source = new AnnotationCacheOperationSource(); private final AnnotationCacheOperationSource source = new AnnotationCacheOperationSource();
private Collection<CacheOperation> getOps(Class<?> target, String name, int expectedNumberOfOperations) {
Collection<CacheOperation> result = getOps(target, name);
assertEquals("Wrong number of operation(s) for '" + name + "'", expectedNumberOfOperations, result.size());
return result;
}
private Collection<CacheOperation> getOps(Class<?> target, String name) {
Method method = ReflectionUtils.findMethod(target, name);
return source.getCacheOperations(method, target);
}
@Test @Test
public void singularAnnotation() throws Exception { public void singularAnnotation() throws Exception {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singular", 1); Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singular", 1);
...@@ -234,6 +222,22 @@ public class AnnotationCacheOperationSourceTests { ...@@ -234,6 +222,22 @@ public class AnnotationCacheOperationSourceTests {
} }
private Collection<CacheOperation> getOps(Class<?> target, String name, int expectedNumberOfOperations) {
Collection<CacheOperation> result = getOps(target, name);
assertEquals("Wrong number of operation(s) for '" + name + "'", expectedNumberOfOperations, result.size());
return result;
}
private Collection<CacheOperation> getOps(Class<?> target, String name) {
try {
Method method = target.getMethod(name);
return source.getCacheOperations(method, target);
}
catch (NoSuchMethodException ex) {
throw new IllegalStateException(ex);
}
}
private void assertSharedConfig(CacheOperation actual, String keyGenerator, String cacheManager, private void assertSharedConfig(CacheOperation actual, String keyGenerator, String cacheManager,
String cacheResolver, String... cacheNames) { String cacheResolver, String... cacheNames) {
...@@ -241,8 +245,8 @@ public class AnnotationCacheOperationSourceTests { ...@@ -241,8 +245,8 @@ public class AnnotationCacheOperationSourceTests {
assertEquals("Wrong cache manager", cacheManager, actual.getCacheManager()); assertEquals("Wrong cache manager", cacheManager, actual.getCacheManager());
assertEquals("Wrong cache resolver", cacheResolver, actual.getCacheResolver()); assertEquals("Wrong cache resolver", cacheResolver, actual.getCacheResolver());
assertEquals("Wrong number of cache names", cacheNames.length, actual.getCacheNames().size()); assertEquals("Wrong number of cache names", cacheNames.length, actual.getCacheNames().size());
Arrays.stream(cacheNames).forEach( Arrays.stream(cacheNames).forEach(cacheName ->
cacheName -> assertTrue("Cache '" + cacheName + "' not found in " + actual.getCacheNames(), assertTrue("Cache '" + cacheName + "' not found in " + actual.getCacheNames(),
actual.getCacheNames().contains(cacheName))); actual.getCacheNames().contains(cacheName)));
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册