radistao
radistao

Reputation: 15504

AssertJ multidimensional arrays assertion (deep equals)

Is there any option in AssertJ to make deep assertion of 2-d (N-d) arrays? Pretty much the same as java.util.Arrays#deepEquals() does but with assertion exception and prettified fail message like "element arr1[i][j] expected to be X, but was Y"

Here i found only 1d arrays assertions:

https://github.com/joel-costigliola/assertj-examples/blob/master/assertions-examples/src/test/java/org/assertj/examples/ArrayAssertionsExamples.java

Upvotes: 0

Views: 1174

Answers (3)

Kirill
Kirill

Reputation: 8056

There is a isDeepEqualTo() method available since 3.17.0. Check out Array2DAssertionsExamples

Upvotes: 2

Joel Costigliola
Joel Costigliola

Reputation: 7066

Unfortunately, there is no such feature in AssertJ but contributions are welcome. I voted for Kevin Welker suggestion.

Upvotes: 1

Kevin Welker
Kevin Welker

Reputation: 7937

I don't see one, but you could write your own with: AbstractAssert, or using a Comparator and the usingComparator method

Upvotes: 1

Related Questions