### Question:
FilterAttributeMetadataConverter implements Function<__InputValue, FilterAttributeMetadata> { @Override public FilterAttributeMetadata apply(final __InputValue inputField) { FilterAttributeMetadataImpl metadata = new FilterAttributeMetadataImpl(); metadata.setAttributeCode(inputField.getName()); metadata.setFilterInputType(inputField.getType().getName()); allAttributeMetadata.stream() .filter(attribute -> inputField.getName().equals(attribute.getAttributeCode())) .findFirst().ifPresent(attribute -> { metadata.setAttributeType(attribute.getAttributeType()); metadata.setAttributeInputType(attribute.getInputType()); }); return metadata; } FilterAttributeMetadataConverter(final List<Attribute> allAttributeMetadata); @Override FilterAttributeMetadata apply(final __InputValue inputField);  }### Answer:
@Test public void testConvertsForInputAlone() { final String CODE = "cool_attribute"; final String TYPE_NAME = "OK"; when(inputField.getName()).thenReturn(CODE); when(inputField.getType().getName()).thenReturn(TYPE_NAME); converterUnderTest = new FilterAttributeMetadataConverter(new ArrayList<>()); final FilterAttributeMetadata result = converterUnderTest.apply(inputField); assertThat(result).isNotNull(); assertThat(result.getAttributeCode()).isEqualTo(CODE); assertThat(result.getFilterInputType()).isEqualTo(TYPE_NAME); }
@Test public void testConvertsForInputWithMatchingAttribute() { final String CODE = "cool_attribute"; final String TYPE_NAME = "AWildInputAppears"; final String ATTRIBUTE_TYPE = "Int"; final String INPUT_TYPE = "boolean"; when(inputField.getName()).thenReturn(CODE); when(inputField.getType().getName()).thenReturn(TYPE_NAME); when(attribute.getAttributeCode()).thenReturn(CODE); when(attribute.getAttributeType()).thenReturn(ATTRIBUTE_TYPE); when(attribute.getInputType()).thenReturn(INPUT_TYPE); converterUnderTest = new FilterAttributeMetadataConverter(Arrays.asList(attribute)); final FilterAttributeMetadata result = converterUnderTest.apply(inputField); assertThat(result.getAttributeInputType()).isEqualTo(INPUT_TYPE); assertThat(result.getAttributeType()).isEqualTo(ATTRIBUTE_TYPE); }
@Test public void testConverteOnlyMatchesAttributeCodes() { final String CODE = "cool_attribute"; final String DIFFERENT_CODE = "uncool_attribute"; final String TYPE_NAME = "AWildInputAppears"; final String ATTRIBUTE_TYPE = "Int"; final String INPUT_TYPE = "boolean"; when(inputField.getName()).thenReturn(CODE); when(inputField.getType().getName()).thenReturn(TYPE_NAME); when(attribute.getAttributeCode()).thenReturn(DIFFERENT_CODE); when(attribute.getAttributeType()).thenReturn(ATTRIBUTE_TYPE); when(attribute.getInputType()).thenReturn(INPUT_TYPE); converterUnderTest = new FilterAttributeMetadataConverter(Arrays.asList(attribute)); final FilterAttributeMetadata result = converterUnderTest.apply(inputField); assertThat(result.getAttributeInputType()).isNullOrEmpty(); assertThat(result.getAttributeType()).isNullOrEmpty(); }