简体   繁体   中英

Assertj+ How to create custom assertion for iterables

I need to create custom assertion for list items.

For example, I have ArrayList in which there is an Address Object, now I need to create a custom assertion to check anySatisfy

Assertions.assertThat(results.result).anySatisfy(p->{
        assertThat(p.getAddress().getCity()).withFailMessage("expected city: "+ "Caseros1").isEqualTo("Caseros1");
        assertThat(p.getAddress().getCountryName()).isEqualTo("Argentina");
    });

Any suggestion. Thanks!

This issue, which was since some time already available on allSatisfy is now also available in release 3.12 , see the respective issue .

So please upgrade to the latest AssertJ release and verify that this is working for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM