package au.id.zancanaro; 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), seed): 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]"; } } } }