Skip to content

Recursive comparison fails if ignored fields are not found in expected #3226

@scordio

Description

@scordio

Source: #2115 (comment)

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"));

// should work but fails
assertThat(mapA).usingRecursiveComparison()
                .ignoringFields("description", "submap.description")
                .isEqualTo(mapB);
assertThat(mapA).usingRecursiveComparison()
                .ignoringFieldsMatchingRegexes(".*description")
                .isEqualTo(mapB);
java.lang.AssertionError: 
Expecting actual:
  {"description"="foobar", "foo"="bar", "submap"={"description"="subFooBar", "subFoo"="subBar"}}
to be equal to:
  {"description"="barfoo", "foo"="bar", "submap"={"subFoo"="subBar"}}
when recursively comparing field by field, but found the following difference:

field/property 'submap' differ:
- actual value  : {"description"="subFooBar", "subFoo"="subBar"}
- expected value: {"subFoo"="subBar"}
actual and expected values are maps of different size, actual size=2 when expected size=1

Metadata

Metadata

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions