protected <T extends Comparable<? super T>> void checkBoundsValidity(T start, T end, boolean inclusiveStart, boolean inclusiveEnd) { // don't use isLessThanOrEqualTo or isGreaterThanOrEqualTo to avoid equal comparison which makes BigDecimal // to fail when start = end with different precision, ex: [10.0, 10.00]. boolean inclusiveBoundsCheck = inclusiveEnd && inclusiveStart && !isGreaterThan(start, end); boolean strictBoundsCheck = !inclusiveEnd && !inclusiveStart && isLessThan(start, end); String operator = inclusiveEnd && inclusiveStart ? "less than" : "less than or equal to"; String boundsCheckErrorMessage = format("The end value <%s> must not be %s the start value <%s>%s!", end, operator, start, (comparisonStrategy.isStandard() ? "" : " (using " + comparisonStrategy + ")")); checkArgument(inclusiveBoundsCheck || strictBoundsCheck, boundsCheckErrorMessage); } }
protected <T extends Comparable<? super T>> void checkBoundsValidity(T start, T end, boolean inclusiveStart, boolean inclusiveEnd) { // don't use isLessThanOrEqualTo or isGreaterThanOrEqualTo to avoid equal comparison which makes BigDecimal // to fail when start = end with different precision, ex: [10.0, 10.00]. boolean inclusiveBoundsCheck = inclusiveEnd && inclusiveStart && !isGreaterThan(start, end); boolean strictBoundsCheck = !inclusiveEnd && !inclusiveStart && isLessThan(start, end); String operator = inclusiveEnd && inclusiveStart ? "less than" : "less than or equal to"; String boundsCheckErrorMessage = format("The end value <%s> must not be %s the start value <%s>%s!", end, operator, start, (comparisonStrategy.isStandard() ? "" : " (using " + comparisonStrategy + ")")); checkArgument(inclusiveBoundsCheck || strictBoundsCheck, boundsCheckErrorMessage); } }
/** * Builds and returns an error message from the given description using {@link #expected} and {@link #actual} basic * representation if their description differ otherwise use * {@link #defaultDetailedErrorMessage(Description, Representation)} to represent them differently. * * @param description the {@link Description} used to build the returned error message * @param representation the {@link org.assertj.core.presentation.Representation} used to build String representation * of object * @return the error message from description using {@link #expected} and {@link #actual} "smart" representation. */ private String smartErrorMessage(Description description, Representation representation) { if (actualAndExpectedHaveSameStringRepresentation()) { // This happens for example when actual = 42f and expected = 42d, which will give this error: // actual : "42" and expected : "42". // JUnit 4 manages this case even worst, it will output something like : // "java.lang.String expected:java.lang.String<42.0> but was: java.lang.String<42.0>" // which makes things even more confusing since we lost the fact that 42 was a float or a double. // It is therefore better to built our own description without using ComparisonFailure, the // only drawback is that it won't look nice in IDEs. return defaultDetailedErrorMessage(description, representation); } return comparisonStrategy.isStandard() ? messageFormatter.format(description, representation, EXPECTED_BUT_WAS_MESSAGE, actual, expected) : messageFormatter.format(description, representation, EXPECTED_BUT_WAS_MESSAGE_USING_COMPARATOR, actual, expected, comparisonStrategy); }
/** * Builds and returns an error message from the given description using {@link #expected} and {@link #actual} basic * representation if their description differ otherwise use * {@link #defaultDetailedErrorMessage(Description, Representation)} to represent them differently. * * @param description the {@link Description} used to build the returned error message * @param representation the {@link org.assertj.core.presentation.Representation} used to build String representation * of object * @return the error message from description using {@link #expected} and {@link #actual} "smart" representation. */ private String smartErrorMessage(Description description, Representation representation) { if (actualAndExpectedHaveSameStringRepresentation()) { // This happens for example when actual = 42f and expected = 42d, which will give this error: // actual : "42" and expected : "42". // JUnit 4 manages this case even worst, it will output something like : // "java.lang.String expected:java.lang.String<42.0> but was: java.lang.String<42.0>" // which makes things even more confusing since we lost the fact that 42 was a float or a double. // It is therefore better to built our own description without using ComparisonFailure, the // only drawback is that it won't look nice in IDEs. return defaultDetailedErrorMessage(description, representation); } return comparisonStrategy.isStandard() ? messageFormatter.format(description, representation, EXPECTED_BUT_WAS_MESSAGE, actual, expected) : messageFormatter.format(description, representation, EXPECTED_BUT_WAS_MESSAGE_USING_COMPARATOR, actual, expected, comparisonStrategy); }
if (comparisonStrategy.isStandard() && !actualAndExpectedHaveSameStringRepresentation()) {
if (comparisonStrategy.isStandard() && !actualAndExpectedHaveSameStringRepresentation()) {
/** * Builds and returns an error message from description using {@link #expected} and {@link #actual} basic * representation. * * @param description the {@link Description} used to build the returned error message * @param representation the {@link org.assertj.core.presentation.Representation} used to build String representation * of object * @return the error message from description using {@link #expected} and {@link #actual} basic representation. */ private String defaultErrorMessage(Description description, Representation representation) { return comparisonStrategy.isStandard() ? messageFormatter.format(description, representation, EXPECTED_BUT_WAS_MESSAGE, actual, expected) : messageFormatter.format(description, representation, EXPECTED_BUT_WAS_MESSAGE_USING_COMPARATOR, actual, expected, comparisonStrategy); }
if (comparisonStrategy.isStandard()) {