Skip to content

Recursive comparison does not honor ignored fieds when comparing maps #2115

@joel-costigliola

Description

@joel-costigliola

Summary

The recursive does not set field location properly for maps and thus is not evaluating ignored fields rules properly.

Example

Map<String, Object> mapA = Map.of("foo", "bar", 
                                  "description", "foobar", 
                                  "submap", Map.of("subFoo", "subBar", "description", "subFooBar"));
Map<String, Object> mapB = Map.of("foo", "bar", 
                                  "description", "barfoo", 
                                  "submap", Map.of("subFoo", "subBar", "description", "subBarFoo"));

// should work but fails
assertThat(mapA).usingRecursiveComparison()
                .ignoringFields("description", "submap.description")
                .isEqualTo(mapB);
assertThat(mapA).usingRecursiveComparison()
                .ignoringFieldsMatchingRegexes(".*description")
                .isEqualTo(mapB);

with the above maps, AssertJ should compare these fields (fieldname: actual value vs expected value)

  • foo : bar vs bar
  • description : foobar vs barfor
  • submap.subfoo: subBar vs subBar
  • submap.description: subFooBar vs subBarFoo

instead it compares actual expected values without field location:

  • "" : bar vs bar
  • "" : foobar vs barfor
  • "": subBar vs subBar
  • "": subFooBar vs subBarFoo

The fix consists in properly setting the field location to the entry key.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions