@Test(expected = IllegalArgumentException.class) public void test_flatMap_null() { // prepare final String left = "hoge"; final String right = "foo"; Pair<String> pair = new Pair<>(left, right); // action pair.flatMap(null); // check // - nothing }
@Test public void test_flatMap_null_right() { // prepare final String left = "foo"; Pair<String> pair = new Pair<>(left, null); // action Pair<Integer> result = pair.flatMap( (l, r) -> { final int lengthL = (l == null ? 0 : l.length()); final int lengthR = (r == null ? 0 : r.length()); Pair<Integer> tmp = new Pair<>(lengthL, lengthR); reverse(tmp); return tmp; }); // check assertEquals(left.length(), result.getRight().intValue()); assertEquals(0, result.getLeft().intValue()); }