MetadataConverterUtils { public static Year extractYearOrNull(String date, Logger log) { if (StringUtils.isNotBlank(date)) { return parseYearOrGetNull(date.indexOf('-') == 4 ? date.substring(0, date.indexOf('-')) : date, log); } else { return null; } } private  MetadataConverterUtils(); static List<String> extractValues(Collection<StructuredProperty> source, FieldApprover fieldApprover); static Year extractYearOrNull(String date, Logger log);  }
@Test public void testExtractYearOrNullWithValidInput() { assertEquals(Year.of(2020), MetadataConverterUtils.extractYearOrNull("2020-12-31", log)); assertEquals(Year.of(2010), MetadataConverterUtils.extractYearOrNull("2010-1-1", log)); assertEquals(Year.of(1900), MetadataConverterUtils.extractYearOrNull("1900-2", log)); assertEquals(Year.of(2020), MetadataConverterUtils.extractYearOrNull("2020", log)); }
@Test public void testExtractYearOrNullWithInvalidInput() { assertNull(MetadataConverterUtils.extractYearOrNull("invalid", log)); assertNull(MetadataConverterUtils.extractYearOrNull("20200304", log)); assertNull(MetadataConverterUtils.extractYearOrNull("20-20-01", log)); assertNull(MetadataConverterUtils.extractYearOrNull("", log)); assertNull(MetadataConverterUtils.extractYearOrNull(null, log)); }