com.decathlon.tzatziki.steps.DynamicTransformers Maven / Gradle / Ivy
package com.decathlon.tzatziki.steps;
import com.decathlon.tzatziki.utils.Mapper;
import io.cucumber.java.DefaultParameterTransformer;
import java.lang.reflect.Type;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Function;
import static com.decathlon.tzatziki.utils.Types.rawTypeOf;
public class DynamicTransformers {
private static final Map> PARAMETER_TRANSFORMERS = new LinkedHashMap<>();
@SuppressWarnings("unchecked")
public static void register(Class type, Function method) {
PARAMETER_TRANSFORMERS.put(type, (Function) method);
}
@DefaultParameterTransformer
public Object defaultTransformer(Object fromValue, Type toValueType) {
if (toValueType.equals(String.class)) {
return fromValue;
}
return PARAMETER_TRANSFORMERS.getOrDefault(toValueType, v -> {
Class