AnnotationUtilsTests.java 22.5 KB
Newer Older
A
Arjen Poutsma 已提交
1
/*
2
 * Copyright 2002-2014 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
		// TODO: actually found on OpenJDK 8 b99! assertNull(m.getAnnotation(Transactional.class));
A
Arjen Poutsma 已提交
89 90 91 92 93
		assertNotNull(getAnnotation(m, Transactional.class));
		assertNotNull(findAnnotation(m, Transactional.class));
	}

	// TODO consider whether we want this to handle annotations on interfaces
94
	// public void findMethodAnnotationFromInterfaceImplementedByRoot()
A
Arjen Poutsma 已提交
95 96 97 98 99 100 101
	// throws Exception {
	// Method m = Leaf.class.getMethod("fromInterfaceImplementedByRoot",
	// (Class[]) null);
	// Order o = findAnnotation(Order.class, m, Leaf.class);
	// assertNotNull(o);
	// }

102
	@Test
103
	public void findAnnotationFavorsInterfacesOverLocalMetaAnnotations() {
104
		Component component = AnnotationUtils.findAnnotation(
105 106
			ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface.class, Component.class);
		assertNotNull(component);
107 108 109 110

		// By inspecting ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface, one
		// might expect that "meta2" should be found; however, with the current
		// implementation "meta1" will be found.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
		assertEquals("meta1", component.value());
	}

	@Test
	public void findAnnotationFavorsInheritedAnnotationsOverMoreLocallyDeclaredComposedAnnotations() {
		Transactional transactional = AnnotationUtils.findAnnotation(SubSubClassWithInheritedAnnotation.class,
			Transactional.class);
		assertNotNull(transactional);

		// By inspecting SubSubClassWithInheritedAnnotation, one might expect that the
		// readOnly flag should be true, since the immediate superclass is annotated with
		// @Composed2; however, with the current implementation the readOnly flag will be
		// false since @Transactional is declared as @Inherited.
		assertFalse("readOnly flag for SubSubClassWithInheritedAnnotation", transactional.readOnly());
	}

	@Test
	public void findAnnotationFavorsInheritedComposedAnnotationsOverMoreLocallyDeclaredComposedAnnotations() {
		Component component = AnnotationUtils.findAnnotation(SubSubClassWithInheritedMetaAnnotation.class,
			Component.class);
131
		assertNotNull(component);
132 133 134 135 136

		// By inspecting SubSubClassWithInheritedMetaAnnotation, one might expect that
		// "meta2" should be found, since the immediate superclass is annotated with
		// @Meta2; however, with the current implementation "meta1" will be found since
		// @Meta1 is declared as @Inherited.
137 138 139
		assertEquals("meta1", component.value());
	}

140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
	@Test
	public void findAnnotationOnMetaMetaAnnotatedClass() {
		Component component = AnnotationUtils.findAnnotation(MetaMetaAnnotatedClass.class, Component.class);
		assertNotNull("Should find meta-annotation on composed annotation on class", component);
		assertEquals("meta2", component.value());
	}

	@Test
	public void findAnnotationOnMetaMetaMetaAnnotatedClass() {
		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
	public void findAnnotationOnAnnotatedClassWithMissingTargetMetaAnnotation() {
		// 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
	public void findAnnotationOnMetaCycleAnnotatedClassWithMissingTargetMetaAnnotation() {
		Component component = AnnotationUtils.findAnnotation(MetaCycleAnnotatedClass.class, Component.class);
		assertNull("Should not find @Component on MetaCycleAnnotatedClass", component);
	}

167
	@Test
A
Arjen Poutsma 已提交
168 169 170 171 172 173
	public void testFindAnnotationDeclaringClass() throws Exception {
		// no class-level annotation
		assertNull(findAnnotationDeclaringClass(Transactional.class, NonAnnotatedInterface.class));
		assertNull(findAnnotationDeclaringClass(Transactional.class, NonAnnotatedClass.class));

		// inherited class-level annotation; note: @Transactional is inherited
174 175
		assertEquals(InheritedAnnotationInterface.class,
			findAnnotationDeclaringClass(Transactional.class, InheritedAnnotationInterface.class));
A
Arjen Poutsma 已提交
176
		assertNull(findAnnotationDeclaringClass(Transactional.class, SubInheritedAnnotationInterface.class));
177 178 179 180
		assertEquals(InheritedAnnotationClass.class,
			findAnnotationDeclaringClass(Transactional.class, InheritedAnnotationClass.class));
		assertEquals(InheritedAnnotationClass.class,
			findAnnotationDeclaringClass(Transactional.class, SubInheritedAnnotationClass.class));
A
Arjen Poutsma 已提交
181 182

		// non-inherited class-level annotation; note: @Order is not inherited,
183 184 185
		// but findAnnotationDeclaringClass() should still find it on classes.
		assertEquals(NonInheritedAnnotationInterface.class,
			findAnnotationDeclaringClass(Order.class, NonInheritedAnnotationInterface.class));
A
Arjen Poutsma 已提交
186
		assertNull(findAnnotationDeclaringClass(Order.class, SubNonInheritedAnnotationInterface.class));
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
		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 已提交
203
		assertNull(findAnnotationDeclaringClassForTypes(transactionalCandidateList, SubInheritedAnnotationInterface.class));
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
		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() {
223
		List<Class<? extends Annotation>> candidates = Arrays.<Class<? extends Annotation>> asList(Transactional.class, Order.class);
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254

		// 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 已提交
255 256
	}

257
	@Test
A
Arjen Poutsma 已提交
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
	public void testIsAnnotationDeclaredLocally() throws Exception {
		// 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));
	}

276
	@Test
A
Arjen Poutsma 已提交
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
	public void testIsAnnotationInherited() throws Exception {
		// 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));
	}

298
	@Test
299
	public void getValueFromAnnotation() throws Exception {
300 301
		Method method = SimpleFoo.class.getMethod("something", Object.class);
		Order order = findAnnotation(method, Order.class);
A
Arjen Poutsma 已提交
302 303 304 305 306

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

307
	@Test
308 309 310 311 312 313 314 315 316 317 318 319
	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 {
320 321
		Method method = SimpleFoo.class.getMethod("something", Object.class);
		Order order = findAnnotation(method, Order.class);
A
Arjen Poutsma 已提交
322 323 324 325 326

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

327
	@Test
328 329 330 331 332 333 334 335 336 337 338 339
	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 已提交
340 341 342 343
		assertEquals(Ordered.LOWEST_PRECEDENCE, AnnotationUtils.getDefaultValue(Order.class, AnnotationUtils.VALUE));
		assertEquals(Ordered.LOWEST_PRECEDENCE, AnnotationUtils.getDefaultValue(Order.class));
	}

344
	@Test
345
	public void findAnnotationFromInterface() throws Exception {
346 347 348 349 350 351
		Method method = ImplementsInterfaceWithAnnotatedMethod.class.getMethod("foo");
		Order order = findAnnotation(method, Order.class);
		assertNotNull(order);
	}

	@Test
352
	public void findAnnotationFromInterfaceOnSuper() throws Exception {
353 354 355 356 357
		Method method = SubOfImplementsInterfaceWithAnnotatedMethod.class.getMethod("foo");
		Order order = findAnnotation(method, Order.class);
		assertNotNull(order);
	}

358
	@Test
J
Juergen Hoeller 已提交
359
	public void findAnnotationFromInterfaceWhenSuperDoesNotImplementMethod() throws Exception {
360 361 362 363 364
		Method method = SubOfAbstractImplementsInterfaceWithAnnotatedMethod.class.getMethod("foo");
		Order order = findAnnotation(method, Order.class);
		assertNotNull(order);
	}

365 366 367 368 369 370 371
	@Test
	public void findRepeatableAnnotationOnComposedAnnotation() {
		Repeatable repeatable = findAnnotation(MyRepeatableMeta.class, Repeatable.class);
		assertNotNull(repeatable);
		assertEquals(MyRepeatableContainer.class, repeatable.value());
	}

372
	@Test
373
	public void getRepeatableFromMethod() throws Exception {
374 375 376 377 378 379 380 381 382 383 384
		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"))));
	}

385

386
	@Component(value = "meta1")
387
	@Order
388
	@Retention(RetentionPolicy.RUNTIME)
389
	@Inherited
390 391 392
	@interface Meta1 {
	}

393 394
	@Component(value = "meta2")
	@Transactional(readOnly = true)
395 396 397 398
	@Retention(RetentionPolicy.RUNTIME)
	@interface Meta2 {
	}

399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
	@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 {
	}

424
	@Meta1
425 426 427
	static interface InterfaceWithMetaAnnotation {
	}

428
	@Meta2
429
	static class ClassWithLocalMetaAnnotationAndMetaAnnotatedInterface implements InterfaceWithMetaAnnotation {
430 431
	}

432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
	@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 {
	}

454 455 456 457 458 459 460 461 462 463 464
	@MetaMeta
	static class MetaMetaAnnotatedClass {
	}

	@MetaMetaMeta
	static class MetaMetaMetaAnnotatedClass {
	}

	@MetaCycle3
	static class MetaCycleAnnotatedClass {
	}
465

A
Arjen Poutsma 已提交
466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
	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() {
		}

488
		@Override
A
Arjen Poutsma 已提交
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
		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 已提交
509 510 511
	@Retention(RetentionPolicy.RUNTIME)
	@Inherited
	@interface Transactional {
512 513

		boolean readOnly() default false;
J
Juergen Hoeller 已提交
514 515
	}

A
Arjen Poutsma 已提交
516 517 518 519 520 521 522 523
	public static abstract class Foo<T> {

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

	public static class SimpleFoo extends Foo<String> {

524
		@Override
A
Arjen Poutsma 已提交
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 551 552 553 554 555 556 557 558 559 560 561 562 563
		@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 {
	}

564 565 566 567 568
	@Transactional
	public static class TransactionalClass {
	}

	@Order
569
	public static class TransactionalAndOrderedClass extends TransactionalClass {
570 571 572 573
	}

	public static class SubTransactionalAndOrderedClass extends TransactionalAndOrderedClass {
	}
574 575 576 577 578 579 580 581 582

	public static interface InterfaceWithAnnotatedMethod {

		@Order
		void foo();
	}

	public static class ImplementsInterfaceWithAnnotatedMethod implements InterfaceWithAnnotatedMethod {

583
		@Override
584 585 586 587 588 589
		public void foo() {
		}
	}

	public static class SubOfImplementsInterfaceWithAnnotatedMethod extends ImplementsInterfaceWithAnnotatedMethod {

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

J
Juergen Hoeller 已提交
595 596
	public abstract static class AbstractDoesNotImplementInterfaceWithAnnotatedMethod
			implements InterfaceWithAnnotatedMethod {
597 598
	}

J
Juergen Hoeller 已提交
599 600
	public static class SubOfAbstractImplementsInterfaceWithAnnotatedMethod
			extends AbstractDoesNotImplementInterfaceWithAnnotatedMethod {
601

602
		@Override
603 604 605 606
		public void foo() {
		}
	}

J
Juergen Hoeller 已提交
607 608 609
	@Retention(RetentionPolicy.RUNTIME)
	@Inherited
	@interface MyRepeatableContainer {
610

J
Juergen Hoeller 已提交
611
		MyRepeatable[] value();
612 613
	}

J
Juergen Hoeller 已提交
614 615 616 617
	@Retention(RetentionPolicy.RUNTIME)
	@Inherited
	@Repeatable(MyRepeatableContainer.class)
	@interface MyRepeatable {
618

J
Juergen Hoeller 已提交
619 620
		String value();
	}
621

J
Juergen Hoeller 已提交
622 623 624 625 626
	@Retention(RetentionPolicy.RUNTIME)
	@Inherited
	@MyRepeatable("meta")
	@interface MyRepeatableMeta {
	}
627

J
Juergen Hoeller 已提交
628
	public static interface InterfaceWithRepeated {
629

J
Juergen Hoeller 已提交
630 631 632 633 634
		@MyRepeatable("a")
		@MyRepeatableContainer({ @MyRepeatable("b"), @MyRepeatable("c") })
		@MyRepeatableMeta
		void foo();
	}
635 636

}