diff --git a/documentation/src/docs/asciidoc/release-notes/release-notes-5.12.0-M1.adoc b/documentation/src/docs/asciidoc/release-notes/release-notes-5.12.0-M1.adoc index 504d94de8d48..fe7125ac15c3 100644 --- a/documentation/src/docs/asciidoc/release-notes/release-notes-5.12.0-M1.adoc +++ b/documentation/src/docs/asciidoc/release-notes/release-notes-5.12.0-M1.adoc @@ -29,6 +29,8 @@ JUnit repository on GitHub. * Introduce `ReflectionSupport.makeAccessible(Field)` for third-party use rather than calling the internal `ReflectionUtils.makeAccessible(Field)` method directly. +* Support both the primitive type `void` and the wrapper type `Void` in the internal + `ReflectionUtils` to support `String` to `Class` conversion in parameterized tests. [[release-notes-5.12.0-M1-junit-jupiter]] diff --git a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ReflectionUtils.java b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ReflectionUtils.java index dd18b8d13cd6..26bd8e1698cf 100644 --- a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ReflectionUtils.java +++ b/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ReflectionUtils.java @@ -186,6 +186,7 @@ public enum HierarchyTraversalMode { long.class, float.class, double.class, + void.class, boolean[].class, byte[].class, @@ -213,6 +214,7 @@ public enum HierarchyTraversalMode { Long.class, Float.class, Double.class, + Void.class, String.class, Boolean[].class, @@ -246,7 +248,7 @@ public enum HierarchyTraversalMode { classNameToTypeMap = Collections.unmodifiableMap(classNamesToTypes); - Map, Class> primitivesToWrappers = new IdentityHashMap<>(8); + Map, Class> primitivesToWrappers = new IdentityHashMap<>(9); primitivesToWrappers.put(boolean.class, Boolean.class); primitivesToWrappers.put(byte.class, Byte.class); @@ -256,6 +258,7 @@ public enum HierarchyTraversalMode { primitivesToWrappers.put(long.class, Long.class); primitivesToWrappers.put(float.class, Float.class); primitivesToWrappers.put(double.class, Double.class); + primitivesToWrappers.put(void.class, Void.class); primitiveToWrapperMap = Collections.unmodifiableMap(primitivesToWrappers); } diff --git a/jupiter-tests/src/test/java/org/junit/jupiter/params/converter/DefaultArgumentConverterTests.java b/jupiter-tests/src/test/java/org/junit/jupiter/params/converter/DefaultArgumentConverterTests.java index 1c03dc3bed90..3dfe8c44dd89 100644 --- a/jupiter-tests/src/test/java/org/junit/jupiter/params/converter/DefaultArgumentConverterTests.java +++ b/jupiter-tests/src/test/java/org/junit/jupiter/params/converter/DefaultArgumentConverterTests.java @@ -132,7 +132,7 @@ void convertsStringsToPrimitiveWrapperTypes() { @ParameterizedTest(name = "[{index}] {0}") @ValueSource(classes = { char.class, boolean.class, short.class, byte.class, int.class, long.class, float.class, - double.class }) + double.class, void.class }) void throwsExceptionForNullToPrimitiveTypeConversion(Class type) { assertThatExceptionOfType(ArgumentConversionException.class) // .isThrownBy(() -> convert(null, type)) // @@ -261,8 +261,10 @@ void convertsStringToPath() { @Test void convertsStringToClass() { assertConverts("java.lang.Integer", Class.class, Integer.class); + assertConverts("java.lang.Void", Class.class, Void.class); assertConverts("java.lang.Thread$State", Class.class, State.class); assertConverts("byte", Class.class, byte.class); + assertConverts("void", Class.class, void.class); assertConverts("char[]", Class.class, char[].class); assertConverts("java.lang.Long[][]", Class.class, Long[][].class); assertConverts("[[[I", Class.class, int[][][].class); diff --git a/platform-tests/src/test/java/org/junit/platform/commons/util/ReflectionUtilsTests.java b/platform-tests/src/test/java/org/junit/platform/commons/util/ReflectionUtilsTests.java index 394c7f73aaa9..843b07a85ab1 100644 --- a/platform-tests/src/test/java/org/junit/platform/commons/util/ReflectionUtilsTests.java +++ b/platform-tests/src/test/java/org/junit/platform/commons/util/ReflectionUtilsTests.java @@ -559,6 +559,7 @@ void isAssignableTo() { // Wrappers to Primitives assertTrue(ReflectionUtils.isAssignableTo(Integer.class, int.class)); assertTrue(ReflectionUtils.isAssignableTo(Boolean.class, boolean.class)); + assertTrue(ReflectionUtils.isAssignableTo(Void.class, void.class)); // Widening Conversions from Wrappers to Primitives assertTrue(ReflectionUtils.isAssignableTo(Integer.class, long.class)); @@ -759,6 +760,7 @@ void loadClass() { @Test void tryToLoadClass() { assertThat(ReflectionUtils.tryToLoadClass(Integer.class.getName())).isEqualTo(success(Integer.class)); + assertThat(ReflectionUtils.tryToLoadClass(Void.class.getName())).isEqualTo(success(Void.class)); } @Test @@ -770,6 +772,7 @@ void tryToLoadClassTrimsClassName() { @Test void tryToLoadClassForPrimitive() { assertThat(ReflectionUtils.tryToLoadClass(int.class.getName())).isEqualTo(success(int.class)); + assertThat(ReflectionUtils.tryToLoadClass(void.class.getName())).isEqualTo(success(void.class)); } @Test