summaryrefslogtreecommitdiff
path: root/src/main/java/au/id/zancanaro/javacheck/junit
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/au/id/zancanaro/javacheck/junit')
-rw-r--r--src/main/java/au/id/zancanaro/javacheck/junit/Properties.java57
-rw-r--r--src/main/java/au/id/zancanaro/javacheck/junit/PropertyError.java4
2 files changed, 33 insertions, 28 deletions
diff --git a/src/main/java/au/id/zancanaro/javacheck/junit/Properties.java b/src/main/java/au/id/zancanaro/javacheck/junit/Properties.java
index 6ff0538..1e3f502 100644
--- a/src/main/java/au/id/zancanaro/javacheck/junit/Properties.java
+++ b/src/main/java/au/id/zancanaro/javacheck/junit/Properties.java
@@ -16,6 +16,7 @@ import org.junit.runners.model.TestClass;
import java.lang.reflect.*;
import java.util.*;
+@SuppressWarnings("WeakerAccess")
public class Properties extends BlockJUnit4ClassRunner {
private final Map<Type, Generator<?>> generators = new HashMap<>();
@@ -35,32 +36,36 @@ public class Properties extends BlockJUnit4ClassRunner {
Field[] fields = getTestClass().getJavaClass().getDeclaredFields();
for (Field field : fields) {
- if (!field.isAnnotationPresent(DataSource.class)) {
- continue;
- }
- Type type = field.getGenericType();
- if (!(type instanceof ParameterizedType)) {
- continue;
- }
- ParameterizedType parameterizedType = (ParameterizedType) type;
- if (!(parameterizedType.getRawType() instanceof Class)) {
- continue;
- }
- Class<?> c = (Class) parameterizedType.getRawType();
- if (c != Generator.class) {
- continue;
- }
- boolean error = false;
- if (!Modifier.isStatic(field.getModifiers())) {
- errors.add(new Error("Generator field " + field.getName() + " must be static"));
- error = true;
- }
- if (!Modifier.isPublic(field.getModifiers())) {
- errors.add(new Error("Generator field " + field.getName() + " must be public"));
- error = true;
- }
- if (!error) {
- result.add(parameterizedType.getActualTypeArguments()[0]);
+ 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;
diff --git a/src/main/java/au/id/zancanaro/javacheck/junit/PropertyError.java b/src/main/java/au/id/zancanaro/javacheck/junit/PropertyError.java
index 2cd1325..44c071b 100644
--- a/src/main/java/au/id/zancanaro/javacheck/junit/PropertyError.java
+++ b/src/main/java/au/id/zancanaro/javacheck/junit/PropertyError.java
@@ -5,6 +5,7 @@ import au.id.zancanaro.javacheck.ShrinkResult;
import java.util.Arrays;
import java.util.Iterator;
+@SuppressWarnings("WeakerAccess")
public class PropertyError extends AssertionError {
public PropertyError(String methodName, long seed, ShrinkResult shrunk) {
super(shrunk.thrown.getMessage() == null ?
@@ -18,8 +19,7 @@ public class PropertyError extends AssertionError {
initCause(shrunk.thrown);
}
-
- public static String joinArgs(Object... params) {
+ private static String joinArgs(Object... params) {
StringBuilder sb = new StringBuilder();
Iterator<Object> iterator = Arrays.asList(params).iterator();
while (iterator.hasNext()) {