|
7 | 7 | import au.com.origin.snapshots.config.SnapshotConfigInjector;
|
8 | 8 | import au.com.origin.snapshots.exceptions.SnapshotMatchException;
|
9 | 9 | import au.com.origin.snapshots.logging.LoggingHelper;
|
| 10 | +import au.com.origin.snapshots.utils.ReflectionUtils; |
10 | 11 | import java.lang.reflect.Field;
|
11 |
| -import java.util.Arrays; |
12 | 12 | import lombok.extern.slf4j.Slf4j;
|
13 |
| -import org.junit.jupiter.api.extension.*; |
| 13 | +import org.junit.jupiter.api.extension.AfterAllCallback; |
| 14 | +import org.junit.jupiter.api.extension.BeforeAllCallback; |
| 15 | +import org.junit.jupiter.api.extension.BeforeEachCallback; |
| 16 | +import org.junit.jupiter.api.extension.ExtensionContext; |
| 17 | +import org.junit.jupiter.api.extension.ParameterContext; |
| 18 | +import org.junit.jupiter.api.extension.ParameterResolutionException; |
| 19 | +import org.junit.jupiter.api.extension.ParameterResolver; |
14 | 20 | import org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor;
|
15 | 21 | import org.junit.jupiter.engine.descriptor.ClassTestDescriptor;
|
16 | 22 |
|
@@ -104,13 +110,12 @@ public Object resolveParameter(
|
104 | 110 | @Override
|
105 | 111 | public void beforeEach(ExtensionContext context) {
|
106 | 112 | if (context.getTestInstance().isPresent() && context.getTestMethod().isPresent()) {
|
107 |
| - Arrays.stream(context.getTestClass().get().getDeclaredFields()) |
108 |
| - .filter(it -> it.getType() == Expect.class) |
109 |
| - .findFirst() |
| 113 | + ReflectionUtils.findFieldByPredicate( |
| 114 | + context.getTestClass().get(), (field) -> field.getType() == Expect.class) |
110 | 115 | .ifPresent(
|
111 |
| - field -> { |
| 116 | + (field) -> { |
112 | 117 | Expect expect = Expect.of(snapshotVerifier, context.getTestMethod().get());
|
113 |
| - field.setAccessible(true); |
| 118 | + ReflectionUtils.makeAccessible(field); |
114 | 119 | try {
|
115 | 120 | field.set(context.getTestInstance().get(), expect);
|
116 | 121 | } catch (IllegalAccessException e) {
|
|
0 commit comments