assertj icon indicating copy to clipboard operation
assertj copied to clipboard

hasNoNullFields does not detect null collections

Open eijckron opened this issue 10 months ago • 1 comments

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();
    }
}

eijckron avatar Mar 25 '25 17:03 eijckron

I'd like to take this if it's possible, thanks !

reduan96 avatar Mar 26 '25 23:03 reduan96

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.

joel-costigliola avatar Sep 28 '25 17:09 joel-costigliola