1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.atlassian.fugue;
17
18 import org.hamcrest.Matchers;
19 import org.junit.Test;
20
21 import static io.atlassian.fugue.Iterables.drop;
22 import static io.atlassian.fugue.Iterables.dropWhile;
23 import static io.atlassian.fugue.IterablesTakeTest.asIterable;
24 import static java.util.Arrays.asList;
25 import static java.util.Collections.emptyList;
26 import static org.hamcrest.Matchers.contains;
27 import static org.hamcrest.Matchers.emptyIterable;
28 import static org.hamcrest.Matchers.is;
29 import static org.junit.Assert.assertThat;
30
31 public class IterablesDropTest {
32 @Test public void dropOneFromList() {
33 assertThat(drop(1, asList(1, 2, 3, 4)), contains(2, 3, 4));
34 }
35
36 @Test public void dropOneFromNonList() {
37 assertThat(drop(1, asIterable(1, 2, 3, 4)), contains(2, 3, 4));
38 }
39
40 @Test public void dropNoneFromList() {
41 assertThat(drop(0, asList(1, 2, 3, 4)), contains(1, 2, 3, 4));
42 }
43
44 @Test public void dropNoneFromNonList() {
45 assertThat(drop(0, asIterable(1, 2, 3, 4)), contains(1, 2, 3, 4));
46 }
47
48 @Test public void dropAllFromList() {
49 assertThat(drop(4, asList(1, 2, 3, 4)), Matchers.<Integer> emptyIterable());
50 }
51
52 @Test public void dropAllFromNonList() {
53 assertThat(drop(4, asIterable(1, 2, 3, 4)), Matchers.<Integer> emptyIterable());
54 }
55
56 @Test public void dropMoreFromList() {
57 assertThat(drop(12, asList(1, 2, 3, 4)), Matchers.<Integer> emptyIterable());
58 }
59
60 @Test public void dropMoreFromNonList() {
61 assertThat(drop(12, asIterable(1, 2, 3, 4)), Matchers.<Integer> emptyIterable());
62 }
63
64 @Test public void dropOneToString() {
65 assertThat(drop(1, asIterable(1, 2, 3, 4)).toString(), is("[2, 3, 4]"));
66 }
67
68 @Test(expected = NullPointerException.class) public void dropNull() {
69 drop(0, null);
70 }
71
72 @Test(expected = IllegalArgumentException.class) public void dropNegativeFromList() {
73 drop(-1, emptyList());
74 }
75
76 @Test public void dropWhileTest() {
77 assertThat(dropWhile(asList(1, 2, 3, 4), i -> i < 2), contains(2, 3, 4));
78 }
79
80 @Test public void dropWhileAll() {
81 assertThat(dropWhile(asList(1, 2, 3, 4), i -> true), emptyIterable());
82 }
83
84 @Test public void dropWhileNone() {
85 assertThat(dropWhile(asList(1, 2, 3, 4), i -> false), contains(1, 2, 3, 4));
86 }
87
88 @Test(expected = NullPointerException.class) public void dropWhileNull() {
89 dropWhile(null, null);
90 }
91
92 @Test(expected = NullPointerException.class) public void dropWhileNullWithPredicate() {
93 dropWhile(null, x -> true);
94 }
95
96 @Test(expected = NullPointerException.class) public void dropWhileNullPredicate() {
97 dropWhile(Iterables.emptyIterable(), null);
98 }
99
100 @Test public void dropWhileNotAfter() {
101 assertThat(dropWhile(asList(1, 2, 3, 4, 1, 2), i -> i < 2), contains(2, 3, 4, 1, 2));
102 }
103 }