use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class PeekTest method testPeekFirst.
@Test
public void testPeekFirst() throws InterruptedException, ExecutionException {
Queue<Integer> peeked = new ConcurrentLinkedQueue<Integer>();
List<String> strings = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3).peek(it -> peeked.add(it)).then(it -> it * 100).then(it -> "*" + it).block();
assertThat(peeked.size(), is(strings.size()));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class PeekTest method testPeek.
@Test
public void testPeek() throws InterruptedException, ExecutionException {
Queue<String> peeked = new ConcurrentLinkedQueue<String>();
List<String> strings = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3).then(it -> it * 100).<String>then(it -> "*" + it).peek((String it) -> peeked.add(it)).block();
assertThat(peeked.size(), is(strings.size()));
assertThat(strings, hasItem(peeked.peek()));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class SimpleReactTest method testCaptureNull.
@Test
public void testCaptureNull() throws InterruptedException, ExecutionException {
Throwable[] error = { null };
List<String> strings = new SimpleReact().<Integer>ofAsync(() -> 1, () -> 2, () -> 3).then((it) -> it * 100).then((it) -> {
if (it == 100)
throw new RuntimeException("boo!");
return it;
}).onFail(e -> 1).then((it) -> "*" + it).capture(e -> error[0] = e).block();
boolean[] foundOne = { false };
strings.forEach((string) -> {
assertThat(string, is(containsString("*")));
if (Integer.valueOf(string.substring(1)) == 1)
foundOne[0] = true;
});
assertThat(foundOne[0], is(true));
assertThat(error[0], is(nullValue()));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class SimpleReactTest method testReactMixedTypes.
@Test
public void testReactMixedTypes() {
List list = new ArrayList();
List<Object> result = new SimpleReact().ofAsync(() -> "Hello", () -> list).block();
assertThat(result.size(), is(2));
assertThat(result, hasItem("Hello"));
assertThat(result, hasItem(list));
}
use of cyclops.futurestream.SimpleReact in project cyclops by aol.
the class SimpleReactTest method testThenPrimitive.
@Test
public void testThenPrimitive() {
List<Boolean> result = new SimpleReact().ofAsync(() -> 1, () -> 1).then(it -> true).block();
assertThat(result.size(), is(2));
assertThat(result.get(0), is(true));
}
Aggregations