diff options
Diffstat (limited to 'src/main/java/au/id/zancanaro/javacheck/junit')
-rw-r--r-- | src/main/java/au/id/zancanaro/javacheck/junit/Properties.java | 24 | ||||
-rw-r--r-- | src/main/java/au/id/zancanaro/javacheck/junit/PropertyError.java | 25 |
2 files changed, 21 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 0507413..64bd9ab 100644 --- a/src/main/java/au/id/zancanaro/javacheck/junit/Properties.java +++ b/src/main/java/au/id/zancanaro/javacheck/junit/Properties.java @@ -16,12 +16,11 @@ import org.junit.runners.model.TestClass; import java.lang.reflect.*; import java.util.*; - public class Properties extends BlockJUnit4ClassRunner { private final Map<Type, Generator<?>> generators = new HashMap<>(); - public Properties(Class<?> klass) throws InitializationError { - super(klass); + public Properties(Class<?> classObject) throws InitializationError { + super(classObject); } @Override @@ -43,11 +42,11 @@ public class Properties extends BlockJUnit4ClassRunner { if (!(type instanceof ParameterizedType)) { continue; } - ParameterizedType ptype = (ParameterizedType) type; - if (!(ptype.getRawType() instanceof Class)) { + ParameterizedType parameterizedType = (ParameterizedType) type; + if (!(parameterizedType.getRawType() instanceof Class)) { continue; } - Class<?> c = (Class) ptype.getRawType(); + Class<?> c = (Class) parameterizedType.getRawType(); if (c != Generator.class) { continue; } @@ -61,7 +60,7 @@ public class Properties extends BlockJUnit4ClassRunner { error = true; } if (!error) { - result.add(ptype.getActualTypeArguments()[0]); + result.add(parameterizedType.getActualTypeArguments()[0]); } } return result; @@ -105,16 +104,16 @@ public class Properties extends BlockJUnit4ClassRunner { if (!(type instanceof ParameterizedType)) { continue; } - ParameterizedType ptype = (ParameterizedType) type; - if (!(ptype.getRawType() instanceof Class)) { + ParameterizedType parameterizedType = (ParameterizedType) type; + if (!(parameterizedType.getRawType() instanceof Class)) { continue; } - Class<?> c = (Class) ptype.getRawType(); + Class<?> c = (Class) parameterizedType.getRawType(); if (c != Generator.class) { continue; } try { - Type target = ptype.getActualTypeArguments()[0]; + Type target = parameterizedType.getActualTypeArguments()[0]; @SuppressWarnings("unchecked") Generator<Object> generator = (Generator<Object>) field.get(null); generators.put(target, generator); @@ -122,7 +121,7 @@ public class Properties extends BlockJUnit4ClassRunner { generators.put(rawTypes.get(target), generator); } } catch (IllegalAccessException ex) { - + throw new RuntimeException(ex); } } } @@ -213,7 +212,6 @@ public class Properties extends BlockJUnit4ClassRunner { if (assumptionsViolated++ == 50) { throw new Error("Violated 50 assumptions in a row: failing test"); } - ; } catch (Throwable ex) { // tree.print(new OutputStreamWriter(System.out), Arrays::toString); throw new PropertyError(method.getName(), seed, shrink(tree, ex)); 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 138c47f..2cd1325 100644 --- a/src/main/java/au/id/zancanaro/javacheck/junit/PropertyError.java +++ b/src/main/java/au/id/zancanaro/javacheck/junit/PropertyError.java @@ -3,35 +3,30 @@ package au.id.zancanaro.javacheck.junit; import au.id.zancanaro.javacheck.ShrinkResult; import java.util.Arrays; -import java.util.Collection; import java.util.Iterator; public class PropertyError extends AssertionError { public PropertyError(String methodName, long seed, ShrinkResult shrunk) { super(shrunk.thrown.getMessage() == null ? - String.format("%s(%s)\n\tSeed: %s", - methodName, join(", ", shrunk.args), + String.format("%s(%s)%n\tSeed: %s", + methodName, joinArgs(shrunk.args), seed): - String.format("%s(%s)\n\tSeed: %s\n%s", - methodName, join(", ", shrunk.args), + String.format("%s(%s)%n\tSeed: %s%n%s", + methodName, joinArgs(shrunk.args), seed, shrunk.thrown.getMessage())); initCause(shrunk.thrown); } - public static String join(String delimiter, Object... params) { - return join(delimiter, Arrays.asList(params)); - } - - public static String join(String delimiter, Collection<Object> values) { + public static String joinArgs(Object... params) { StringBuilder sb = new StringBuilder(); - Iterator<Object> iter = values.iterator(); - while (iter.hasNext()) { - Object next = iter.next(); + Iterator<Object> iterator = Arrays.asList(params).iterator(); + while (iterator.hasNext()) { + Object next = iterator.next(); sb.append(stringValueOf(next)); - if (iter.hasNext()) { - sb.append(delimiter); + if (iterator.hasNext()) { + sb.append(", "); } } return sb.toString(); |