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