Skip to content

Commit ed88b7f

Browse files
committed
Reorganize tests in AnnotationUtilsTests for greater clarity
1 parent 8a1f9f8 commit ed88b7f

File tree

1 file changed

+32
-41
lines changed

1 file changed

+32
-41
lines changed

spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -85,25 +85,37 @@ public void findMethodAnnotationOnBridgeMethod() throws Exception {
8585
assertNull(m.getAnnotation(Order.class));
8686
assertNull(getAnnotation(m, Order.class));
8787
assertNotNull(findAnnotation(m, Order.class));
88-
// TODO: actually found on OpenJDK 8 b99! assertNull(m.getAnnotation(Transactional.class));
88+
assertNull(m.getAnnotation(Transactional.class));
8989
assertNotNull(getAnnotation(m, Transactional.class));
9090
assertNotNull(findAnnotation(m, Transactional.class));
9191
}
9292

93-
// TODO consider whether we want this to handle annotations on interfaces
94-
// public void findMethodAnnotationFromInterfaceImplementedByRoot()
95-
// throws Exception {
96-
// Method m = Leaf.class.getMethod("fromInterfaceImplementedByRoot",
97-
// (Class[]) null);
98-
// Order o = findAnnotation(Order.class, m, Leaf.class);
99-
// assertNotNull(o);
100-
// }
93+
@Test
94+
public void findMethodAnnotationFromInterface() throws Exception {
95+
Method method = ImplementsInterfaceWithAnnotatedMethod.class.getMethod("foo");
96+
Order order = findAnnotation(method, Order.class);
97+
assertNotNull(order);
98+
}
99+
100+
@Test
101+
public void findMethodAnnotationFromInterfaceOnSuper() throws Exception {
102+
Method method = SubOfImplementsInterfaceWithAnnotatedMethod.class.getMethod("foo");
103+
Order order = findAnnotation(method, Order.class);
104+
assertNotNull(order);
105+
}
106+
107+
@Test
108+
public void findMethodAnnotationFromInterfaceWhenSuperDoesNotImplementMethod() throws Exception {
109+
Method method = SubOfAbstractImplementsInterfaceWithAnnotatedMethod.class.getMethod("foo");
110+
Order order = findAnnotation(method, Order.class);
111+
assertNotNull(order);
112+
}
101113

102114
/**
103115
* @since 4.1.2
104116
*/
105117
@Test
106-
public void findAnnotationFavorsLocalMetaAnnotationsOverInterfaces() {
118+
public void findClassAnnotationFavorsLocalMetaAnnotationsOverInterfaces() {
107119
Component component = AnnotationUtils.findAnnotation(
108120
ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, Component.class);
109121
assertNotNull(component);
@@ -114,7 +126,7 @@ public void findAnnotationFavorsLocalMetaAnnotationsOverInterfaces() {
114126
* @since 4.0.3
115127
*/
116128
@Test
117-
public void findAnnotationFavorsInheritedAnnotationsOverMoreLocallyDeclaredComposedAnnotations() {
129+
public void findClassAnnotationFavorsInheritedAnnotationsOverMoreLocallyDeclaredComposedAnnotations() {
118130
Transactional transactional = AnnotationUtils.findAnnotation(
119131
SubSubClassWithInheritedAnnotation.class, Transactional.class);
120132
assertNotNull(transactional);
@@ -125,42 +137,42 @@ public void findAnnotationFavorsInheritedAnnotationsOverMoreLocallyDeclaredCompo
125137
* @since 4.0.3
126138
*/
127139
@Test
128-
public void findAnnotationFavorsInheritedComposedAnnotationsOverMoreLocallyDeclaredComposedAnnotations() {
140+
public void findClassAnnotationFavorsInheritedComposedAnnotationsOverMoreLocallyDeclaredComposedAnnotations() {
129141
Component component = AnnotationUtils.findAnnotation(
130142
SubSubClassWithInheritedMetaAnnotation.class, Component.class);
131143
assertNotNull(component);
132144
assertEquals("meta2", component.value());
133145
}
134146

135147
@Test
136-
public void findAnnotationOnMetaMetaAnnotatedClass() {
148+
public void findClassAnnotationOnMetaMetaAnnotatedClass() {
137149
Component component = AnnotationUtils.findAnnotation(MetaMetaAnnotatedClass.class, Component.class);
138150
assertNotNull("Should find meta-annotation on composed annotation on class", component);
139151
assertEquals("meta2", component.value());
140152
}
141153

142154
@Test
143-
public void findAnnotationOnMetaMetaMetaAnnotatedClass() {
155+
public void findClassAnnotationOnMetaMetaMetaAnnotatedClass() {
144156
Component component = AnnotationUtils.findAnnotation(MetaMetaMetaAnnotatedClass.class, Component.class);
145157
assertNotNull("Should find meta-annotation on meta-annotation on composed annotation on class", component);
146158
assertEquals("meta2", component.value());
147159
}
148160

149161
@Test
150-
public void findAnnotationOnAnnotatedClassWithMissingTargetMetaAnnotation() {
162+
public void findClassAnnotationOnAnnotatedClassWithMissingTargetMetaAnnotation() {
151163
// TransactionalClass is NOT annotated or meta-annotated with @Component
152164
Component component = AnnotationUtils.findAnnotation(TransactionalClass.class, Component.class);
153165
assertNull("Should not find @Component on TransactionalClass", component);
154166
}
155167

156168
@Test
157-
public void findAnnotationOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() {
169+
public void findClassAnnotationOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() {
158170
Component component = AnnotationUtils.findAnnotation(MetaCycleAnnotatedClass.class, Component.class);
159171
assertNull("Should not find @Component on MetaCycleAnnotatedClass", component);
160172
}
161173

162174
@Test
163-
public void testFindAnnotationDeclaringClass() throws Exception {
175+
public void findAnnotationDeclaringClassForAllScenarios() throws Exception {
164176
// no class-level annotation
165177
assertNull(findAnnotationDeclaringClass(Transactional.class, NonAnnotatedInterface.class));
166178
assertNull(findAnnotationDeclaringClass(Transactional.class, NonAnnotatedClass.class));
@@ -250,7 +262,7 @@ public void findAnnotationDeclaringClassForTypesWithMultipleCandidateTypes() {
250262
}
251263

252264
@Test
253-
public void testIsAnnotationDeclaredLocally() throws Exception {
265+
public void isAnnotationDeclaredLocallyForAllScenarios() throws Exception {
254266
// no class-level annotation
255267
assertFalse(isAnnotationDeclaredLocally(Transactional.class, NonAnnotatedInterface.class));
256268
assertFalse(isAnnotationDeclaredLocally(Transactional.class, NonAnnotatedClass.class));
@@ -269,7 +281,7 @@ public void testIsAnnotationDeclaredLocally() throws Exception {
269281
}
270282

271283
@Test
272-
public void testIsAnnotationInherited() throws Exception {
284+
public void isAnnotationInheritedForAllScenarios() throws Exception {
273285
// no class-level annotation
274286
assertFalse(isAnnotationInherited(Transactional.class, NonAnnotatedInterface.class));
275287
assertFalse(isAnnotationInherited(Transactional.class, NonAnnotatedClass.class));
@@ -336,27 +348,6 @@ public void getDefaultValueFromAnnotationType() throws Exception {
336348
assertEquals(Ordered.LOWEST_PRECEDENCE, AnnotationUtils.getDefaultValue(Order.class));
337349
}
338350

339-
@Test
340-
public void findAnnotationFromInterface() throws Exception {
341-
Method method = ImplementsInterfaceWithAnnotatedMethod.class.getMethod("foo");
342-
Order order = findAnnotation(method, Order.class);
343-
assertNotNull(order);
344-
}
345-
346-
@Test
347-
public void findAnnotationFromInterfaceOnSuper() throws Exception {
348-
Method method = SubOfImplementsInterfaceWithAnnotatedMethod.class.getMethod("foo");
349-
Order order = findAnnotation(method, Order.class);
350-
assertNotNull(order);
351-
}
352-
353-
@Test
354-
public void findAnnotationFromInterfaceWhenSuperDoesNotImplementMethod() throws Exception {
355-
Method method = SubOfAbstractImplementsInterfaceWithAnnotatedMethod.class.getMethod("foo");
356-
Order order = findAnnotation(method, Order.class);
357-
assertNotNull(order);
358-
}
359-
360351
@Test
361352
public void findRepeatableAnnotationOnComposedAnnotation() {
362353
Repeatable repeatable = findAnnotation(MyRepeatableMeta.class, Repeatable.class);

0 commit comments

Comments
 (0)