[jsemver] 28/95: Create setters for Pre-release version & Build metadata
Alexandre Viau
reazem-guest at moszumanska.debian.org
Mon Feb 16 14:58:27 UTC 2015
This is an automated email from the git hooks/post-receive script.
reazem-guest pushed a commit to branch master
in repository jsemver.
commit 98abdb4c029cd901e5559f9b640c75180eef777b
Author: Zafar Khaja <zafarkhaja at gmail.com>
Date: Sat Mar 30 21:42:11 2013 +0400
Create setters for Pre-release version & Build metadata
---
.../java/com/github/zafarkhaja/semver/Version.java | 8 ++++++
.../com/github/zafarkhaja/semver/VersionTest.java | 30 ++++++++++++++++++++++
2 files changed, 38 insertions(+)
diff --git a/src/main/java/com/github/zafarkhaja/semver/Version.java b/src/main/java/com/github/zafarkhaja/semver/Version.java
index 8859cb1..01e83f3 100644
--- a/src/main/java/com/github/zafarkhaja/semver/Version.java
+++ b/src/main/java/com/github/zafarkhaja/semver/Version.java
@@ -133,6 +133,14 @@ public class Version implements Comparable<Version> {
);
}
+ public Version setPreReleaseVersion(String preRelease) {
+ return new Version(normal, new MetadataVersion(preRelease));
+ }
+
+ public Version setBuildMetadata(String build) {
+ return new Version(normal, preRelease, new MetadataVersion(build));
+ }
+
public int getMajorVersion() {
return normal.getMajor();
}
diff --git a/src/test/java/com/github/zafarkhaja/semver/VersionTest.java b/src/test/java/com/github/zafarkhaja/semver/VersionTest.java
index b13d7e7..e90a974 100644
--- a/src/test/java/com/github/zafarkhaja/semver/VersionTest.java
+++ b/src/test/java/com/github/zafarkhaja/semver/VersionTest.java
@@ -204,14 +204,44 @@ public class VersionTest {
}
@Test
+ public void shouldProvideSetPreReleaseVersionMethod() {
+ Version v1 = Version.valueOf("1.0.0");
+ Version v2 = v1.setPreReleaseVersion("alpha");
+ assertEquals("1.0.0-alpha", v2.toString());
+ }
+
+ @Test
+ public void shouldDropBuildMetadataWhenSettingPreReleaseVersion() {
+ Version v1 = Version.valueOf("1.0.0-alpha+build");
+ Version v2 = v1.setPreReleaseVersion("beta");
+ assertEquals("1.0.0-beta", v2.toString());
+ }
+
+ @Test
+ public void shouldProvideSetBuildMetadataMethod() {
+ Version v1 = Version.valueOf("1.0.0");
+ Version v2 = v1.setBuildMetadata("build");
+ assertEquals("1.0.0+build", v2.toString());
+ }
+
+ @Test
public void shouldBeImmutable() {
Version version = Version.valueOf("1.2.3");
+
Version incementedMajor = version.incrementMajorVersion();
assertNotSame(version, incementedMajor);
+
Version incementedMinor = version.incrementMinorVersion();
assertNotSame(version, incementedMinor);
+
Version incementedPatch = version.incrementPatchVersion();
assertNotSame(version, incementedPatch);
+
+ Version preReleaseSet = version.setPreReleaseVersion("alpha");
+ assertNotSame(version, preReleaseSet);
+
+ Version buildSet = version.setBuildMetadata("build");
+ assertNotSame(version, buildSet);
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jsemver.git
More information about the pkg-java-commits
mailing list