1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.atlassian.fugue;
17
18 import org.junit.Test;
19
20 import java.util.function.Function;
21
22 import static io.atlassian.fugue.Option.some;
23 import static io.atlassian.fugue.UtilityFunctions.toStringFunction;
24 import static org.hamcrest.MatcherAssert.assertThat;
25 import static org.hamcrest.Matchers.is;
26
27 public class OptionCompositionTest {
28 @Test public void composeLaw() {
29 final Function<Integer, Integer> plusOne = input -> input + 1;
30 assertThat(some(1).map(plusOne).map(toStringFunction()), is(some(1).map(Functions.compose(toStringFunction(), plusOne))));
31 }
32
33 @Test public void composeNull() {
34 final Function<Integer, Integer> nasty = input -> null;
35 final Function<Object, String> constant = Functions.constant("foo");
36 assertThat(some(1).map(nasty).map(constant), is(some(1).map(Functions.compose(constant, nasty))));
37 }
38 }