Skip to content

Instantly share code, notes, and snippets.

@ajurasz
Created May 14, 2019 17:29
Show Gist options
  • Save ajurasz/2fe0e61ce3272a052bcdc4efd40acfd4 to your computer and use it in GitHub Desktop.
Save ajurasz/2fe0e61ce3272a052bcdc4efd40acfd4 to your computer and use it in GitHub Desktop.
EveryItem hamcrest matcher usage
import static org.hamcrest.core.Every.everyItem;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
public class EveryItemTest
{
@Test
public void every_item_in_list_is() {
Collection<String> array = Arrays.asList("a", "a", "a");
assertThat(array, everyItem(is("a")));
}
@Test
public void not_every_item_in_list_is() {
Collection<String> array = Arrays.asList("a", "b", "a");
assertThat(array, not(everyItem(is("a"))));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment