[jsemver] 09/95: Override toString() method
Alexandre Viau
reazem-guest at moszumanska.debian.org
Mon Feb 16 14:58:25 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 3f0c079f59568d90ad9a026f7fba95187e5c948d
Author: Zafar Khaja <zafarkhaja at gmail.com>
Date: Sat Dec 1 01:33:13 2012 +0400
Override toString() method
---
src/main/java/com/github/zafarkhaja/semver/Version.java | 9 +++++++++
src/test/java/com/github/zafarkhaja/semver/VersionTest.java | 7 +++++++
2 files changed, 16 insertions(+)
diff --git a/src/main/java/com/github/zafarkhaja/semver/Version.java b/src/main/java/com/github/zafarkhaja/semver/Version.java
index 54da22e..537bac5 100644
--- a/src/main/java/com/github/zafarkhaja/semver/Version.java
+++ b/src/main/java/com/github/zafarkhaja/semver/Version.java
@@ -33,6 +33,8 @@ import java.util.regex.Pattern;
*/
public class Version implements Comparable<Version> {
+ private String rawVersion;
+
private int majorVersion;
private int minorVersion;
private int patchVersion;
@@ -60,6 +62,8 @@ public class Version implements Comparable<Version> {
"Illegal version format"
);
}
+ rawVersion = version;
+
majorVersion = Integer.parseInt(matcher.group("major"));
minorVersion = Integer.parseInt(matcher.group("minor"));
patchVersion = Integer.parseInt(matcher.group("patch"));
@@ -146,6 +150,11 @@ public class Version implements Comparable<Version> {
}
@Override
+ public String toString() {
+ return rawVersion;
+ }
+
+ @Override
public int compareTo(Version other) {
int result = compareNormalVersions(other);
if (result == 0) {
diff --git a/src/test/java/com/github/zafarkhaja/semver/VersionTest.java b/src/test/java/com/github/zafarkhaja/semver/VersionTest.java
index 7e8be8e..fed740b 100644
--- a/src/test/java/com/github/zafarkhaja/semver/VersionTest.java
+++ b/src/test/java/com/github/zafarkhaja/semver/VersionTest.java
@@ -273,4 +273,11 @@ public class VersionTest {
assertTrue(version1.equals(version2));
assertEquals(version1.hashCode(), version2.hashCode());
}
+
+ @Test public void
+ shouldOverrideToStringMethod() {
+ String versionString = "1.2.3-beta+build";
+ Version version = new Version(versionString);
+ assertEquals(versionString, version.toString());
+ }
}
--
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