Browse Source

Support merging custom TELs with default TELs

Prior to this commit, if a custom TestExecutionListener was registered
via @TestExecutionListeners the defaults would not be registered. Thus,
if a user wanted to declare a custom listener and use the default
listeners, the user was forced to manually declare all default
listeners in addition to any custom listeners. This unfortunately
required that the user know exactly which listeners were registered by
default. Moreover, the set of default listeners can change from release
to release, and with the support for automatic discovery of default
listeners introduced in SPR-11466 it is no longer even possible to know
what the set of default TestExecutionListeners is before runtime.

This commit addresses this issue by introducing a mechanism for merging
custom declared listeners with the defaults for the current
environment. Specifically, @TestExecutionListeners supports a new
MergeMode that is used to control whether or not explicitly declared
listeners are merged with the default listeners when
@TestExecutionListeners is declared on a class that does not inherit
listeners from a superclass.

Issue: SPR-8854
pull/623/merge
Sam Brannen 12 years ago
parent
commit
66250b1f8e
  1. 65
      spring-test/src/main/java/org/springframework/test/context/TestExecutionListeners.java
  2. 33
      spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java
  3. 222
      spring-test/src/test/java/org/springframework/test/context/TestExecutionListenersTests.java

65
spring-test/src/main/java/org/springframework/test/context/TestExecutionListeners.java

@ -24,9 +24,9 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
/** /**
* {@code TestExecutionListeners} defines class-level metadata for * {@code TestExecutionListeners} defines class-level metadata for configuring
* configuring which {@link TestExecutionListener TestExecutionListeners} should * which {@link TestExecutionListener TestExecutionListeners} should be
* be registered with a {@link TestContextManager}. * registered with a {@link TestContextManager}.
* *
* <p>Typically, {@code @TestExecutionListeners} will be used in conjunction with * <p>Typically, {@code @TestExecutionListeners} will be used in conjunction with
* {@link ContextConfiguration @ContextConfiguration}. * {@link ContextConfiguration @ContextConfiguration}.
@ -47,7 +47,40 @@ import java.lang.annotation.Target;
public @interface TestExecutionListeners { public @interface TestExecutionListeners {
/** /**
* Alias for {@link #listeners() listeners}. * Enumeration of <em>modes</em> that dictate whether or not explicitly
* declared listeners are merged with the default listeners when
* {@code @TestExecutionListeners} is declared on a class that does
* <strong>not</strong> inherit listeners from a superclass.
* @since 4.1
*/
static enum MergeMode {
/**
* Indicates that locally declared listeners should replace the default
* listeners.
*/
REPLACE_DEFAULTS,
/**
* Indicates that locally declared listeners should be merged with the
* default listeners.
* <p>The merging algorithm ensures that duplicates are removed from
* the list and that the resulting set of merged listeners is sorted
* according to the semantics of
* {@link org.springframework.core.annotation.AnnotationAwareOrderComparator
* AnnotationAwareOrderComparator}. If a listener implements
* {@link org.springframework.core.Ordered Ordered} or is annotated
* with {@link org.springframework.core.annotation.Order @Order} it can
* influence the position in which it is merged with the defaults; otherwise,
* locally declared listeners will simply be appended to the list of default
* listeners when merged.
*/
MERGE_WITH_DEFAULTS,
}
/**
* Alias for {@link #listeners}.
* *
* <p>This attribute may <strong>not</strong> be used in conjunction with * <p>This attribute may <strong>not</strong> be used in conjunction with
* {@link #listeners}, but it may be used instead of {@link #listeners}. * {@link #listeners}, but it may be used instead of {@link #listeners}.
@ -56,7 +89,7 @@ public @interface TestExecutionListeners {
/** /**
* The {@link TestExecutionListener TestExecutionListeners} to register with * The {@link TestExecutionListener TestExecutionListeners} to register with
* a {@link TestContextManager}. * the {@link TestContextManager}.
* *
* <p>This attribute may <strong>not</strong> be used in conjunction with * <p>This attribute may <strong>not</strong> be used in conjunction with
* {@link #value}, but it may be used instead of {@link #value}. * {@link #value}, but it may be used instead of {@link #value}.
@ -65,14 +98,15 @@ public @interface TestExecutionListeners {
* @see org.springframework.test.context.support.DependencyInjectionTestExecutionListener * @see org.springframework.test.context.support.DependencyInjectionTestExecutionListener
* @see org.springframework.test.context.support.DirtiesContextTestExecutionListener * @see org.springframework.test.context.support.DirtiesContextTestExecutionListener
* @see org.springframework.test.context.transaction.TransactionalTestExecutionListener * @see org.springframework.test.context.transaction.TransactionalTestExecutionListener
* @see org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener
*/ */
Class<? extends TestExecutionListener>[] listeners() default {}; Class<? extends TestExecutionListener>[] listeners() default {};
/** /**
* Whether or not {@link #value() TestExecutionListeners} from superclasses * Whether or not {@link #listeners TestExecutionListeners} from superclasses
* should be <em>inherited</em>. * should be <em>inherited</em>.
* <p> *
* The default value is {@code true}, which means that an annotated * <p>The default value is {@code true}, which means that an annotated
* class will <em>inherit</em> the listeners defined by an annotated * class will <em>inherit</em> the listeners defined by an annotated
* superclass. Specifically, the listeners for an annotated class will be * superclass. Specifically, the listeners for an annotated class will be
* appended to the list of listeners defined by an annotated superclass. * appended to the list of listeners defined by an annotated superclass.
@ -106,4 +140,19 @@ public @interface TestExecutionListeners {
*/ */
boolean inheritListeners() default true; boolean inheritListeners() default true;
/**
* The <em>merge mode</em> to use when {@code @TestExecutionListeners} is
* declared on a class that does <strong>not</strong> inherit listeners
* from a superclass.
* <p>Can be set to {@link MergeMode#MERGE_WITH_DEFAULTS MERGE_WITH_DEFAULTS}
* to have locally declared listeners <em>merged</em> with the default
* listeners.
* <p>The mode is ignored if listeners are inherited from a superclass.
* <p>Defaults to {@link MergeMode#REPLACE_DEFAULTS REPLACE_DEFAULTS}
* for backwards compatibility.
* @see MergeMode
* @since 4.1
*/
MergeMode mergeMode() default MergeMode.REPLACE_DEFAULTS;
} }

