private String buildUserAgent() { final String defaultVersion = "0.0.0"; final String defaultJavaVersion = "0.0.0"; try { final Properties gitRepositoryState = new Properties(); final URL resourceURL = Resources.getResource(GIT_PROPERTIES_FILE); final CharSource charSource = Resources.asCharSource(resourceURL, Charset.forName("UTF-8")); Reader reader = null; try { reader = charSource.openStream(); gitRepositoryState.load(reader); } finally { if (reader != null) { reader.close(); } } final String version = MoreObjects.firstNonNull(getVersionFromGitRepositoryState(gitRepositoryState), defaultVersion); final String javaVersion = MoreObjects.firstNonNull(StandardSystemProperty.JAVA_VERSION.value(), defaultJavaVersion); return String.format("KillBill/%s; %s", version, javaVersion); } catch (final Exception e) { return String.format("KillBill/%s; %s", defaultVersion, defaultJavaVersion); } }
@Test(groups = "fast") public void testEmptyGitRepositoryState() throws Exception { final Properties gitRepositoryState = new Properties(); Assert.assertNull(recurlyClient.getVersionFromGitRepositoryState(gitRepositoryState)); } }
@Test(groups = "fast") public void testEmptyGitRepositoryState() throws Exception { final Properties gitRepositoryState = new Properties(); Assert.assertNull(recurlyClient.getVersionFromGitRepositoryState(gitRepositoryState)); } }
@Test(groups = "fast") public void testReleasedVersion() throws Exception { final Properties gitRepositoryState = new Properties(); gitRepositoryState.put(RecurlyClient.GIT_COMMIT_ID_DESCRIBE_SHORT, "recurly-java-library-0.2.5"); Assert.assertEquals(recurlyClient.getVersionFromGitRepositoryState(gitRepositoryState), "0.2.5"); }
@Test(groups = "fast") public void testUnreleasedVersion() throws Exception { final Properties gitRepositoryState = new Properties(); gitRepositoryState.put(RecurlyClient.GIT_COMMIT_ID_DESCRIBE_SHORT, "recurly-java-library-0.2.4-12"); Assert.assertEquals(recurlyClient.getVersionFromGitRepositoryState(gitRepositoryState), "0.2.4"); }
@Test(groups = "fast") public void testReleasedVersion() throws Exception { final Properties gitRepositoryState = new Properties(); gitRepositoryState.put(RecurlyClient.GIT_COMMIT_ID_DESCRIBE_SHORT, "recurly-java-library-0.2.5"); Assert.assertEquals(recurlyClient.getVersionFromGitRepositoryState(gitRepositoryState), "0.2.5"); }
@Test(groups = "fast") public void testUnreleasedVersion() throws Exception { final Properties gitRepositoryState = new Properties(); gitRepositoryState.put(RecurlyClient.GIT_COMMIT_ID_DESCRIBE_SHORT, "recurly-java-library-0.2.4-12"); Assert.assertEquals(recurlyClient.getVersionFromGitRepositoryState(gitRepositoryState), "0.2.4"); }