|
1 | 1 | package org.metafacture.metafix;
|
2 | 2 |
|
3 | 3 | import org.junit.jupiter.api.Assertions;
|
| 4 | +import org.junit.jupiter.api.Test; |
| 5 | +import org.junit.jupiter.api.extension.AfterAllCallback; |
4 | 6 | import org.junit.jupiter.api.extension.ConditionEvaluationResult;
|
5 | 7 | import org.junit.jupiter.api.extension.ExecutionCondition;
|
6 | 8 | import org.junit.jupiter.api.extension.ExtendWith;
|
|
25 | 27 |
|
26 | 28 | String value();
|
27 | 29 |
|
28 |
| - class Extension implements InvocationInterceptor { |
| 30 | + class Extension implements AfterAllCallback, InvocationInterceptor { |
29 | 31 |
|
30 | 32 | private static final boolean DISABLE_TO_DO = Boolean.parseBoolean(System.getProperty("org.metafacture.metafix.disableToDo"));
|
31 | 33 |
|
| 34 | + private boolean annotationPresent; |
| 35 | + |
32 | 36 | private Extension() {
|
33 | 37 | }
|
34 | 38 |
|
| 39 | + @Override |
| 40 | + public void afterAll(final ExtensionContext context) { |
| 41 | + if (!annotationPresent) { |
| 42 | + for (final Method method : context.getTestClass().get().getDeclaredMethods()) { |
| 43 | + if (method.isAnnotationPresent(Test.class) && method.isAnnotationPresent(MetafixToDo.class)) { |
| 44 | + return; |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + Assertions.fail("Unused extension (no annotations present): " + Handler.EXTENSION_NAME); |
| 49 | + } |
| 50 | + } |
| 51 | + |
35 | 52 | @Override
|
36 | 53 | public void interceptTestMethod(final InvocationInterceptor.Invocation<Void> invocation, final ReflectiveInvocationContext<Method> invocationContext, final ExtensionContext extensionContext) throws Throwable {
|
37 | 54 | if (DISABLE_TO_DO) {
|
@@ -61,6 +78,7 @@ private void handleAnnotation(final ReflectiveInvocationContext<Method> invocati
|
61 | 78 | final MetafixToDo annotation = invocationContext.getExecutable().getAnnotation(MetafixToDo.class);
|
62 | 79 |
|
63 | 80 | if (annotation != null) {
|
| 81 | + annotationPresent = true; |
64 | 82 | consumer.accept(annotation);
|
65 | 83 | }
|
66 | 84 | }
|
|
0 commit comments