33
spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java

@ -19,6 +19,7 @@ package org.springframework.test.context.support;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -45,6 +46,7 @@ import org.springframework.test.context.SmartContextLoader;
import org.springframework.test.context.TestContextBootstrapper; import org.springframework.test.context.TestContextBootstrapper;
import org.springframework.test.context.TestExecutionListener; import org.springframework.test.context.TestExecutionListener;
import org.springframework.test.context.TestExecutionListeners; import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.TestExecutionListeners.MergeMode;
import org.springframework.test.util.MetaAnnotationUtils; import org.springframework.test.util.MetaAnnotationUtils;
import org.springframework.test.util.MetaAnnotationUtils.AnnotationDescriptor; import org.springframework.test.util.MetaAnnotationUtils.AnnotationDescriptor;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -137,14 +139,37 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
listenerClasses = valueListenerClasses; listenerClasses = valueListenerClasses;
} }
if (listenerClasses != null) { boolean inheritListeners = annAttrs.getBoolean("inheritListeners");
classesList.addAll(0, Arrays.<Class<? extends TestExecutionListener>> asList(listenerClasses)); AnnotationDescriptor<TestExecutionListeners> superDescriptor = MetaAnnotationUtils.findAnnotationDescriptor(
descriptor.getRootDeclaringClass().getSuperclass(), annotationType);
// If there are no listeners to inherit, we might need to merge the
// locally declared listeners with the defaults.
if ((!inheritListeners || superDescriptor == null)
&& (annAttrs.getEnum("mergeMode") == MergeMode.MERGE_WITH_DEFAULTS)) {
if (logger.isDebugEnabled()) {
logger.debug(String.format(
"Merging default listeners with listeners configured via @TestExecutionListeners for class [%s].",
clazz.getName()));
}
usingDefaults = true;
classesList.addAll(getDefaultTestExecutionListenerClasses());
} }
descriptor = (annAttrs.getBoolean("inheritListeners") ? MetaAnnotationUtils.findAnnotationDescriptor(
descriptor.getRootDeclaringClass().getSuperclass(), annotationType) : null); classesList.addAll(0, Arrays.<Class<? extends TestExecutionListener>> asList(listenerClasses));
descriptor = (inheritListeners ? superDescriptor : null);
} }
} }
// Remove possible duplicates if we loaded default listeners.
if (usingDefaults) {
Set<Class<? extends TestExecutionListener>> classesSet = new HashSet<Class<? extends TestExecutionListener>>();
classesSet.addAll(classesList);
classesList.clear();
classesList.addAll(classesSet);
}
List<TestExecutionListener> listeners = instantiateListeners(classesList); List<TestExecutionListener> listeners = instantiateListeners(classesList);
// Sort by Ordered/@Order if we loaded default listeners. // Sort by Ordered/@Order if we loaded default listeners.

222
spring-test/src/test/java/org/springframework/test/context/TestExecutionListenersTests.java

@ -18,23 +18,30 @@ package org.springframework.test.context;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.Test; import org.junit.Test;
import org.springframework.core.Ordered;
import org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener;
import org.springframework.test.context.support.AbstractTestExecutionListener; import org.springframework.test.context.support.AbstractTestExecutionListener;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
import org.springframework.test.context.web.ServletTestExecutionListener;
import static java.util.Arrays.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.springframework.test.context.TestExecutionListeners.MergeMode.*;
/** /**
* <p> * Unit tests for the {@link TestExecutionListeners @TestExecutionListeners}
* JUnit 4 based unit test for the {@link TestExecutionListeners * annotation, which verify:
* &#064;TestExecutionListeners} annotation, which verifies:
* </p>
* <ul> * <ul>
* <li>Proper registering of {@link TestExecutionListener listeners} in * <li>Proper registering of {@link TestExecutionListener listeners} in
* conjunction with a {@link TestContextManager}</li> * conjunction with a {@link TestContextManager}</li>
* <li><em>Inherited</em> functionality proposed in <a * <li><em>Inherited</em> functionality proposed in
* href="http://opensource.atlassian.com/projects/spring/browse/SPR-3896" * <a href="https://jira.spring.io/browse/SPR-3896" target="_blank">SPR-3896</a></li>
* target="_blank">SPR-3896</a></li>
* </ul> * </ul>
* *
* @author Sam Brannen * @author Sam Brannen
@ -42,140 +49,195 @@ import static org.junit.Assert.*;
*/ */
public class TestExecutionListenersTests { public class TestExecutionListenersTests {
private List<Class<?>> classes(TestContextManager testContextManager) {
return testContextManager.getTestExecutionListeners().stream().map(listener -> listener.getClass()).collect(
Collectors.toList());
}
private List<String> names(List<Class<?>> classes) {
return classes.stream().map(clazz -> clazz.getSimpleName()).collect(Collectors.toList());
}
private void assertRegisteredListeners(Class<?> testClass, List<Class<?>> expected) {
TestContextManager testContextManager = new TestContextManager(testClass);
assertEquals("TELs registered for " + testClass.getSimpleName(), names(expected),
names(classes(testContextManager)));
}
@Test @Test
public void verifyNumDefaultListenersRegistered() throws Exception { public void defaultListeners() {
TestContextManager testContextManager = new TestContextManager(DefaultListenersExampleTestCase.class); List<Class<?>> expected = asList(ServletTestExecutionListener.class,
assertEquals("Num registered TELs for DefaultListenersExampleTestCase.", 5, DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class,
testContextManager.getTestExecutionListeners().size()); TransactionalTestExecutionListener.class, SqlScriptsTestExecutionListener.class);
assertRegisteredListeners(DefaultListenersTestCase.class, expected);
} }
/**
* @since 4.1
*/
@Test @Test
public void verifyNumNonInheritedDefaultListenersRegistered() throws Exception { public void defaultListenersMergedWithCustomListenerPrepended() {
TestContextManager testContextManager = new TestContextManager( List<Class<?>> expected = asList(QuuxTestExecutionListener.class, ServletTestExecutionListener.class,
NonInheritedDefaultListenersExampleTestCase.class); DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class,
assertEquals("Num registered TELs for NonInheritedDefaultListenersExampleTestCase.", 1, TransactionalTestExecutionListener.class, SqlScriptsTestExecutionListener.class);
testContextManager.getTestExecutionListeners().size()); assertRegisteredListeners(MergedDefaultListenersWithCustomListenerPrependedTestCase.class, expected);
} }
/**
* @since 4.1
*/
@Test @Test
public void verifyNumInheritedDefaultListenersRegistered() throws Exception { public void defaultListenersMergedWithCustomListenerAppended() {
TestContextManager testContextManager = new TestContextManager(InheritedDefaultListenersExampleTestCase.class); List<Class<?>> expected = asList(ServletTestExecutionListener.class,
assertEquals("Num registered TELs for InheritedDefaultListenersExampleTestCase.", 1, DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class,
testContextManager.getTestExecutionListeners().size()); TransactionalTestExecutionListener.class, SqlScriptsTestExecutionListener.class,
BazTestExecutionListener.class);
assertRegisteredListeners(MergedDefaultListenersWithCustomListenerAppendedTestCase.class, expected);
}
testContextManager = new TestContextManager(SubInheritedDefaultListenersExampleTestCase.class); /**
assertEquals("Num registered TELs for SubInheritedDefaultListenersExampleTestCase.", 1, * @since 4.1
testContextManager.getTestExecutionListeners().size()); */
@Test
public void defaultListenersMergedWithCustomListenerInserted() {
List<Class<?>> expected = asList(ServletTestExecutionListener.class,
DependencyInjectionTestExecutionListener.class, BarTestExecutionListener.class,
DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class,
SqlScriptsTestExecutionListener.class);
assertRegisteredListeners(MergedDefaultListenersWithCustomListenerInsertedTestCase.class, expected);
}
testContextManager = new TestContextManager(SubSubInheritedDefaultListenersExampleTestCase.class); @Test
assertEquals("Num registered TELs for SubSubInheritedDefaultListenersExampleTestCase.", 2, public void nonInheritedDefaultListeners() {
testContextManager.getTestExecutionListeners().size()); assertRegisteredListeners(NonInheritedDefaultListenersTestCase.class, asList(QuuxTestExecutionListener.class));
} }
@Test @Test
public void verifyNumListenersRegistered() throws Exception { public void inheritedDefaultListeners() {
TestContextManager testContextManager = new TestContextManager(ExampleTestCase.class); assertRegisteredListeners(InheritedDefaultListenersTestCase.class, asList(QuuxTestExecutionListener.class));
assertEquals("Num registered TELs for ExampleTestCase.", 3, assertRegisteredListeners(SubInheritedDefaultListenersTestCase.class, asList(QuuxTestExecutionListener.class));
testContextManager.getTestExecutionListeners().size()); assertRegisteredListeners(SubSubInheritedDefaultListenersTestCase.class,
asList(QuuxTestExecutionListener.class, EnigmaTestExecutionListener.class));
} }
@Test @Test
public void verifyNumNonInheritedListenersRegistered() throws Exception { public void customListeners() {
TestContextManager testContextManager = new TestContextManager(NonInheritedListenersExampleTestCase.class); TestContextManager testContextManager = new TestContextManager(ExplicitListenersTestCase.class);
assertEquals("Num registered TELs for NonInheritedListenersExampleTestCase.", 1, assertEquals("Num registered TELs for ExplicitListenersTestCase.", 3,
testContextManager.getTestExecutionListeners().size()); testContextManager.getTestExecutionListeners().size());
} }
@Test @Test
public void verifyNumInheritedListenersRegistered() throws Exception { public void nonInheritedListeners() {
TestContextManager testContextManager = new TestContextManager(InheritedListenersExampleTestCase.class); TestContextManager testContextManager = new TestContextManager(NonInheritedListenersTestCase.class);
assertEquals("Num registered TELs for InheritedListenersExampleTestCase.", 4, assertEquals("Num registered TELs for NonInheritedListenersTestCase.", 1,
testContextManager.getTestExecutionListeners().size()); testContextManager.getTestExecutionListeners().size());
} }
@Test @Test
public void verifyNumListenersRegisteredViaMetaAnnotation() throws Exception { public void inheritedListeners() {
TestContextManager testContextManager = new TestContextManager(MetaExampleTestCase.class); TestContextManager testContextManager = new TestContextManager(InheritedListenersTestCase.class);
assertEquals("Num registered TELs for MetaExampleTestCase.", 3, assertEquals("Num registered TELs for InheritedListenersTestCase.", 4,
testContextManager.getTestExecutionListeners().size()); testContextManager.getTestExecutionListeners().size());
} }
@Test @Test
public void verifyNumNonInheritedListenersRegisteredViaMetaAnnotation() throws Exception { public void customListenersRegisteredViaMetaAnnotation() {
TestContextManager testContextManager = new TestContextManager(MetaNonInheritedListenersExampleTestCase.class); TestContextManager testContextManager = new TestContextManager(MetaTestCase.class);
assertEquals("Num registered TELs for MetaNonInheritedListenersExampleTestCase.", 1, assertEquals("Num registered TELs for MetaTestCase.", 3, testContextManager.getTestExecutionListeners().size());
}
@Test
public void nonInheritedListenersRegisteredViaMetaAnnotation() {
TestContextManager testContextManager = new TestContextManager(MetaNonInheritedListenersTestCase.class);
assertEquals("Num registered TELs for MetaNonInheritedListenersTestCase.", 1,
testContextManager.getTestExecutionListeners().size()); testContextManager.getTestExecutionListeners().size());
} }
@Test @Test
public void verifyNumInheritedListenersRegisteredViaMetaAnnotation() throws Exception { public void inheritedListenersRegisteredViaMetaAnnotation() {
TestContextManager testContextManager = new TestContextManager(MetaInheritedListenersExampleTestCase.class); TestContextManager testContextManager = new TestContextManager(MetaInheritedListenersTestCase.class);
assertEquals("Num registered TELs for MetaInheritedListenersExampleTestCase.", 4, assertEquals("Num registered TELs for MetaInheritedListenersTestCase.", 4,
testContextManager.getTestExecutionListeners().size()); testContextManager.getTestExecutionListeners().size());
} }
@Test @Test
public void verifyNumListenersRegisteredViaMetaAnnotationWithOverrides() throws Exception { public void customListenersRegisteredViaMetaAnnotationWithOverrides() {
TestContextManager testContextManager = new TestContextManager(MetaWithOverridesExampleTestCase.class); TestContextManager testContextManager = new TestContextManager(MetaWithOverridesTestCase.class);
assertEquals("Num registered TELs for MetaWithOverridesExampleTestCase.", 3, assertEquals("Num registered TELs for MetaWithOverridesTestCase.", 3,
testContextManager.getTestExecutionListeners().size()); testContextManager.getTestExecutionListeners().size());
} }
@Test @Test
public void verifyNumListenersRegisteredViaMetaAnnotationWithInheritedListenersWithOverrides() throws Exception { public void customsListenersRegisteredViaMetaAnnotationWithInheritedListenersWithOverrides() {
TestContextManager testContextManager = new TestContextManager( TestContextManager testContextManager = new TestContextManager(
MetaInheritedListenersWithOverridesExampleTestCase.class); MetaInheritedListenersWithOverridesTestCase.class);
assertEquals("Num registered TELs for MetaInheritedListenersWithOverridesExampleTestCase.", 5, assertEquals("Num registered TELs for MetaInheritedListenersWithOverridesTestCase.", 5,
testContextManager.getTestExecutionListeners().size()); testContextManager.getTestExecutionListeners().size());
} }
@Test @Test
public void verifyNumListenersRegisteredViaMetaAnnotationWithNonInheritedListenersWithOverrides() throws Exception { public void customListenersRegisteredViaMetaAnnotationWithNonInheritedListenersWithOverrides() {
TestContextManager testContextManager = new TestContextManager( TestContextManager testContextManager = new TestContextManager(
MetaNonInheritedListenersWithOverridesExampleTestCase.class); MetaNonInheritedListenersWithOverridesTestCase.class);
assertEquals("Num registered TELs for MetaNonInheritedListenersWithOverridesExampleTestCase.", 8, assertEquals("Num registered TELs for MetaNonInheritedListenersWithOverridesTestCase.", 8,
testContextManager.getTestExecutionListeners().size()); testContextManager.getTestExecutionListeners().size());
} }
@Test(expected = IllegalStateException.class) @Test(expected = IllegalStateException.class)
public void verifyDuplicateListenersConfigThrowsException() throws Exception { public void listenersAndValueAttributesDeclared() {
new TestContextManager(DuplicateListenersConfigExampleTestCase.class); new TestContextManager(DuplicateListenersConfigTestCase.class);
} }
static class DefaultListenersExampleTestCase { // -------------------------------------------------------------------
static class DefaultListenersTestCase {
}
@TestExecutionListeners(listeners = { QuuxTestExecutionListener.class,
DependencyInjectionTestExecutionListener.class }, mergeMode = MERGE_WITH_DEFAULTS)
static class MergedDefaultListenersWithCustomListenerPrependedTestCase {
}
@TestExecutionListeners(listeners = BazTestExecutionListener.class, mergeMode = MERGE_WITH_DEFAULTS)
static class MergedDefaultListenersWithCustomListenerAppendedTestCase {
}
@TestExecutionListeners(listeners = BarTestExecutionListener.class, mergeMode = MERGE_WITH_DEFAULTS)
static class MergedDefaultListenersWithCustomListenerInsertedTestCase {
} }
@TestExecutionListeners(QuuxTestExecutionListener.class) @TestExecutionListeners(QuuxTestExecutionListener.class)
static class InheritedDefaultListenersExampleTestCase extends DefaultListenersExampleTestCase { static class InheritedDefaultListenersTestCase extends DefaultListenersTestCase {
} }
static class SubInheritedDefaultListenersExampleTestCase extends InheritedDefaultListenersExampleTestCase { static class SubInheritedDefaultListenersTestCase extends InheritedDefaultListenersTestCase {
} }
@TestExecutionListeners(EnigmaTestExecutionListener.class) @TestExecutionListeners(EnigmaTestExecutionListener.class)
static class SubSubInheritedDefaultListenersExampleTestCase extends SubInheritedDefaultListenersExampleTestCase { static class SubSubInheritedDefaultListenersTestCase extends SubInheritedDefaultListenersTestCase {
} }
@TestExecutionListeners(listeners = { QuuxTestExecutionListener.class }, inheritListeners = false) @TestExecutionListeners(listeners = { QuuxTestExecutionListener.class }, inheritListeners = false)
static class NonInheritedDefaultListenersExampleTestCase extends InheritedDefaultListenersExampleTestCase { static class NonInheritedDefaultListenersTestCase extends InheritedDefaultListenersTestCase {
} }
@TestExecutionListeners({ FooTestExecutionListener.class, BarTestExecutionListener.class, @TestExecutionListeners({ FooTestExecutionListener.class, BarTestExecutionListener.class,
BazTestExecutionListener.class }) BazTestExecutionListener.class })
static class ExampleTestCase { static class ExplicitListenersTestCase {
} }
@TestExecutionListeners(QuuxTestExecutionListener.class) @TestExecutionListeners(QuuxTestExecutionListener.class)
static class InheritedListenersExampleTestCase extends ExampleTestCase { static class InheritedListenersTestCase extends ExplicitListenersTestCase {
} }
@TestExecutionListeners(listeners = QuuxTestExecutionListener.class, inheritListeners = false) @TestExecutionListeners(listeners = QuuxTestExecutionListener.class, inheritListeners = false)
static class NonInheritedListenersExampleTestCase extends InheritedListenersExampleTestCase { static class NonInheritedListenersTestCase extends InheritedListenersTestCase {
} }
@TestExecutionListeners(listeners = FooTestExecutionListener.class, value = BarTestExecutionListener.class) @TestExecutionListeners(listeners = FooTestExecutionListener.class, value = BarTestExecutionListener.class)
static class DuplicateListenersConfigExampleTestCase { static class DuplicateListenersConfigTestCase {
} }
@TestExecutionListeners({// @TestExecutionListeners({//
@ -224,15 +286,15 @@ public class TestExecutionListenersTests {
} }
@MetaListeners @MetaListeners
static class MetaExampleTestCase { static class MetaTestCase {
} }
@MetaInheritedListeners @MetaInheritedListeners
static class MetaInheritedListenersExampleTestCase extends MetaExampleTestCase { static class MetaInheritedListenersTestCase extends MetaTestCase {
} }
@MetaNonInheritedListeners @MetaNonInheritedListeners
static class MetaNonInheritedListenersExampleTestCase extends MetaInheritedListenersExampleTestCase { static class MetaNonInheritedListenersTestCase extends MetaInheritedListenersTestCase {
} }
@MetaListenersWithOverrides(listeners = {// @MetaListenersWithOverrides(listeners = {//
@ -240,11 +302,11 @@ public class TestExecutionListenersTests {
BarTestExecutionListener.class,// BarTestExecutionListener.class,//
BazTestExecutionListener.class // BazTestExecutionListener.class //
}) })
static class MetaWithOverridesExampleTestCase { static class MetaWithOverridesTestCase {
} }
@MetaInheritedListenersWithOverrides(listeners = { FooTestExecutionListener.class, BarTestExecutionListener.class }) @MetaInheritedListenersWithOverrides(listeners = { FooTestExecutionListener.class, BarTestExecutionListener.class })
static class MetaInheritedListenersWithOverridesExampleTestCase extends MetaWithOverridesExampleTestCase { static class MetaInheritedListenersWithOverridesTestCase extends MetaWithOverridesTestCase {
} }
@MetaNonInheritedListenersWithOverrides(listeners = {// @MetaNonInheritedListenersWithOverrides(listeners = {//
@ -253,20 +315,36 @@ public class TestExecutionListenersTests {
BazTestExecutionListener.class // BazTestExecutionListener.class //
},// },//
inheritListeners = true) inheritListeners = true)
static class MetaNonInheritedListenersWithOverridesExampleTestCase extends static class MetaNonInheritedListenersWithOverridesTestCase extends MetaInheritedListenersWithOverridesTestCase {
MetaInheritedListenersWithOverridesExampleTestCase {
} }
static class FooTestExecutionListener extends AbstractTestExecutionListener { static class FooTestExecutionListener extends AbstractTestExecutionListener {
} }
static class BarTestExecutionListener extends AbstractTestExecutionListener { static class BarTestExecutionListener extends AbstractTestExecutionListener {
@Override
public int getOrder() {
// 2500 is between DependencyInjectionTestExecutionListener (2000) and
// DirtiesContextTestExecutionListener (3000)
return 2500;
}
} }
static class BazTestExecutionListener extends AbstractTestExecutionListener { static class BazTestExecutionListener extends AbstractTestExecutionListener {
@Override
public int getOrder() {
return Ordered.LOWEST_PRECEDENCE;
}
} }
static class QuuxTestExecutionListener extends AbstractTestExecutionListener { static class QuuxTestExecutionListener extends AbstractTestExecutionListener {
@Override
public int getOrder() {
return Ordered.HIGHEST_PRECEDENCE;
}
} }
static class EnigmaTestExecutionListener extends AbstractTestExecutionListener { static class EnigmaTestExecutionListener extends AbstractTestExecutionListener {

Loading…
Cancel
Save