Unfortunatelly, was not able to reproduce your problem.
I suppose, it might be some version conflicts or other environment issues. For example, following snippet is working as expected:
class Person {
private final List<Phone> phones;
Person(List<Phone> phones) {
this.phones = phones;
}
}
class Phone {
private final String number;
Phone(String number) {
this.number = number;
}
}
class PersonTest {
@Test
void samePerson() {
Person expected = new Person(List.of(
new Phone("2"),
new Phone("3"),
new Phone("1")));
Person actual = new Person(List.of(
new Phone("1"),
new Phone("2"),
new Phone("3")));
assertThat(actual).usingRecursiveComparison()
.ignoringCollectionOrder()
.isEqualTo(expected);
}
}
Notes:
Here are relevant dependencies from pom.xml
:
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.4.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.4.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.17.2</version>
<scope>test</scope>
</dependency>