From 51b8b99dfc4d3cfcd0b8d73cb476f5c74af600be Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Mon, 6 Jul 2009 13:41:01 +0000 Subject: [PATCH] [SPR-4702] JavaDoc updates --- .../test/context/TestExecutionListener.java | 8 + .../AbstractJUnit38SpringContextTests.java | 156 +++++++++++------- 2 files changed, 100 insertions(+), 64 deletions(-) diff --git a/org.springframework.test/src/main/java/org/springframework/test/context/TestExecutionListener.java b/org.springframework.test/src/main/java/org/springframework/test/context/TestExecutionListener.java index 4870c15d543..2b67223d938 100644 --- a/org.springframework.test/src/main/java/org/springframework/test/context/TestExecutionListener.java +++ b/org.springframework.test/src/main/java/org/springframework/test/context/TestExecutionListener.java @@ -54,6 +54,10 @@ public interface TestExecutionListener { *

* This method should be called immediately before framework-specific * before class lifecycle callbacks. + *

+ * If a given testing framework (e.g., JUnit 3.8) does not support + * before class lifecycle callbacks, this method will not be called + * for that framework. * * @param testContext the test context for the test; never null * @throws Exception allows any exception to propagate @@ -108,6 +112,10 @@ public interface TestExecutionListener { *

* This method should be called immediately after framework-specific * after class lifecycle callbacks. + *

+ * If a given testing framework (e.g., JUnit 3.8) does not support + * after class lifecycle callbacks, this method will not be called + * for that framework. * * @param testContext the test context for the test; never null * @throws Exception allows any exception to propagate diff --git a/org.springframework.test/src/main/java/org/springframework/test/context/junit38/AbstractJUnit38SpringContextTests.java b/org.springframework.test/src/main/java/org/springframework/test/context/junit38/AbstractJUnit38SpringContextTests.java index c841db88547..16f6261dfce 100644 --- a/org.springframework.test/src/main/java/org/springframework/test/context/junit38/AbstractJUnit38SpringContextTests.java +++ b/org.springframework.test/src/main/java/org/springframework/test/context/junit38/AbstractJUnit38SpringContextTests.java @@ -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"); * 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.TestCase; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.test.annotation.ExpectedException; @@ -39,47 +39,67 @@ import org.springframework.test.context.support.DirtiesContextTestExecutionListe /** *

- * Abstract base {@link TestCase} which integrates the - * Spring TestContext Framework with explicit - * {@link ApplicationContext} testing support in a JUnit 3.8 - * environment. + * Abstract base {@link TestCase} which integrates the Spring TestContext + * Framework and explicit {@link ApplicationContext} testing support in a + * JUnit 3.8 environment. *

*

* Concrete subclasses: *

* *

* The following list constitutes all annotations currently supported directly - * by AbstractJUnit38SpringContextTests. - * (Note that additional annotations may be supported by various - * {@link org.springframework.test.context.TestExecutionListener TestExecutionListeners}) + * by AbstractJUnit38SpringContextTests. (Note that additional + * annotations may be supported by various + * {@link org.springframework.test.context.TestExecutionListener + * TestExecutionListeners}) *

* - * + *

+ * JUnit 3.8 does not support before class or after class + * lifecycle callbacks. The following + * {@link org.springframework.test.context.TestExecutionListener + * TestExecutionListener} methods are therefore unsupported in a JUnit 3.8 + * environment: + *

+ * * @author Sam Brannen * @author Juergen Hoeller * @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.testng.AbstractTestNGSpringContextTests */ -@TestExecutionListeners({DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class}) +@TestExecutionListeners( { DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class }) public abstract class AbstractJUnit38SpringContextTests extends TestCase implements ApplicationContextAware { private static int disabledTestCount = 0; @@ -117,8 +137,8 @@ public abstract class AbstractJUnit38SpringContextTests extends TestCase impleme /** * {@link ProfileValueSource} available to subclasses but primarily intended - * for internal use to provide support for - * {@link IfProfileValue @IfProfileValue}. + * for internal use to provide support for {@link IfProfileValue + * @IfProfileValue}. */ protected final ProfileValueSource profileValueSource; @@ -126,9 +146,9 @@ public abstract class AbstractJUnit38SpringContextTests extends TestCase impleme /** - * Constructs a new AbstractJUnit38SpringContextTests instance; - * initializes the internal {@link TestContextManager} for the current test; - * and retrieves the configured (or default) {@link ProfileValueSource}. + * Constructs a new AbstractJUnit38SpringContextTests instance; initializes + * the internal {@link TestContextManager} for the current test; and + * retrieves the configured (or default) {@link ProfileValueSource}. */ public AbstractJUnit38SpringContextTests() { super(); @@ -141,6 +161,7 @@ public abstract class AbstractJUnit38SpringContextTests extends TestCase impleme * supplied name; initializes the internal * {@link TestContextManager} for the current test; and retrieves the * configured (or default) {@link ProfileValueSource}. + * * @param name the name of the current test to execute */ public AbstractJUnit38SpringContextTests(String name) { @@ -149,7 +170,6 @@ public abstract class AbstractJUnit38SpringContextTests extends TestCase impleme this.profileValueSource = ProfileValueUtils.retrieveProfileValueSource(getClass()); } - /** * Sets the {@link ApplicationContext} to be used by this test instance, * provided via {@link ApplicationContextAware} semantics. @@ -158,24 +178,26 @@ public abstract class AbstractJUnit38SpringContextTests extends TestCase impleme this.applicationContext = applicationContext; } - /** * Runs the Spring TestContext Framework test sequence. - *

In addition to standard {@link TestCase#runBare()} semantics, this + *

+ * In addition to standard {@link TestCase#runBare()} semantics, this * implementation performs the following: *

+ * * @see ProfileValueUtils#isTestEnabledInThisEnvironment */ @Override @@ -189,6 +211,7 @@ public abstract class AbstractJUnit38SpringContextTests extends TestCase impleme } runTestTimed(new TestExecutionCallback() { + public void run() throws Throwable { runManaged(testMethod); } @@ -214,10 +237,12 @@ public abstract class AbstractJUnit38SpringContextTests extends TestCase impleme } /** - * Runs a timed test via the supplied {@link TestExecutionCallback}, - * providing support for the {@link Timed @Timed} annotation. + * Runs a timed test via the supplied {@link TestExecutionCallback} + * , providing support for the {@link Timed @Timed} annotation. + * * @param tec the test execution callback to run - * @param testMethod the actual test method: used to retrieve the timeout + * @param testMethod the actual test method: used to retrieve the + * timeout * @throws Throwable if any exception is thrown * @see Timed * @see #runTest @@ -243,21 +268,22 @@ public abstract class AbstractJUnit38SpringContextTests extends TestCase impleme /** * Runs a test via the supplied {@link TestExecutionCallback}, providing - * support for the {@link ExpectedException @ExpectedException} and - * {@link Repeat @Repeat} annotations. + * support for the {@link ExpectedException @ExpectedException} and + * {@link Repeat @Repeat} annotations. + * * @param tec the test execution callback to run * @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 * @see ExpectedException * @see Repeat */ private void runTest(TestExecutionCallback tec, Method testMethod) throws Throwable { ExpectedException expectedExceptionAnnotation = testMethod.getAnnotation(ExpectedException.class); - boolean exceptionIsExpected = (expectedExceptionAnnotation != null && - expectedExceptionAnnotation.value() != null); - Class expectedException = - (exceptionIsExpected ? expectedExceptionAnnotation.value() : null); + boolean exceptionIsExpected = (expectedExceptionAnnotation != null && expectedExceptionAnnotation.value() != null); + Class expectedException = (exceptionIsExpected ? expectedExceptionAnnotation.value() + : null); Repeat repeat = testMethod.getAnnotation(Repeat.class); 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())) { // Wrap the unexpected throwable with an explicit message. - AssertionFailedError assertionError = new AssertionFailedError("Unexpected exception, expected <" + - expectedException.getName() + "> but was <" + ex.getClass().getName() + ">"); + AssertionFailedError assertionError = new AssertionFailedError("Unexpected exception, expected <" + + expectedException.getName() + "> but was <" + ex.getClass().getName() + ">"); assertionError.initCause(ex); throw assertionError; } @@ -291,6 +317,7 @@ public abstract class AbstractJUnit38SpringContextTests extends TestCase impleme * Calls {@link TestContextManager#beforeTestMethod(Object,Method)} and * {@link TestContextManager#afterTestMethod(Object,Method,Throwable)} at * the appropriate test execution points. + * * @param testMethod the test method to run * @throws Throwable if any exception is thrown * @see #runBare() @@ -344,6 +371,7 @@ public abstract class AbstractJUnit38SpringContextTests extends TestCase impleme * Records the supplied test method as disabled in the current * environment by incrementing the total number of disabled tests and * logging a debug message. + * * @param testMethod the test method that is disabled. * @see #getDisabledTestCount() */ @@ -357,8 +385,8 @@ public abstract class AbstractJUnit38SpringContextTests extends TestCase impleme /** - * Private inner class that defines a callback analogous to - * {@link Runnable}, just declaring Throwable. + * Private inner class that defines a callback analogous to {@link Runnable} + * , just declaring Throwable. */ private static interface TestExecutionCallback {