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

Recursive comparison still compares ignored types in unordered collection #3287

Closed
ylecaillez opened this issue Dec 6, 2023 · 1 comment
Closed
Labels
theme: recursive comparison An issue related to the recursive comparison
Milestone

Comments

@ylecaillez
Copy link

ylecaillez commented Dec 6, 2023

Recursive comparison is still performing recursive comparison on types which have been configured as ignored.

  • assertj core version: 3.24.2
  • java version: 17
    public void testOrderedVsUnordered() {
        class NumberHolder {
            private final Number number;

            NumberHolder(final Number number) {
                this.number = number;
            }

            public Number getNumber() {
                return number;
            }

            @Override
            public String toString() {
                return number.toString();
            }
        }

        class Foo {
            private final Collection<NumberHolder> holders;

            Foo(Collection<NumberHolder> holders) {
                this.holders = holders;
            }

            Collection<NumberHolder> getOrderedNumberHolders() {
                return holders;
            }
        }

        final RecursiveComparisonConfiguration ignoreDouble =
                RecursiveComparisonConfiguration.builder().withIgnoredFieldsOfTypes(NumberHolder.class).build();
        final Number intValue = Integer.valueOf(12);
        final Double doubleValueA = Double.valueOf(12.34);
        final Double doubleValueB = Double.valueOf(56.78);
        final List<NumberHolder> holdersA = asList(new NumberHolder(intValue), new NumberHolder(doubleValueA));
        final List<NumberHolder> holdersB= asList(new NumberHolder(intValue), new NumberHolder(doubleValueB));

        // Pass
        assertThat(new Foo(List.copyOf(holdersA))).usingRecursiveComparison(ignoreDouble)
                                                  .isEqualTo(new Foo(List.copyOf(holdersB)));

        // Fail, NumberHolder is not ignored
        assertThat(new Foo(Set.copyOf(holdersA))).usingRecursiveComparison(ignoreDouble)
                                                 .isEqualTo(new Foo(Set.copyOf(holdersB)));
    }

A possible workaround:

        final RecursiveComparisonConfiguration ignoreDouble =
                RecursiveComparisonConfiguration.builder().withEqualsForType((c1, c2) -> true, NumberHolder.class)
                                                .build();
@joel-costigliola
Copy link
Member

Thanks for reporting this @ylecaillez ! I'll check it on the main branch this weed end

@scordio scordio added the theme: recursive comparison An issue related to the recursive comparison label Dec 8, 2023
@joel-costigliola joel-costigliola added this to the 3.25.0 milestone Dec 17, 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

No branches or pull requests

3 participants