net.jqwik.engine.hooks.lifecycle.BeforeTryMembersHook Maven / Gradle / Ivy
package net.jqwik.engine.hooks.lifecycle;
import java.lang.reflect.*;
import java.util.*;
import java.util.function.*;
import org.junit.platform.commons.support.*;
import org.junit.platform.engine.support.hierarchical.*;
import net.jqwik.api.*;
import net.jqwik.api.lifecycle.*;
import net.jqwik.engine.hooks.*;
import net.jqwik.engine.support.*;
import static org.junit.platform.commons.support.AnnotationSupport.*;
public class BeforeTryMembersHook implements AroundTryHook {
private static List findBeforeTryFields(Class> testClass) {
Predicate isAnnotated = method -> isAnnotated(method, BeforeTry.class);
return JqwikReflectionSupport.findFieldsPotentiallyOuter(testClass, isAnnotated, HierarchyTraversalMode.TOP_DOWN);
}
private void beforeTry(TryLifecycleContext context) {
List beforeTryFields = findBeforeTryFields(context.containerClass());
initializeFields(beforeTryFields, context);
}
private void initializeFields(List fields, TryLifecycleContext context) {
List