Skip to content

Fix implementation of containsExactly #327

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

Closed
wants to merge 1 commit into from

Conversation

koenpunt
Copy link
Contributor

The implementation was the same for contains and containsExactly, but containsExactly should fail when the number items doesn't match the size of the expected items list.

@koenpunt koenpunt force-pushed the fix-containsExactly branch from c2a1290 to 8b246cc Compare March 14, 2022 12:09
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 14, 2022
@dugenkui03
Copy link
Contributor

dugenkui03 commented Mar 14, 2022

(a,b).containsExactly(a,a) will result in true in this pr.

org.assertj:assertj-core seems to be useful, but it is only allow in test.

@koenpunt
Copy link
Contributor Author

(a,b).containsExactly(a,a) will result in true in this pr.

Yes order isn't checked with this. But I don't think that's the purpose of this method.

If you want to assert the order, you can do so using isEqualTo;

In Kotlin (which looks a bit funky because generics can't be inferred):

.path("some[*].id")
  .entityList(String::class.java)
  .isEqualTo<GraphQlTester.ListEntitySpec<String>>(listOf("a", "b"))

Or in java:

.path("some[*].id")
  .entityList(String.class)
  .isEqualTo(Arrays.asList("a", "b"))

@rstoyanchev rstoyanchev added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 16, 2022
@rstoyanchev rstoyanchev self-assigned this Mar 16, 2022
@rstoyanchev rstoyanchev added this to the 1.0.0-M6 milestone Mar 16, 2022
@rstoyanchev
Copy link
Contributor

rstoyanchev commented Mar 16, 2022

The terminology is aligned with AssertJ and there containsExactly is "contains exactly the given values and nothing else, in order". It would make sense to align the behavior too and I think the Javadoc could also use some improvement.

@koenpunt koenpunt force-pushed the fix-containsExactly branch from 8b246cc to fd9768a Compare March 18, 2022 14:24
@koenpunt
Copy link
Contributor Author

I've updated it to use equals, which does just that:

Compares the specified object with this list for equality. Returns true if and only if the specified object is also a list, both lists have the same size, and all corresponding pairs of elements in the two lists are equal.

rstoyanchev pushed a commit that referenced this pull request Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants