Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
private Iterable<Object[]> convert(final Iterable<Object[]> data) {
List<Object[]> parameters = new ArrayList<>();
for (Object[] args : data) {
Object[] params = new Object[args.length];
for (int i = 0; i < args.length; i++) {
final Class<?> parameterClazz = method.getMethod()
.getParameterTypes()[i];
params[i] = convertParameter(args[i], parameterClazz);
}
parameters.add(params);
}
return parameters;
}
private Object convertParameter(final Object parameter,
final Class<?> parameterClass) {
return getParameterConverter(parameterClass)
.map(converter -> converter.convert(parameter))
.orElseThrow(() -> new NotFoundParameterGeneratorException("Cannot convert " + parameter + " to " + parameterClass));
}
private Optional<? extends ParameterConverter<Object, ?>> getParameterConverter(final Class<?> parameterClass) {
return Optional.ofNullable(convertersByClass.get(parameterClass));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment