net.jqwik.engine.hooks.lifecycle.TryLifecycleMethodsHook Maven / Gradle / Ivy
package net.jqwik.engine.hooks.lifecycle;
import java.lang.reflect.*;
import java.util.*;
import org.junit.platform.engine.support.hierarchical.*;
import net.jqwik.api.lifecycle.*;
import net.jqwik.engine.hooks.*;
import net.jqwik.engine.support.*;
public class TryLifecycleMethodsHook implements AroundTryHook {
private void beforeTry(TryLifecycleContext context) {
List beforeTryMethods = LifecycleMethods.findBeforeTryMethods(context.containerClass());
callTryMethods(beforeTryMethods, context);
}
private void callTryMethods(List methods, TryLifecycleContext context) {
ThrowableCollector throwableCollector = new ThrowableCollector(ignore -> false);
for (Method method : methods) {
Object[] parameters = MethodParameterResolver.resolveParameters(method, context);
throwableCollector.execute(() -> callMethod(method, context.testInstances(), parameters));
}
throwableCollector.assertEmpty();
}
private void callMethod(Method method, List