[SPR-4702] JavaDoc updates
This commit is contained in:
@@ -54,6 +54,10 @@ public interface TestExecutionListener {
|
|||||||
* <p>
|
* <p>
|
||||||
* This method should be called immediately before framework-specific
|
* This method should be called immediately before framework-specific
|
||||||
* <em>before class</em> lifecycle callbacks.
|
* <em>before class</em> lifecycle callbacks.
|
||||||
|
* <p>
|
||||||
|
* If a given testing framework (e.g., JUnit 3.8) does not support
|
||||||
|
* <em>before class</em> lifecycle callbacks, this method will not be called
|
||||||
|
* for that framework.
|
||||||
*
|
*
|
||||||
* @param testContext the test context for the test; never <code>null</code>
|
* @param testContext the test context for the test; never <code>null</code>
|
||||||
* @throws Exception allows any exception to propagate
|
* @throws Exception allows any exception to propagate
|
||||||
@@ -108,6 +112,10 @@ public interface TestExecutionListener {
|
|||||||
* <p>
|
* <p>
|
||||||
* This method should be called immediately after framework-specific
|
* This method should be called immediately after framework-specific
|
||||||
* <em>after class</em> lifecycle callbacks.
|
* <em>after class</em> lifecycle callbacks.
|
||||||
|
* <p>
|
||||||
|
* If a given testing framework (e.g., JUnit 3.8) does not support
|
||||||
|
* <em>after class</em> lifecycle callbacks, this method will not be called
|
||||||
|
* for that framework.
|
||||||
*
|
*
|
||||||
* @param testContext the test context for the test; never <code>null</code>
|
* @param testContext the test context for the test; never <code>null</code>
|
||||||
* @throws Exception allows any exception to propagate
|
* @throws Exception allows any exception to propagate
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2009 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -21,9 +21,9 @@ import java.lang.reflect.Modifier;
|
|||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
import junit.framework.AssertionFailedError;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.context.ApplicationContextAware;
|
||||||
import org.springframework.test.annotation.ExpectedException;
|
import org.springframework.test.annotation.ExpectedException;
|
||||||
@@ -39,47 +39,67 @@ import org.springframework.test.context.support.DirtiesContextTestExecutionListe
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Abstract base {@link TestCase} which integrates the
|
* Abstract base {@link TestCase} which integrates the <i>Spring TestContext
|
||||||
* <em>Spring TestContext Framework</em> with explicit
|
* Framework</i> and explicit {@link ApplicationContext} testing support in a
|
||||||
* {@link ApplicationContext} testing support in a <strong>JUnit 3.8</strong>
|
* <strong>JUnit 3.8</strong> environment.
|
||||||
* environment.
|
|
||||||
* </p>
|
* </p>
|
||||||
* <p>
|
* <p>
|
||||||
* Concrete subclasses:
|
* Concrete subclasses:
|
||||||
* </p>
|
* </p>
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>Typically declare a class-level
|
* <li>Typically declare a class-level
|
||||||
* {@link org.springframework.test.context.ContextConfiguration @ContextConfiguration}
|
* {@link org.springframework.test.context.ContextConfiguration
|
||||||
* annotation to configure the {@link ApplicationContext application context}
|
* @ContextConfiguration} annotation to configure the
|
||||||
* {@link org.springframework.test.context.ContextConfiguration#locations() resource locations}.
|
* {@link ApplicationContext application context}
|
||||||
* <em>If your test does not need to load an
|
* {@link org.springframework.test.context.ContextConfiguration#locations()
|
||||||
* application context, you may choose to omit the
|
* resource locations}. <i>If your test does not need to load an application
|
||||||
* {@link org.springframework.test.context.ContextConfiguration @ContextConfiguration} declaration and configure
|
* context, you may choose to omit the
|
||||||
* the appropriate {@link org.springframework.test.context.TestExecutionListener TestExecutionListeners}
|
* {@link org.springframework.test.context.ContextConfiguration
|
||||||
* manually.</em></li>
|
* @ContextConfiguration} declaration and configure the appropriate
|
||||||
|
* {@link org.springframework.test.context.TestExecutionListener
|
||||||
|
* TestExecutionListeners} manually.</i></li>
|
||||||
* <li>Must declare public constructors which match the signatures of
|
* <li>Must declare public constructors which match the signatures of
|
||||||
* {@link #AbstractJUnit38SpringContextTests() AbstractJUnit38SpringContextTests()}
|
* {@link #AbstractJUnit38SpringContextTests()
|
||||||
* and
|
* AbstractJUnit38SpringContextTests()} and
|
||||||
* {@link #AbstractJUnit38SpringContextTests(String) AbstractJUnit38SpringContextTests(String)}
|
* {@link #AbstractJUnit38SpringContextTests(String)
|
||||||
* and delegate to <code>super();</code> and <code>super(name);</code>
|
* AbstractJUnit38SpringContextTests(String)} and delegate to
|
||||||
* respectively.</li>
|
* <code>super();</code> and <code>super(name);</code> respectively.</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
* <p>
|
* <p>
|
||||||
* The following list constitutes all annotations currently supported directly
|
* The following list constitutes all annotations currently supported directly
|
||||||
* by <code>AbstractJUnit38SpringContextTests</code>.
|
* by <code>AbstractJUnit38SpringContextTests</code>. <i>(Note that additional
|
||||||
* <em>(Note that additional annotations may be supported by various
|
* annotations may be supported by various
|
||||||
* {@link org.springframework.test.context.TestExecutionListener TestExecutionListeners})</em>
|
* {@link org.springframework.test.context.TestExecutionListener
|
||||||
|
* TestExecutionListeners})</i>
|
||||||
* </p>
|
* </p>
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>{@link org.springframework.test.annotation.DirtiesContext @DirtiesContext}
|
* <li>{@link org.springframework.test.annotation.DirtiesContext
|
||||||
* (via the configured {@link DirtiesContextTestExecutionListener})</li>
|
* @DirtiesContext} (via the configured
|
||||||
* <li>{@link org.springframework.test.annotation.ProfileValueSourceConfiguration @ProfileValueSourceConfiguration}</li>
|
* {@link DirtiesContextTestExecutionListener}; only supported on methods for
|
||||||
* <li>{@link IfProfileValue @IfProfileValue}</li>
|
* JUnit 3.8)</li>
|
||||||
* <li>{@link ExpectedException @ExpectedException}</li>
|
* <li>
|
||||||
* <li>{@link Timed @Timed}</li>
|
* {@link org.springframework.test.annotation.ProfileValueSourceConfiguration
|
||||||
* <li>{@link Repeat @Repeat}</li>
|
* @ProfileValueSourceConfiguration}</li>
|
||||||
|
* <li>{@link IfProfileValue @IfProfileValue}</li>
|
||||||
|
* <li>{@link ExpectedException @ExpectedException}</li>
|
||||||
|
* <li>{@link Timed @Timed}</li>
|
||||||
|
* <li>{@link Repeat @Repeat}</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
* <p>
|
||||||
|
* JUnit 3.8 does not support <i>before class</i> or <i>after class</i>
|
||||||
|
* lifecycle callbacks. The following
|
||||||
|
* {@link org.springframework.test.context.TestExecutionListener
|
||||||
|
* TestExecutionListener} methods are therefore unsupported in a JUnit 3.8
|
||||||
|
* environment:
|
||||||
|
* <ul>
|
||||||
|
* <li>
|
||||||
|
* {@link org.springframework.test.context.TestExecutionListener#beforeTestClass(org.springframework.test.context.TestContext)
|
||||||
|
* beforeTestClass()}</li>
|
||||||
|
* <li>
|
||||||
|
* {@link org.springframework.test.context.TestExecutionListener#afterTestClass(org.springframework.test.context.TestContext)
|
||||||
|
* afterTestClass()}</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @since 2.5
|
* @since 2.5
|
||||||
@@ -90,7 +110,7 @@ import org.springframework.test.context.support.DirtiesContextTestExecutionListe
|
|||||||
* @see org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests
|
* @see org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests
|
||||||
* @see org.springframework.test.context.testng.AbstractTestNGSpringContextTests
|
* @see org.springframework.test.context.testng.AbstractTestNGSpringContextTests
|
||||||
*/
|
*/
|
||||||
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class})
|
@TestExecutionListeners( { DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class })
|
||||||
public abstract class AbstractJUnit38SpringContextTests extends TestCase implements ApplicationContextAware {
|
public abstract class AbstractJUnit38SpringContextTests extends TestCase implements ApplicationContextAware {
|
||||||
|
|
||||||
private static int disabledTestCount = 0;
|
private static int disabledTestCount = 0;
|
||||||
@@ -117,8 +137,8 @@ public abstract class AbstractJUnit38SpringContextTests extends TestCase impleme
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link ProfileValueSource} available to subclasses but primarily intended
|
* {@link ProfileValueSource} available to subclasses but primarily intended
|
||||||
* for internal use to provide support for
|
* for internal use to provide support for {@link IfProfileValue
|
||||||
* {@link IfProfileValue @IfProfileValue}.
|
* @IfProfileValue}.
|
||||||
*/
|
*/
|
||||||
protected final ProfileValueSource profileValueSource;
|
protected final ProfileValueSource profileValueSource;
|
||||||
|
|
||||||
@@ -126,9 +146,9 @@ public abstract class AbstractJUnit38SpringContextTests extends TestCase impleme
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new AbstractJUnit38SpringContextTests instance;
|
* Constructs a new AbstractJUnit38SpringContextTests instance; initializes
|
||||||
* initializes the internal {@link TestContextManager} for the current test;
|
* the internal {@link TestContextManager} for the current test; and
|
||||||
* and retrieves the configured (or default) {@link ProfileValueSource}.
|
* retrieves the configured (or default) {@link ProfileValueSource}.
|
||||||
*/
|
*/
|
||||||
public AbstractJUnit38SpringContextTests() {
|
public AbstractJUnit38SpringContextTests() {
|
||||||
super();
|
super();
|
||||||
@@ -141,6 +161,7 @@ public abstract class AbstractJUnit38SpringContextTests extends TestCase impleme
|
|||||||
* supplied <code>name</code>; initializes the internal
|
* supplied <code>name</code>; initializes the internal
|
||||||
* {@link TestContextManager} for the current test; and retrieves the
|
* {@link TestContextManager} for the current test; and retrieves the
|
||||||
* configured (or default) {@link ProfileValueSource}.
|
* configured (or default) {@link ProfileValueSource}.
|
||||||
|
*
|
||||||
* @param name the name of the current test to execute
|
* @param name the name of the current test to execute
|
||||||
*/
|
*/
|
||||||
public AbstractJUnit38SpringContextTests(String name) {
|
public AbstractJUnit38SpringContextTests(String name) {
|
||||||
@@ -149,7 +170,6 @@ public abstract class AbstractJUnit38SpringContextTests extends TestCase impleme
|
|||||||
this.profileValueSource = ProfileValueUtils.retrieveProfileValueSource(getClass());
|
this.profileValueSource = ProfileValueUtils.retrieveProfileValueSource(getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the {@link ApplicationContext} to be used by this test instance,
|
* Sets the {@link ApplicationContext} to be used by this test instance,
|
||||||
* provided via {@link ApplicationContextAware} semantics.
|
* provided via {@link ApplicationContextAware} semantics.
|
||||||
@@ -158,24 +178,26 @@ public abstract class AbstractJUnit38SpringContextTests extends TestCase impleme
|
|||||||
this.applicationContext = applicationContext;
|
this.applicationContext = applicationContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs the <em>Spring TestContext Framework</em> test sequence.
|
* Runs the <em>Spring TestContext Framework</em> test sequence.
|
||||||
* <p>In addition to standard {@link TestCase#runBare()} semantics, this
|
* <p>
|
||||||
|
* In addition to standard {@link TestCase#runBare()} semantics, this
|
||||||
* implementation performs the following:
|
* implementation performs the following:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>Calls
|
* <li>Calls {@link TestContextManager#prepareTestInstance(Object)
|
||||||
* {@link TestContextManager#prepareTestInstance(Object) prepareTestInstance()},
|
* prepareTestInstance()},
|
||||||
* {@link TestContextManager#beforeTestMethod(Object,Method) beforeTestMethod()},
|
* {@link TestContextManager#beforeTestMethod(Object,Method)
|
||||||
* and
|
* beforeTestMethod()}, and
|
||||||
* {@link TestContextManager#afterTestMethod(Object,Method,Throwable) afterTestMethod()}
|
* {@link TestContextManager#afterTestMethod(Object,Method,Throwable)
|
||||||
* on this test's {@link TestContextManager} at the appropriate test
|
* afterTestMethod()} on this test's {@link TestContextManager} at the
|
||||||
* execution points.</li>
|
* appropriate test execution points.</li>
|
||||||
* <li>Provides support for {@link IfProfileValue @IfProfileValue}.</li>
|
* <li>Provides support for {@link IfProfileValue @IfProfileValue}.</li>
|
||||||
* <li>Provides support for {@link Repeat @Repeat}.</li>
|
* <li>Provides support for {@link Repeat @Repeat}.</li>
|
||||||
* <li>Provides support for {@link Timed @Timed}.</li>
|
* <li>Provides support for {@link Timed @Timed}.</li>
|
||||||
* <li>Provides support for {@link ExpectedException @ExpectedException}.</li>
|
* <li>Provides support for {@link ExpectedException
|
||||||
|
* @ExpectedException}.</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
|
*
|
||||||
* @see ProfileValueUtils#isTestEnabledInThisEnvironment
|
* @see ProfileValueUtils#isTestEnabledInThisEnvironment
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@@ -189,6 +211,7 @@ public abstract class AbstractJUnit38SpringContextTests extends TestCase impleme
|
|||||||
}
|
}
|
||||||
|
|
||||||
runTestTimed(new TestExecutionCallback() {
|
runTestTimed(new TestExecutionCallback() {
|
||||||
|
|
||||||
public void run() throws Throwable {
|
public void run() throws Throwable {
|
||||||
runManaged(testMethod);
|
runManaged(testMethod);
|
||||||
}
|
}
|
||||||
@@ -214,10 +237,12 @@ public abstract class AbstractJUnit38SpringContextTests extends TestCase impleme
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs a <em>timed</em> test via the supplied {@link TestExecutionCallback},
|
* Runs a <em>timed</em> test via the supplied {@link TestExecutionCallback}
|
||||||
* providing support for the {@link Timed @Timed} annotation.
|
* , providing support for the {@link Timed @Timed} annotation.
|
||||||
|
*
|
||||||
* @param tec the test execution callback to run
|
* @param tec the test execution callback to run
|
||||||
* @param testMethod the actual test method: used to retrieve the <code>timeout</code>
|
* @param testMethod the actual test method: used to retrieve the
|
||||||
|
* <code>timeout</code>
|
||||||
* @throws Throwable if any exception is thrown
|
* @throws Throwable if any exception is thrown
|
||||||
* @see Timed
|
* @see Timed
|
||||||
* @see #runTest
|
* @see #runTest
|
||||||
@@ -243,21 +268,22 @@ public abstract class AbstractJUnit38SpringContextTests extends TestCase impleme
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs a test via the supplied {@link TestExecutionCallback}, providing
|
* Runs a test via the supplied {@link TestExecutionCallback}, providing
|
||||||
* support for the {@link ExpectedException @ExpectedException} and
|
* support for the {@link ExpectedException @ExpectedException} and
|
||||||
* {@link Repeat @Repeat} annotations.
|
* {@link Repeat @Repeat} annotations.
|
||||||
|
*
|
||||||
* @param tec the test execution callback to run
|
* @param tec the test execution callback to run
|
||||||
* @param testMethod the actual test method: used to retrieve the
|
* @param testMethod the actual test method: used to retrieve the
|
||||||
* {@link ExpectedException @ExpectedException} and {@link Repeat @Repeat} annotations
|
* {@link ExpectedException @ExpectedException} and {@link Repeat
|
||||||
|
* @Repeat} annotations
|
||||||
* @throws Throwable if any exception is thrown
|
* @throws Throwable if any exception is thrown
|
||||||
* @see ExpectedException
|
* @see ExpectedException
|
||||||
* @see Repeat
|
* @see Repeat
|
||||||
*/
|
*/
|
||||||
private void runTest(TestExecutionCallback tec, Method testMethod) throws Throwable {
|
private void runTest(TestExecutionCallback tec, Method testMethod) throws Throwable {
|
||||||
ExpectedException expectedExceptionAnnotation = testMethod.getAnnotation(ExpectedException.class);
|
ExpectedException expectedExceptionAnnotation = testMethod.getAnnotation(ExpectedException.class);
|
||||||
boolean exceptionIsExpected = (expectedExceptionAnnotation != null &&
|
boolean exceptionIsExpected = (expectedExceptionAnnotation != null && expectedExceptionAnnotation.value() != null);
|
||||||
expectedExceptionAnnotation.value() != null);
|
Class<? extends Throwable> expectedException = (exceptionIsExpected ? expectedExceptionAnnotation.value()
|
||||||
Class<? extends Throwable> expectedException =
|
: null);
|
||||||
(exceptionIsExpected ? expectedExceptionAnnotation.value() : null);
|
|
||||||
|
|
||||||
Repeat repeat = testMethod.getAnnotation(Repeat.class);
|
Repeat repeat = testMethod.getAnnotation(Repeat.class);
|
||||||
int runs = ((repeat != null) && (repeat.value() > 1)) ? repeat.value() : 1;
|
int runs = ((repeat != null) && (repeat.value() > 1)) ? repeat.value() : 1;
|
||||||
@@ -278,8 +304,8 @@ public abstract class AbstractJUnit38SpringContextTests extends TestCase impleme
|
|||||||
}
|
}
|
||||||
if (!expectedException.isAssignableFrom(ex.getClass())) {
|
if (!expectedException.isAssignableFrom(ex.getClass())) {
|
||||||
// Wrap the unexpected throwable with an explicit message.
|
// Wrap the unexpected throwable with an explicit message.
|
||||||
AssertionFailedError assertionError = new AssertionFailedError("Unexpected exception, expected <" +
|
AssertionFailedError assertionError = new AssertionFailedError("Unexpected exception, expected <"
|
||||||
expectedException.getName() + "> but was <" + ex.getClass().getName() + ">");
|
+ expectedException.getName() + "> but was <" + ex.getClass().getName() + ">");
|
||||||
assertionError.initCause(ex);
|
assertionError.initCause(ex);
|
||||||
throw assertionError;
|
throw assertionError;
|
||||||
}
|
}
|
||||||
@@ -291,6 +317,7 @@ public abstract class AbstractJUnit38SpringContextTests extends TestCase impleme
|
|||||||
* Calls {@link TestContextManager#beforeTestMethod(Object,Method)} and
|
* Calls {@link TestContextManager#beforeTestMethod(Object,Method)} and
|
||||||
* {@link TestContextManager#afterTestMethod(Object,Method,Throwable)} at
|
* {@link TestContextManager#afterTestMethod(Object,Method,Throwable)} at
|
||||||
* the appropriate test execution points.
|
* the appropriate test execution points.
|
||||||
|
*
|
||||||
* @param testMethod the test method to run
|
* @param testMethod the test method to run
|
||||||
* @throws Throwable if any exception is thrown
|
* @throws Throwable if any exception is thrown
|
||||||
* @see #runBare()
|
* @see #runBare()
|
||||||
@@ -344,6 +371,7 @@ public abstract class AbstractJUnit38SpringContextTests extends TestCase impleme
|
|||||||
* Records the supplied test method as <em>disabled</em> in the current
|
* Records the supplied test method as <em>disabled</em> in the current
|
||||||
* environment by incrementing the total number of disabled tests and
|
* environment by incrementing the total number of disabled tests and
|
||||||
* logging a debug message.
|
* logging a debug message.
|
||||||
|
*
|
||||||
* @param testMethod the test method that is disabled.
|
* @param testMethod the test method that is disabled.
|
||||||
* @see #getDisabledTestCount()
|
* @see #getDisabledTestCount()
|
||||||
*/
|
*/
|
||||||
@@ -357,8 +385,8 @@ public abstract class AbstractJUnit38SpringContextTests extends TestCase impleme
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private inner class that defines a callback analogous to
|
* Private inner class that defines a callback analogous to {@link Runnable}
|
||||||
* {@link Runnable}, just declaring Throwable.
|
* , just declaring Throwable.
|
||||||
*/
|
*/
|
||||||
private static interface TestExecutionCallback {
|
private static interface TestExecutionCallback {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user