MetadataConverterUtils { public static List<String> extractValues(Collection<StructuredProperty> source, FieldApprover fieldApprover) { return source.stream() .filter(x -> fieldApprover.approve(x.getDataInfo())) .map(StructuredProperty::getValue) .filter(StringUtils::isNotBlank) .collect(Collectors.toList()); } private  MetadataConverterUtils(); static List<String> extractValues(Collection<StructuredProperty> source, FieldApprover fieldApprover); static Year extractYearOrNull(String date, Logger log);  }
@Test(expected = NullPointerException.class) public void testExtractValuesForNullApprover() { Collection<StructuredProperty> source = Lists.newArrayList(); String validValue = "someValue"; source.add(generateStructuredProperty(validValue, null)); MetadataConverterUtils.extractValues(source, null); }
@Test(expected = NullPointerException.class) public void testExtractValuesForNullSource() { MetadataConverterUtils.extractValues(null, mock(FieldApprover.class)); }
@Test public void testExtractValuesForEmptySource() { List<String> results = MetadataConverterUtils.extractValues(Lists.newArrayList(), mock(FieldApprover.class)); assertNotNull(results); assertTrue(results.isEmpty()); }
@Test public void testExtractValues() { FieldApprover notNullDataInfoFieldApprover = Objects::nonNull; DataInfo dataInfo = new DataInfo(); Collection<StructuredProperty> source = Lists.newArrayList(); String validValue = "someValue"; source.add(generateStructuredProperty(validValue, dataInfo)); source.add(generateStructuredProperty(null, dataInfo)); source.add(generateStructuredProperty("", dataInfo)); source.add(generateStructuredProperty("toBeRejectedBecauseOfNullDataInfo", null)); List<String> results = MetadataConverterUtils.extractValues(source, notNullDataInfoFieldApprover); assertNotNull(results); assertEquals(1, results.size()); assertEquals(validValue, results.get(0)); }