AnnotationUtilsTests.java 21.6 KB
Newer Older
A
Arjen Poutsma 已提交
1
/*
2
 * Copyright 2002-2015 the original author or authors.
A
Arjen Poutsma 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.core.annotation;

19
import java.lang.annotation.Annotation;
20
import java.lang.annotation.Inherited;
21
import java.lang.annotation.Repeatable;
22 23
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
A
Arjen Poutsma 已提交
24
import java.lang.reflect.Method;
25
import java.util.Arrays;
26
import java.util.HashSet;
27
import java.util.List;
28
import java.util.Set;
29

30
import org.junit.Test;
J
Juergen Hoeller 已提交
31

A
Arjen Poutsma 已提交
32
import org.springframework.core.Ordered;
33
import org.springframework.core.annotation.subpackage.NonPublicAnnotatedClass;
34
import org.springframework.stereotype.Component;
A
Arjen Poutsma 已提交
35

36
import static org.hamcrest.Matchers.*;
37 38 39
import static org.junit.Assert.*;
import static org.springframework.core.annotation.AnnotationUtils.*;

A
Arjen Poutsma 已提交
40
/**
J
Juergen Hoeller 已提交
41 42
 * Unit tests for {@link AnnotationUtils}.
 *
A
Arjen Poutsma 已提交
43 44 45
 * @author Rod Johnson
 * @author Juergen Hoeller
 * @author Sam Brannen
46
 * @author Chris Beams
47
 * @author Phillip Webb
A
Arjen Poutsma 已提交
48
 */
49
public class AnnotationUtilsTests {
A
Arjen Poutsma 已提交
50

51
	@Test
52
	public void findMethodAnnotationOnLeaf() throws Exception {
53
		Method m = Leaf.class.getMethod("annotatedOnLeaf", (Class[]) null);
A
Arjen Poutsma 已提交
54 55 56 57 58
		assertNotNull(m.getAnnotation(Order.class));
		assertNotNull(getAnnotation(m, Order.class));
		assertNotNull(findAnnotation(m, Order.class));
	}

59
	@Test
60
	public void findMethodAnnotationOnRoot() throws Exception {
61
		Method m = Leaf.class.getMethod("annotatedOnRoot", (Class[]) null);
A
Arjen Poutsma 已提交
62 63 64 65 66
		assertNotNull(m.getAnnotation(Order.class));
		assertNotNull(getAnnotation(m, Order.class));
		assertNotNull(findAnnotation(m, Order.class));
	}

67
	@Test
68
	public void findMethodAnnotationOnRootButOverridden() throws Exception {
69
		Method m = Leaf.class.getMethod("overrideWithoutNewAnnotation", (Class[]) null);
A
Arjen Poutsma 已提交
70 71 72 73 74
		assertNull(m.getAnnotation(Order.class));
		assertNull(getAnnotation(m, Order.class));
		assertNotNull(findAnnotation(m, Order.class));
	}

75
	@Test
76
	public void findMethodAnnotationNotAnnotated() throws Exception {
77
		Method m = Leaf.class.getMethod("notAnnotated", (Class[]) null);
A
Arjen Poutsma 已提交
78 79 80
		assertNull(findAnnotation(m, Order.class));
	}

81
	@Test
82
	public void findMethodAnnotationOnBridgeMethod() throws Exception {
83
		Method m = SimpleFoo.class.getMethod("something", Object.class);
A
Arjen Poutsma 已提交
84 85 86 87
		assertTrue(m.isBridge());
		assertNull(m.getAnnotation(Order.class));
		assertNull(getAnnotation(m, Order.class));
		assertNotNull(findAnnotation(m, Order.class));
88 89
		// TODO: actually found on OpenJDK 8 b99 and higher!
		// assertNull(m.getAnnotation(Transactional.class));
A
Arjen Poutsma 已提交
90 91 92 93
		assertNotNull(getAnnotation(m, Transactional.class));
		assertNotNull(findAnnotation(m, Transactional.class));
	}

94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
	@Test
	public void findMethodAnnotationFromInterface() throws Exception {
		Method method = ImplementsInterfaceWithAnnotatedMethod.class.getMethod("foo");
		Order order = findAnnotation(method, Order.class);
		assertNotNull(order);
	}

	@Test
	public void findMethodAnnotationFromInterfaceOnSuper() throws Exception {
		Method method = SubOfImplementsInterfaceWithAnnotatedMethod.class.getMethod("foo");
		Order order = findAnnotation(method, Order.class);
		assertNotNull(order);
	}

	@Test
	public void findMethodAnnotationFromInterfaceWhenSuperDoesNotImplementMethod() throws Exception {
		Method method = SubOfAbstractImplementsInterfaceWithAnnotatedMethod.class.getMethod("foo");
		Order order = findAnnotation(method, Order.class);
		assertNotNull(order);
	}
A
Arjen Poutsma 已提交
114

115 116 117
	/**
	 * @since 4.1.2
	 */
118
	@Test
119
	public void findClassAnnotationFavorsLocalMetaAnnotationsOverInterfaces() {
120
		Component component = AnnotationUtils.findAnnotation(
121
				ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, Component.class);
122
		assertNotNull(component);
123
		assertEquals("meta2", component.value());
124 125
	}

126 127 128
	/**
	 * @since 4.0.3
	 */
129
	@Test
130
	public void findClassAnnotationFavorsInheritedAnnotationsOverMoreLocallyDeclaredComposedAnnotations() {
131 132
		Transactional transactional = AnnotationUtils.findAnnotation(
				SubSubClassWithInheritedAnnotation.class, Transactional.class);
133
		assertNotNull(transactional);
134
		assertTrue("readOnly flag for SubSubClassWithInheritedAnnotation", transactional.readOnly());
135 136
	}

137 138 139
	/**
	 * @since 4.0.3
	 */
140
	@Test
141
	public void findClassAnnotationFavorsInheritedComposedAnnotationsOverMoreLocallyDeclaredComposedAnnotations() {
142 143
		Component component = AnnotationUtils.findAnnotation(
				SubSubClassWithInheritedMetaAnnotation.class, Component.class);
144
		assertNotNull(component);
145
		assertEquals("meta2", component.value());
146 147
	}

148
	@Test
149
	public void findClassAnnotationOnMetaMetaAnnotatedClass() {
150 151 152 153 154 155
		Component component = AnnotationUtils.findAnnotation(MetaMetaAnnotatedClass.class, Component.class);
		assertNotNull("Should find meta-annotation on composed annotation on class", component);
		assertEquals("meta2", component.value());
	}

	@Test
156
	public void findClassAnnotationOnMetaMetaMetaAnnotatedClass() {
157 158 159 160 161 162
		Component component = AnnotationUtils.findAnnotation(MetaMetaMetaAnnotatedClass.class, Component.class);
		assertNotNull("Should find meta-annotation on meta-annotation on composed annotation on class", component);
		assertEquals("meta2", component.value());
	}

	@Test
163
	public void findClassAnnotationOnAnnotatedClassWithMissingTargetMetaAnnotation() {
164 165 166 167 168 169
		// TransactionalClass is NOT annotated or meta-annotated with @Component
		Component component = AnnotationUtils.findAnnotation(TransactionalClass.class, Component.class);
		assertNull("Should not find @Component on TransactionalClass", component);
	}

	@Test
170
	public void findClassAnnotationOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() {
171 172 173 174
		Component component = AnnotationUtils.findAnnotation(MetaCycleAnnotatedClass.class, Component.class);
		assertNull("Should not find @Component on MetaCycleAnnotatedClass", component);
	}

175
	@Test
176
	public void findAnnotationDeclaringClassForAllScenarios() throws Exception {
A
Arjen Poutsma 已提交
177 178 179 180 181
		// no class-level annotation
		assertNull(findAnnotationDeclaringClass(Transactional.class, NonAnnotatedInterface.class));
		assertNull(findAnnotationDeclaringClass(Transactional.class, NonAnnotatedClass.class));

		// inherited class-level annotation; note: @Transactional is inherited
182 183
		assertEquals(InheritedAnnotationInterface.class,
			findAnnotationDeclaringClass(Transactional.class, InheritedAnnotationInterface.class));
A
Arjen Poutsma 已提交
184
		assertNull(findAnnotationDeclaringClass(Transactional.class, SubInheritedAnnotationInterface.class));
185 186 187 188
		assertEquals(InheritedAnnotationClass.class,
			findAnnotationDeclaringClass(Transactional.class, InheritedAnnotationClass.class));
		assertEquals(InheritedAnnotationClass.class,
			findAnnotationDeclaringClass(Transactional.class, SubInheritedAnnotationClass.class));
A
Arjen Poutsma 已提交
189 190

		// non-inherited class-level annotation; note: @Order is not inherited,
191 192 193
		// but findAnnotationDeclaringClass() should still find it on classes.
		assertEquals(NonInheritedAnnotationInterface.class,
			findAnnotationDeclaringClass(Order.class, NonInheritedAnnotationInterface.class));
A
Arjen Poutsma 已提交
194
		assertNull(findAnnotationDeclaringClass(Order.class, SubNonInheritedAnnotationInterface.class));
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
		assertEquals(NonInheritedAnnotationClass.class,
			findAnnotationDeclaringClass(Order.class, NonInheritedAnnotationClass.class));
		assertEquals(NonInheritedAnnotationClass.class,
			findAnnotationDeclaringClass(Order.class, SubNonInheritedAnnotationClass.class));
	}

	@Test
	public void findAnnotationDeclaringClassForTypesWithSingleCandidateType() {
		// no class-level annotation
		List<Class<? extends Annotation>> transactionalCandidateList = Arrays.<Class<? extends Annotation>> asList(Transactional.class);
		assertNull(findAnnotationDeclaringClassForTypes(transactionalCandidateList, NonAnnotatedInterface.class));
		assertNull(findAnnotationDeclaringClassForTypes(transactionalCandidateList, NonAnnotatedClass.class));

		// inherited class-level annotation; note: @Transactional is inherited
		assertEquals(InheritedAnnotationInterface.class,
			findAnnotationDeclaringClassForTypes(transactionalCandidateList, InheritedAnnotationInterface.class));
J
Juergen Hoeller 已提交
211
		assertNull(findAnnotationDeclaringClassForTypes(transactionalCandidateList, SubInheritedAnnotationInterface.class));
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
		assertEquals(InheritedAnnotationClass.class,
			findAnnotationDeclaringClassForTypes(transactionalCandidateList, InheritedAnnotationClass.class));
		assertEquals(InheritedAnnotationClass.class,
			findAnnotationDeclaringClassForTypes(transactionalCandidateList, SubInheritedAnnotationClass.class));

		// non-inherited class-level annotation; note: @Order is not inherited,
		// but findAnnotationDeclaringClassForTypes() should still find it on classes.
		List<Class<? extends Annotation>> orderCandidateList = Arrays.<Class<? extends Annotation>> asList(Order.class);
		assertEquals(NonInheritedAnnotationInterface.class,
			findAnnotationDeclaringClassForTypes(orderCandidateList, NonInheritedAnnotationInterface.class));
		assertNull(findAnnotationDeclaringClassForTypes(orderCandidateList, SubNonInheritedAnnotationInterface.class));
		assertEquals(NonInheritedAnnotationClass.class,
			findAnnotationDeclaringClassForTypes(orderCandidateList, NonInheritedAnnotationClass.class));
		assertEquals(NonInheritedAnnotationClass.class,
			findAnnotationDeclaringClassForTypes(orderCandidateList, SubNonInheritedAnnotationClass.class));
	}

