CertificateLoader { @VisibleForTesting static Path resolvePath(String certificatePath) { Path path; if (certificatePath.startsWith("file:")) { try { logger.info("using file resolver for {}", certificatePath); path = Paths.get(new URL(certificatePath).toURI()); if (!Files.exists(path)) { throw new FileNotFoundException(); } return path; } catch (Exception e) { throw new FeatureException( Problem.localProblem("certificatePath resolver failed " + certificatePath, e.getMessage()), e); } } if (certificatePath.startsWith("classpath:")) { logger.info("using classpath resolver for {}", certificatePath); String resource = getResourceUrl( certificatePath.substring("classpath:".length(), certificatePath.length())).getPath(); return Paths.get(resource); } throw new FeatureException( Problem.localProblem( "certificatePath must start with file: or classpath: " + certificatePath, "")); } CertificateLoader(String certificatePath);   }
@Test public void resolvePath() throws IOException { try { CertificateLoader.resolvePath("classpath:cer"); fail("exception expected for unknown classpath"); } catch (Exception ignored) { } try { CertificateLoader.resolvePath("file: fail("exception expected for file uri component"); } catch (Exception ignored) { } try { CertificateLoader.resolvePath("file: fail("exception expected for missing path"); } catch (Exception ignored) { } Path pathC = CertificateLoader.resolvePath("classpath:certs"); assertTrue(pathC != null); String fPath = "file: Path pathF = CertificateLoader.resolvePath(fPath); assertTrue(pathF != null); }