Skip to content

Instantly share code, notes, and snippets.

@magneticflux-
Created March 21, 2017 13:30
Show Gist options
  • Save magneticflux-/4c3478e21540b3f3652ec041752a36a3 to your computer and use it in GitHub Desktop.
Save magneticflux-/4c3478e21540b3f3652ec041752a36a3 to your computer and use it in GitHub Desktop.
Mockito TestRule replacement example
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.mockito.internal.configuration.IndependentAnnotationEngine;
import org.mockito.plugins.AnnotationEngine;
public class MockitoTestRule implements TestRule {
@Override
public Statement apply(Statement base, Description description) {
return new Statement() {
public void evaluate() throws Throwable {
AnnotationEngine annotationEngine = new IndependentAnnotationEngine();
annotationEngine.process(description.getTestClass(), null);
base.evaluate();
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment