Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display Improve readability of containsExactly when the order of elements does not match #2629

Closed
vlsi opened this issue May 27, 2022 · 4 comments
Assignees
Labels
status: ideal for contribution An issue that a contributor can help us with
Milestone

Comments

@vlsi
Copy link
Contributor

vlsi commented May 27, 2022

Feature summary

assertThat(Arrays.asList(1, 2, 3, 4)).containsExactly(1, 3, 2, 4);

yields the following error message:

java.lang.AssertionError: 
Actual and expected have the same elements but not in the same order, at index 1 actual element was:
  2
whereas expected element was:
  3

Note that 1 and 4 are not displayed in the error message.

I suggest that AssertJ should print the full expected and actual set of elements in case the order does not match.

For instance, when the value does not match, then AssertJ does print all the elements:

assertThat(Arrays.asList(1, 2, 3, 4)).containsExactly(1, 2, 4, 4);
java.lang.AssertionError: 
Expecting actual:
  [1, 2, 3, 4]
to contain exactly (and in same order):
  [1, 2, 4, 4]
but some elements were not found:
  [4]
and others were not expected:
  [3]

Example

The following methods seems to be affected:

org.assertj.core.api.AbstractIterableAssert#containsExactly(ELEMENT... values)
org.assertj.core.api.AbstractIterableAssert#containsExactlyElementsOf(Iterable<? extends ELEMENT> iterable)
@joel-costigliola
Copy link
Member

Fair enough @vlsi.

@joel-costigliola joel-costigliola added this to the 3.24.0 milestone May 28, 2022
@joel-costigliola joel-costigliola added the status: ideal for contribution An issue that a contributor can help us with label May 28, 2022
@Giovds
Copy link
Contributor

Giovds commented Jun 1, 2022

I would like to give this one a go!

@joel-costigliola
Copy link
Member

Thanks @Giovds, assigned to you :)

@joel-costigliola
Copy link
Member

Fixed in 41179e5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ideal for contribution An issue that a contributor can help us with
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants