Created
June 26, 2012 21:00
-
-
Save RainerW/2998970 to your computer and use it in GitHub Desktop.
JUnit #25 Idea
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
package com.example.junit25; | |
import org.junit.Ignore; | |
import org.junit.internal.AssumptionViolatedException; | |
import org.junit.internal.runners.model.EachTestNotifier; | |
import org.junit.runner.Description; | |
import org.junit.runner.notification.RunNotifier; | |
import org.junit.runners.BlockJUnit4ClassRunner; | |
import org.junit.runners.model.FrameworkMethod; | |
import org.junit.runners.model.InitializationError; | |
import org.junit.runners.model.Statement; | |
public class JUnit4AssumtionRunner extends BlockJUnit4ClassRunner{ | |
public JUnit4AssumtionRunner(Class<?> klass) throws InitializationError { | |
super(klass); | |
} | |
@Override | |
// just a copy because of JUnit's final policy | |
protected void runChild(final FrameworkMethod method, RunNotifier notifier) { | |
Description description= describeChild(method); | |
if (method.getAnnotation(Ignore.class) != null) { | |
notifier.fireTestIgnored(description); | |
} else { | |
runLeafPatched(methodBlock(method), description, notifier); | |
} | |
} | |
/** | |
* Runs a {@link Statement} that represents a leaf (aka atomic) test. | |
*/ | |
protected final void runLeafPatched(Statement statement, Description description, | |
RunNotifier notifier) { | |
EachTestNotifier eachNotifier= new EachTestNotifier(notifier, description); | |
eachNotifier.fireTestStarted(); | |
try { | |
statement.evaluate(); | |
} catch (AssumptionViolatedException e) { | |
// Actual patch: | |
notifier.fireTestIgnored(description); | |
// eachNotifier.addFailedAssumption(e); | |
} catch (Throwable e) { | |
eachNotifier.addFailure(e); | |
} finally { | |
eachNotifier.fireTestFinished(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment