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 4291635ebecb..d85f942009c0 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 @@ -238,7 +238,7 @@ public enum HierarchyTraversalMode { classNameToTypeMap = Collections.unmodifiableMap(classNamesToTypes); - Map, Class> primitivesToWrappers = new IdentityHashMap<>(9); + Map, Class> primitivesToWrappers = new IdentityHashMap<>(8); primitivesToWrappers.put(boolean.class, Boolean.class); primitivesToWrappers.put(byte.class, Byte.class); @@ -564,7 +564,7 @@ static boolean isWideningConversion(Class sourceType, Class targetType) { * * @param type the primitive type for which to retrieve the wrapper type * @return the corresponding wrapper type or {@code null} if the - * supplied type is {@code null} or not a primitive type + * supplied type is not a primitive type */ public static @Nullable Class getWrapperType(Class type) { return primitiveToWrapperMap.get(type); 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 90a4fd60a4a7..9738a86ef7a6 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 @@ -20,6 +20,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -213,6 +214,19 @@ void wideningConversion() { assertFalse(isWideningConversion(String.class, int.class)); // neither a primitive nor a wrapper } + @Test + void getWrapperType() { + assertEquals(Boolean.class, ReflectionUtils.getWrapperType(boolean.class)); + assertEquals(Byte.class, ReflectionUtils.getWrapperType(byte.class)); + assertEquals(Character.class, ReflectionUtils.getWrapperType(char.class)); + assertEquals(Short.class, ReflectionUtils.getWrapperType(short.class)); + assertEquals(Integer.class, ReflectionUtils.getWrapperType(int.class)); + assertEquals(Long.class, ReflectionUtils.getWrapperType(long.class)); + assertEquals(Float.class, ReflectionUtils.getWrapperType(float.class)); + assertEquals(Double.class, ReflectionUtils.getWrapperType(double.class)); + assertNull(ReflectionUtils.getWrapperType(Object.class)); + } + @Test void getAllClasspathRootDirectories(@TempDir Path tempDirectory) throws Exception { var root1 = tempDirectory.resolve("root1").toAbsolutePath();