1 package io.atlassian.fugue;
2
3 import org.junit.Test;
4
5 import static io.atlassian.fugue.Iterables.cycle;
6 import static io.atlassian.fugue.Iterables.take;
7 import static org.hamcrest.MatcherAssert.assertThat;
8 import static org.hamcrest.Matchers.contains;
9 import static org.hamcrest.Matchers.emptyIterable;
10 import static org.hamcrest.core.Is.is;
11
12 public class IterablesCycleTest {
13
14 @Test public void canCycle() {
15 assertThat(take(5, cycle(1, 2, 3, 4)), contains(1, 2, 3, 4, 1));
16 }
17
18 @Test public void canCycleFewerElements() {
19 assertThat(take(2, cycle(1, 2, 3, 4)), contains(1, 2));
20 }
21
22 @Test public void canCycleNoElements() {
23 assertThat(cycle(), emptyIterable());
24 }
25
26 @Test public void toStringResult() {
27 assertThat(cycle(1, 2, 3).toString(), is("[1, 2, 3...]"));
28 }
29
30 @Test public void toStringResultNull() {
31 assertThat(cycle(1, 2, null).toString(), is("[1, 2, null...]"));
32 }
33
34 @Test(expected = UnsupportedOperationException.class) public void removeOnOutput() {
35 cycle(1, 2, 3).iterator().remove();
36 }
37 }