Assert that the list is not empty - with or without Hamcrest?

19,486

They are the same functionality. The hamcrest provides a more English-like readable language and better error messages. In simple cases like this, I would probably just use the assertFalse

Share:
19,486
unknown_boundaries
Author by

unknown_boundaries

Computer science enthusiast. Learning JS and web development.

Updated on September 16, 2022

Comments

  • unknown_boundaries
    unknown_boundaries over 1 year

    This is related to Checking that a List is not empty in Hamcrest

    I have a question over that - If we can assert the list is not empty without using Hamcrest and just using JUnit as:

    assertFalse(list.isEmpty());
    

    Is using

    assertThat(list.isEmpty(), is(false));
    

    or

    assertThat((Collection)list, is(not(empty())));
    

    Worthwhile?

    I'm not able to understand are we gaining something using Hamcrest version in this case? Are both equivalent?