diff options
| author | Carlo Zancanaro <carlo@zancanaro.id.au> | 2015-05-31 16:48:45 +1000 | 
|---|---|---|
| committer | Carlo Zancanaro <carlo@zancanaro.id.au> | 2015-05-31 16:48:45 +1000 | 
| commit | 199037f9c80afd885f1f536d91b40a8397cd6bf2 (patch) | |
| tree | 2153d808dde4d3b7d5473ba313642ee42d1190b5 /src/main/java/au/id/zancanaro/PropertyTestError.java | |
| parent | c25450f6288748782ad60cc7c4b8e0e0bdc52c1c (diff) | |
Improve lots of things
In particular:
 + make output more sane and less all over the place
 + just ignore original exception, the shrunk one is the only one which really
   matters
 + fit into the jUnit framework more (so now @Before, @After and stuff work)
Diffstat (limited to 'src/main/java/au/id/zancanaro/PropertyTestError.java')
| -rw-r--r-- | src/main/java/au/id/zancanaro/PropertyTestError.java | 45 | 
1 files changed, 45 insertions, 0 deletions
diff --git a/src/main/java/au/id/zancanaro/PropertyTestError.java b/src/main/java/au/id/zancanaro/PropertyTestError.java new file mode 100644 index 0000000..afd614b --- /dev/null +++ b/src/main/java/au/id/zancanaro/PropertyTestError.java @@ -0,0 +1,45 @@ +package au.id.zancanaro; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; + +public class PropertyTestError extends AssertionError { +    public PropertyTestError(String methodName, long seed, ShrinkResult shrunk) { +        super(String.format("%s(%s)\n\tSeed: %s\n%s", +                methodName, join(", ", 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) { +        StringBuilder sb = new StringBuilder(); +        Iterator<Object> iter = values.iterator(); +        while (iter.hasNext()) { +            Object next = iter.next(); +            sb.append(stringValueOf(next)); +            if (iter.hasNext()) { +                sb.append(delimiter); +            } +        } +        return sb.toString(); +    } + +    private static String stringValueOf(Object next) { +        if (next instanceof String) { +            return '"' + ((String) next).replace("\"", "\\\"") + '"'; +        } else { +            try { +                return String.valueOf(next); +            } catch (Throwable e) { +                return "[toString failed]"; +            } +        } +    } +}  | 
