Skip to content

Commit aeb857c

Browse files
committed
Polish ClassUtilsTests
See gh-23572
1 parent 4575f82 commit aeb857c

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

spring-core/src/test/java/org/springframework/util/ClassUtilsTests.java

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
import java.io.Externalizable;
2020
import java.io.Serializable;
21+
import java.lang.annotation.ElementType;
22+
import java.lang.annotation.Retention;
23+
import java.lang.annotation.RetentionPolicy;
24+
import java.lang.annotation.Target;
2125
import java.lang.reflect.InvocationTargetException;
2226
import java.lang.reflect.Method;
2327
import java.lang.reflect.Proxy;
@@ -31,6 +35,8 @@
3135

3236
import org.junit.jupiter.api.BeforeEach;
3337
import org.junit.jupiter.api.Test;
38+
import org.junit.jupiter.params.ParameterizedTest;
39+
import org.junit.jupiter.params.provider.ValueSource;
3440

3541
import org.springframework.tests.sample.objects.DerivedTestObject;
3642
import org.springframework.tests.sample.objects.ITestInterface;
@@ -383,43 +389,39 @@ void determineCommonAncestor() {
383389
assertThat(ClassUtils.determineCommonAncestor(String.class, List.class)).isNull();
384390
}
385391

386-
@Test
387-
public void isPrimitiveWrapper() {
388-
assertThat(ClassUtils.isPrimitiveWrapper(Boolean.class)).isTrue();
389-
assertThat(ClassUtils.isPrimitiveWrapper(Character.class)).isTrue();
390-
assertThat(ClassUtils.isPrimitiveWrapper(Byte.class)).isTrue();
391-
assertThat(ClassUtils.isPrimitiveWrapper(Short.class)).isTrue();
392-
assertThat(ClassUtils.isPrimitiveWrapper(Integer.class)).isTrue();
393-
assertThat(ClassUtils.isPrimitiveWrapper(Long.class)).isTrue();
394-
assertThat(ClassUtils.isPrimitiveWrapper(Float.class)).isTrue();
395-
assertThat(ClassUtils.isPrimitiveWrapper(Double.class)).isTrue();
396-
assertThat(ClassUtils.isPrimitiveWrapper(Void.class)).isTrue();
392+
@ParameterizedTest
393+
@WrapperTypes
394+
void isPrimitiveWrapper(Class<?> type) {
395+
assertThat(ClassUtils.isPrimitiveWrapper(type)).isTrue();
397396
}
398397

399-
@Test
400-
public void isPrimitiveOrWrapper() {
401-
assertThat(ClassUtils.isPrimitiveOrWrapper(boolean.class)).isTrue();
402-
assertThat(ClassUtils.isPrimitiveOrWrapper(char.class)).isTrue();
403-
assertThat(ClassUtils.isPrimitiveOrWrapper(byte.class)).isTrue();
404-
assertThat(ClassUtils.isPrimitiveOrWrapper(short.class)).isTrue();
405-
assertThat(ClassUtils.isPrimitiveOrWrapper(int.class)).isTrue();
406-
assertThat(ClassUtils.isPrimitiveOrWrapper(long.class)).isTrue();
407-
assertThat(ClassUtils.isPrimitiveOrWrapper(float.class)).isTrue();
408-
assertThat(ClassUtils.isPrimitiveOrWrapper(double.class)).isTrue();
409-
assertThat(ClassUtils.isPrimitiveOrWrapper(void.class)).isTrue();
398+
@ParameterizedTest
399+
@PrimitiveTypes
400+
void isPrimitiveOrWrapperWithPrimitive(Class<?> type) {
401+
assertThat(ClassUtils.isPrimitiveOrWrapper(type)).isTrue();
402+
}
410403

411-
assertThat(ClassUtils.isPrimitiveOrWrapper(Boolean.class)).isTrue();
412-
assertThat(ClassUtils.isPrimitiveOrWrapper(Character.class)).isTrue();
413-
assertThat(ClassUtils.isPrimitiveOrWrapper(Byte.class)).isTrue();
414-
assertThat(ClassUtils.isPrimitiveOrWrapper(Short.class)).isTrue();
415-
assertThat(ClassUtils.isPrimitiveOrWrapper(Integer.class)).isTrue();
416-
assertThat(ClassUtils.isPrimitiveOrWrapper(Long.class)).isTrue();
417-
assertThat(ClassUtils.isPrimitiveOrWrapper(Float.class)).isTrue();
418-
assertThat(ClassUtils.isPrimitiveOrWrapper(Double.class)).isTrue();
419-
assertThat(ClassUtils.isPrimitiveOrWrapper(Void.class)).isTrue();
404+
@ParameterizedTest
405+
@WrapperTypes
406+
void isPrimitiveOrWrapperWithWrapper(Class<?> type) {
407+
assertThat(ClassUtils.isPrimitiveOrWrapper(type)).isTrue();
420408
}
421409

422410

411+
@Target(ElementType.METHOD)
412+
@Retention(RetentionPolicy.RUNTIME)
413+
@ValueSource(classes = { Boolean.class, Character.class, Byte.class, Short.class,
414+
Integer.class, Long.class, Float.class, Double.class, Void.class })
415+
@interface WrapperTypes {
416+
}
417+
418+
@Target(ElementType.METHOD)
419+
@Retention(RetentionPolicy.RUNTIME)
420+
@ValueSource(classes = { boolean.class, char.class, byte.class, short.class,
421+
int.class, long.class, float.class, double.class, void.class })
422+
@interface PrimitiveTypes {
423+
}
424+
423425
public static class InnerClass {
424426

425427
static boolean noArgCalled;

0 commit comments

Comments
 (0)