### Question:
DelegatingMappingFunctionWithNullCheck implements BiFunction<TypeSystem, Record, T> { @Override public T apply(TypeSystem typeSystem, Record record) { T t = delegate.apply(typeSystem, record); if (t == null) { throw new IllegalStateException( "Mapping function " + delegate + " returned illegal null value for record " + record); } return t; } DelegatingMappingFunctionWithNullCheck(BiFunction<TypeSystem, Record, T> delegate); @Override T apply(TypeSystem typeSystem, Record record);  }### Answer:
@Test void shouldBeHappyWithNonNullValues() { DelegatingMappingFunctionWithNullCheck<String> function = new DelegatingMappingFunctionWithNullCheck( (typeSystem, record) -> "Tada."); assertThat(function.apply(mock(TypeSystem.class), mock(Record.class))).isEqualTo("Tada."); }
@Test void shouldThrowExceptions() { DelegatingMappingFunctionWithNullCheck<String> function = new DelegatingMappingFunctionWithNullCheck( (typeSystem, record) -> null); assertThatIllegalStateException().isThrownBy(() -> function.apply(mock(TypeSystem.class), mock(Record.class))) .withMessageMatching("Mapping function .* returned illegal null value for record .*"); }