private List<Class> allMaterialConfigsWhichAreDataPointsInThisTest() throws Exception { List<Field> fields = AnnotationUtils.findAnnotatedFields(getClass(), DataPoint.class, field -> true); ArrayList<Class> allDataPointMaterialConfigClasses = new ArrayList<>(); for (Field field : fields) { allDataPointMaterialConfigClasses.add(field.get(this).getClass()); } return allDataPointMaterialConfigClasses; }
private void injectFields(ExtensionContext context, Object testInstance, Predicate<Field> predicate) { findAnnotatedFields(context.getRequiredTestClass(), TempDir.class, predicate).forEach(field -> { assertValidFieldCandidate(field); try { makeAccessible(field).set(testInstance, getPathOrFile(field.getType(), context)); } catch (Throwable t) { ExceptionUtils.throwAsUncheckedException(t); } }); }
/** * Register extensions in the supplied registry from fields in the supplied * class that are annotated with {@link RegisterExtension @RegisterExtension}. * * <p>The extensions will be sorted according to {@link Order @Order} semantics * prior to registration. * * @param registry the registry in which to register the extensions; never {@code null} * @param clazz the class or interface in which to find the fields; never {@code null} * @param instance the instance of the supplied class; may be {@code null} * when searching for {@code static} fields in the class */ static void registerExtensionsFromFields(ExtensionRegistry registry, Class<?> clazz, Object instance) { Preconditions.notNull(clazz, "Class must not be null"); Preconditions.notNull(registry, "ExtensionRegistry must not be null"); Predicate<Field> predicate = (instance == null) ? isStaticExtension : isNonStaticExtension; // Ensure that the list is modifiable, since findAnnotatedFields() returns an unmodifiable list. List<Field> fields = new ArrayList<>(findAnnotatedFields(clazz, RegisterExtension.class, predicate)); // Sort fields based on @Order. fields.sort(orderComparator); fields.forEach(field -> { tryToReadFieldValue(field, instance).ifSuccess(value -> { Preconditions.notNull(value, () -> String.format( "Failed to register extension via @RegisterExtension field [%s]: field must not be null when evaluated.", field)); Extension extension = (Extension) value; registry.registerExtension(extension, field); }); }); }