Assertj-core: AbstractAssert method for asserting with expected/actual

Created on 11 Apr 2020  路  4Comments  路  Source: assertj/assertj-core

Summary

I think that #1731 was great for a certain class of custom assertions. However, i think it would also be a useful addition to AbstractAssert if it had a variant of the failWithMessage() method that you could call directly that would populate expected and actual in the generated AssertionError (where available).

Example

failWithExpectedActual(expected,  actual, "My message %d", myArg);

Most helpful comment

I'm ok with the idea, I would actual first and expected after it. failWithActualAndExpected.
I would prefer not to recommend using directly internal APIs.

All 4 comments

Would it help to use the following?

throw org.assertj.core.internal.Failures.instance().failure(info, shouldBeEqual(actual, expected, info.representation()));

As Failures belongs to internal APIs, using it in custom assertions is probably not so nice.

I'm ok with the idea, I would actual first and expected after it. failWithActualAndExpected.
I would prefer not to recommend using directly internal APIs.

Would it help to use the following?

throw org.assertj.core.internal.Failures.instance().failure(info, shouldBeEqual(actual, expected, info.representation()));

As Failures belongs to internal APIs, using it in custom assertions is probably not so nice.

Thanks @scordio, I tend to agree about it not being nice - but even more than that, if you're using an OSGi environment as I am, you don't account actually have access to the internal packages.

This was implemented by #1833.

Was this page helpful?
0 / 5 - 0 ratings