How to use defaultDetailedErrorMessage method of org.assertj.core.error.ShouldBeEqual class

Best Assertj code snippet using org.assertj.core.error.ShouldBeEqual.defaultDetailedErrorMessage

Source:ShouldBeEqual.java Github

copy

Full Screen

...128 }129 /**130 * Builds and returns an error message from the given description using {@link #expected} and {@link #actual} basic131 * representation if their description differ otherwise use132 * {@link #defaultDetailedErrorMessage(Description, Representation)} to represent them differently.133 *134 * @param description the {@link Description} used to build the returned error message135 * @param representation the {@link org.assertj.core.presentation.Representation} used to build String representation136 * of object137 * @return the error message from description using {@link #expected} and {@link #actual} "smart" representation.138 */139 protected String smartErrorMessage(Description description, Representation representation) {140 if (actualAndExpectedHaveSameStringRepresentation()) {141 // This happens for example when actual = 42f and expected = 42d, which will give this error:142 // actual : "42" and expected : "42".143 // JUnit 4 manages this case even worst, it will output something like :144 // "java.lang.String expected:java.lang.String<42.0> but was: java.lang.String<42.0>"145 // which makes things even more confusing since we lost the fact that 42 was a float or a double.146 // It is therefore better to built our own description without using ComparisonFailure, the147 // only drawback is that it won't look nice in IDEs.148 return defaultDetailedErrorMessage(description, representation);149 }150 return comparisonStrategy.isStandard()151 ? messageFormatter.format(description, representation, EXPECTED_BUT_WAS_MESSAGE, actual, expected)152 : messageFormatter.format(description, representation, EXPECTED_BUT_WAS_MESSAGE_USING_COMPARATOR,153 actual, expected, comparisonStrategy);154 }155 /**156 * Builds and returns an error message from description using {@link #detailedExpected()} and157 * {@link #detailedActual()} detailed representation.158 *159 * @param description the {@link Description} used to build the returned error message160 * @param representation the {@link org.assertj.core.presentation.Representation} used to build String representation161 * of object162 * @return the error message from description using {@link #detailedExpected()} and {@link #detailedActual()}163 * <b>detailed</b> representation.164 */165 protected String defaultDetailedErrorMessage(Description description, Representation representation) {166 if (comparisonStrategy instanceof ComparatorBasedComparisonStrategy)167 return messageFormatter.format(description, representation, EXPECTED_BUT_WAS_MESSAGE_USING_COMPARATOR,168 detailedActual(), detailedExpected(), comparisonStrategy);169 return messageFormatter.format(description, representation, EXPECTED_BUT_WAS_MESSAGE, detailedActual(),170 detailedExpected());171 }172 private AssertionError assertionFailedError(String message, Representation representation) {173 try {174 Object o = constructorInvoker.newInstance("org.opentest4j.AssertionFailedError",175 MSG_ARG_TYPES_FOR_ASSERTION_FAILED_ERROR,176 message,177 representation.toStringOf(expected),178 representation.toStringOf(actual));179 if (o instanceof AssertionError) {...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful