| 1 | package fr.sii.ogham.testing.extension.spock; | |
| 2 | ||
| 3 | import fr.sii.ogham.testing.extension.common.LogTestInformation; | |
| 4 | import org.spockframework.runtime.extension.IAnnotationDrivenExtension; | |
| 5 | import org.spockframework.runtime.model.FeatureInfo; | |
| 6 | import org.spockframework.runtime.model.MethodInfo; | |
| 7 | import org.spockframework.runtime.model.SpecInfo; | |
| 8 | ||
| 9 | /** | |
| 10 | * Register {@link LoggingTestInterceptor} for tests annotated with | |
| 11 | * {@link LogTestInformation} annotation. | |
| 12 | * | |
| 13 | * @author Aurélien Baudet | |
| 14 | * | |
| 15 | */ | |
| 16 | public class LoggingTestExtension implements IAnnotationDrivenExtension<LogTestInformation> { | |
| 17 | ||
| 18 | @Override | |
| 19 | public void visitSpecAnnotation(LogTestInformation annotation, SpecInfo spec) { | |
| 20 | for (FeatureInfo feature : spec.getFeatures()) { | |
| 21 |
1
1. visitSpecAnnotation : negated conditional → RUN_ERROR |
if (!feature.getFeatureMethod().getReflection().isAnnotationPresent(LogTestInformation.class)) { |
| 22 |
1
1. visitSpecAnnotation : removed call to fr/sii/ogham/testing/extension/spock/LoggingTestExtension::intercept → RUN_ERROR |
intercept(annotation, feature.getFeatureMethod()); |
| 23 | } | |
| 24 | } | |
| 25 | } | |
| 26 | ||
| 27 | @Override | |
| 28 | public void visitFixtureAnnotation(LogTestInformation annotation, MethodInfo fixtureMethod) { | |
| 29 |
1
1. visitFixtureAnnotation : removed call to fr/sii/ogham/testing/extension/spock/LoggingTestExtension::intercept → NO_COVERAGE |
intercept(annotation, fixtureMethod); |
| 30 | } | |
| 31 | ||
| 32 | ||
| 33 | private static void intercept(LogTestInformation annotation, MethodInfo methodInfo) { | |
| 34 | try { | |
| 35 |
1
1. intercept : removed call to org/spockframework/runtime/model/MethodInfo::addInterceptor → RUN_ERROR |
methodInfo.addInterceptor(new LoggingTestInterceptor(annotation)); |
| 36 | } catch (InstantiationException | IllegalAccessException e) { | |
| 37 | throw new IllegalArgumentException("Failed to create logger instance", e); | |
| 38 | } | |
| 39 | } | |
| 40 | ||
| 41 | } | |
Mutations | ||
| 21 |
1.1 |
|
| 22 |
1.1 |
|
| 29 |
1.1 |
|
| 35 |
1.1 |