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