13
13
import org .junit .jupiter .api .extension .ExtensionContext .Store ;
14
14
import org .junit .jupiter .api .extension .ExtensionContext .Store .CloseableResource ;
15
15
import org .junit .platform .commons .support .AnnotationSupport ;
16
- import org .junit .platform .commons .util . AnnotationUtils ;
17
- import org .junit .platform .commons .util . Preconditions ;
18
- import org .junit .platform .commons .util . ReflectionUtils ;
16
+ import org .junit .platform .commons .support . HierarchyTraversalMode ;
17
+ import org .junit .platform .commons .support . ModifierSupport ;
18
+ import org .junit .platform .commons .support . ReflectionSupport ;
19
19
import org .testcontainers .DockerClientFactory ;
20
20
import org .testcontainers .lifecycle .Startable ;
21
21
import org .testcontainers .lifecycle .TestDescription ;
@@ -131,7 +131,7 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con
131
131
private Optional <Testcontainers > findTestcontainers (ExtensionContext context ) {
132
132
Optional <ExtensionContext > current = Optional .of (context );
133
133
while (current .isPresent ()) {
134
- Optional <Testcontainers > testcontainers = AnnotationUtils .findAnnotation (
134
+ Optional <Testcontainers > testcontainers = AnnotationSupport .findAnnotation (
135
135
current .get ().getRequiredTestClass (),
136
136
Testcontainers .class
137
137
);
@@ -169,26 +169,26 @@ private Set<Object> collectParentTestInstances(final ExtensionContext context) {
169
169
}
170
170
171
171
private List <StoreAdapter > findSharedContainers (Class <?> testClass ) {
172
- return ReflectionUtils
173
- .findFields (testClass , isSharedContainer (), ReflectionUtils . HierarchyTraversalMode .TOP_DOWN )
172
+ return ReflectionSupport
173
+ .findFields (testClass , isSharedContainer (), HierarchyTraversalMode .TOP_DOWN )
174
174
.stream ()
175
175
.map (f -> getContainerInstance (null , f ))
176
176
.collect (Collectors .toList ());
177
177
}
178
178
179
179
private Predicate <Field > isSharedContainer () {
180
- return isContainer ().and (ReflectionUtils ::isStatic );
180
+ return isContainer ().and (ModifierSupport ::isStatic );
181
181
}
182
182
183
183
private Stream <StoreAdapter > findRestartContainers (Object testInstance ) {
184
- return ReflectionUtils
185
- .findFields (testInstance .getClass (), isRestartContainer (), ReflectionUtils . HierarchyTraversalMode .TOP_DOWN )
184
+ return ReflectionSupport
185
+ .findFields (testInstance .getClass (), isRestartContainer (), HierarchyTraversalMode .TOP_DOWN )
186
186
.stream ()
187
187
.map (f -> getContainerInstance (testInstance , f ));
188
188
}
189
189
190
190
private Predicate <Field > isRestartContainer () {
191
- return isContainer ().and (ReflectionUtils ::isNotStatic );
191
+ return isContainer ().and (ModifierSupport ::isNotStatic );
192
192
}
193
193
194
194
private static Predicate <Field > isContainer () {
@@ -211,10 +211,10 @@ private static Predicate<Field> isContainer() {
211
211
private static StoreAdapter getContainerInstance (final Object testInstance , final Field field ) {
212
212
try {
213
213
field .setAccessible (true );
214
- Startable containerInstance = Preconditions . notNull (
215
- ( Startable ) field . get ( testInstance ),
216
- "Container " + field .getName () + " needs to be initialized"
217
- );
214
+ Startable containerInstance = ( Startable ) field . get ( testInstance );
215
+ if ( containerInstance == null ) {
216
+ throw new ExtensionConfigurationException ( "Container " + field .getName () + " needs to be initialized" );
217
+ }
218
218
return new StoreAdapter (field .getDeclaringClass (), field .getName (), containerInstance );
219
219
} catch (IllegalAccessException e ) {
220
220
throw new ExtensionConfigurationException ("Can not access container defined in field " + field .getName ());
0 commit comments