protected String describeFieldComparatorsByName() { if (comparatorsByPropertyOrField.isEmpty()) { return ""; } List<String> fieldComparatorsDescription = this.comparatorsByPropertyOrField.entrySet().stream() .map(FieldByFieldComparator::formatFieldComparator) .collect(toList()); return format("- for elements fields (by name): {%s}", join(fieldComparatorsDescription).with(", ")); }
private static UncheckedIOException cannotCreateNewFile(String path, String reason, Exception cause) { String message = String.format("Unable to create the new file %s", quote(path)); if (!Strings.isNullOrEmpty(reason)) { message = concat(message, ": ", reason); } if (cause == null) { throw new RuntimeException(message); } if (cause instanceof IOException) { throw new UncheckedIOException(message, (IOException) cause); } throw new RuntimeException(message, cause); }
/** * Returns the path of the system's temporary directory. This method appends the system's file separator at the end of * the path. * * @return the path of the system's temporary directory. */ public static String temporaryFolderPath() { return append(separator).to(System.getProperty("java.io.tmpdir")); }
/** * Formats the given <code>{@link Description}</code> by surrounding its text value with square brackets and adding a space at * the end. * @param d the description to format. It can be {@code null}. * @return the formatted description, or an empty {@code String} if the {@code Description} is {@code null}. */ public String format(Description d) { String s = (d != null) ? d.value() : null; if (isNullOrEmpty(s)) return ""; return String.format("[%s] ", s); }
/** * Returns the given object surrounded by single quotes, only if the object is a {@code String}. * * @param o the given object. * @return the given object surrounded by single quotes, only if the object is a {@code String}. * @see #quote(String) */ public static Object quote(Object o) { return o instanceof String ? quote(o.toString()) : o; }
/** * Returns the given {@code String} surrounded by single quotes, or {@code null} if the given {@code String} is * {@code null}. * * @param s the given {@code String}. * @return the given {@code String} surrounded by single quotes, or {@code null} if the given {@code String} is * {@code null}. */ public static String quote(String s) { return s != null ? concat("'", s, "'") : null; }
private static String describeDifference(Difference difference, Representation representation) { String actualFieldValue = representation.toStringOf(difference.getActual()); String otherFieldValue = representation.toStringOf(difference.getOther()); boolean sameRepresentation = Objects.areEqual(actualFieldValue, otherFieldValue); String actualFieldValueRepresentation = sameRepresentation ? representation.unambiguousToStringOf(difference.getActual()) : actualFieldValue; String otherFieldValueRepresentation = sameRepresentation ? representation.unambiguousToStringOf(difference.getOther()) : otherFieldValue; String additionalInfo = difference.getDescription() .map(desc -> format("%n- reason : %s", escapePercent(desc))) .orElse(""); return format("%nPath to difference: <%s>%n" + "- actual : <%s>%n" + "- expected: <%s>" + additionalInfo, join(difference.getPath()).with("."), escapePercent(actualFieldValueRepresentation), escapePercent(otherFieldValueRepresentation)); }
@Override public String value() { return formatIfArgs(value, args); }
/** * Returns whether the text of this object's description was set. * * @return whether the text of this object's description was set. */ public boolean hasDescription() { return description != null && !isNullOrEmpty(description.value()); }
/** * Returns the given object surrounded by single quotes, only if the object is a {@code String}. * * @param o the given object. * @return the given object surrounded by single quotes, only if the object is a {@code String}. * @see #quote(String) */ public static Object quote(Object o) { return o instanceof String ? quote(o.toString()) : o; }
protected String toStringOf(String s) { return concat("\"", s, "\""); }
private static String describeDifference(Difference difference, Representation representation) { String actualFieldValue = representation.toStringOf(difference.getActual()); String otherFieldValue = representation.toStringOf(difference.getOther()); boolean sameRepresentation = Objects.areEqual(actualFieldValue, otherFieldValue); String actualFieldValueRepresentation = sameRepresentation ? representation.unambiguousToStringOf(difference.getActual()) : actualFieldValue; String otherFieldValueRepresentation = sameRepresentation ? representation.unambiguousToStringOf(difference.getOther()) : otherFieldValue; String additionalInfo = difference.getDescription() .map(desc -> format("%n- reason : %s", escapePercent(desc))) .orElse(""); return format("%nPath to difference: <%s>%n" + "- actual : <%s>%n" + "- expected: <%s>" + additionalInfo, join(difference.getPath()).with("."), escapePercent(actualFieldValueRepresentation), escapePercent(otherFieldValueRepresentation)); }
@Override public String value() { return formatIfArgs(value, args); }
public String getConcatenatedPath() { return join(path).with("."); } }
private static UncheckedIOException cannotCreateNewFile(String path, String reason, Exception cause) { String message = String.format("Unable to create the new file %s", quote(path)); if (!Strings.isNullOrEmpty(reason)) { message = concat(message, ": ", reason); } if (cause == null) { throw new RuntimeException(message); } if (cause instanceof IOException) { throw new UncheckedIOException(message, (IOException) cause); } throw new RuntimeException(message, cause); }
private void validatePropertyOrFieldName(String propertyOrFieldName) { checkArgument(!Strings.isNullOrEmpty(propertyOrFieldName), "The property/field name to filter on should not be null or empty"); }
protected String toStringOf(Comparator<?> comparator) { if (!comparator.toString().contains("@")) return comparator.toString(); String comparatorSimpleClassName = comparator.getClass().getSimpleName(); if (comparatorSimpleClassName.length() == 0) return quote("anonymous comparator class"); // if toString has not been redefined, let's use comparator simple class name. if (comparator.toString().contains(comparatorSimpleClassName + "@")) return comparatorSimpleClassName; return comparator.toString(); }
protected String toStringOf(Character c) { return concat("'", c, "'"); }
/** * Overrides AssertJ default error message by the given one. * <p> * You must set it <b>before</b> calling the assertion otherwise it is ignored as the failing assertion breaks * the chained call by throwing an AssertionError. * <p> * The new error message is built using {@link String#format(String, Object...)} if you provide args parameter (if you * don't, the error message is taken as it is). * <p> * Example : * <pre><code class='java'>assertThat(player.isRookie()).overridingErrorMessage("Expecting Player <%s> to be a rookie but was not.", player) * .isTrue();</code></pre> * * @param newErrorMessage the error message that will replace the default one provided by Assertj. * @param args the args used to fill error message as in {@link String#format(String, Object...)}. * @return this assertion object. */ @CheckReturnValue public SELF overridingErrorMessage(String newErrorMessage, Object... args) { info.overridingErrorMessage(formatIfArgs(newErrorMessage, args)); return myself; }
/** * Returns the path of the system's temporary directory. This method appends the system's file separator at the end of * the path. * * @return the path of the system's temporary directory. */ public static String temporaryFolderPath() { return append(separator).to(System.getProperty("java.io.tmpdir")); }