1
1
/*
2
- * Copyright 2011 the original author or authors.
2
+ * Copyright 2002-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .cache .annotation ;
18
18
19
- import static org .junit .Assert .*;
20
-
21
19
import java .lang .annotation .ElementType ;
22
20
import java .lang .annotation .Retention ;
23
21
import java .lang .annotation .RetentionPolicy ;
27
25
import java .util .Iterator ;
28
26
29
27
import org .junit .Test ;
28
+
30
29
import org .springframework .cache .interceptor .CacheEvictOperation ;
31
30
import org .springframework .cache .interceptor .CacheOperation ;
32
31
import org .springframework .cache .interceptor .CacheableOperation ;
33
- import org .springframework .util .ReflectionUtils ;
32
+
33
+ import static org .junit .Assert .*;
34
34
35
35
/**
36
36
* @author Costin Leau
37
37
*/
38
38
public class AnnotationCacheOperationSourceTests {
39
39
40
- private AnnotationCacheOperationSource source = new AnnotationCacheOperationSource ();
40
+ private final AnnotationCacheOperationSource source = new AnnotationCacheOperationSource ();
41
41
42
- private Collection <CacheOperation > getOps (String name ) {
43
- Method method = ReflectionUtils .findMethod (AnnotatedClass .class , name );
44
- return source .getCacheOperations (method , AnnotatedClass .class );
45
- }
46
42
47
43
@ Test
48
44
public void testSingularAnnotation () throws Exception {
@@ -69,6 +65,12 @@ public void testCaching() throws Exception {
69
65
assertTrue (it .next () instanceof CacheEvictOperation );
70
66
}
71
67
68
+ @ Test
69
+ public void testEmptyCaching () throws Exception {
70
+ Collection <CacheOperation > ops = getOps ("emptyCaching" );
71
+ assertTrue (ops .isEmpty ());
72
+ }
73
+
72
74
@ Test
73
75
public void testSingularStereotype () throws Exception {
74
76
Collection <CacheOperation > ops = getOps ("singleStereotype" );
@@ -90,7 +92,15 @@ public void testMultipleStereotypes() throws Exception {
90
92
assertTrue (next .getCacheNames ().contains ("bar" ));
91
93
}
92
94
95
+
96
+ private Collection <CacheOperation > getOps (String name ) throws Exception {
97
+ Method method = AnnotatedClass .class .getMethod (name );
98
+ return source .getCacheOperations (method , AnnotatedClass .class );
99
+ }
100
+
101
+
93
102
private static class AnnotatedClass {
103
+
94
104
@ Cacheable ("test" )
95
105
public void singular () {
96
106
}
@@ -100,13 +110,16 @@ public void singular() {
100
110
public void multiple () {
101
111
}
102
112
103
- @ Caching (cacheable = { @ Cacheable ("test" ) } , evict = { @ CacheEvict ("test" ) } )
113
+ @ Caching (cacheable = @ Cacheable ("test" ), evict = @ CacheEvict ("test" ))
104
114
public void caching () {
105
115
}
106
116
117
+ @ Caching
118
+ public void emptyCaching () {
119
+ }
120
+
107
121
@ EvictFoo
108
122
public void singleStereotype () {
109
-
110
123
}
111
124
112
125
@ EvictFoo
@@ -120,21 +133,25 @@ public void multipleCaching() {
120
133
}
121
134
}
122
135
136
+
123
137
@ Retention (RetentionPolicy .RUNTIME )
124
138
@ Target (ElementType .METHOD )
125
139
@ Cacheable ("foo" )
126
140
public @interface CacheableFoo {
127
141
}
128
142
143
+
129
144
@ Retention (RetentionPolicy .RUNTIME )
130
145
@ Target (ElementType .METHOD )
131
- @ CacheEvict (value = "foo" )
146
+ @ CacheEvict ("foo" )
132
147
public @interface EvictFoo {
133
148
}
134
149
150
+
135
151
@ Retention (RetentionPolicy .RUNTIME )
136
152
@ Target (ElementType .METHOD )
137
- @ CacheEvict (value = "bar" )
153
+ @ CacheEvict ("bar" )
138
154
public @interface EvictBar {
139
155
}
140
- }
156
+
157
+ }
0 commit comments