Skip to content

Commit 5971581

Browse files
committed
Align getWrapperType Javadoc to declared nullability, add test coverage
1 parent 261c2f5 commit 5971581

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 13 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,18 @@ void wideningConversion() {
213214
assertFalse(isWideningConversion(String.class, int.class)); // neither a primitive nor a wrapper
214215
}
215216

217+
@Test
218+
void getWrapperType() {
219+
assertNull(ReflectionUtils.getWrapperType(Object.class));
220+
assertEquals(Byte.class, ReflectionUtils.getWrapperType(byte.class));
221+
assertEquals(Short.class, ReflectionUtils.getWrapperType(short.class));
222+
assertEquals(Character.class, ReflectionUtils.getWrapperType(char.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+
}
228+
216229
@Test
217230
void getAllClasspathRootDirectories(@TempDir Path tempDirectory) throws Exception {
218231
var root1 = tempDirectory.resolve("root1").toAbsolutePath();

0 commit comments

Comments
 (0)