Search code examples
javanullassertionassertj

How to verify that nulls are in the end of the list


I need to verify that data is sorted according to rule that all null values are in the end of the list. Is any appropriate method exist for it in assertj? I don't want to write something like - I am looking for first null in the list and then verify that all next values are nulls as well.


Solution

  • I think you can use the below code it's just an example I have not tested it yet.

    assertThat(actual).isSortedAccordingTo(Ordering.natural().nullsLast().isOrdered(list));