@@ -126,94 +126,135 @@ public void getAnnotationAttributesFavorsInheritedComposedAnnotationsOverMoreLoc
126
126
attributes .getBoolean ("readOnly" ));
127
127
}
128
128
129
+ // TODO [SPR-11598] Enable test.
130
+ @ Ignore ("Disabled until SPR-11598 is resolved" )
131
+ @ Test
132
+ public void getAnnotationAttributesFromInterfaceImplementedBySuperclass () {
133
+ String name = Transactional .class .getName ();
134
+ AnnotationAttributes attributes = getAnnotationAttributes (ConcreteClassWithInheritedAnnotation .class , name );
135
+ assertNotNull ("Should find @Transactional on ConcreteClassWithInheritedAnnotation" , attributes );
136
+ }
137
+
129
138
/** @since 4.2 */
130
139
@ Test
131
140
public void getAnnotationAttributesOnInheritedAnnotationInterface () {
132
141
String name = Transactional .class .getName ();
133
142
AnnotationAttributes attributes = getAnnotationAttributes (InheritedAnnotationInterface .class , name );
143
+ assertNotNull ("Should get @Transactional on InheritedAnnotationInterface" , attributes );
144
+ }
145
+
146
+ /** @since 4.2 */
147
+ @ Test
148
+ public void findAnnotationAttributesOnInheritedAnnotationInterface () {
149
+ AnnotationAttributes attributes = findAnnotationAttributes (InheritedAnnotationInterface .class , Transactional .class );
134
150
assertNotNull ("Should find @Transactional on InheritedAnnotationInterface" , attributes );
135
151
}
136
152
137
153
/** @since 4.2 */
138
154
@ Test
139
- public void getAnnotationAttributesOnSubInheritedAnnotationInterface () {
140
- String name = Transactional .class .getName ();
141
- AnnotationAttributes attributes = getAnnotationAttributes (SubInheritedAnnotationInterface .class , name );
155
+ public void findAnnotationAttributesOnSubInheritedAnnotationInterface () {
156
+ AnnotationAttributes attributes = findAnnotationAttributes (SubInheritedAnnotationInterface .class , Transactional .class );
142
157
assertNotNull ("Should find @Transactional on SubInheritedAnnotationInterface" , attributes );
143
158
}
144
159
145
160
/** @since 4.2 */
146
161
@ Test
147
- public void getAnnotationAttributesOnSubSubInheritedAnnotationInterface () {
148
- String name = Transactional .class .getName ();
149
- AnnotationAttributes attributes = getAnnotationAttributes (SubSubInheritedAnnotationInterface .class , name );
162
+ public void findAnnotationAttributesOnSubSubInheritedAnnotationInterface () {
163
+ AnnotationAttributes attributes = findAnnotationAttributes (SubSubInheritedAnnotationInterface .class , Transactional .class );
150
164
assertNotNull ("Should find @Transactional on SubSubInheritedAnnotationInterface" , attributes );
151
165
}
152
166
153
167
/** @since 4.2 */
154
168
@ Test
155
- public void getAnnotationAttributesOnNonInheritedAnnotationInterface () {
156
- String name = Order .class .getName ();
157
- AnnotationAttributes attributes = getAnnotationAttributes (NonInheritedAnnotationInterface .class , name );
169
+ public void findAnnotationAttributesOnNonInheritedAnnotationInterface () {
170
+ AnnotationAttributes attributes = findAnnotationAttributes (NonInheritedAnnotationInterface .class , Order .class );
158
171
assertNotNull ("Should find @Order on NonInheritedAnnotationInterface" , attributes );
159
172
}
160
173
161
174
/** @since 4.2 */
162
175
@ Test
163
- public void getAnnotationAttributesOnSubNonInheritedAnnotationInterface () {
164
- String name = Order .class .getName ();
165
- AnnotationAttributes attributes = getAnnotationAttributes (SubNonInheritedAnnotationInterface .class , name );
166
- assertNotNull ("Should find @Order on SubNonInheritedAnnotationInterface" , attributes );
176
+ public void getAnnotationAttributesOnNonInheritedAnnotationInterface () {
177
+ AnnotationAttributes attributes = getAnnotationAttributes (NonInheritedAnnotationInterface .class , Order .class .getName ());
178
+ assertNotNull ("Should get @Order on NonInheritedAnnotationInterface" , attributes );
167
179
}
168
180
169
181
/** @since 4.2 */
170
182
@ Test
171
- public void getAnnotationAttributesOnSubSubNonInheritedAnnotationInterface () {
172
- String name = Order .class .getName ();
173
- AnnotationAttributes attributes = getAnnotationAttributes (SubSubNonInheritedAnnotationInterface .class , name );
174
- assertNotNull ("Should find @Order on SubSubNonInheritedAnnotationInterface" , attributes );
183
+ public void findAnnotationAttributesOnSubNonInheritedAnnotationInterface () {
184
+ AnnotationAttributes attributes = findAnnotationAttributes (SubNonInheritedAnnotationInterface .class , Order .class );
185
+ assertNotNull ("Should find @Order on SubNonInheritedAnnotationInterface" , attributes );
175
186
}
176
187
177
- // TODO [SPR-11598] Enable test.
178
- @ Ignore ("Disabled until SPR-11598 is resolved" )
188
+ /** @since 4.2 */
179
189
@ Test
180
- public void getAnnotationAttributesFromInterfaceImplementedBySuperclass () {
181
- String name = Transactional .class .getName ();
182
- AnnotationAttributes attributes = getAnnotationAttributes (ConcreteClassWithInheritedAnnotation .class , name );
183
- assertNotNull ("Should find @Transactional on ConcreteClassWithInheritedAnnotation" , attributes );
190
+ public void findAnnotationAttributesOnSubSubNonInheritedAnnotationInterface () {
191
+ AnnotationAttributes attributes = findAnnotationAttributes (SubSubNonInheritedAnnotationInterface .class , Order .class );
192
+ assertNotNull ("Should find @Order on SubSubNonInheritedAnnotationInterface" , attributes );
184
193
}
185
194
186
- // TODO [SPR-12738] Enable test.
187
- @ Ignore ("Disabled until SPR-12738 is resolved" )
195
+ /** @since 4.2 */
188
196
@ Test
189
- public void getAnnotationAttributesInheritedFromInterfaceMethod () throws NoSuchMethodException {
190
- String name = Order .class .getName ();
197
+ public void findAnnotationAttributesInheritedFromInterfaceMethod () throws NoSuchMethodException {
191
198
Method method = ConcreteClassWithInheritedAnnotation .class .getMethod ("handleFromInterface" );
192
- AnnotationAttributes attributes = getAnnotationAttributes (method , name );
193
- assertNotNull ("Should find @Order on ConcreteClassWithInheritedAnnotation.handleFromInterface() method" ,
194
- attributes );
199
+ AnnotationAttributes attributes = findAnnotationAttributes (method , Order .class );
200
+ assertNotNull ("Should find @Order on ConcreteClassWithInheritedAnnotation.handleFromInterface() method" , attributes );
195
201
}
196
202
197
- // TODO [SPR-12738] Enable test.
198
- @ Ignore ("Disabled until SPR-12738 is resolved" )
203
+ /** @since 4.2 */
199
204
@ Test
200
- public void getAnnotationAttributesInheritedFromAbstractMethod () throws NoSuchMethodException {
201
- String name = Transactional .class .getName ();
205
+ public void findAnnotationAttributesInheritedFromAbstractMethod () throws NoSuchMethodException {
202
206
Method method = ConcreteClassWithInheritedAnnotation .class .getMethod ("handle" );
203
- AnnotationAttributes attributes = getAnnotationAttributes (method , name );
207
+ AnnotationAttributes attributes = findAnnotationAttributes (method , Transactional . class );
204
208
assertNotNull ("Should find @Transactional on ConcreteClassWithInheritedAnnotation.handle() method" , attributes );
205
209
}
206
210
207
- // TODO [SPR-12738] Enable test.
211
+ /**
212
+ * TODO [SPR-12738] Enable test.
213
+ *
214
+ * <p>{@code AbstractClassWithInheritedAnnotation} declares {@code handleParameterized(T)}; whereas,
215
+ * {@code ConcreteClassWithInheritedAnnotation} declares {@code handleParameterized(String)}.
216
+ *
217
+ * <p>Thus, this test fails because {@code AnnotatedElementUtils.processWithFindSemantics()}
218
+ * does not resolve an equivalent method for {@code handleParameterized(String)}
219
+ * in {@code AbstractClassWithInheritedAnnotation}.
220
+ *
221
+ * @since 4.2
222
+ */
208
223
@ Ignore ("Disabled until SPR-12738 is resolved" )
209
224
@ Test
210
- public void getAnnotationAttributesInheritedFromParameterizedMethod () throws NoSuchMethodException {
211
- String name = Transactional .class .getName ();
225
+ public void findAnnotationAttributesInheritedFromBridgedMethod () throws NoSuchMethodException {
212
226
Method method = ConcreteClassWithInheritedAnnotation .class .getMethod ("handleParameterized" , String .class );
213
- AnnotationAttributes attributes = getAnnotationAttributes (method , name );
227
+ AnnotationAttributes attributes = findAnnotationAttributes (method , Transactional . class );
214
228
assertNotNull ("Should find @Transactional on ConcreteClassWithInheritedAnnotation.handleParameterized() method" , attributes );
215
229
}
216
230
231
+ /**
232
+ * Bridge/bridged method setup code copied from
233
+ * {@link org.springframework.core.BridgeMethodResolverTests#testWithGenericParameter()}.
234
+ * @since 4.2
235
+ */
236
+ @ Test
237
+ public void findAnnotationAttributesFromBridgeMethod () throws NoSuchMethodException {
238
+ Method [] methods = StringGenericParameter .class .getMethods ();
239
+ Method bridgeMethod = null ;
240
+ Method bridgedMethod = null ;
241
+ for (Method method : methods ) {
242
+ if ("getFor" .equals (method .getName ()) && !method .getParameterTypes ()[0 ].equals (Integer .class )) {
243
+ if (method .getReturnType ().equals (Object .class )) {
244
+ bridgeMethod = method ;
245
+ }
246
+ else {
247
+ bridgedMethod = method ;
248
+ }
249
+ }
250
+ }
251
+ assertTrue (bridgeMethod != null && bridgeMethod .isBridge ());
252
+ assertTrue (bridgedMethod != null && !bridgedMethod .isBridge ());
253
+
254
+ AnnotationAttributes attributes = findAnnotationAttributes (bridgeMethod , Order .class );
255
+ assertNotNull ("Should find @Order on StringGenericParameter.getFor() method" , attributes );
256
+ }
257
+
217
258
218
259
// -------------------------------------------------------------------------
219
260
@@ -349,6 +390,26 @@ public void handleFromInterface() {
349
390
}
350
391
}
351
392
393
+ public static interface GenericParameter <T > {
394
+
395
+ T getFor (Class <T > cls );
396
+ }
397
+
398
+ @ SuppressWarnings ("unused" )
399
+ private static class StringGenericParameter implements GenericParameter <String > {
400
+
401
+ @ Order
402
+ @ Override
403
+ public String getFor (Class <String > cls ) {
404
+ return "foo" ;
405
+ }
406
+
407
+ public String getFor (Integer integer ) {
408
+ return "foo" ;
409
+ }
410
+ }
411
+
412
+
352
413
@ Transactional
353
414
public static interface InheritedAnnotationInterface {
354
415
}
0 commit comments