assert that a list is not empty in JUnit

Renaud is Not Bill Gates picture Renaud is Not Bill Gates · Feb 17, 2016 · Viewed 92.6k times · Source

I want to assert that a list is not empty in JUnit 4, when I googled about it I found this post : Checking that a List is not empty in Hamcrest which was using Hamcrest.

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

which gives me this error :

The method is(boolean) is undefined for the type MaintenanceDaoImplTest

how can I do that without using Hamcrest.

Answer

JB Nizet picture JB Nizet · Feb 17, 2016

You can simply use

assertFalse(result.isEmpty());

Regarding your problem, it's simply caused by the fact that you forgot to statically import the is() method from Hamcrest;

import static org.hamcrest.CoreMatchers.is;