From 199037f9c80afd885f1f536d91b40a8397cd6bf2 Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Sun, 31 May 2015 16:48:45 +1000 Subject: 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) --- .../java/au/id/zancanaro/PropertyTestError.java | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/main/java/au/id/zancanaro/PropertyTestError.java (limited to 'src/main/java/au/id/zancanaro/PropertyTestError.java') 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 values) { + StringBuilder sb = new StringBuilder(); + Iterator 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]"; + } + } + } +} -- cgit v1.2.3