### Question:
Pair extends Single<R> implements Second<S>,
                   MappableSecond<S, Pair<R, ?>> { @Override public <A> Pair<R, A> mapSecond(UnaryFunction<S, A> function) { return pair(getFirst(), function.call(getSecond())); } Pair(R first, S second); static Pair<R, S> pair(R first, S second); @Override S getSecond(); @Override Pair<A, S> mapFirst(UnaryFunction<R, A> function); @Override Pair<R, A> mapSecond(UnaryFunction<S, A> function); @Override Iterable<Object> getValues();  }### Answer:
@Test public void shouldBeMappableUsingMapperOnSecondPosition() throws Exception { Pair<Integer, String> pair = tuple(5, "Five"); Mapper<String, Integer> mapper = new Mapper<String, Integer>() { @Override public Integer map(String input) { return input.length(); } }; Pair<Integer, Integer> expected = tuple(5, 4); Pair<Integer, Integer> actual = pair.mapSecond(mapper); assertThat(actual, is(expected)); }
@Test(expected = NullPointerException.class) public void shouldThrowNullPointerExceptionIfNullMapperPassedToMapSecond() throws Exception { Pair<Integer, String> pair = tuple(5, "Five"); Mapper<String, Integer> mapper = null; pair.mapSecond(mapper); }
@Test public void shouldBeMappableUsingUnaryFunctionOnSecondPosition() throws Exception { Pair<Integer, String> pair = tuple(5, "Five"); UnaryFunction<String, Integer> function = new UnaryFunction<String, Integer>() { @Override public Integer call(String input) { return input.length(); } }; Pair<Integer, Integer> expected = tuple(5, 4); Pair<Integer, Integer> actual = pair.mapSecond(function); assertThat(actual, is(expected)); }
@Test(expected = NullPointerException.class) public void shouldThrowNullPointerExceptionIfNullUnaryFunctionPassedToMapSecond() throws Exception { Pair<Integer, String> pair = tuple(5, "Five"); UnaryFunction<String, Integer> function = null; pair.mapSecond(function); }