diff --git a/guava/src/test/java/org/baeldung/hamcrest/HamcrestExamplesTest.java b/guava/src/test/java/org/baeldung/hamcrest/HamcrestExamplesTest.java index 99a9209b36..a44ce766f0 100644 --- a/guava/src/test/java/org/baeldung/hamcrest/HamcrestExamplesTest.java +++ b/guava/src/test/java/org/baeldung/hamcrest/HamcrestExamplesTest.java @@ -1,11 +1,15 @@ package org.baeldung.hamcrest; import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.emptyArray; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.everyItem; +import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasItems; +import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertThat; @@ -13,6 +17,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import org.hamcrest.Matchers; import org.junit.Test; import com.google.common.collect.Lists; @@ -32,15 +37,21 @@ public class HamcrestExamplesTest { @Test public final void whenVerifyingMultipleElementsArePartOfCollection_thenCorrect1() { final List collection = Lists.newArrayList("ab", "cd", "ef"); - assertThat(collection, hasItems("cd", "ef")); + assertThat(collection, hasItems("ef", "cd")); } @Test - public final void whenVerifyingMultipleElementsArePartOfCollection_thenCorrect2() { + public final void whenVerifyingMultipleElementsArePartOfCollectionInStrictOrder_thenCorrect2() { final List collection = Lists.newArrayList("ab", "cd", "ef"); assertThat(collection, contains("ab", "cd", "ef")); } + @Test + public final void whenVerifyingMultipleElementsArePartOfCollectionInAnyOrder_thenCorrect2() { + final List collection = Lists.newArrayList("ab", "cd", "ef"); + assertThat(collection, containsInAnyOrder("cd", "ab", "ef")); + } + @Test public final void givenCollectionIsEmpty_whenChecking_thenEmpty() { final List collection = Lists.newArrayList(); @@ -65,4 +76,22 @@ public class HamcrestExamplesTest { assertThat(array, not(emptyArray())); } + @Test + public final void whenCollectionSizeIsChecked_thenCorrect() { + final List collection = Lists.newArrayList("ab", "cd", "ef"); + assertThat(collection, hasSize(3)); + } + + @Test + public final void whenIterableSizeIsChecked_thenCorrect() { + final Iterable collection = Lists.newArrayList("ab", "cd", "ef"); + assertThat(collection, Matchers. iterableWithSize(3)); + } + + @Test + public final void whenCheckingConditionOverEachItem_thenCorrect() { + final List collection = Lists.newArrayList(15, 20, 25, 30); + assertThat(collection, everyItem(greaterThan(10))); + } + }