GribUtilities { public static boolean isValid(File file) { String dir = file.getAbsolutePath(); if (!file.exists()) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning("The specified path doesn't refer " + "to an existing folder. Please check the path: " + dir); } return false; } else if (!file.isDirectory()) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning("The specified path doesn't refer " + "to a directory. Please check the path: " + dir); } return false; } else if (!file.canWrite()) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning("The specified path refers to " + "a directory which can't be written. Please check the path and" + " the permissions for: " + dir); } return false; } return true; }  static boolean isValid(File file); static final String GRIB_CACHE_DIR; }
@Test public void testDataDir() throws FileNotFoundException, IOException { File wrongDir = new File("wrongfolderfortests"); final File testDir = TestData.file(this, ".").getCanonicalFile(); System.setProperty("GRIB_CACHE_DIR", testDir.getAbsolutePath()); boolean isValid = GribUtilities.isValid(testDir); assertTrue(isValid); isValid = GribUtilities.isValid(wrongDir); assertFalse(isValid); wrongDir = TestData.file(this, "sampleGrib.grb2").getCanonicalFile(); isValid = GribUtilities.isValid(wrongDir); assertFalse(isValid); }