diff --git a/README.md b/README.md index d37be3a..2117254 100644 --- a/README.md +++ b/README.md @@ -172,3 +172,7 @@ ## TODO ## 1. Handle embedded objects & parameterized objects on insert, delete, update + +## Dependencies ## + +- reflection-utils diff --git a/pom.xml b/pom.xml index ea2efeb..7966ce4 100644 --- a/pom.xml +++ b/pom.xml @@ -18,6 +18,11 @@ + com.ljunggren + reflection-utils + 1.0.0-SNAPSHOT + + org.apache.commons commons-lang3 3.10 diff --git a/src/main/java/com/ljunggren/storm/StormRepository.java b/src/main/java/com/ljunggren/storm/StormRepository.java index 985f277..4e5f3aa 100644 --- a/src/main/java/com/ljunggren/storm/StormRepository.java +++ b/src/main/java/com/ljunggren/storm/StormRepository.java @@ -10,6 +10,7 @@ import java.util.Iterator; import java.util.function.Consumer; +import com.ljunggren.reflectionUtils.ReflectionUtils; import com.ljunggren.storm.annotation.Database; import com.ljunggren.storm.context.Context; import com.ljunggren.storm.context.ContextFactory; @@ -22,7 +23,6 @@ import com.ljunggren.storm.crud.UpdateQuery; import com.ljunggren.storm.exceptions.StormException; import com.ljunggren.storm.utils.AnnotationUtils; -import com.ljunggren.storm.utils.ReflectionUtils; public class StormRepository implements InvocationHandler { diff --git a/src/main/java/com/ljunggren/storm/builders/DeleteQueryBuilder.java b/src/main/java/com/ljunggren/storm/builders/DeleteQueryBuilder.java index e5d3bfe..44c04c3 100644 --- a/src/main/java/com/ljunggren/storm/builders/DeleteQueryBuilder.java +++ b/src/main/java/com/ljunggren/storm/builders/DeleteQueryBuilder.java @@ -3,9 +3,9 @@ import java.lang.reflect.Field; import java.util.List; +import com.ljunggren.reflectionUtils.ReflectionUtils; import com.ljunggren.storm.annotation.entity.Id; import com.ljunggren.storm.utils.AnnotationUtils; -import com.ljunggren.storm.utils.ReflectionUtils; public class DeleteQueryBuilder extends QueryBuilder { diff --git a/src/main/java/com/ljunggren/storm/builders/InsertBatchQueryBuilder.java b/src/main/java/com/ljunggren/storm/builders/InsertBatchQueryBuilder.java index 11e759a..c43cd94 100644 --- a/src/main/java/com/ljunggren/storm/builders/InsertBatchQueryBuilder.java +++ b/src/main/java/com/ljunggren/storm/builders/InsertBatchQueryBuilder.java @@ -5,9 +5,9 @@ import java.util.List; import java.util.stream.Collectors; +import com.ljunggren.reflectionUtils.ReflectionUtils; import com.ljunggren.storm.utils.AnnotationUtils; import com.ljunggren.storm.utils.ExceptionUtils; -import com.ljunggren.storm.utils.ReflectionUtils; public class InsertBatchQueryBuilder extends QueryBuilder { diff --git a/src/main/java/com/ljunggren/storm/builders/InsertQueryBuilder.java b/src/main/java/com/ljunggren/storm/builders/InsertQueryBuilder.java index 545ffbc..2c7c57a 100644 --- a/src/main/java/com/ljunggren/storm/builders/InsertQueryBuilder.java +++ b/src/main/java/com/ljunggren/storm/builders/InsertQueryBuilder.java @@ -6,9 +6,9 @@ import org.apache.commons.lang3.StringUtils; +import com.ljunggren.reflectionUtils.ReflectionUtils; import com.ljunggren.storm.utils.AnnotationUtils; import com.ljunggren.storm.utils.ExceptionUtils; -import com.ljunggren.storm.utils.ReflectionUtils; public class InsertQueryBuilder extends QueryBuilder { diff --git a/src/main/java/com/ljunggren/storm/builders/QueryBuilder.java b/src/main/java/com/ljunggren/storm/builders/QueryBuilder.java index f7f9c17..f5a2320 100644 --- a/src/main/java/com/ljunggren/storm/builders/QueryBuilder.java +++ b/src/main/java/com/ljunggren/storm/builders/QueryBuilder.java @@ -5,10 +5,10 @@ import java.util.List; import java.util.stream.Collectors; +import com.ljunggren.reflectionUtils.ReflectionUtils; import com.ljunggren.storm.annotation.entity.ColumnProperty; import com.ljunggren.storm.annotation.entity.Table; import com.ljunggren.storm.utils.AnnotationUtils; -import com.ljunggren.storm.utils.ReflectionUtils; public abstract class QueryBuilder { diff --git a/src/main/java/com/ljunggren/storm/builders/UpdateQueryBuilder.java b/src/main/java/com/ljunggren/storm/builders/UpdateQueryBuilder.java index 2a8bb85..e75e69a 100644 --- a/src/main/java/com/ljunggren/storm/builders/UpdateQueryBuilder.java +++ b/src/main/java/com/ljunggren/storm/builders/UpdateQueryBuilder.java @@ -6,10 +6,10 @@ import org.apache.commons.lang3.StringUtils; +import com.ljunggren.reflectionUtils.ReflectionUtils; import com.ljunggren.storm.annotation.entity.Id; import com.ljunggren.storm.utils.AnnotationUtils; import com.ljunggren.storm.utils.ExceptionUtils; -import com.ljunggren.storm.utils.ReflectionUtils; public class UpdateQueryBuilder extends QueryBuilder { diff --git a/src/main/java/com/ljunggren/storm/crud/DeleteQuery.java b/src/main/java/com/ljunggren/storm/crud/DeleteQuery.java index 7401ef7..13700b4 100644 --- a/src/main/java/com/ljunggren/storm/crud/DeleteQuery.java +++ b/src/main/java/com/ljunggren/storm/crud/DeleteQuery.java @@ -6,12 +6,12 @@ import java.util.function.Consumer; import java.util.stream.Collectors; +import com.ljunggren.reflectionUtils.ReflectionUtils; import com.ljunggren.storm.annotation.crud.Delete; import com.ljunggren.storm.builders.DeleteQueryBuilder; import com.ljunggren.storm.builders.QueryBuilder; import com.ljunggren.storm.context.Context; import com.ljunggren.storm.utils.ExceptionUtils; -import com.ljunggren.storm.utils.ReflectionUtils; public class DeleteQuery extends QueryChain { diff --git a/src/main/java/com/ljunggren/storm/crud/InsertQuery.java b/src/main/java/com/ljunggren/storm/crud/InsertQuery.java index a991524..3925b89 100644 --- a/src/main/java/com/ljunggren/storm/crud/InsertQuery.java +++ b/src/main/java/com/ljunggren/storm/crud/InsertQuery.java @@ -6,12 +6,12 @@ import java.util.function.Consumer; import java.util.stream.Collectors; +import com.ljunggren.reflectionUtils.ReflectionUtils; import com.ljunggren.storm.annotation.crud.Insert; import com.ljunggren.storm.builders.InsertQueryBuilder; import com.ljunggren.storm.builders.QueryBuilder; import com.ljunggren.storm.context.Context; import com.ljunggren.storm.utils.ExceptionUtils; -import com.ljunggren.storm.utils.ReflectionUtils; public class InsertQuery extends QueryChain { diff --git a/src/main/java/com/ljunggren/storm/crud/UpdateQuery.java b/src/main/java/com/ljunggren/storm/crud/UpdateQuery.java index bf4c555..1a42ea8 100644 --- a/src/main/java/com/ljunggren/storm/crud/UpdateQuery.java +++ b/src/main/java/com/ljunggren/storm/crud/UpdateQuery.java @@ -6,12 +6,12 @@ import java.util.function.Consumer; import java.util.stream.Collectors; +import com.ljunggren.reflectionUtils.ReflectionUtils; import com.ljunggren.storm.annotation.crud.Update; import com.ljunggren.storm.builders.QueryBuilder; import com.ljunggren.storm.builders.UpdateQueryBuilder; import com.ljunggren.storm.context.Context; import com.ljunggren.storm.utils.ExceptionUtils; -import com.ljunggren.storm.utils.ReflectionUtils; public class UpdateQuery extends QueryChain { diff --git a/src/main/java/com/ljunggren/storm/mapper/ArrayMapper.java b/src/main/java/com/ljunggren/storm/mapper/ArrayMapper.java index 8ec08d1..62cb534 100644 --- a/src/main/java/com/ljunggren/storm/mapper/ArrayMapper.java +++ b/src/main/java/com/ljunggren/storm/mapper/ArrayMapper.java @@ -7,7 +7,7 @@ import java.util.Arrays; import java.util.List; -import com.ljunggren.storm.utils.ReflectionUtils; +import com.ljunggren.reflectionUtils.ReflectionUtils; public class ArrayMapper extends MapperChain { diff --git a/src/main/java/com/ljunggren/storm/mapper/ListMapper.java b/src/main/java/com/ljunggren/storm/mapper/ListMapper.java index 8a458db..d84b9e0 100644 --- a/src/main/java/com/ljunggren/storm/mapper/ListMapper.java +++ b/src/main/java/com/ljunggren/storm/mapper/ListMapper.java @@ -6,7 +6,7 @@ import java.util.ArrayList; import java.util.List; -import com.ljunggren.storm.utils.ReflectionUtils; +import com.ljunggren.reflectionUtils.ReflectionUtils; public class ListMapper extends MapperChain { diff --git a/src/main/java/com/ljunggren/storm/mapper/MapperChain.java b/src/main/java/com/ljunggren/storm/mapper/MapperChain.java index 1e0d515..57cbb4e 100644 --- a/src/main/java/com/ljunggren/storm/mapper/MapperChain.java +++ b/src/main/java/com/ljunggren/storm/mapper/MapperChain.java @@ -10,9 +10,9 @@ import org.apache.commons.lang3.reflect.FieldUtils; +import com.ljunggren.reflectionUtils.ReflectionUtils; import com.ljunggren.storm.annotation.entity.ColumnProperty; import com.ljunggren.storm.utils.AnnotationUtils; -import com.ljunggren.storm.utils.ReflectionUtils; public abstract class MapperChain { diff --git a/src/main/java/com/ljunggren/storm/mapper/ObjectMapper.java b/src/main/java/com/ljunggren/storm/mapper/ObjectMapper.java index d7f3a68..d9909c7 100644 --- a/src/main/java/com/ljunggren/storm/mapper/ObjectMapper.java +++ b/src/main/java/com/ljunggren/storm/mapper/ObjectMapper.java @@ -5,7 +5,7 @@ import java.sql.ResultSet; import java.util.List; -import com.ljunggren.storm.utils.ReflectionUtils; +import com.ljunggren.reflectionUtils.ReflectionUtils; public class ObjectMapper extends MapperChain { diff --git a/src/main/java/com/ljunggren/storm/mapper/PrimitiveMapper.java b/src/main/java/com/ljunggren/storm/mapper/PrimitiveMapper.java index 046f85f..b9d985f 100644 --- a/src/main/java/com/ljunggren/storm/mapper/PrimitiveMapper.java +++ b/src/main/java/com/ljunggren/storm/mapper/PrimitiveMapper.java @@ -3,7 +3,7 @@ import java.lang.reflect.Type; import java.sql.ResultSet; -import com.ljunggren.storm.utils.ReflectionUtils; +import com.ljunggren.reflectionUtils.ReflectionUtils; public class PrimitiveMapper extends MapperChain { diff --git a/src/main/java/com/ljunggren/storm/mapper/SetMapper.java b/src/main/java/com/ljunggren/storm/mapper/SetMapper.java index 9fdc212..f52f2e0 100644 --- a/src/main/java/com/ljunggren/storm/mapper/SetMapper.java +++ b/src/main/java/com/ljunggren/storm/mapper/SetMapper.java @@ -7,7 +7,7 @@ import java.util.List; import java.util.Set; -import com.ljunggren.storm.utils.ReflectionUtils; +import com.ljunggren.reflectionUtils.ReflectionUtils; public class SetMapper extends MapperChain { diff --git a/src/main/java/com/ljunggren/storm/utils/ReflectionUtils.java b/src/main/java/com/ljunggren/storm/utils/ReflectionUtils.java deleted file mode 100644 index 96491f7..0000000 --- a/src/main/java/com/ljunggren/storm/utils/ReflectionUtils.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.ljunggren.storm.utils; - -import java.lang.reflect.Field; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.Collection; -import java.util.List; -import java.util.Set; -import java.util.stream.Stream; - -import org.apache.commons.lang3.ClassUtils; -import org.apache.commons.lang3.reflect.FieldUtils; - -public class ReflectionUtils { - - public static Type getOwnerType(Type type) { - return type instanceof ParameterizedType ? ((ParameterizedType) type).getRawType() : null; - } - - public static Type[] getParameterizedTypes(Type type) { - if (type instanceof ParameterizedType) { - return ((ParameterizedType) type).getActualTypeArguments(); - } - return new Type[] {}; - } - - public static Type getParameterizedType(Type type) { - Type[] types = getParameterizedTypes(type); - return types.length == 1 ? types[0] : null; - } - - public static Type getArrayComponentType(Type type) { - return isArray(type) ? ((Class) type).getComponentType() : null; - } - - public static List getObjectFields(Class clazz) { - return FieldUtils.getAllFieldsList(clazz); - } - - public static boolean isPrimitive(Type type) { - if (isParameterized(type)) { - return false; - } - return ClassUtils.isPrimitiveOrWrapper((Class) type); - } - - public static boolean isInteger(Type type) { - if (isPrimitive(type)) { - return type.getTypeName().equals(Integer.class.getName()) || - type.getTypeName().equals(int.class.getName()); - } - return false; - } - - public static boolean isParameterized(Type type) { - return type instanceof ParameterizedType; - } - - public static boolean isString(Type type) { - if (isParameterized(type)) { - return false; - } - return type.getTypeName().equals(String.class.getName()); - } - - public static boolean isList(Type type) { - if (isParameterized(type)) { - return getOwnerType(type).getTypeName().equals(List.class.getName()); - } - return false; - } - - public static boolean isArray(Type type) { - if (isParameterized(type)) { - return false; - } - return ((Class) type).isArray(); - } - - public static boolean isSet(Type type) { - if (isParameterized(type)) { - return getOwnerType(type).getTypeName().equals(Set.class.getName()); - } - return false; - } - - public static boolean hasNoArgsContrustor(Class clazz) { - return Stream.of(clazz.getConstructors()) - .allMatch(constructor -> constructor.getParameterCount() == 0); - } - - public static boolean isCollection(Class clazz) { - return Collection.class.isAssignableFrom(clazz); - } - - public static Object getFieldValue(Field field, Object target) throws IllegalAccessException { - return FieldUtils.readField(field, target, true); - } - -} diff --git a/src/test/java/com/ljunggren/storm/utils/AnnotationUtilsTest.java b/src/test/java/com/ljunggren/storm/utils/AnnotationUtilsTest.java index 6c67a58..fe933df 100644 --- a/src/test/java/com/ljunggren/storm/utils/AnnotationUtilsTest.java +++ b/src/test/java/com/ljunggren/storm/utils/AnnotationUtilsTest.java @@ -1,6 +1,7 @@ package com.ljunggren.storm.utils; -import static org.junit.Assert.*; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.lang.annotation.Annotation; import java.lang.reflect.Field; @@ -8,6 +9,7 @@ import org.junit.Test; +import com.ljunggren.reflectionUtils.ReflectionUtils; import com.ljunggren.storm.TestUser; import com.ljunggren.storm.annotation.Database; import com.ljunggren.storm.annotation.entity.Id; diff --git a/src/test/java/com/ljunggren/storm/utils/ReflectionUtilsTest.java b/src/test/java/com/ljunggren/storm/utils/ReflectionUtilsTest.java deleted file mode 100644 index 63829c8..0000000 --- a/src/test/java/com/ljunggren/storm/utils/ReflectionUtilsTest.java +++ /dev/null @@ -1,299 +0,0 @@ -package com.ljunggren.storm.utils; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.lang.reflect.Field; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.junit.Test; - -import com.ljunggren.storm.TestUser; - -public class ReflectionUtilsTest { - - List stringList; - Set integerSet; - Collection booleanCollection; - Map integerStringMap; - String[] stringArray; - boolean primitiveBoolean; - Boolean objectBoolean; - String string; - Set intergerSet; - int primitiveInteger; - Integer objectInteger; - TestUser testUser; - - @Test - public void constructorTest() { - ReflectionUtils reflectionUtils = new ReflectionUtils(); - assertTrue(reflectionUtils instanceof ReflectionUtils); - } - - @Test - public void getObjectFieldsTest() { - List fields = ReflectionUtils.getObjectFields(this.getClass()); - boolean hasStringList = fields.stream().anyMatch(field -> field.getName().equals("stringList")); - assertTrue(hasStringList); - } - - @Test - public void getOwnerTypeNullTest() { - Type type = ReflectionUtils.getOwnerType(null); - assertEquals(null, type); - } - - @Test - public void getOwnerTypeStringTest() { - Type type = ReflectionUtils.getOwnerType(String.class); - assertEquals(null, type); - } - - @Test - public void getOwnerTypeListTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("stringList"); - Type fieldType = field.getGenericType(); - Type type = ReflectionUtils.getOwnerType(fieldType); - assertEquals(List.class, type); - } - - @Test - public void getOwnerTypeSetTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("integerSet"); - Type fieldType = field.getGenericType(); - Type type = ReflectionUtils.getOwnerType(fieldType); - assertEquals(Set.class, type); - } - - @Test - public void getOwnerTypeBooleanTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("booleanCollection"); - Type fieldType = field.getGenericType(); - Type type = ReflectionUtils.getOwnerType(fieldType); - assertEquals(Collection.class, type); - } - - @Test - public void getParameterizedTypesNullTest() { - Type[] types = ReflectionUtils.getParameterizedTypes(null); - assertEquals(0, types.length); - } - - @Test - public void getParameterizedTypesMapTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("integerStringMap"); - Type fieldType = field.getGenericType(); - Type[] types = ReflectionUtils.getParameterizedTypes(fieldType); - assertEquals(2, types.length); - assertEquals(Integer.class, types[0]); - assertEquals(String.class, types[1]); - } - - @Test - public void getParameterizedTypeNullTest() { - Type type = ReflectionUtils.getParameterizedType(null); - assertNull(type); - } - - @Test - public void getParameterizedTypeNonParameterizedTest() { - Type type = ReflectionUtils.getOwnerType(String.class); - assertEquals(null, type); - } - - @Test - public void getParameterizedTypeStringTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("stringList"); - Type fieldType = field.getGenericType(); - Type type = ReflectionUtils.getParameterizedType(fieldType); - assertEquals(String.class, type); - } - - @Test - public void getArrayComponentTypeTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("stringArray"); - Type fieldType = field.getGenericType(); - Type type = ReflectionUtils.getArrayComponentType(fieldType); - assertEquals(String.class, type); - } - - @Test - public void getArrayComponentTypeFalseTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("string"); - Type fieldType = field.getGenericType(); - Type type = ReflectionUtils.getArrayComponentType(fieldType); - assertEquals(null, type); - } - - @Test - public void isPrimitiveTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("primitiveBoolean"); - Type fieldType = field.getGenericType(); - assertTrue(ReflectionUtils.isPrimitive(fieldType)); - } - - @Test - public void isIntegerPrimitiveTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("primitiveInteger"); - Type fieldType = field.getGenericType(); - assertTrue(ReflectionUtils.isInteger(fieldType)); - } - - @Test - public void isIntegerObjectTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("objectInteger"); - Type fieldType = field.getGenericType(); - assertTrue(ReflectionUtils.isInteger(fieldType)); - } - - @Test - public void isIntegerFalseTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("string"); - Type fieldType = field.getGenericType(); - assertFalse(ReflectionUtils.isInteger(fieldType)); - } - - @Test - public void isPrimitiveFalseTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("stringList"); - Type fieldType = field.getGenericType(); - assertFalse(ReflectionUtils.isPrimitive(fieldType)); - } - - @Test - public void isPrimitiveWrappedTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("objectBoolean"); - Type fieldType = field.getGenericType(); - assertTrue(ReflectionUtils.isPrimitive(fieldType)); - } - - @Test - public void isParameterizedTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("stringList"); - Type fieldType = field.getGenericType(); - assertTrue(ReflectionUtils.isParameterized(fieldType)); - } - - @Test - public void isParameterizedFalseTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("primitiveBoolean"); - Type fieldType = field.getGenericType(); - assertFalse(ReflectionUtils.isParameterized(fieldType)); - } - - @Test - public void isListTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("stringList"); - Type fieldType = field.getGenericType(); - assertTrue(ReflectionUtils.isList(fieldType)); - } - - @Test - public void isListFalseTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("string"); - Type fieldType = field.getGenericType(); - assertFalse(ReflectionUtils.isList(fieldType)); - } - - @Test - public void isListParamaterizedFalseTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("integerSet"); - Type fieldType = field.getGenericType(); - assertFalse(ReflectionUtils.isList(fieldType)); - } - - @Test - public void isArrayTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("stringArray"); - Type fieldType = field.getGenericType(); - assertTrue(ReflectionUtils.isArray(fieldType)); - } - - @Test - public void isArrayFalseTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("stringList"); - Type fieldType = field.getGenericType(); - assertFalse(ReflectionUtils.isArray(fieldType)); - } - - @Test - public void isStringTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("string"); - Type fieldType = field.getGenericType(); - assertTrue(ReflectionUtils.isString(fieldType)); - } - - @Test - public void isStringFalseTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("objectBoolean"); - Type fieldType = field.getGenericType(); - assertFalse(ReflectionUtils.isString(fieldType)); - } - - @Test - public void isStringParameterizedTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("stringList"); - Type fieldType = field.getGenericType(); - assertFalse(ReflectionUtils.isString(fieldType)); - } - - @Test - public void isSetTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("integerSet"); - Type fieldType = field.getGenericType(); - assertTrue(ReflectionUtils.isSet(fieldType)); - } - - @Test - public void isSetParameterizedFalseTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("stringList"); - Type fieldType = field.getGenericType(); - assertFalse(ReflectionUtils.isSet(fieldType)); - } - - @Test - public void isSetFalseTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("string"); - Type fieldType = field.getGenericType(); - assertFalse(ReflectionUtils.isSet(fieldType)); - } - - @Test - public void hasNoArgsConstructorTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("testUser"); - Type fieldType = field.getGenericType(); - assertTrue(ReflectionUtils.hasNoArgsContrustor((Class) fieldType)); - } - - @Test - public void hasNoArgsConstructorFalseTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("string"); - Type fieldType = field.getGenericType(); - assertFalse(ReflectionUtils.hasNoArgsContrustor((Class) fieldType)); - } - - @Test - public void isCollectionTest() throws NoSuchFieldException, SecurityException { - Field field = ReflectionUtilsTest.class.getDeclaredField("stringList"); - Type fieldType = ((ParameterizedType) field.getGenericType()).getRawType(); - Class clazz = ((Class) fieldType); - assertTrue(ReflectionUtils.isCollection(clazz)); - } - - @Test - public void getFieldValueTest() throws NoSuchFieldException, SecurityException, IllegalAccessException { - string = "test"; - Field field = ReflectionUtilsTest.class.getDeclaredField("string"); - String value = (String) ReflectionUtils.getFieldValue(field, this); - assertEquals("test", value); - } - -}