Polish ClassUtils.resolvePrimitiveClassName()

See gh-24192
This commit is contained in:
Sam Brannen 2019-12-13 15:47:05 +01:00
parent 09b6730f3d
commit 49ddf798e0
2 changed files with 25 additions and 1 deletions

View File

@ -455,7 +455,7 @@ public abstract class ClassUtils {
Class<?> result = null;
// Most class names will be quite long, considering that they
// SHOULD sit in a package, so a length check is worthwhile.
if (name != null && name.length() <= 8) {
if (name != null && name.length() <= 7) {
// Could be a primitive - likely.
result = primitiveTypeNameMap.get(name);
}

View File

@ -36,6 +36,7 @@ import java.util.Set;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.tests.sample.objects.DerivedTestObject;
@ -155,6 +156,29 @@ class ClassUtilsTests {
assertThat(ClassUtils.isCacheSafe(composite, childLoader3)).isTrue();
}
@ParameterizedTest
@CsvSource({
"boolean, boolean",
"byte, byte",
"char, char",
"short, short",
"int, int",
"long, long",
"float, float",
"double, double",
"[Z, boolean[]",
"[B, byte[]",
"[C, char[]",
"[S, short[]",
"[I, int[]",
"[J, long[]",
"[F, float[]",
"[D, double[]"
})
void resolvePrimitiveClassName(String input, Class<?> output) {
assertThat(ClassUtils.resolvePrimitiveClassName(input)).isEqualTo(output);
}
@Test
void getShortName() {
String className = ClassUtils.getShortName(getClass());