-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore classes that are deprecated for 6 years
This reverts commit 745ca05. The deletion of the classes caused some problems for users (see https://groups.yahoo.com/neo/groups/junit/conversations/topics/24572). In addition, the new coding style has been applied and "major" has been added to the deprecation messages in the Javadoc.
- Loading branch information
1 parent
e561590
commit 883c1bb
Showing
11 changed files
with
823 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.junit.internal.runners; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.List; | ||
|
||
import org.junit.internal.AssumptionViolatedException; | ||
import org.junit.runner.Description; | ||
import org.junit.runner.notification.Failure; | ||
import org.junit.runner.notification.RunNotifier; | ||
import org.junit.runners.BlockJUnit4ClassRunner; | ||
|
||
/** | ||
* @deprecated Included for backwards compatibility with JUnit 4.4. Will be | ||
* removed in the next major release. Please use | ||
* {@link BlockJUnit4ClassRunner} in place of {@link JUnit4ClassRunner}. | ||
*/ | ||
@Deprecated | ||
public class ClassRoadie { | ||
private RunNotifier notifier; | ||
private TestClass testClass; | ||
private Description description; | ||
private final Runnable runnable; | ||
|
||
public ClassRoadie(RunNotifier notifier, TestClass testClass, | ||
Description description, Runnable runnable) { | ||
this.notifier = notifier; | ||
this.testClass = testClass; | ||
this.description = description; | ||
this.runnable = runnable; | ||
} | ||
|
||
protected void runUnprotected() { | ||
runnable.run(); | ||
} | ||
|
||
protected void addFailure(Throwable targetException) { | ||
notifier.fireTestFailure(new Failure(description, targetException)); | ||
} | ||
|
||
public void runProtected() { | ||
try { | ||
runBefores(); | ||
runUnprotected(); | ||
} catch (FailedBefore e) { | ||
} finally { | ||
runAfters(); | ||
} | ||
} | ||
|
||
private void runBefores() throws FailedBefore { | ||
try { | ||
try { | ||
List<Method> befores = testClass.getBefores(); | ||
for (Method before : befores) { | ||
before.invoke(null); | ||
} | ||
} catch (InvocationTargetException e) { | ||
throw e.getTargetException(); | ||
} | ||
} catch (AssumptionViolatedException e) { | ||
throw new FailedBefore(); | ||
} catch (Throwable e) { | ||
addFailure(e); | ||
throw new FailedBefore(); | ||
} | ||
} | ||
|
||
private void runAfters() { | ||
List<Method> afters = testClass.getAfters(); | ||
for (Method after : afters) { | ||
try { | ||
after.invoke(null); | ||
} catch (InvocationTargetException e) { | ||
addFailure(e.getTargetException()); | ||
} catch (Throwable e) { | ||
addFailure(e); // Untested, but seems impossible | ||
} | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/org/junit/internal/runners/FailedBefore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.junit.internal.runners; | ||
|
||
import org.junit.runners.BlockJUnit4ClassRunner; | ||
|
||
/** | ||
* @deprecated Included for backwards compatibility with JUnit 4.4. Will be | ||
* removed in the next major release. Please use | ||
* {@link BlockJUnit4ClassRunner} in place of {@link JUnit4ClassRunner}. | ||
*/ | ||
@Deprecated | ||
class FailedBefore extends Exception { | ||
private static final long serialVersionUID = 1L; | ||
} |
147 changes: 147 additions & 0 deletions
147
src/main/java/org/junit/internal/runners/JUnit4ClassRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
package org.junit.internal.runners; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import org.junit.runner.Description; | ||
import org.junit.runner.Runner; | ||
import org.junit.runner.manipulation.Filter; | ||
import org.junit.runner.manipulation.Filterable; | ||
import org.junit.runner.manipulation.NoTestsRemainException; | ||
import org.junit.runner.manipulation.Sortable; | ||
import org.junit.runner.manipulation.Sorter; | ||
import org.junit.runner.notification.Failure; | ||
import org.junit.runner.notification.RunNotifier; | ||
import org.junit.runners.BlockJUnit4ClassRunner; | ||
|
||
/** | ||
* @deprecated Included for backwards compatibility with JUnit 4.4. Will be | ||
* removed in the next major release. Please use | ||
* {@link BlockJUnit4ClassRunner} in place of {@link JUnit4ClassRunner}. | ||
*/ | ||
@Deprecated | ||
public class JUnit4ClassRunner extends Runner implements Filterable, Sortable { | ||
private final List<Method> testMethods; | ||
private TestClass testClass; | ||
|
||
public JUnit4ClassRunner(Class<?> klass) throws InitializationError { | ||
testClass = new TestClass(klass); | ||
testMethods = getTestMethods(); | ||
validate(); | ||
} | ||
|
||
protected List<Method> getTestMethods() { | ||
return testClass.getTestMethods(); | ||
} | ||
|
||
protected void validate() throws InitializationError { | ||
MethodValidator methodValidator = new MethodValidator(testClass); | ||
methodValidator.validateMethodsForDefaultRunner(); | ||
methodValidator.assertValid(); | ||
} | ||
|
||
@Override | ||
public void run(final RunNotifier notifier) { | ||
new ClassRoadie(notifier, testClass, getDescription(), new Runnable() { | ||
public void run() { | ||
runMethods(notifier); | ||
} | ||
}).runProtected(); | ||
} | ||
|
||
protected void runMethods(final RunNotifier notifier) { | ||
for (Method method : testMethods) { | ||
invokeTestMethod(method, notifier); | ||
} | ||
} | ||
|
||
@Override | ||
public Description getDescription() { | ||
Description spec = Description.createSuiteDescription(getName(), classAnnotations()); | ||
List<Method> testMethods = this.testMethods; | ||
for (Method method : testMethods) { | ||
spec.addChild(methodDescription(method)); | ||
} | ||
return spec; | ||
} | ||
|
||
protected Annotation[] classAnnotations() { | ||
return testClass.getJavaClass().getAnnotations(); | ||
} | ||
|
||
protected String getName() { | ||
return getTestClass().getName(); | ||
} | ||
|
||
protected Object createTest() throws Exception { | ||
return getTestClass().getConstructor().newInstance(); | ||
} | ||
|
||
protected void invokeTestMethod(Method method, RunNotifier notifier) { | ||
Description description = methodDescription(method); | ||
Object test; | ||
try { | ||
test = createTest(); | ||
} catch (InvocationTargetException e) { | ||
testAborted(notifier, description, e.getCause()); | ||
return; | ||
} catch (Exception e) { | ||
testAborted(notifier, description, e); | ||
return; | ||
} | ||
TestMethod testMethod = wrapMethod(method); | ||
new MethodRoadie(test, testMethod, notifier, description).run(); | ||
} | ||
|
||
private void testAborted(RunNotifier notifier, Description description, | ||
Throwable e) { | ||
notifier.fireTestStarted(description); | ||
notifier.fireTestFailure(new Failure(description, e)); | ||
notifier.fireTestFinished(description); | ||
} | ||
|
||
protected TestMethod wrapMethod(Method method) { | ||
return new TestMethod(method, testClass); | ||
} | ||
|
||
protected String testName(Method method) { | ||
return method.getName(); | ||
} | ||
|
||
protected Description methodDescription(Method method) { | ||
return Description.createTestDescription(getTestClass().getJavaClass(), testName(method), testAnnotations(method)); | ||
} | ||
|
||
protected Annotation[] testAnnotations(Method method) { | ||
return method.getAnnotations(); | ||
} | ||
|
||
public void filter(Filter filter) throws NoTestsRemainException { | ||
for (Iterator<Method> iter = testMethods.iterator(); iter.hasNext(); ) { | ||
Method method = iter.next(); | ||
if (!filter.shouldRun(methodDescription(method))) { | ||
iter.remove(); | ||
} | ||
} | ||
if (testMethods.isEmpty()) { | ||
throw new NoTestsRemainException(); | ||
} | ||
} | ||
|
||
public void sort(final Sorter sorter) { | ||
Collections.sort(testMethods, new Comparator<Method>() { | ||
public int compare(Method o1, Method o2) { | ||
return sorter.compare(methodDescription(o1), methodDescription(o2)); | ||
} | ||
}); | ||
} | ||
|
||
protected TestClass getTestClass() { | ||
return testClass; | ||
} | ||
} |
Oops, something went wrong.