assertj
assertj copied to clipboard
hasNoNullFields does not detect null collections
Describe the bug The hasNoNullFields assertion does not detect null values for collections while it works fine for other types
- assertj core version: 3.27.3
- java version: 21
- test framework version: junit-jupiter 5.10.3
Test case reproducing the bug The following test should fail for both assertions however the first passes while the second one correctly fails
class NullCheckTest {
public record Data(List<String> l, String s){};
@Test
void testNullString() {
Data data1 = new Data(null, "");
Data data2 = new Data(List.of(), null);
assertThat(data1).usingRecursiveAssertion().hasNoNullFields();
assertThat(data2).usingRecursiveAssertion().hasNoNullFields();
}
}
I'd like to take this if it's possible, thanks !
That's a bug Sorry for the late answer, this is actually supported if you select the CollectionAssertionPolicy.COLLECTION_OBJECT_AND_ELEMENTS which should have been the default but was not.