The following compiles with 3.26.3:
record Container(String name, ArrayList<Object> elements) {
}
Container container = new Container("", new ArrayList<>());
assertThat(container)
// returns AbstractListAssert<?, List<?>, Object, ObjectAssert<Object>>
.extracting(Container::name, Container::elements)
.contains("", List.of());
However, it doesn't compile with 3.27.0:
assertThat(container)
// returns AbstractListAssert<?, List<? extends Serializable>, Serializable, ObjectAssert<Serializable>>
.extracting(Container::name, Container::elements)
.contains("", List.of()); // Cannot resolve method 'contains(String, List<E>)'
This is a consequence of:
which changed the minimum accepted type of contains values from Object to Serializable.
Arguably, the following wouldn't compile even with 3.26.3:
assertThat(List.of(container.name(), container.elements()))
.contains("", List.of()); // Cannot resolve method 'contains(String, List<E>)'
Therefore, I'm unsure whether the previous behavior of extracting chained with contains should be supported.
The workaround for both examples is to create an ArrayList from the expected List:
import static org.assertj.core.util.Lists.newArrayList;
assertThat(container)
.extracting(Container::name, Container::elements)
.contains("", newArrayList());
assertThat(List.of(container.name(), container.elements()))
.contains("", newArrayList());
The following compiles with 3.26.3:
However, it doesn't compile with 3.27.0:
This is a consequence of:
extracting(Function...)#3673which changed the minimum accepted type of
containsvalues fromObjecttoSerializable.Arguably, the following wouldn't compile even with 3.26.3:
Therefore, I'm unsure whether the previous behavior of
extractingchained withcontainsshould be supported.The workaround for both examples is to create an
ArrayListfrom the expectedList: