ClassPathManifestInfoProvider implements ManifestInfoProvider { @Override public ManifestInfo getManifestInfo() { final Properties properties = new Properties(); final InputStream gitProperties = ClassPathManifestInfoProvider.class.getResourceAsStream(resource); if (gitProperties != null) { try { properties.load(gitProperties); } catch (IOException e) { LOGGER.debug("Unable to read from resource '{}'.", resource, e); } } else { LOGGER.debug("Resource '{}' does not exist.", resource); } final String versionId = Optional.ofNullable(properties.getProperty("git.build.version")).orElse("N/A"); final String buildId = Optional.ofNullable(properties.getProperty("git.commit.id.abbrev")).orElse("N/A"); return new ManifestInfo(versionId, buildId); } ClassPathManifestInfoProvider(String resource, String name); @Override String getName(); @Override ManifestInfo getManifestInfo();  }
@Test public void shouldReadFromFile() throws Exception { final ClassPathManifestInfoProvider provider = new ClassPathManifestInfoProvider("/git.properties", "source1"); final ManifestInfo manifestInfo = provider.getManifestInfo(); assertEquals("1.0.0", manifestInfo.getVersionId()); assertEquals("abcd1234", manifestInfo.getBuildId()); }
@Test public void shouldReadFromMissingFile() throws Exception { final ClassPathManifestInfoProvider provider = new ClassPathManifestInfoProvider("/intentionally_missing_file.properties", "source2"); final ManifestInfo manifestInfo = provider.getManifestInfo(); assertEquals("N/A", manifestInfo.getVersionId()); assertEquals("N/A", manifestInfo.getBuildId()); }