|
24 | 24 | import java.lang.annotation.Target;
|
25 | 25 |
|
26 | 26 | /**
|
27 |
| - * {@code TestExecutionListeners} defines class-level metadata for |
28 |
| - * configuring which {@link TestExecutionListener TestExecutionListeners} should |
29 |
| - * be registered with a {@link TestContextManager}. |
| 27 | + * {@code TestExecutionListeners} defines class-level metadata for configuring |
| 28 | + * which {@link TestExecutionListener TestExecutionListeners} should be |
| 29 | + * registered with a {@link TestContextManager}. |
30 | 30 | *
|
31 | 31 | * <p>Typically, {@code @TestExecutionListeners} will be used in conjunction with
|
32 | 32 | * {@link ContextConfiguration @ContextConfiguration}.
|
|
47 | 47 | public @interface TestExecutionListeners {
|
48 | 48 |
|
49 | 49 | /**
|
50 |
| - * Alias for {@link #listeners() listeners}. |
| 50 | + * Enumeration of <em>modes</em> that dictate whether or not explicitly |
| 51 | + * declared listeners are merged with the default listeners when |
| 52 | + * {@code @TestExecutionListeners} is declared on a class that does |
| 53 | + * <strong>not</strong> inherit listeners from a superclass. |
| 54 | + * @since 4.1 |
| 55 | + */ |
| 56 | + static enum MergeMode { |
| 57 | + |
| 58 | + /** |
| 59 | + * Indicates that locally declared listeners should replace the default |
| 60 | + * listeners. |
| 61 | + */ |
| 62 | + REPLACE_DEFAULTS, |
| 63 | + |
| 64 | + /** |
| 65 | + * Indicates that locally declared listeners should be merged with the |
| 66 | + * default listeners. |
| 67 | + * <p>The merging algorithm ensures that duplicates are removed from |
| 68 | + * the list and that the resulting set of merged listeners is sorted |
| 69 | + * according to the semantics of |
| 70 | + * {@link org.springframework.core.annotation.AnnotationAwareOrderComparator |
| 71 | + * AnnotationAwareOrderComparator}. If a listener implements |
| 72 | + * {@link org.springframework.core.Ordered Ordered} or is annotated |
| 73 | + * with {@link org.springframework.core.annotation.Order @Order} it can |
| 74 | + * influence the position in which it is merged with the defaults; otherwise, |
| 75 | + * locally declared listeners will simply be appended to the list of default |
| 76 | + * listeners when merged. |
| 77 | + */ |
| 78 | + MERGE_WITH_DEFAULTS, |
| 79 | + } |
| 80 | + |
| 81 | + |
| 82 | + /** |
| 83 | + * Alias for {@link #listeners}. |
51 | 84 | *
|
52 | 85 | * <p>This attribute may <strong>not</strong> be used in conjunction with
|
53 | 86 | * {@link #listeners}, but it may be used instead of {@link #listeners}.
|
|
56 | 89 |
|
57 | 90 | /**
|
58 | 91 | * The {@link TestExecutionListener TestExecutionListeners} to register with
|
59 |
| - * a {@link TestContextManager}. |
| 92 | + * the {@link TestContextManager}. |
60 | 93 | *
|
61 | 94 | * <p>This attribute may <strong>not</strong> be used in conjunction with
|
62 | 95 | * {@link #value}, but it may be used instead of {@link #value}.
|
|
65 | 98 | * @see org.springframework.test.context.support.DependencyInjectionTestExecutionListener
|
66 | 99 | * @see org.springframework.test.context.support.DirtiesContextTestExecutionListener
|
67 | 100 | * @see org.springframework.test.context.transaction.TransactionalTestExecutionListener
|
| 101 | + * @see org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener |
68 | 102 | */
|
69 | 103 | Class<? extends TestExecutionListener>[] listeners() default {};
|
70 | 104 |
|
71 | 105 | /**
|
72 |
| - * Whether or not {@link #value() TestExecutionListeners} from superclasses |
| 106 | + * Whether or not {@link #listeners TestExecutionListeners} from superclasses |
73 | 107 | * should be <em>inherited</em>.
|
74 |
| - * <p> |
75 |
| - * The default value is {@code true}, which means that an annotated |
| 108 | + * |
| 109 | + * <p>The default value is {@code true}, which means that an annotated |
76 | 110 | * class will <em>inherit</em> the listeners defined by an annotated
|
77 | 111 | * superclass. Specifically, the listeners for an annotated class will be
|
78 | 112 | * appended to the list of listeners defined by an annotated superclass.
|
|
106 | 140 | */
|
107 | 141 | boolean inheritListeners() default true;
|
108 | 142 |
|
| 143 | + /** |
| 144 | + * The <em>merge mode</em> to use when {@code @TestExecutionListeners} is |
| 145 | + * declared on a class that does <strong>not</strong> inherit listeners |
| 146 | + * from a superclass. |
| 147 | + * <p>Can be set to {@link MergeMode#MERGE_WITH_DEFAULTS MERGE_WITH_DEFAULTS} |
| 148 | + * to have locally declared listeners <em>merged</em> with the default |
| 149 | + * listeners. |
| 150 | + * <p>The mode is ignored if listeners are inherited from a superclass. |
| 151 | + * <p>Defaults to {@link MergeMode#REPLACE_DEFAULTS REPLACE_DEFAULTS} |
| 152 | + * for backwards compatibility. |
| 153 | + * @see MergeMode |
| 154 | + * @since 4.1 |
| 155 | + */ |
| 156 | + MergeMode mergeMode() default MergeMode.REPLACE_DEFAULTS; |
| 157 | + |
109 | 158 | }
|
0 commit comments