Skip to content

Commit 76d8c68

Browse files
committed
Remove null support from getWrapperType input, add test coverage
1 parent 261c2f5 commit 76d8c68

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

junit-platform-commons/src/main/java/org/junit/platform/commons/util/ReflectionUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public enum HierarchyTraversalMode {
238238

239239
classNameToTypeMap = Collections.unmodifiableMap(classNamesToTypes);
240240

241-
Map<Class<?>, Class<?>> primitivesToWrappers = new IdentityHashMap<>(9);
241+
Map<Class<?>, Class<?>> primitivesToWrappers = new IdentityHashMap<>(8);
242242

243243
primitivesToWrappers.put(boolean.class, Boolean.class);
244244
primitivesToWrappers.put(byte.class, Byte.class);
@@ -564,7 +564,7 @@ static boolean isWideningConversion(Class<?> sourceType, Class<?> targetType) {
564564
*
565565
* @param type the primitive type for which to retrieve the wrapper type
566566
* @return the corresponding wrapper type or {@code null} if the
567-
* supplied type is {@code null} or not a primitive type
567+
* supplied type is not a primitive type
568568
*/
569569
public static @Nullable Class<?> getWrapperType(Class<?> type) {
570570
return primitiveToWrapperMap.get(type);

platform-tests/src/test/java/org/junit/platform/commons/util/ReflectionUtilsTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static org.junit.jupiter.api.Assertions.assertEquals;
2121
import static org.junit.jupiter.api.Assertions.assertFalse;
2222
import static org.junit.jupiter.api.Assertions.assertNotNull;
23+
import static org.junit.jupiter.api.Assertions.assertNull;
2324
import static org.junit.jupiter.api.Assertions.assertThrows;
2425
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
2526
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -213,6 +214,19 @@ void wideningConversion() {
213214
assertFalse(isWideningConversion(String.class, int.class)); // neither a primitive nor a wrapper
214215
}
215216

217+
@Test
218+
void getWrapperType() {
219+
assertEquals(Boolean.class, ReflectionUtils.getWrapperType(boolean.class));
220+
assertEquals(Byte.class, ReflectionUtils.getWrapperType(byte.class));
221+
assertEquals(Character.class, ReflectionUtils.getWrapperType(char.class));
222+
assertEquals(Short.class, ReflectionUtils.getWrapperType(short.class));
223+
assertEquals(Integer.class, ReflectionUtils.getWrapperType(int.class));
224+
assertEquals(Long.class, ReflectionUtils.getWrapperType(long.class));
225+
assertEquals(Float.class, ReflectionUtils.getWrapperType(float.class));
226+
assertEquals(Double.class, ReflectionUtils.getWrapperType(double.class));
227+
assertNull(ReflectionUtils.getWrapperType(Object.class));
228+
}
229+
216230
@Test
217231
void getAllClasspathRootDirectories(@TempDir Path tempDirectory) throws Exception {
218232
var root1 = tempDirectory.resolve("root1").toAbsolutePath();

0 commit comments

Comments
 (0)