Skip to content

Commit 3d0def7

Browse files
author
Eugen Paraschiv
committed
testing work for hamcrest
1 parent e2371ce commit 3d0def7

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

guava/src/test/java/org/baeldung/hamcrest/HamcrestExamplesTest.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
package org.baeldung.hamcrest;
22

33
import static org.hamcrest.Matchers.contains;
4+
import static org.hamcrest.Matchers.containsInAnyOrder;
45
import static org.hamcrest.Matchers.empty;
56
import static org.hamcrest.Matchers.emptyArray;
67
import static org.hamcrest.Matchers.equalTo;
8+
import static org.hamcrest.Matchers.everyItem;
9+
import static org.hamcrest.Matchers.greaterThan;
710
import static org.hamcrest.Matchers.hasItem;
811
import static org.hamcrest.Matchers.hasItems;
12+
import static org.hamcrest.Matchers.hasSize;
913
import static org.hamcrest.Matchers.not;
1014
import static org.junit.Assert.assertThat;
1115

1216
import java.util.Collections;
1317
import java.util.List;
1418
import java.util.Map;
1519

20+
import org.hamcrest.Matchers;
1621
import org.junit.Test;
1722

1823
import com.google.common.collect.Lists;
@@ -32,15 +37,21 @@ public final void whenVerifyingSingleElementIsPartOfCollection_thenCorrect() {
3237
@Test
3338
public final void whenVerifyingMultipleElementsArePartOfCollection_thenCorrect1() {
3439
final List<String> collection = Lists.newArrayList("ab", "cd", "ef");
35-
assertThat(collection, hasItems("cd", "ef"));
40+
assertThat(collection, hasItems("ef", "cd"));
3641
}
3742

3843
@Test
39-
public final void whenVerifyingMultipleElementsArePartOfCollection_thenCorrect2() {
44+
public final void whenVerifyingMultipleElementsArePartOfCollectionInStrictOrder_thenCorrect2() {
4045
final List<String> collection = Lists.newArrayList("ab", "cd", "ef");
4146
assertThat(collection, contains("ab", "cd", "ef"));
4247
}
4348

49+
@Test
50+
public final void whenVerifyingMultipleElementsArePartOfCollectionInAnyOrder_thenCorrect2() {
51+
final List<String> collection = Lists.newArrayList("ab", "cd", "ef");
52+
assertThat(collection, containsInAnyOrder("cd", "ab", "ef"));
53+
}
54+
4455
@Test
4556
public final void givenCollectionIsEmpty_whenChecking_thenEmpty() {
4657
final List<String> collection = Lists.newArrayList();
@@ -65,4 +76,22 @@ public final void givenArrayIsEmpty_whenChecking_thenEmpty() {
6576
assertThat(array, not(emptyArray()));
6677
}
6778

79+
@Test
80+
public final void whenCollectionSizeIsChecked_thenCorrect() {
81+
final List<String> collection = Lists.newArrayList("ab", "cd", "ef");
82+
assertThat(collection, hasSize(3));
83+
}
84+
85+
@Test
86+
public final void whenIterableSizeIsChecked_thenCorrect() {
87+
final Iterable<String> collection = Lists.newArrayList("ab", "cd", "ef");
88+
assertThat(collection, Matchers.<String> iterableWithSize(3));
89+
}
90+
91+
@Test
92+
public final void whenCheckingConditionOverEachItem_thenCorrect() {
93+
final List<Integer> collection = Lists.newArrayList(15, 20, 25, 30);
94+
assertThat(collection, everyItem(greaterThan(10)));
95+
}
96+
6897
}

0 commit comments

Comments
 (0)