### Question:
Pair extends Single<R> implements Second<S>,
                   MappableSecond<S, Pair<R, ?>> { @Override public <A> Pair<A, S> mapFirst(UnaryFunction<R, A> function) { return pair(function.call(getFirst()), 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 shouldBeMappableUsingMapperOnFirstPosition() throws Exception { Pair<Integer, String> pair = tuple(5, "Five"); Mapper<Integer, String> mapper = new Mapper<Integer, String>() { @Override public String map(Integer input) { return String.valueOf(input); } }; Pair<String, String> expected = tuple("5", "Five"); Pair<String, String> actual = pair.mapFirst(mapper); assertThat(actual, is(expected)); }
@Test(expected = NullPointerException.class) public void shouldThrowNullPointerExceptionIfNullMapperPassedToMapFirst() throws Exception { Pair<Integer, String> pair = tuple(5, "Five"); Mapper<Integer, String> mapper = null; pair.mapFirst(mapper); }
@Test public void shouldBeMappableUsingUnaryFunctionOnFirstPosition() throws Exception { Pair<Integer, String> pair = tuple(5, "Five"); UnaryFunction<Integer, String> function = new UnaryFunction<Integer, String>() { @Override public String call(Integer input) { return String.valueOf(input); } }; Pair<String, String> expected = tuple("5", "Five"); Pair<String, String> actual = pair.mapFirst(function); assertThat(actual, is(expected)); }
@Test(expected = NullPointerException.class) public void shouldThrowNullPointerExceptionIfNullUnaryFunctionPassedToMapFirst() throws Exception { Pair<Integer, String> pair = tuple(5, "Five"); UnaryFunction<Integer, String> function = null; pair.mapFirst(function); }