-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathStreamWithMatchTest.java
46 lines (32 loc) · 1.03 KB
/
StreamWithMatchTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package streams;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.*;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
public class StreamWithMatchTest {
@Test
public void shouldCheckIfThereIsANumberGreaterThan4() throws Exception {
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
boolean anyNumberGreaterThan4 = numbers
.stream()
.anyMatch(number -> number > 4);
assertThat(anyNumberGreaterThan4, is(true));
}
@Test
public void shouldCheckIfEachNumberIsPair() throws Exception {
List<Integer> numbers = Arrays.asList(2, 4, 6);
boolean eachNumberIsPair = numbers
.stream()
.allMatch(number -> number % 2 == 0);
assertThat(eachNumberIsPair, is(true));
}
@Test
public void shouldCheckIfEachNumberIsNotPair() throws Exception {
List<Integer> numbers = Arrays.asList(3, 5, 7);
boolean eachNumberIsNotPair = numbers
.stream()
.noneMatch(number -> number % 2 == 0);
assertThat(eachNumberIsNotPair, is(true));
}
}