From 9fc405295561409e39b38616aaef7a273c4fbaec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Michael?= Date: Sun, 6 Oct 2024 11:29:31 +0200 Subject: [PATCH 1/4] Support "void" in ReflectionUtils MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Björn Michael --- .../org/junit/platform/commons/util/ReflectionUtils.java | 7 ++++++- .../junit/platform/commons/util/ReflectionUtilsTests.java | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) 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..f5ebe7e24104 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, @@ -223,6 +225,7 @@ public enum HierarchyTraversalMode { Long[].class, Float[].class, Double[].class, + Void[].class, String[].class, Boolean[][].class, @@ -233,6 +236,7 @@ public enum HierarchyTraversalMode { Long[][].class, Float[][].class, Double[][].class, + Void[][].class, String[][].class ); // @formatter:on @@ -246,7 +250,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 +260,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/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 From 7db50b2a0e9125140e0045c8afe0edf9261a30ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Michael?= Date: Sun, 6 Oct 2024 14:57:24 +0200 Subject: [PATCH 2/4] Code review amendments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Björn Michael --- .../platform/commons/util/ReflectionUtils.java | 2 -- .../DefaultArgumentConverterTests.java | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) 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 f5ebe7e24104..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 @@ -225,7 +225,6 @@ public enum HierarchyTraversalMode { Long[].class, Float[].class, Double[].class, - Void[].class, String[].class, Boolean[][].class, @@ -236,7 +235,6 @@ public enum HierarchyTraversalMode { Long[][].class, Float[][].class, Double[][].class, - Void[][].class, String[][].class ); // @formatter:on 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..ce92ac9a36d9 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 @@ -12,6 +12,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -45,6 +46,7 @@ import java.util.UUID; import java.util.concurrent.TimeUnit; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ParameterContext; import org.junit.jupiter.params.ParameterizedTest; @@ -132,7 +134,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 +263,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); @@ -354,6 +358,17 @@ void convertsStringToUUID() { assertConverts(uuid, UUID.class, UUID.fromString(uuid)); } + @Nested + class IntegrationTests { + + @ParameterizedTest + @ValueSource(strings = { "boolean", "byte", "char", "short", "int", "long", "float", "double", "void" }) + void convertsStringToPrimitiveClass(Class clazz) { + assertTrue(clazz.isPrimitive()); + } + + } + // ------------------------------------------------------------------------- private void assertConverts(Object input, Class targetClass, Object expectedOutput) { From ce74a44a0cde964cd7cf7811afee5e9790f13915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Michael?= Date: Mon, 7 Oct 2024 17:54:04 +0200 Subject: [PATCH 3/4] Code review amendments #2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Björn Michael --- .../release-notes/release-notes-5.12.0-M1.adoc | 3 ++- .../converter/DefaultArgumentConverterTests.java | 13 ------------- 2 files changed, 2 insertions(+), 14 deletions(-) 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..69ff09075253 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,7 +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 allow String to Class conversion in parametrized tests [[release-notes-5.12.0-M1-junit-jupiter]] === JUnit Jupiter 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 ce92ac9a36d9..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 @@ -12,7 +12,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -46,7 +45,6 @@ import java.util.UUID; import java.util.concurrent.TimeUnit; -import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ParameterContext; import org.junit.jupiter.params.ParameterizedTest; @@ -358,17 +356,6 @@ void convertsStringToUUID() { assertConverts(uuid, UUID.class, UUID.fromString(uuid)); } - @Nested - class IntegrationTests { - - @ParameterizedTest - @ValueSource(strings = { "boolean", "byte", "char", "short", "int", "long", "float", "double", "void" }) - void convertsStringToPrimitiveClass(Class clazz) { - assertTrue(clazz.isPrimitive()); - } - - } - // ------------------------------------------------------------------------- private void assertConverts(Object input, Class targetClass, Object expectedOutput) { From 40db2f3524bcf71e38c9659e2118196c187771b8 Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Tue, 8 Oct 2024 10:22:52 +0200 Subject: [PATCH 4/4] Polish release notes --- .../docs/asciidoc/release-notes/release-notes-5.12.0-M1.adoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 69ff09075253..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 @@ -30,7 +30,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 allow String to Class conversion in parametrized tests + `ReflectionUtils` to support `String` to `Class` conversion in parameterized tests. + [[release-notes-5.12.0-M1-junit-jupiter]] === JUnit Jupiter