	@Test
	public void findAnnotationDeclaringClassForTypesWithMultipleCandidateTypes() {
231
		List<Class<? extends Annotation>> candidates = Arrays.<Class<? extends Annotation>> asList(Transactional.class, Order.class);
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262

		// no class-level annotation
		assertNull(findAnnotationDeclaringClassForTypes(candidates, NonAnnotatedInterface.class));
		assertNull(findAnnotationDeclaringClassForTypes(candidates, NonAnnotatedClass.class));

		// inherited class-level annotation; note: @Transactional is inherited
		assertEquals(InheritedAnnotationInterface.class,
			findAnnotationDeclaringClassForTypes(candidates, InheritedAnnotationInterface.class));
		assertNull(findAnnotationDeclaringClassForTypes(candidates, SubInheritedAnnotationInterface.class));
		assertEquals(InheritedAnnotationClass.class,
			findAnnotationDeclaringClassForTypes(candidates, InheritedAnnotationClass.class));
		assertEquals(InheritedAnnotationClass.class,
			findAnnotationDeclaringClassForTypes(candidates, SubInheritedAnnotationClass.class));

		// non-inherited class-level annotation; note: @Order is not inherited,
		// but findAnnotationDeclaringClassForTypes() should still find it on classes.
		assertEquals(NonInheritedAnnotationInterface.class,
			findAnnotationDeclaringClassForTypes(candidates, NonInheritedAnnotationInterface.class));
		assertNull(findAnnotationDeclaringClassForTypes(candidates, SubNonInheritedAnnotationInterface.class));
		assertEquals(NonInheritedAnnotationClass.class,
			findAnnotationDeclaringClassForTypes(candidates, NonInheritedAnnotationClass.class));
		assertEquals(NonInheritedAnnotationClass.class,
			findAnnotationDeclaringClassForTypes(candidates, SubNonInheritedAnnotationClass.class));

		// class hierarchy mixed with @Transactional and @Order declarations
		assertEquals(TransactionalClass.class,
			findAnnotationDeclaringClassForTypes(candidates, TransactionalClass.class));
		assertEquals(TransactionalAndOrderedClass.class,
			findAnnotationDeclaringClassForTypes(candidates, TransactionalAndOrderedClass.class));
		assertEquals(TransactionalAndOrderedClass.class,
			findAnnotationDeclaringClassForTypes(candidates, SubTransactionalAndOrderedClass.class));
A
Arjen Poutsma 已提交
263 264
	}

265
	@Test
266
	public void isAnnotationDeclaredLocallyForAllScenarios() throws Exception {
A
Arjen Poutsma 已提交
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
		// no class-level annotation
		assertFalse(isAnnotationDeclaredLocally(Transactional.class, NonAnnotatedInterface.class));
		assertFalse(isAnnotationDeclaredLocally(Transactional.class, NonAnnotatedClass.class));

		// inherited class-level annotation; note: @Transactional is inherited
		assertTrue(isAnnotationDeclaredLocally(Transactional.class, InheritedAnnotationInterface.class));
		assertFalse(isAnnotationDeclaredLocally(Transactional.class, SubInheritedAnnotationInterface.class));
		assertTrue(isAnnotationDeclaredLocally(Transactional.class, InheritedAnnotationClass.class));
		assertFalse(isAnnotationDeclaredLocally(Transactional.class, SubInheritedAnnotationClass.class));

		// non-inherited class-level annotation; note: @Order is not inherited
		assertTrue(isAnnotationDeclaredLocally(Order.class, NonInheritedAnnotationInterface.class));
		assertFalse(isAnnotationDeclaredLocally(Order.class, SubNonInheritedAnnotationInterface.class));
		assertTrue(isAnnotationDeclaredLocally(Order.class, NonInheritedAnnotationClass.class));
		assertFalse(isAnnotationDeclaredLocally(Order.class, SubNonInheritedAnnotationClass.class));
	}

284
	@Test
285
	public void isAnnotationInheritedForAllScenarios() throws Exception {
A
Arjen Poutsma 已提交
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
		// no class-level annotation
		assertFalse(isAnnotationInherited(Transactional.class, NonAnnotatedInterface.class));
		assertFalse(isAnnotationInherited(Transactional.class, NonAnnotatedClass.class));

		// inherited class-level annotation; note: @Transactional is inherited
		assertFalse(isAnnotationInherited(Transactional.class, InheritedAnnotationInterface.class));
		// isAnnotationInherited() does not currently traverse interface
		// hierarchies. Thus the following, though perhaps counter intuitive,
		// must be false:
		assertFalse(isAnnotationInherited(Transactional.class, SubInheritedAnnotationInterface.class));
		assertFalse(isAnnotationInherited(Transactional.class, InheritedAnnotationClass.class));
		assertTrue(isAnnotationInherited(Transactional.class, SubInheritedAnnotationClass.class));

		// non-inherited class-level annotation; note: @Order is not inherited
		assertFalse(isAnnotationInherited(Order.class, NonInheritedAnnotationInterface.class));
		assertFalse(isAnnotationInherited(Order.class, SubNonInheritedAnnotationInterface.class));
		assertFalse(isAnnotationInherited(Order.class, NonInheritedAnnotationClass.class));
		assertFalse(isAnnotationInherited(Order.class, SubNonInheritedAnnotationClass.class));
	}

306
	@Test
307
	public void getValueFromAnnotation() throws Exception {
308 309
		Method method = SimpleFoo.class.getMethod("something", Object.class);
		Order order = findAnnotation(method, Order.class);
A
Arjen Poutsma 已提交
310 311 312 313 314

		assertEquals(1, AnnotationUtils.getValue(order, AnnotationUtils.VALUE));
		assertEquals(1, AnnotationUtils.getValue(order));
	}

315
	@Test
316 317 318 319 320 321 322 323 324 325 326 327
	public void getValueFromNonPublicAnnotation() throws Exception {
		Annotation[] declaredAnnotations = NonPublicAnnotatedClass.class.getDeclaredAnnotations();
		assertEquals(1, declaredAnnotations.length);
		Annotation annotation = declaredAnnotations[0];
		assertNotNull(annotation);
		assertEquals("NonPublicAnnotation", annotation.annotationType().getSimpleName());
		assertEquals(42, AnnotationUtils.getValue(annotation, AnnotationUtils.VALUE));
		assertEquals(42, AnnotationUtils.getValue(annotation));
	}

	@Test
	public void getDefaultValueFromAnnotation() throws Exception {
328 329
		Method method = SimpleFoo.class.getMethod("something", Object.class);
		Order order = findAnnotation(method, Order.class);
A
Arjen Poutsma 已提交
330 331 332 333 334

		assertEquals(Ordered.LOWEST_PRECEDENCE, AnnotationUtils.getDefaultValue(order, AnnotationUtils.VALUE));
		assertEquals(Ordered.LOWEST_PRECEDENCE, AnnotationUtils.getDefaultValue(order));
	}

335
	@Test
336 337 338 339 340 341 342 343 344 345 346 347
	public void getDefaultValueFromNonPublicAnnotation() throws Exception {
		Annotation[] declaredAnnotations = NonPublicAnnotatedClass.class.getDeclaredAnnotations();
		assertEquals(1, declaredAnnotations.length);
		Annotation annotation = declaredAnnotations[0];
		assertNotNull(annotation);
		assertEquals("NonPublicAnnotation", annotation.annotationType().getSimpleName());
		assertEquals(-1, AnnotationUtils.getDefaultValue(annotation, AnnotationUtils.VALUE));
		assertEquals(-1, AnnotationUtils.getDefaultValue(annotation));
	}

	@Test
	public void getDefaultValueFromAnnotationType() throws Exception {
A
Arjen Poutsma 已提交
348 349 350 351
		assertEquals(Ordered.LOWEST_PRECEDENCE, AnnotationUtils.getDefaultValue(Order.class, AnnotationUtils.VALUE));
		assertEquals(Ordered.LOWEST_PRECEDENCE, AnnotationUtils.getDefaultValue(Order.class));
	}

352 353 354 355 356 357 358
	@Test
	public void findRepeatableAnnotationOnComposedAnnotation() {
		Repeatable repeatable = findAnnotation(MyRepeatableMeta.class, Repeatable.class);
		assertNotNull(repeatable);
		assertEquals(MyRepeatableContainer.class, repeatable.value());
	}

359
	@Test
360
	public void getRepeatableFromMethod() throws Exception {
361 362 363 364 365 366 367 368 369 370 371
		Method method = InterfaceWithRepeated.class.getMethod("foo");
		Set<MyRepeatable> annotions = AnnotationUtils.getRepeatableAnnotation(method,
				MyRepeatableContainer.class, MyRepeatable.class);
		Set<String> values = new HashSet<String>();
		for (MyRepeatable myRepeatable : annotions) {
			values.add(myRepeatable.value());
		}
		assertThat(values, equalTo((Set<String>) new HashSet<String>(
				Arrays.asList("a", "b", "c", "meta"))));
	}

372

373
	@Component(value = "meta1")
374
	@Order
375
	@Retention(RetentionPolicy.RUNTIME)
376
	@Inherited
377 378 379
	@interface Meta1 {
	}

380 381
	@Component(value = "meta2")
	@Transactional(readOnly = true)
382 383 384 385
	@Retention(RetentionPolicy.RUNTIME)
	@interface Meta2 {
	}

386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
	@Meta2
	@Retention(RetentionPolicy.RUNTIME)
	@interface MetaMeta {
	}

	@MetaMeta
	@Retention(RetentionPolicy.RUNTIME)
	@interface MetaMetaMeta {
	}

	@MetaCycle3
	@Retention(RetentionPolicy.RUNTIME)
	@interface MetaCycle1 {
	}

	@MetaCycle1
	@Retention(RetentionPolicy.RUNTIME)
	@interface MetaCycle2 {
	}

	@MetaCycle2
	@Retention(RetentionPolicy.RUNTIME)
	@interface MetaCycle3 {
	}

411
	@Meta1
412 413 414
	static interface InterfaceWithMetaAnnotation {
	}

415
	@Meta2
416
	static class ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface implements InterfaceWithMetaAnnotation {
417 418
	}

419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
	@Meta1
	static class ClassWithInheritedMetaAnnotation {
	}

	@Meta2
	static class SubClassWithInheritedMetaAnnotation extends ClassWithInheritedMetaAnnotation {
	}

	static class SubSubClassWithInheritedMetaAnnotation extends SubClassWithInheritedMetaAnnotation {
	}

	@Transactional
	static class ClassWithInheritedAnnotation {
	}

	@Meta2
	static class SubClassWithInheritedAnnotation extends ClassWithInheritedAnnotation {
	}

	static class SubSubClassWithInheritedAnnotation extends SubClassWithInheritedAnnotation {
	}

441 442 443 444 445 446 447 448 449 450 451
	@MetaMeta
	static class MetaMetaAnnotatedClass {
	}

	@MetaMetaMeta
	static class MetaMetaMetaAnnotatedClass {
	}

	@MetaCycle3
	static class MetaCycleAnnotatedClass {
	}
452

A
Arjen Poutsma 已提交
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474
	public static interface AnnotatedInterface {

		@Order(0)
		void fromInterfaceImplementedByRoot();
	}

	public static class Root implements AnnotatedInterface {

		@Order(27)
		public void annotatedOnRoot() {
		}

		public void overrideToAnnotate() {
		}

		@Order(27)
		public void overrideWithoutNewAnnotation() {
		}

		public void notAnnotated() {
		}

475
		@Override
A
Arjen Poutsma 已提交
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
		public void fromInterfaceImplementedByRoot() {
		}
	}

	public static class Leaf extends Root {

		@Order(25)
		public void annotatedOnLeaf() {
		}

		@Override
		@Order(1)
		public void overrideToAnnotate() {
		}

		@Override
		public void overrideWithoutNewAnnotation() {
		}
	}

J
Juergen Hoeller 已提交
496 497 498
	@Retention(RetentionPolicy.RUNTIME)
	@Inherited
	@interface Transactional {
499 500

		boolean readOnly() default false;
J
Juergen Hoeller 已提交
501 502
	}

A
Arjen Poutsma 已提交
503 504 505 506 507 508 509 510
	public static abstract class Foo<T> {

		@Order(1)
		public abstract void something(T arg);
	}

	public static class SimpleFoo extends Foo<String> {

511
		@Override
A
Arjen Poutsma 已提交
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
		@Transactional
		public void something(final String arg) {
		}
	}

	@Transactional
	public static interface InheritedAnnotationInterface {
	}

	public static interface SubInheritedAnnotationInterface extends InheritedAnnotationInterface {
	}

	@Order
	public static interface NonInheritedAnnotationInterface {
	}

	public static interface SubNonInheritedAnnotationInterface extends NonInheritedAnnotationInterface {
	}

	public static class NonAnnotatedClass {
	}

	public static interface NonAnnotatedInterface {
	}

	@Transactional
	public static class InheritedAnnotationClass {
	}

	public static class SubInheritedAnnotationClass extends InheritedAnnotationClass {
	}

	@Order
	public static class NonInheritedAnnotationClass {
	}

	public static class SubNonInheritedAnnotationClass extends NonInheritedAnnotationClass {
	}

551 552 553 554 555
	@Transactional
	public static class TransactionalClass {
	}

	@Order
556
	public static class TransactionalAndOrderedClass extends TransactionalClass {
557 558 559 560
	}

	public static class SubTransactionalAndOrderedClass extends TransactionalAndOrderedClass {
	}
561 562 563 564 565 566 567 568 569

	public static interface InterfaceWithAnnotatedMethod {

		@Order
		void foo();
	}

	public static class ImplementsInterfaceWithAnnotatedMethod implements InterfaceWithAnnotatedMethod {

570
		@Override
571 572 573 574 575 576
		public void foo() {
		}
	}

	public static class SubOfImplementsInterfaceWithAnnotatedMethod extends ImplementsInterfaceWithAnnotatedMethod {

577
		@Override
578 579 580 581
		public void foo() {
		}
	}

J
Juergen Hoeller 已提交
582 583
	public abstract static class AbstractDoesNotImplementInterfaceWithAnnotatedMethod
			implements InterfaceWithAnnotatedMethod {
584 585
	}

J
Juergen Hoeller 已提交
586 587
	public static class SubOfAbstractImplementsInterfaceWithAnnotatedMethod
			extends AbstractDoesNotImplementInterfaceWithAnnotatedMethod {
588

589
		@Override
590 591 592 593
		public void foo() {
		}
	}

J
Juergen Hoeller 已提交
594 595 596
	@Retention(RetentionPolicy.RUNTIME)
	@Inherited
	@interface MyRepeatableContainer {
597

J
Juergen Hoeller 已提交
598
		MyRepeatable[] value();
599 600
	}

J
Juergen Hoeller 已提交
601 602 603 604
	@Retention(RetentionPolicy.RUNTIME)
	@Inherited
	@Repeatable(MyRepeatableContainer.class)
	@interface MyRepeatable {
605

J
Juergen Hoeller 已提交
606 607
		String value();
	}
608

J
Juergen Hoeller 已提交
609 610 611 612 613
	@Retention(RetentionPolicy.RUNTIME)
	@Inherited
	@MyRepeatable("meta")
	@interface MyRepeatableMeta {
	}
614

J
Juergen Hoeller 已提交
615
	public static interface InterfaceWithRepeated {
616

J
Juergen Hoeller 已提交
617 618 619 620 621
		@MyRepeatable("a")
		@MyRepeatableContainer({ @MyRepeatable("b"), @MyRepeatable("c") })
		@MyRepeatableMeta
		void foo();
	}
622 623

}