Skip to content

Commit 51b8b99

Browse files
committed
[SPR-4702] JavaDoc updates
1 parent 8dec6af commit 51b8b99

File tree

2 files changed

+100
-64
lines changed

2 files changed

+100
-64
lines changed

org.springframework.test/src/main/java/org/springframework/test/context/TestExecutionListener.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ public interface TestExecutionListener {
5454
* <p>
5555
* This method should be called immediately before framework-specific
5656
* <em>before class</em> lifecycle callbacks.
57+
* <p>
58+
* If a given testing framework (e.g., JUnit 3.8) does not support
59+
* <em>before class</em> lifecycle callbacks, this method will not be called
60+
* for that framework.
5761
*
5862
* @param testContext the test context for the test; never <code>null</code>
5963
* @throws Exception allows any exception to propagate
@@ -108,6 +112,10 @@ public interface TestExecutionListener {
108112
* <p>
109113
* This method should be called immediately after framework-specific
110114
* <em>after class</em> lifecycle callbacks.
115+
* <p>
116+
* If a given testing framework (e.g., JUnit 3.8) does not support
117+
* <em>after class</em> lifecycle callbacks, this method will not be called
118+
* for that framework.
111119
*
112120
* @param testContext the test context for the test; never <code>null</code>
113121
* @throws Exception allows any exception to propagate

org.springframework.test/src/main/java/org/springframework/test/context/junit38/AbstractJUnit38SpringContextTests.java

Lines changed: 92 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2008 the original author or authors.
2+
* Copyright 2002-2009 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,9 +21,9 @@
2121

2222
import junit.framework.AssertionFailedError;
2323
import junit.framework.TestCase;
24+
2425
import org.apache.commons.logging.Log;
2526
import org.apache.commons.logging.LogFactory;
26-
2727
import org.springframework.context.ApplicationContext;
2828
import org.springframework.context.ApplicationContextAware;
2929
import org.springframework.test.annotation.ExpectedException;
@@ -39,47 +39,67 @@
3939

4040
/**
4141
* <p>
42-
* Abstract base {@link TestCase} which integrates the
43-
* <em>Spring TestContext Framework</em> with explicit
44-
* {@link ApplicationContext} testing support in a <strong>JUnit 3.8</strong>
45-
* environment.
42+
* Abstract base {@link TestCase} which integrates the <i>Spring TestContext
43+
* Framework</i> and explicit {@link ApplicationContext} testing support in a
44+
* <strong>JUnit 3.8</strong> environment.
4645
* </p>
4746
* <p>
4847
* Concrete subclasses:
4948
* </p>
5049
* <ul>
5150
* <li>Typically declare a class-level
52-
* {@link org.springframework.test.context.ContextConfiguration @ContextConfiguration}
53-
* annotation to configure the {@link ApplicationContext application context}
54-
* {@link org.springframework.test.context.ContextConfiguration#locations() resource locations}.
55-
* <em>If your test does not need to load an
56-
* application context, you may choose to omit the
57-
* {@link org.springframework.test.context.ContextConfiguration @ContextConfiguration} declaration and configure
58-
* the appropriate {@link org.springframework.test.context.TestExecutionListener TestExecutionListeners}
59-
* manually.</em></li>
51+
* {@link org.springframework.test.context.ContextConfiguration
52+
* &#064;ContextConfiguration} annotation to configure the
53+
* {@link ApplicationContext application context}
54+
* {@link org.springframework.test.context.ContextConfiguration#locations()
55+
* resource locations}. <i>If your test does not need to load an application
56+
* context, you may choose to omit the
57+
* {@link org.springframework.test.context.ContextConfiguration
58+
* &#064;ContextConfiguration} declaration and configure the appropriate
59+
* {@link org.springframework.test.context.TestExecutionListener
60+
* TestExecutionListeners} manually.</i></li>
6061
* <li>Must declare public constructors which match the signatures of
61-
* {@link #AbstractJUnit38SpringContextTests() AbstractJUnit38SpringContextTests()}
62-
* and
63-
* {@link #AbstractJUnit38SpringContextTests(String) AbstractJUnit38SpringContextTests(String)}
64-
* and delegate to <code>super();</code> and <code>super(name);</code>
65-
* respectively.</li>
62+
* {@link #AbstractJUnit38SpringContextTests()
63+
* AbstractJUnit38SpringContextTests()} and
64+
* {@link #AbstractJUnit38SpringContextTests(String)
65+
* AbstractJUnit38SpringContextTests(String)} and delegate to
66+
* <code>super();</code> and <code>super(name);</code> respectively.</li>
6667
* </ul>
6768
* <p>
6869
* The following list constitutes all annotations currently supported directly
69-
* by <code>AbstractJUnit38SpringContextTests</code>.
70-
* <em>(Note that additional annotations may be supported by various
71-
* {@link org.springframework.test.context.TestExecutionListener TestExecutionListeners})</em>
70+
* by <code>AbstractJUnit38SpringContextTests</code>. <i>(Note that additional
71+
* annotations may be supported by various
72+
* {@link org.springframework.test.context.TestExecutionListener
73+
* TestExecutionListeners})</i>
7274
* </p>
7375
* <ul>
74-
* <li>{@link org.springframework.test.annotation.DirtiesContext @DirtiesContext}
75-
* (via the configured {@link DirtiesContextTestExecutionListener})</li>
76-
* <li>{@link org.springframework.test.annotation.ProfileValueSourceConfiguration @ProfileValueSourceConfiguration}</li>
77-
* <li>{@link IfProfileValue @IfProfileValue}</li>
78-
* <li>{@link ExpectedException @ExpectedException}</li>
79-
* <li>{@link Timed @Timed}</li>
80-
* <li>{@link Repeat @Repeat}</li>
76+
* <li>{@link org.springframework.test.annotation.DirtiesContext
77+
* &#064;DirtiesContext} (via the configured
78+
* {@link DirtiesContextTestExecutionListener}; only supported on methods for
79+
* JUnit 3.8)</li>
80+
* <li>
81+
* {@link org.springframework.test.annotation.ProfileValueSourceConfiguration
82+
* &#064;ProfileValueSourceConfiguration}</li>
83+
* <li>{@link IfProfileValue &#064;IfProfileValue}</li>
84+
* <li>{@link ExpectedException &#064;ExpectedException}</li>
85+
* <li>{@link Timed &#064;Timed}</li>
86+
* <li>{@link Repeat &#064;Repeat}</li>
8187
* </ul>
82-
*
88+
* <p>
89+
* JUnit 3.8 does not support <i>before class</i> or <i>after class</i>
90+
* lifecycle callbacks. The following
91+
* {@link org.springframework.test.context.TestExecutionListener
92+
* TestExecutionListener} methods are therefore unsupported in a JUnit 3.8
93+
* environment:
94+
* <ul>
95+
* <li>
96+
* {@link org.springframework.test.context.TestExecutionListener#beforeTestClass(org.springframework.test.context.TestContext)
97+
* beforeTestClass()}</li>
98+
* <li>
99+
* {@link org.springframework.test.context.TestExecutionListener#afterTestClass(org.springframework.test.context.TestContext)
100+
* afterTestClass()}</li>
101+
* </ul>
102+
*
83103
* @author Sam Brannen
84104
* @author Juergen Hoeller
85105
* @since 2.5
@@ -90,7 +110,7 @@
90110
* @see org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests
91111
* @see org.springframework.test.context.testng.AbstractTestNGSpringContextTests
92112
*/
93-
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class})
113+
@TestExecutionListeners( { DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class })
94114
public abstract class AbstractJUnit38SpringContextTests extends TestCase implements ApplicationContextAware {
95115

96116
private static int disabledTestCount = 0;
@@ -117,18 +137,18 @@ public static int getDisabledTestCount() {
117137

118138
/**
119139
* {@link ProfileValueSource} available to subclasses but primarily intended
120-
* for internal use to provide support for
121-
* {@link IfProfileValue @IfProfileValue}.
140+
* for internal use to provide support for {@link IfProfileValue
141+
* &#064;IfProfileValue}.
122142
*/
123143
protected final ProfileValueSource profileValueSource;
124144

125145
private final TestContextManager testContextManager;
126146

127147

128148
/**
129-
* Constructs a new AbstractJUnit38SpringContextTests instance;
130-
* initializes the internal {@link TestContextManager} for the current test;
131-
* and retrieves the configured (or default) {@link ProfileValueSource}.
149+
* Constructs a new AbstractJUnit38SpringContextTests instance; initializes
150+
* the internal {@link TestContextManager} for the current test; and
151+
* retrieves the configured (or default) {@link ProfileValueSource}.
132152
*/
133153
public AbstractJUnit38SpringContextTests() {
134154
super();
@@ -141,6 +161,7 @@ public AbstractJUnit38SpringContextTests() {
141161
* supplied <code>name</code>; initializes the internal
142162
* {@link TestContextManager} for the current test; and retrieves the
143163
* configured (or default) {@link ProfileValueSource}.
164+
*
144165
* @param name the name of the current test to execute
145166
*/
146167
public AbstractJUnit38SpringContextTests(String name) {
@@ -149,7 +170,6 @@ public AbstractJUnit38SpringContextTests(String name) {
149170
this.profileValueSource = ProfileValueUtils.retrieveProfileValueSource(getClass());
150171
}
151172

152-
153173
/**
154174
* Sets the {@link ApplicationContext} to be used by this test instance,
155175
* provided via {@link ApplicationContextAware} semantics.
@@ -158,24 +178,26 @@ public final void setApplicationContext(final ApplicationContext applicationCont
158178
this.applicationContext = applicationContext;
159179
}
160180

161-
162181
/**
163182
* Runs the <em>Spring TestContext Framework</em> test sequence.
164-
* <p>In addition to standard {@link TestCase#runBare()} semantics, this
183+
* <p>
184+
* In addition to standard {@link TestCase#runBare()} semantics, this
165185
* implementation performs the following:
166186
* <ul>
167-
* <li>Calls
168-
* {@link TestContextManager#prepareTestInstance(Object) prepareTestInstance()},
169-
* {@link TestContextManager#beforeTestMethod(Object,Method) beforeTestMethod()},
170-
* and
171-
* {@link TestContextManager#afterTestMethod(Object,Method,Throwable) afterTestMethod()}
172-
* on this test's {@link TestContextManager} at the appropriate test
173-
* execution points.</li>
174-
* <li>Provides support for {@link IfProfileValue @IfProfileValue}.</li>
175-
* <li>Provides support for {@link Repeat @Repeat}.</li>
176-
* <li>Provides support for {@link Timed @Timed}.</li>
177-
* <li>Provides support for {@link ExpectedException @ExpectedException}.</li>
187+
* <li>Calls {@link TestContextManager#prepareTestInstance(Object)
188+
* prepareTestInstance()},
189+
* {@link TestContextManager#beforeTestMethod(Object,Method)
190+
* beforeTestMethod()}, and
191+
* {@link TestContextManager#afterTestMethod(Object,Method,Throwable)
192+
* afterTestMethod()} on this test's {@link TestContextManager} at the
193+
* appropriate test execution points.</li>
194+
* <li>Provides support for {@link IfProfileValue &#064;IfProfileValue}.</li>
195+
* <li>Provides support for {@link Repeat &#064;Repeat}.</li>
196+
* <li>Provides support for {@link Timed &#064;Timed}.</li>
197+
* <li>Provides support for {@link ExpectedException
198+
* &#064;ExpectedException}.</li>
178199
* </ul>
200+
*
179201
* @see ProfileValueUtils#isTestEnabledInThisEnvironment
180202
*/
181203
@Override
@@ -189,6 +211,7 @@ public void runBare() throws Throwable {
189211
}
190212

191213
runTestTimed(new TestExecutionCallback() {
214+
192215
public void run() throws Throwable {
193216
runManaged(testMethod);
194217
}
@@ -214,10 +237,12 @@ private Method getTestMethod() {
214237
}
215238

216239
/**
217-
* Runs a <em>timed</em> test via the supplied {@link TestExecutionCallback},
218-
* providing support for the {@link Timed @Timed} annotation.
240+
* Runs a <em>timed</em> test via the supplied {@link TestExecutionCallback}
241+
* , providing support for the {@link Timed &#064;Timed} annotation.
242+
*
219243
* @param tec the test execution callback to run
220-
* @param testMethod the actual test method: used to retrieve the <code>timeout</code>
244+
* @param testMethod the actual test method: used to retrieve the
245+
* <code>timeout</code>
221246
* @throws Throwable if any exception is thrown
222247
* @see Timed
223248
* @see #runTest
@@ -243,21 +268,22 @@ private void runTestTimed(TestExecutionCallback tec, Method testMethod) throws T
243268

244269
/**
245270
* Runs a test via the supplied {@link TestExecutionCallback}, providing
246-
* support for the {@link ExpectedException @ExpectedException} and
247-
* {@link Repeat @Repeat} annotations.
271+
* support for the {@link ExpectedException &#064;ExpectedException} and
272+
* {@link Repeat &#064;Repeat} annotations.
273+
*
248274
* @param tec the test execution callback to run
249275
* @param testMethod the actual test method: used to retrieve the
250-
* {@link ExpectedException @ExpectedException} and {@link Repeat @Repeat} annotations
276+
* {@link ExpectedException &#064;ExpectedException} and {@link Repeat
277+
* &#064;Repeat} annotations
251278
* @throws Throwable if any exception is thrown
252279
* @see ExpectedException
253280
* @see Repeat
254281
*/
255282
private void runTest(TestExecutionCallback tec, Method testMethod) throws Throwable {
256283
ExpectedException expectedExceptionAnnotation = testMethod.getAnnotation(ExpectedException.class);
257-
boolean exceptionIsExpected = (expectedExceptionAnnotation != null &&
258-
expectedExceptionAnnotation.value() != null);
259-
Class<? extends Throwable> expectedException =
260-
(exceptionIsExpected ? expectedExceptionAnnotation.value() : null);
284+
boolean exceptionIsExpected = (expectedExceptionAnnotation != null && expectedExceptionAnnotation.value() != null);
285+
Class<? extends Throwable> expectedException = (exceptionIsExpected ? expectedExceptionAnnotation.value()
286+
: null);
261287

262288
Repeat repeat = testMethod.getAnnotation(Repeat.class);
263289
int runs = ((repeat != null) && (repeat.value() > 1)) ? repeat.value() : 1;
@@ -278,8 +304,8 @@ private void runTest(TestExecutionCallback tec, Method testMethod) throws Throwa
278304
}
279305
if (!expectedException.isAssignableFrom(ex.getClass())) {
280306
// Wrap the unexpected throwable with an explicit message.
281-
AssertionFailedError assertionError = new AssertionFailedError("Unexpected exception, expected <" +
282-
expectedException.getName() + "> but was <" + ex.getClass().getName() + ">");
307+
AssertionFailedError assertionError = new AssertionFailedError("Unexpected exception, expected <"
308+
+ expectedException.getName() + "> but was <" + ex.getClass().getName() + ">");
283309
assertionError.initCause(ex);
284310
throw assertionError;
285311
}
@@ -291,6 +317,7 @@ private void runTest(TestExecutionCallback tec, Method testMethod) throws Throwa
291317
* Calls {@link TestContextManager#beforeTestMethod(Object,Method)} and
292318
* {@link TestContextManager#afterTestMethod(Object,Method,Throwable)} at
293319
* the appropriate test execution points.
320+
*
294321
* @param testMethod the test method to run
295322
* @throws Throwable if any exception is thrown
296323
* @see #runBare()
@@ -344,6 +371,7 @@ private void runManaged(Method testMethod) throws Throwable {
344371
* Records the supplied test method as <em>disabled</em> in the current
345372
* environment by incrementing the total number of disabled tests and
346373
* logging a debug message.
374+
*
347375
* @param testMethod the test method that is disabled.
348376
* @see #getDisabledTestCount()
349377
*/
@@ -357,8 +385,8 @@ protected void recordDisabled(Method testMethod) {
357385

358386

359387
/**
360-
* Private inner class that defines a callback analogous to
361-
* {@link Runnable}, just declaring Throwable.
388+
* Private inner class that defines a callback analogous to {@link Runnable}
389+
* , just declaring Throwable.
362390
*/
363391
private static interface TestExecutionCallback {
364392

0 commit comments

Comments
 (0)