All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.jqwik.engine.execution.lifecycle.CombinedResolveParameterHook Maven / Gradle / Ivy

The newest version!
package net.jqwik.engine.execution.lifecycle;

import java.util.*;
import java.util.stream.*;

import net.jqwik.api.*;
import net.jqwik.api.Tuple.*;
import net.jqwik.api.lifecycle.*;
import net.jqwik.engine.support.*;

class CombinedResolveParameterHook implements ResolveParameterHook {

	private List resolveParameterHooks;

	public CombinedResolveParameterHook(List resolveParameterHooks) {
		this.resolveParameterHooks = resolveParameterHooks;
	}

	@Override
	public Optional resolve(ParameterResolutionContext parameterContext, LifecycleContext lifecycleContext) {
		List>> resolvers =
			resolveParameterHooks.stream()
								 .map(hook -> Tuple.of(hook, hook.resolve(parameterContext, lifecycleContext)))
								 .filter(tuple -> tuple.get2().isPresent())
								 .collect(Collectors.toList());
		if (resolvers.isEmpty()) {
			return Optional.empty();
		}
		if (resolvers.size() > 1) {
			List> resolverTypes =
				resolvers.stream()
						 .map(tuple -> tuple.get1().getClass())
						 .collect(Collectors.toList());
			String info = String.format("Competing resolvers %s", JqwikStringSupport.displayString(resolverTypes));
			throw new CannotResolveParameterException(parameterContext, info);
		}
		return resolvers.get(0).get2();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy