diff --git a/src/main/java/com/ljunggren/reflectionUtils/ReflectionUtils.java b/src/main/java/com/ljunggren/reflectionUtils/ReflectionUtils.java index e76dfc9..20f67bd 100644 --- a/src/main/java/com/ljunggren/reflectionUtils/ReflectionUtils.java +++ b/src/main/java/com/ljunggren/reflectionUtils/ReflectionUtils.java @@ -130,6 +130,17 @@ return BigDecimal.class.getName().equals(clazz.getName()); } + public static boolean isByte(Type type) { + if (isParameterized(type)) { + return false; + } + return isByte((Class) type); + } + + public static boolean isByte(Class clazz) { + return Byte.class.getName().equals(clazz.getName()); + } + public static boolean isString(Type type) { if (isParameterized(type)) { return false; diff --git a/src/test/java/com/ljunggren/reflectionUtils/ReflectionUtilsTest.java b/src/test/java/com/ljunggren/reflectionUtils/ReflectionUtilsTest.java index 8ea1f24..ed7675f 100644 --- a/src/test/java/com/ljunggren/reflectionUtils/ReflectionUtilsTest.java +++ b/src/test/java/com/ljunggren/reflectionUtils/ReflectionUtilsTest.java @@ -26,18 +26,19 @@ Short shortObject; Long longObject; Float floatObject; + BigDecimal bigDecimal; List stringList; Set integerSet; Collection booleanCollection; Map integerStringMap; HashMap integerStringHashMap; + Set intergerSet; + Iterable stringIterable; + Byte byteObject; + String string; String[] stringArray; boolean booleanPrimitive; Boolean booleanObject; - String string; - Set intergerSet; - Iterable stringIterable; - BigDecimal bigDecimal; @Test public void constructorTest() { @@ -400,6 +401,27 @@ } @Test + public void isByteTest() throws NoSuchFieldException, SecurityException { + Field field = ReflectionUtilsTest.class.getDeclaredField("byteObject"); + Type fieldType = field.getGenericType(); + assertTrue(ReflectionUtils.isByte(fieldType)); + } + + @Test + public void isByteFalseTest() throws NoSuchFieldException, SecurityException { + Field field = ReflectionUtilsTest.class.getDeclaredField("string"); + Type fieldType = field.getGenericType(); + assertFalse(ReflectionUtils.isByte(fieldType)); + } + + @Test + public void isByteParameterizedTest() throws NoSuchFieldException, SecurityException { + Field field = ReflectionUtilsTest.class.getDeclaredField("stringList"); + Type fieldType = field.getGenericType(); + assertFalse(ReflectionUtils.isByte(fieldType)); + } + + @Test public void isStringTest() throws NoSuchFieldException, SecurityException { Field field = ReflectionUtilsTest.class.getDeclaredField("string"); Type fieldType = field.getGenericType();