### Question:
SingleValueMappingFunction implements BiFunction<TypeSystem, Record, T> { @Override public T apply(TypeSystem typeSystem, Record record) { if (record.size() == 0) { throw new IllegalArgumentException("Record has no elements, cannot map nothing."); } if (record.size() > 1) { throw new IllegalArgumentException( "Records with more than one value cannot be converted without a mapper."); } Value source = record.get(0); return source == null || source == Values.NULL ? null : conversionService.convert(source, targetClass); } SingleValueMappingFunction(ConversionService conversionService,
		Class<T> targetClass); @Override T apply(TypeSystem typeSystem, Record record);  }### Answer:
@Test void shouldWorkWithNullValues() { when(record.size()).thenReturn(1); when(record.get(0)).thenReturn(Values.NULL); SingleValueMappingFunction<String> mappingFunction = new SingleValueMappingFunction<>(conversionService, String.class); assertThat(mappingFunction.apply(typeSystem, record)).isNull(); }
@Test void shouldCheckReturnType() { when(record.size()).thenReturn(1); when(record.get(0)).thenReturn(Values.value("Guten Tag.")); SingleValueMappingFunction<Period> mappingFunction = new SingleValueMappingFunction<>(conversionService, Period.class); assertThatExceptionOfType(ConversionFailedException.class).isThrownBy(() -> mappingFunction.apply(typeSystem, record)) .withMessageStartingWith("Failed to convert from type [org.neo4j.driver.internal.value.StringValue] to type [java.time.Period] for value '\"Guten Tag.\"'"); }
@Test void mappingShouldWorkForSupportedTypes() { LocalDate aDate = LocalDate.of(2019, 4, 10); when(record.size()).thenReturn(1); when(record.get(0)).thenReturn(Values.value(aDate)); SingleValueMappingFunction<LocalDate> mappingFunction = new SingleValueMappingFunction<>(conversionService, LocalDate.class); assertThat(mappingFunction.apply(typeSystem, record)).isEqualTo(aDate); }