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

usingRecursiveComparison().ignoringFields("fieldName") is not working properly when maps sizes are different #2988

Open
Anass-ELGHAOUI opened this issue Mar 17, 2023 · 3 comments · May be fixed by #3003
Labels
theme: recursive comparison An issue related to the recursive comparison
Milestone

Comments

@Anass-ELGHAOUI
Copy link

Summary

usingRecursiveComparison().ignoringFields("fieldName") is not working properly when comparing two maps with different sizes.

Example

using the following code the ingested node will be the same size as the expected one after ignoring "ingestionDate". So I suppose that start comparing the size of the maps makes the method more limited such as in this case for example.

assertThat(ingestedNode).usingRecursiveComparison().ignoringFields("ingestionDate").isEqualTo(expectedNode);
@joel-costigliola
Copy link
Member

Thanks for reporting this @Anass-ELGHAOUI, could provide a test reproducing the issue to help us investigate? thanks!

@Anass-ELGHAOUI
Copy link
Author

@joel-costigliola yes sure.

@Test
  void test_assertj_ignoring_fields() {
    Map<String, Object> mapWithTwoElements =
        Map.ofEntries(entry("firstName", "John"), entry("lastName", "Doe"));
    Map<String, Object> mapWithThreeElements =
        Map.ofEntries(
            entry("firstName", "John"),
            entry("lastName", "Doe"),
            entry("profession", "software Engineer"));
    assertThat(mapWithThreeElements)
        .usingRecursiveComparison()
        .ignoringFields("profession")
        .isEqualTo(mapWithTwoElements);
  }

@scordio scordio added the theme: recursive comparison An issue related to the recursive comparison label Mar 17, 2023
OlivierCavadenti added a commit to OlivierCavadenti/assertj that referenced this issue Mar 25, 2023
Fix ignoringFields behavior that doesn't work properly when using
maps of different sizes with usingRecursiveComparison and isEqualTo for example.

Fix assertj#2988
@OlivierCavadenti OlivierCavadenti linked a pull request Mar 25, 2023 that will close this issue
@JitendraProgrammer
Copy link

Hi I want to join your community so that I can also help you guys

@joel-costigliola joel-costigliola added this to the 4.0.0 milestone Nov 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: recursive comparison An issue related to the recursive comparison
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants