org.spockframework.junit4.ExceptionAdapterExtension Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spock-junit4 Show documentation
Show all versions of spock-junit4 Show documentation
Spock is a testing and specification framework for Java and Groovy applications.
What makes it stand out from the crowd is its beautiful and highly expressive specification language.
Thanks to its JUnit runner, Spock is compatible with most IDEs, build tools, and continuous integration servers.
Spock is inspired from JUnit, jMock, RSpec, Groovy, Scala, Vulcans, and other fascinating life forms.
package org.spockframework.junit4;
import org.spockframework.runtime.extension.AbstractGlobalExtension;
import org.spockframework.runtime.model.*;
public class ExceptionAdapterExtension extends AbstractGlobalExtension {
private static ExceptionAdapterInterceptor exceptionAdapterInterceptor = new ExceptionAdapterInterceptor();
@Override
public void visitSpec(SpecInfo spec) {
spec.getSetupMethods().forEach(it -> it.addInterceptor(exceptionAdapterInterceptor));
spec.getCleanupMethods().forEach(it -> it.addInterceptor(exceptionAdapterInterceptor));
spec.getSetupSpecMethods().forEach(it -> it.addInterceptor(exceptionAdapterInterceptor));
spec.getCleanupSpecMethods().forEach(it -> it.addInterceptor(exceptionAdapterInterceptor));
spec.getBottomSpec().getAllFeatures().forEach(this::addInterceptorToFeature);
}
private void addInterceptorToFeature(FeatureInfo featureInfo) {
featureInfo.getFeatureMethod().addInterceptor(exceptionAdapterInterceptor);
featureInfo.addIterationInterceptor(exceptionAdapterInterceptor);
}
}