diff options
author | Carlo Zancanaro <carlo@zancanaro.id.au> | 2015-06-09 23:31:54 +1000 |
---|---|---|
committer | Carlo Zancanaro <carlo@zancanaro.id.au> | 2015-06-09 23:31:54 +1000 |
commit | 40961d4950c40643d5d71721a7e024e3951323ce (patch) | |
tree | 330af94a98468ab0c10cff76c2bb36eb28a64ef0 /src/main/java/au/id/zancanaro/javacheck/DataSourceHelper.java | |
parent | dd9f72b94eb7b2c37061c80457e74e8d7ac3e18f (diff) |
Generalise the ObjectGeneration stuff
The new ObjectGeneration stuff is now used to generate everything for a test
case, which means it's all unified and "nice" now.
Add a @UseGenerator annotation to be used to specify how to generate specific
field values.
Obviously, not everything can be generated magically, so if you specify a
@DataSource in your test then it will be used in preference to any magically
generated value.
Diffstat (limited to 'src/main/java/au/id/zancanaro/javacheck/DataSourceHelper.java')
-rw-r--r-- | src/main/java/au/id/zancanaro/javacheck/DataSourceHelper.java | 46 |
1 files changed, 3 insertions, 43 deletions
diff --git a/src/main/java/au/id/zancanaro/javacheck/DataSourceHelper.java b/src/main/java/au/id/zancanaro/javacheck/DataSourceHelper.java index 522fd26..f118649 100644 --- a/src/main/java/au/id/zancanaro/javacheck/DataSourceHelper.java +++ b/src/main/java/au/id/zancanaro/javacheck/DataSourceHelper.java @@ -3,10 +3,11 @@ package au.id.zancanaro.javacheck; import au.id.zancanaro.javacheck.annotations.DataSource; import java.lang.reflect.Field; -import java.lang.reflect.Modifier; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; -import java.util.*; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; public class DataSourceHelper { private final Class<?> classObject; @@ -17,47 +18,6 @@ public class DataSourceHelper { this.generators = new HashMap<>(); } - public static Set<Type> validateGeneratorFields(Class<?> classObject, List<Throwable> errors) { - Set<Type> result = new HashSet<>(); - - for (Field field : classObject.getDeclaredFields()) { - if (field.isAnnotationPresent(DataSource.class)) { - boolean error = false; - if (!Modifier.isStatic(field.getModifiers())) { - errors.add(new Error("@DataSource field " + field.getName() + " must be static")); - error = true; - } - if (!Modifier.isPublic(field.getModifiers())) { - errors.add(new Error("@DataSource field " + field.getName() + " must be public")); - error = true; - } - - Type type = field.getGenericType(); - ParameterizedType parameterizedType; - if (type instanceof ParameterizedType) { - parameterizedType = (ParameterizedType) type; - if (parameterizedType.getRawType() instanceof Class) { - Class<?> c = (Class) parameterizedType.getRawType(); - if (c == Generator.class) { - if (!error) { - result.add(parameterizedType.getActualTypeArguments()[0]); - } - } else { - errors.add(new Error("@DataSource fields must be of type Generator<T>")); - } - } else { - errors.add(new Error("@DataSource fields must be of type Generator<T>")); - } - } else { - errors.add(new Error("@DataSource fields must be of type Generator<T>")); - } - } - } - - return result; - } - - private static final Map<Type, Type> rawTypes; static { |