@Test(expected = NullPointerException.class) public void shouldThrowNullPointerExceptionIfNullMapperPassedToMapSecond() throws Exception { // Given Triple<Integer, String, Boolean> triple = tuple(5, "Five", true); Mapper<String, Integer> mapper = null; // When triple.mapSecond(mapper); // Then a NullPointerException is thrown }
@Test public void shouldBeMappableUsingUnaryFunctionOnSecondPosition() throws Exception { // Given 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); // When Triple<Integer, Integer, Boolean> actual = triple.mapSecond(function); // Then assertThat(actual, is(expected)); }