-
-
Notifications
You must be signed in to change notification settings - Fork 748
Closed
Closed
🐛 Regression
Copy link
Labels
theme: recursive comparisonAn issue related to the recursive comparisonAn issue related to the recursive comparison
Milestone
Description
Describe the bug
It appears that 3.25.0 has changed behavior of recursive comparison
- assertj core version: 3.25.0
- java version: 17
- test framework version: junit platform 5.10.1
The below test succeeds in 3.24.2 but fails in 3.25.0
@Test
void testRecursiveCompare() {
var a1 = new A();
a1.name = "test1";
var b1 = new B();
a1.b = b1;
b1.name = "test2";
var a2 = new A();
a2.name = "test1";
a2.b = b1;
var list1 = List.of(a1);
var list2 = List.of(a2);
var cfg = RecursiveComparisonConfiguration.builder().withComparedFields("name", "b").build();
cfg.useOverriddenEquals();
assertThat(list1)
.usingRecursiveFieldByFieldElementComparator(cfg)
.containsExactlyElementsOf(list2);
}
private static class A {
private String name;
private String guid = UUID.randomUUID().toString();
private B b;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof A a)) {
return false;
}
return Objects.equals(name, a.name) && Objects.equals(guid, a.guid) && Objects.equals(b, a.b);
}
@Override
public int hashCode() {
return Objects.hash(name, guid, b);
}
}
private static class B {
private String name;
private String guid = UUID.randomUUID().toString();
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof B b)) {
return false;
}
return Objects.equals(name, b.name) && Objects.equals(guid, b.guid);
}
}
Metadata
Metadata
Assignees
Labels
theme: recursive comparisonAn issue related to the recursive comparisonAn issue related to the recursive comparison