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

Feature: Check that specific object present in List #2902

Merged
merged 1 commit into from
Apr 28, 2023

Conversation

dbudim
Copy link
Contributor

@dbudim dbudim commented Apr 27, 2023

Feature: Check that specific object present in List

Motivation
It's a common use case to check if some object present in list. There are objects with overridden and not overridden equals() & hashCode().

So is very repeating operation to write code as:
Assert.assertTrue(list.stream().anyMatch(user -> user.name.equals(userName)), "list not contains user");
Assert.assertTrue(list.contains(user), "list not contains user");

I propose to add methods to simplify this action and convenient use:
Assert.assertListContains(users, user -> user.name.equals(userName), "user " + userName);
Assert.assertListContainsObject(users, user, "user " + user.name);

assertListContains uses a Predicate
assertListContainsObject uses contains() method of List

Did you remember to?

  • Add test case(s)
  • Update CHANGES.txt
  • Auto applied styling via ./gradlew autostyleApply

@dbudim dbudim changed the title Add list contains asserions Feature: Check that specific object present in List Apr 27, 2023
@dbudim dbudim force-pushed the add_list_contains_asserions branch from 2a163e2 to ab8673d Compare April 27, 2023 13:45
@dbudim dbudim marked this pull request as ready for review April 27, 2023 13:46
@dbudim dbudim force-pushed the add_list_contains_asserions branch 2 times, most recently from 68fe543 to c12d8e1 Compare April 27, 2023 14:21
@dbudim dbudim force-pushed the add_list_contains_asserions branch from 0851d39 to 4c61314 Compare April 27, 2023 16:18
Copy link
Member

@juherr juherr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not but we recommend to use assertj

@dbudim
Copy link
Contributor Author

dbudim commented Apr 28, 2023

Why not but we recommend to use assertj

You right, but nice to have a built in feature, because not always possible to add a new library)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants