|
16 | 16 |
|
17 | 17 | package org.springframework.scheduling.annotation;
|
18 | 18 |
|
| 19 | +import java.lang.annotation.Retention; |
| 20 | +import java.lang.annotation.RetentionPolicy; |
| 21 | + |
19 | 22 | import org.junit.Test;
|
20 | 23 |
|
21 | 24 | import static org.hamcrest.CoreMatchers.*;
|
|
25 | 28 | * Unit tests for {@link AnnotationAsyncExecutionInterceptor}.
|
26 | 29 | *
|
27 | 30 | * @author Chris Beams
|
28 |
| - * @since 3.1.2 |
| 31 | + * @since 3.2 |
29 | 32 | */
|
30 | 33 | public class AnnotationAsyncExecutionInterceptorTests {
|
31 | 34 |
|
32 | 35 | @Test
|
33 | 36 | @SuppressWarnings("unused")
|
34 | 37 | public void testGetExecutorQualifier() throws SecurityException, NoSuchMethodException {
|
35 | 38 | AnnotationAsyncExecutionInterceptor i = new AnnotationAsyncExecutionInterceptor(null);
|
36 |
| - { |
| 39 | + { // method level |
37 | 40 | class C { @Async("qMethod") void m() { } }
|
38 | 41 | assertThat(i.getExecutorQualifier(C.class.getDeclaredMethod("m")), is("qMethod"));
|
39 | 42 | }
|
40 |
| - { |
| 43 | + { // class level |
41 | 44 | @Async("qClass") class C { void m() { } }
|
42 | 45 | assertThat(i.getExecutorQualifier(C.class.getDeclaredMethod("m")), is("qClass"));
|
43 | 46 | }
|
44 |
| - { |
| 47 | + { // method and class level -> method value overrides |
45 | 48 | @Async("qClass") class C { @Async("qMethod") void m() { } }
|
46 | 49 | assertThat(i.getExecutorQualifier(C.class.getDeclaredMethod("m")), is("qMethod"));
|
47 | 50 | }
|
48 |
| - { |
| 51 | + { // method and class level -> method value, even if empty, overrides |
49 | 52 | @Async("qClass") class C { @Async void m() { } }
|
50 | 53 | assertThat(i.getExecutorQualifier(C.class.getDeclaredMethod("m")), is(""));
|
51 | 54 | }
|
| 55 | + { // meta annotation with qualifier |
| 56 | + @MyAsync class C { void m() { } } |
| 57 | + assertThat(i.getExecutorQualifier(C.class.getDeclaredMethod("m")), is("qMeta")); |
| 58 | + } |
52 | 59 | }
|
| 60 | + |
| 61 | + @Async("qMeta") |
| 62 | + @Retention(RetentionPolicy.RUNTIME) |
| 63 | + @interface MyAsync { } |
53 | 64 | }
|
0 commit comments