### Question:
CustomNameExtractor { public static Optional<String> getName( Supplier<String> nameSupplier, Supplier<String> valueSupplier ) { String name = nameSupplier.get().trim(); if ( !name.isEmpty() ) { return Optional.of( name ); } String value = valueSupplier.get().trim(); if ( !value.isEmpty() ) { return Optional.of( value ); } return Optional.empty(); } private  CustomNameExtractor(); static Optional<String> getName( Supplier<String> nameSupplier, Supplier<String> valueSupplier );  }### Answer:
@Test public void favours_name_over_value() { assertThat(CustomNameExtractor.getName( () -> "name", () -> "value" )).contains( "name" ); assertThat(CustomNameExtractor.getName( () -> "name", () -> "" )).contains( "name" ); assertThat(CustomNameExtractor.getName( () -> "name", () -> " " )).contains( "name" ); assertThat(CustomNameExtractor.getName( () -> " name ", () -> " " )).contains( "name" ); }
@Test public void returns_value_if_trimmed_name_is_empty() { assertThat(CustomNameExtractor.getName( () -> "", () -> "value" )).contains( "value" ); assertThat(CustomNameExtractor.getName( () -> " ", () -> "value" )).contains( "value" ); assertThat(CustomNameExtractor.getName( () -> " ", () -> " value " )).contains( "value" ); }
@Test public void returns_nothing_if_none_defined() { assertThat(CustomNameExtractor.getName( () -> "", () -> "" )).isEmpty(); assertThat(CustomNameExtractor.getName( () -> " ", () -> "" )).isEmpty(); assertThat(CustomNameExtractor.getName( () -> "", () -> " " )).isEmpty(); assertThat(CustomNameExtractor.getName( () -> " ", () -> " " )).isEmpty(); }