Skip to content

Commit

Permalink
remove no longer required workaround as junit-jupiter compatibility i…
Browse files Browse the repository at this point in the history
…s now >= 5.4.0 anyway
  • Loading branch information
aaschmid committed Jul 4, 2019
1 parent bd76f3b commit 0c9a16e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,36 +69,6 @@ protected Stream<? extends Arguments> convertData(Method testMethod, Object data
checkNotNull(data, "'data' must not be null");
checkNotNull(context, "'context' must not be null");

return dataConverter.convert(data, testMethod.isVarArgs(), testMethod.getParameterTypes(), context).stream()
.map(objects -> {
Class<?>[] parameterTypes = testMethod.getParameterTypes();
for (int idx = 0; idx < objects.length; idx++) {
// TODO workaround for https://github.com/junit-team/junit5/issues/1092
Class<?> parameterType = parameterTypes[idx];
if (parameterType.isPrimitive()) {
objects[idx] = convertToBoxedTypeAsWorkaroundForNotWorkingWideningAndUnboxingConversion(
objects[idx], parameterType);
}
}
return objects;
}).map(Arguments::of);
}

private Object convertToBoxedTypeAsWorkaroundForNotWorkingWideningAndUnboxingConversion(Object result,
Class<?> parameterType) {
if (short.class.equals(parameterType)) {
return ((Number) result).shortValue();
} else if (byte.class.equals(parameterType)) {
return ((Number) result).byteValue();
} else if (int.class.equals(parameterType)) {
return ((Number) result).intValue();
} else if (long.class.equals(parameterType)) {
return ((Number) result).longValue();
} else if (float.class.equals(parameterType)) {
return ((Number) result).floatValue();
} else if (double.class.equals(parameterType)) {
return ((Number) result).doubleValue();
}
return result;
return dataConverter.convert(data, testMethod.isVarArgs(), testMethod.getParameterTypes(), context).stream().map(Arguments::of);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,6 @@ public boolean supportsParameter(ParameterContext parameterContext, ExtensionCon
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
throws ParameterResolutionException {
Object result = arguments.get(parameterContext.getIndex());

// TODO workaround for https://github.com/junit-team/junit5/issues/1092
Class<?> parameterType = parameterContext.getParameter().getType();
if (parameterType.isPrimitive()) {
return convertToBoxedTypeAsWorkaroundForNotWorkingWideningAndUnboxingConversion(result, parameterType);
}

return result;
}

private Object convertToBoxedTypeAsWorkaroundForNotWorkingWideningAndUnboxingConversion(Object result,
Class<?> parameterType) {
if (short.class.equals(parameterType)) {
return ((Number) result).shortValue();
} else if (byte.class.equals(parameterType)) {
return ((Number) result).byteValue();
} else if (int.class.equals(parameterType)) {
return ((Number) result).intValue();
} else if (long.class.equals(parameterType)) {
return ((Number) result).longValue();
} else if (float.class.equals(parameterType)) {
return ((Number) result).floatValue();
} else if (double.class.equals(parameterType)) {
return ((Number) result).doubleValue();
}
return result;
return arguments.get(parameterContext.getIndex());
}
}
}

0 comments on commit 0c9a16e

Please sign in to comment.