package au.id.zancanaro.javacheck.junit; import au.id.zancanaro.javacheck.ShrinkResult; import java.util.Iterator; import java.util.List; @SuppressWarnings("WeakerAccess") public class PropertyError extends AssertionError { private static final long serialVersionUID = 1L; public PropertyError(String methodName, long seed, ShrinkResult shrunk) { super(shrunk.thrown.getMessage() == null ? String.format("%s(%s)%n\tSeed: %s%n\tVisited: %s; Depth: %s", methodName, joinArgs(shrunk.args), seed, shrunk.visited, shrunk.depth): String.format("%s(%s)%n\tSeed: %s%n\tVisited: %s; Depth: %s%n%s", methodName, joinArgs(shrunk.args), seed, shrunk.visited, shrunk.depth, shrunk.thrown.getMessage())); initCause(shrunk.thrown); } private static String joinArgs(List params) { StringBuilder sb = new StringBuilder(); Iterator iterator = params.iterator(); while (iterator.hasNext()) { Object next = iterator.next(); sb.append(stringValueOf(next)); if (iterator.hasNext()) { sb.append(", "); } } 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]"; } } } }