FilenameDateExtractor { public ProductData.UTC getDate(File file) { try { if (isValidFilename(file)) { return timeStampExtractor.extractTimeStamps(file.getName())[0]; } } catch (ValidationException ignored) { } return null; } FilenameDateExtractor(); boolean isValidFilename(File file); ProductData.UTC getDate(File file);  }
@Test public void testGetDate() { ProductData.UTC date = filenameDateExtractor.getDate(new File("20020304_blah.shp")); assertNotNull(date); final int year = 2002; final int month = 3; final int day = 4; assertEquals(year, date.getAsCalendar().get(Calendar.YEAR)); assertEquals(month, date.getAsCalendar().get(Calendar.MONTH) + 1); assertEquals(day, date.getAsCalendar().get(Calendar.DAY_OF_MONTH)); }
@Test public void testGetDate_null_if_invalid_filename() { ProductData.UTC date = filenameDateExtractor.getDate(new File("invalid_20020304_blah.shp")); assertNull(date); }