SummaryCSVTool { public void summarize(File inputDir) { final File[] shapeFiles = inputDir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".shp"); } }); for (File shapeFile : shapeFiles) { if (!isValidDateExtractableFileName(shapeFile)) { continue; } final File mappingFile = new File(inputDir, FileUtils.getFilenameWithoutExtension(shapeFile).concat("_band_mapping.txt")); if (!mappingFile.isFile()) { continue; } try { final ProductData.UTC date = filenameDateExtractor.getDate(shapeFile); final FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = shapeFileReader.read(shapeFile); final Properties properties = new Properties(); properties.load(new FileReader(mappingFile)); statisticsDatabase.append(date, featureCollection, properties); } catch (IOException e) { logger.log(Level.WARNING, e.getMessage()); e.printStackTrace(); } } } SummaryCSVTool(Logger logger, ShapeFileReader shapeFileReader, String nameColumn); static void main(String[] args); void summarize(File inputDir);  }
@Test public void testThatAnErrorWasLoggedIfAnIOExceptionIsThrownWhileReadingAShapeFile() throws IOException { final String exceptionMessage = "Unable To read"; when(shapeFileReader.read(any(File.class))).thenThrow(new IOException(exceptionMessage)); summaryCSVTool.summarize(inputDir); verify(logger, times(1)).log(Level.WARNING, exceptionMessage); }
@Test public void testThatNoErrorIsLoggedWhenShapeFileNameDoesCorrespondToDatePattern() throws IOException { when(shapeFileReader.read(any(File.class))).thenReturn(null); when(inputDir.listFiles(any(FilenameFilter.class))).thenReturn(new File[]{new File("20120509_chl.shp")}); summaryCSVTool.summarize(inputDir); verifyNoMoreInteractions(logger); }
@Test public void testThatAnErrorIsLoggedWhenShapeFileNameDoesNotCorrespondToDatePattern() { when(inputDir.listFiles(any(FilenameFilter.class))).thenReturn(new File[]{new File("blah_20120509.shp")}); summaryCSVTool.summarize(inputDir); String expectedMessage = "The filename 'blah_20120509.shp' does not match the pattern yyyyMMdd_*.shp."; verify(logger, times(1)).log(Level.WARNING, expectedMessage); }