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

Add values() navigation method to AbstractMapAssert #3291

Open
xenoterracide opened this issue Dec 8, 2023 · 3 comments · May be fixed by #3297
Open

Add values() navigation method to AbstractMapAssert #3291

xenoterracide opened this issue Dec 8, 2023 · 3 comments · May be fixed by #3297
Labels
status: ideal for contribution An issue that a contributor can help us with type: new feature A new feature

Comments

@xenoterracide
Copy link

xenoterracide commented Dec 8, 2023

Feature summary

Improve matching only MapAssert Value Properties.

Example

I feel like this could be one statement

assertThat(cpCard.getAltIds())
  .as("AlternateId saved on card")
  .hasSize(1); // avoids getAltIds() possible NPE... 

assertThat(cpCard.getAltIds().values())
  .as("AlternateId saved on Card")
  .first()
  .returns(LoyaltyCardsValueAltIdsValue.StatusEnum.ACTIVE, LoyaltyCardsValueAltIdsValue::getStatus);

It feels like I should be able to do something like. I tried a number of extracting but it all ended up more convoluted than 2 statements, or required a weaker static typing

assertThat(cpCard.getAltIds())
  .hasSize(1)
  .values()
  .first()
  .returns(...);
@scordio
Copy link
Member

scordio commented Dec 8, 2023

I slightly modified the formatting of your code snippets to better visualize each method call.

If I understand it correctly, the second snippet contains what you'd like to have.

With values, the following could be written:

assertThat(cpCard.getAltIds())
  .values() // returns AbstractCollectionAssert after calling Map::values
  .singleElement()
  .returns(...);

Would that satisfy your use case?

@xenoterracide
Copy link
Author

xenoterracide commented Dec 8, 2023

in this particular case sure. I just grabbed first() from the existing chain. I'm not certain though that there isn't another case that wouldn't need more. I guess it made sense to me that after grabbing values I'd be in the same context/matcher as the thing that works and so the API would be the same.

Basically, I'm fine with whatever API that makes this simple ;) .

@scordio
Copy link
Member

scordio commented Dec 8, 2023

Ok, so let's add values as a start and see if any other concrete use cases arise.

@scordio scordio changed the title MapAssert allow for values Add values() navigation method to AbstractMapAssert Dec 8, 2023
@scordio scordio added status: ideal for contribution An issue that a contributor can help us with type: new feature A new feature labels Dec 8, 2023
Kruschenstein added a commit to Kruschenstein/assertj that referenced this issue Dec 14, 2023
Kruschenstein added a commit to Kruschenstein/assertj that referenced this issue Dec 14, 2023
Kruschenstein added a commit to Kruschenstein/assertj that referenced this issue Dec 14, 2023
Kruschenstein added a commit to Kruschenstein/assertj that referenced this issue Dec 24, 2023
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 type: new feature A new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants