All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.spockframework.junit4.ExceptionAdapterExtension Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 2.4-M4-groovy-4.0
Show newest version
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);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy