update unit test
This commit is contained in:
parent
33841c2034
commit
54796738f8
|
@ -19,8 +19,8 @@ public class PrimitiveTypeUtil {
|
|||
WRAPPER_TYPE_MAP.put(Void.class, void.class);
|
||||
}
|
||||
|
||||
public boolean isPrimitiveType(Class<?> sourceClass) {
|
||||
return WRAPPER_TYPE_MAP.containsKey(sourceClass);
|
||||
public static boolean isPrimitiveType(Object source) {
|
||||
return WRAPPER_TYPE_MAP.containsKey(source.getClass());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,37 +4,31 @@ import static org.junit.Assert.assertFalse;
|
|||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.apache.commons.lang3.ClassUtils;
|
||||
import org.junit.Before;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.primitives.Primitives;
|
||||
|
||||
public class PrimitiveTypeUnitTest {
|
||||
|
||||
private PrimitiveTypeUtil primitiveTypeUtil;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
primitiveTypeUtil = new PrimitiveTypeUtil();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAClass_whenCheckWithPrimitiveTypeUtil_thenShouldValidate() {
|
||||
assertTrue(primitiveTypeUtil.isPrimitiveType(Boolean.class));
|
||||
assertFalse(primitiveTypeUtil.isPrimitiveType(String.class));
|
||||
assertTrue(PrimitiveTypeUtil.isPrimitiveType(false));
|
||||
assertTrue(PrimitiveTypeUtil.isPrimitiveType(1L));
|
||||
assertFalse(PrimitiveTypeUtil.isPrimitiveType(StringUtils.EMPTY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAClass_whenCheckWithCommonsLang_thenShouldValidate() {
|
||||
assertTrue(ClassUtils.isPrimitiveOrWrapper(Boolean.class));
|
||||
assertTrue(ClassUtils.isPrimitiveOrWrapper(Boolean.FALSE.getClass()));
|
||||
assertTrue(ClassUtils.isPrimitiveOrWrapper(boolean.class));
|
||||
assertFalse(ClassUtils.isPrimitiveOrWrapper(String.class));
|
||||
assertFalse(ClassUtils.isPrimitiveOrWrapper(StringUtils.EMPTY.getClass()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAClass_whenCheckWithGuava_thenShouldValidate() {
|
||||
assertTrue(Primitives.isWrapperType(Boolean.class));
|
||||
assertFalse(Primitives.isWrapperType(String.class));
|
||||
assertFalse(Primitives.isWrapperType(boolean.class));
|
||||
assertTrue(Primitives.isWrapperType(Boolean.FALSE.getClass()));
|
||||
assertFalse(Primitives.isWrapperType(StringUtils.EMPTY.getClass()));
|
||||
assertFalse(Primitives.isWrapperType(Boolean.TYPE.getClass()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue