Make minor improvements

This commit is contained in:
Zafar Khaja 2013-03-03 23:44:34 +04:00
parent 5d0aa683cb
commit 838d40e90e
7 changed files with 124 additions and 120 deletions

View File

@ -4,7 +4,7 @@
<groupId>com.github.zafarkhaja</groupId> <groupId>com.github.zafarkhaja</groupId>
<artifactId>semver</artifactId> <artifactId>semver</artifactId>
<version>0.2.0-SNAPSHOT</version> <version>0.2.1-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>semver</name> <name>semver</name>
@ -46,7 +46,7 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>

View File

@ -27,21 +27,19 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /**
* *
* @author Zafar Khaja <zafarkhaja@gmail.com> * @author Zafar Khaja <zafarkhaja@gmail.com>
*/ */
class AlphaNumericVersion implements Comparable<AlphaNumericVersion> { class AlphaNumericVersion implements Comparable<AlphaNumericVersion> {
private String value;
static final String FORMAT = "([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)"; static final String FORMAT = "([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)";
private static final Pattern PATTERN = Pattern.compile("^" + FORMAT + "$"); private static final Pattern PATTERN = Pattern.compile("^" + FORMAT + "$");
private String value;
AlphaNumericVersion(String value) { AlphaNumericVersion(String value) {
if (value == null) { if (value == null) {
throw new NullPointerException( throw new NullPointerException("Alpha-numeric version MUST NOT be NULL");
"Alpha-numeric version MUST NOT be NULL"
);
} }
Matcher matcher = PATTERN.matcher(value); Matcher matcher = PATTERN.matcher(value);
if (!matcher.matches()) { if (!matcher.matches()) {
@ -51,40 +49,40 @@ class AlphaNumericVersion implements Comparable<AlphaNumericVersion> {
} }
this.value = matcher.group(0); this.value = matcher.group(0);
} }
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
if (this == other) { if (this == other) {
return true; return true;
} }
if (!(other instanceof AlphaNumericVersion)) { if (!(other instanceof AlphaNumericVersion)) {
return false; return false;
} }
return compareTo((AlphaNumericVersion) other) == 0 ? true : false; return compareTo((AlphaNumericVersion) other) == 0 ? true : false;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return value.hashCode(); return value.hashCode();
} }
@Override @Override
public String toString() { public String toString() {
return value; return value;
} }
@Override @Override
public int compareTo(AlphaNumericVersion other) { public int compareTo(AlphaNumericVersion other) {
String[] thisIds = value.split("\\."); String[] thisIds = value.split("\\.");
String[] otherIds = other.value.split("\\."); String[] otherIds = other.value.split("\\.");
int result = compareIdentifierArrays(thisIds, otherIds); int result = compareIdentifierArrays(thisIds, otherIds);
if (result == 0) { if (result == 0) {
result = thisIds.length - otherIds.length; result = thisIds.length - otherIds.length;
} }
return result; return result;
} }
private int compareIdentifierArrays(String[] ids1, String[] ids2) { private int compareIdentifierArrays(String[] ids1, String[] ids2) {
int result = 0; int result = 0;
int length = getLeastCommonArrayLength(ids1, ids2); int length = getLeastCommonArrayLength(ids1, ids2);
@ -96,11 +94,11 @@ class AlphaNumericVersion implements Comparable<AlphaNumericVersion> {
} }
return result; return result;
} }
private int getLeastCommonArrayLength(String[] arr1, String[] arr2) { private int getLeastCommonArrayLength(String[] arr1, String[] arr2) {
return arr1.length <= arr2.length ? arr1.length : arr2.length; return arr1.length <= arr2.length ? arr1.length : arr2.length;
} }
private int compareIdentifiers(String id1, String id2) { private int compareIdentifiers(String id1, String id2) {
if (isInt(id1) && isInt(id2)) { if (isInt(id1) && isInt(id2)) {
return Integer.parseInt(id1) - Integer.parseInt(id2); return Integer.parseInt(id1) - Integer.parseInt(id2);
@ -108,7 +106,7 @@ class AlphaNumericVersion implements Comparable<AlphaNumericVersion> {
return id1.compareTo(id2); return id1.compareTo(id2);
} }
} }
private boolean isInt(String str) { private boolean isInt(String str) {
try { try {
Integer.parseInt(str); Integer.parseInt(str);

View File

@ -35,10 +35,10 @@ class NormalVersion implements Comparable<NormalVersion> {
private int major; private int major;
private int minor; private int minor;
private int patch; private int patch;
static final String FORMAT = "(\\d+)\\.(\\d+)\\.(\\d+)"; static final String FORMAT = "(\\d+)\\.(\\d+)\\.(\\d+)";
private static final Pattern PATTERN = Pattern.compile("^" + FORMAT + "$"); private static final Pattern PATTERN = Pattern.compile("^" + FORMAT + "$");
NormalVersion(int major, int minor, int patch) { NormalVersion(int major, int minor, int patch) {
if (major < 0 || minor < 0 || patch < 0) { if (major < 0 || minor < 0 || patch < 0) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
@ -49,7 +49,7 @@ class NormalVersion implements Comparable<NormalVersion> {
this.minor = minor; this.minor = minor;
this.patch = patch; this.patch = patch;
} }
static NormalVersion valueOf(String value) { static NormalVersion valueOf(String value) {
Matcher matcher = PATTERN.matcher(value); Matcher matcher = PATTERN.matcher(value);
if (!matcher.matches()) { if (!matcher.matches()) {
@ -73,13 +73,13 @@ class NormalVersion implements Comparable<NormalVersion> {
int getPatch() { int getPatch() {
return patch; return patch;
} }
void incrementMajor() { void incrementMajor() {
major = major + 1; major = major + 1;
minor = 0; minor = 0;
patch = 0; patch = 0;
} }
void incrementMinor() { void incrementMinor() {
minor = minor + 1; minor = minor + 1;
patch = 0; patch = 0;
@ -100,7 +100,7 @@ class NormalVersion implements Comparable<NormalVersion> {
} }
return result; return result;
} }
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
if (this == other) { if (this == other) {
@ -120,12 +120,12 @@ class NormalVersion implements Comparable<NormalVersion> {
hash = 31 * hash + patch; hash = 31 * hash + patch;
return hash; return hash;
} }
/** /**
* Returns the string representation of this normal version. * Returns the string representation of this normal version.
* *
* A normal version number MUST take the form X.Y.Z where X, Y, and Z are * A normal version number MUST take the form X.Y.Z where X, Y, and Z are
* non-negative integers. X is the major version, Y is the minor version, * non-negative integers. X is the major version, Y is the minor version,
* and Z is the patch version. (SemVer p.2) * and Z is the patch version. (SemVer p.2)
*/ */
@Override @Override

View File

@ -31,19 +31,19 @@ import java.util.regex.Pattern;
* @author Zafar Khaja <zafarkhaja@gmail.com> * @author Zafar Khaja <zafarkhaja@gmail.com>
*/ */
public class Version implements Comparable<Version> { public class Version implements Comparable<Version> {
private NormalVersion normal; private NormalVersion normal;
private AlphaNumericVersion preRelease; private AlphaNumericVersion preRelease;
private AlphaNumericVersion build; private AlphaNumericVersion build;
private static final String PRE_RELEASE_PREFIX = "-"; private static final String PRE_RELEASE_PREFIX = "-";
private static final String BUILD_PREFIX = "+"; private static final String BUILD_PREFIX = "+";
private static final Pattern SEMVER_PATTERN; private static final Pattern SEMVER_PATTERN;
static { static {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("^"); sb.append("^");
sb.append(NormalVersion.FORMAT); sb.append(NormalVersion.FORMAT);
sb.append("(?:"); sb.append("(?:");
@ -56,91 +56,89 @@ public class Version implements Comparable<Version> {
sb.append(AlphaNumericVersion.FORMAT); sb.append(AlphaNumericVersion.FORMAT);
sb.append(")?"); sb.append(")?");
sb.append("$"); sb.append("$");
SEMVER_PATTERN = Pattern.compile(sb.toString()); SEMVER_PATTERN = Pattern.compile(sb.toString());
} }
Version( Version(
NormalVersion normal, NormalVersion normal,
AlphaNumericVersion preRelease, AlphaNumericVersion preRelease,
AlphaNumericVersion build AlphaNumericVersion build
) { ) {
this.normal = normal; this.normal = normal;
this.preRelease = preRelease; this.preRelease = preRelease;
this.build = build; this.build = build;
} }
public static Version valueOf(String value) { public static Version valueOf(String value) {
Matcher matcher = SEMVER_PATTERN.matcher(value); Matcher matcher = SEMVER_PATTERN.matcher(value);
if (!matcher.matches()) { if (!matcher.matches()) {
throw new IllegalArgumentException( throw new IllegalArgumentException("Illegal version format");
"Illegal version format"
);
} }
NormalVersion normal = new NormalVersion( NormalVersion normal = new NormalVersion(
Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(1)),
Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(2)),
Integer.parseInt(matcher.group(3)) Integer.parseInt(matcher.group(3))
); );
AlphaNumericVersion preRelease = AlphaNumericVersion preRelease =
(matcher.group(4) != null) ? (matcher.group(4) != null) ?
new AlphaNumericVersion(matcher.group(4)) : new AlphaNumericVersion(matcher.group(4)) :
null; null;
AlphaNumericVersion build = AlphaNumericVersion build =
(matcher.group(5) != null) ? (matcher.group(5) != null) ?
new AlphaNumericVersion(matcher.group(5)) : new AlphaNumericVersion(matcher.group(5)) :
null; null;
return new Version(normal, preRelease, build); return new Version(normal, preRelease, build);
} }
public int getMajorVersion() { public int getMajorVersion() {
return normal.getMajor(); return normal.getMajor();
} }
public int getMinorVersion() { public int getMinorVersion() {
return normal.getMinor(); return normal.getMinor();
} }
public int getPatchVersion() { public int getPatchVersion() {
return normal.getPatch(); return normal.getPatch();
} }
public String getNormalVersion() { public String getNormalVersion() {
return normal.toString(); return normal.toString();
} }
public String getPreReleaseVersion() { public String getPreReleaseVersion() {
return (preRelease != null) ? preRelease.toString() : ""; return (preRelease != null) ? preRelease.toString() : "";
} }
public String getBuildVersion() { public String getBuildVersion() {
return (build != null) ? build.toString() : ""; return (build != null) ? build.toString() : "";
} }
public boolean greaterThan(Version other) { public boolean greaterThan(Version other) {
return compareTo(other) > 0 ? true : false; return compareTo(other) > 0 ? true : false;
} }
public boolean greaterThanOrEqualsTo(Version other) { public boolean greaterThanOrEqualsTo(Version other) {
return compareTo(other) >= 0 ? true : false; return compareTo(other) >= 0 ? true : false;
} }
public boolean lessThan(Version other) { public boolean lessThan(Version other) {
return compareTo(other) < 0 ? true : false; return compareTo(other) < 0 ? true : false;
} }
public boolean lessThanOrEqualsTo(Version other) { public boolean lessThanOrEqualsTo(Version other) {
return compareTo(other) <= 0 ? true : false; return compareTo(other) <= 0 ? true : false;
} }
@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
if (this == other) { if (this == other) {
return true; return true;
} }
if (!(other instanceof Version)) { if (!(other instanceof Version)) {
return false; return false;
@ -156,7 +154,7 @@ public class Version implements Comparable<Version> {
hash = 97 * hash + (build != null ? build.hashCode() : 0); hash = 97 * hash + (build != null ? build.hashCode() : 0);
return hash; return hash;
} }
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(getNormalVersion()); StringBuilder sb = new StringBuilder(getNormalVersion());
@ -170,7 +168,7 @@ public class Version implements Comparable<Version> {
} }
return sb.toString(); return sb.toString();
} }
@Override @Override
public int compareTo(Version other) { public int compareTo(Version other) {
int result = normal.compareTo(other.normal); int result = normal.compareTo(other.normal);
@ -182,23 +180,31 @@ public class Version implements Comparable<Version> {
} }
return result; return result;
} }
private int comparePreReleases(Version other) { private int comparePreReleases(Version other) {
int result = 0; int result = 0;
if (preRelease != null && other.preRelease != null) { if (preRelease != null && other.preRelease != null) {
result = preRelease.compareTo(other.preRelease); result = preRelease.compareTo(other.preRelease);
} else if (preRelease == null ^ other.preRelease == null) { } else if (preRelease == null ^ other.preRelease == null) {
result = preRelease == null ? 1 : -1; /**
* Pre-release versions satisfy but have a lower precedence
* than the associated normal version. (SemVer p.9)
*/
result = (preRelease == null) ? 1 : -1;
} }
return result; return result;
} }
private int compareBuilds(Version other) { private int compareBuilds(Version other) {
int result = 0; int result = 0;
if (build != null && other.build != null) { if (build != null && other.build != null) {
result = build.compareTo(other.build); result = build.compareTo(other.build);
} else if (build == null ^ other.build == null) { } else if (build == null ^ other.build == null) {
result = build == null ? -1 : 1; /**
* Build versions satisfy and have a higher precedence
* than the associated normal version. (SemVer p.10)
*/
result = (build == null) ? -1 : 1;
} }
return result; return result;
} }

View File

@ -34,16 +34,16 @@ import org.junit.runner.RunWith;
*/ */
@RunWith(Enclosed.class) @RunWith(Enclosed.class)
public class AlphaNumericVersionTest { public class AlphaNumericVersionTest {
public static class CoreFunctionalityTest { public static class CoreFunctionalityTest {
@Test @Test
public void mustConsistOfDotSeparatedIdentifiersOfAlphaNumericsAndHyphen() { public void mustConsistOfDotSeparatedIdentifiersOfAlphaNumericsAndHyphen() {
String[] invalidVersions = { String[] invalidVersions = {
null, null,
"", "",
"123!", "123!",
"1a:2b:3c", "1a:2b:3c",
"123,abc,123", "123,abc,123",
}; };
for (String ver : invalidVersions) { for (String ver : invalidVersions) {
@ -88,14 +88,14 @@ public class AlphaNumericVersionTest {
public void shouldOverrideEqualsMethod() { public void shouldOverrideEqualsMethod() {
AlphaNumericVersion v1 = new AlphaNumericVersion("alpha.123"); AlphaNumericVersion v1 = new AlphaNumericVersion("alpha.123");
AlphaNumericVersion v2 = new AlphaNumericVersion("alpha.123"); AlphaNumericVersion v2 = new AlphaNumericVersion("alpha.123");
AlphaNumericVersion v3 = new AlphaNumericVersion("alpha.321"); AlphaNumericVersion v3 = new AlphaNumericVersion("alpha.321");
assertTrue(v1.equals(v2)); assertTrue(v1.equals(v2));
assertFalse(v1.equals(v3)); assertFalse(v1.equals(v3));
} }
} }
public static class EqualsMethodTest { public static class EqualsMethodTest {
@Test @Test
public void shouldBeReflexive() { public void shouldBeReflexive() {
AlphaNumericVersion v = new AlphaNumericVersion("alpha.123"); AlphaNumericVersion v = new AlphaNumericVersion("alpha.123");
@ -142,9 +142,9 @@ public class AlphaNumericVersionTest {
assertFalse(v1.equals(v2)); assertFalse(v1.equals(v2));
} }
} }
public static class HashCodeMethodTest { public static class HashCodeMethodTest {
@Test @Test
public void shouldReturnSameHashCodeIfVersionsAreEqual() { public void shouldReturnSameHashCodeIfVersionsAreEqual() {
AlphaNumericVersion v1 = new AlphaNumericVersion("alpha.123"); AlphaNumericVersion v1 = new AlphaNumericVersion("alpha.123");
@ -153,9 +153,9 @@ public class AlphaNumericVersionTest {
assertEquals(v1.hashCode(), v2.hashCode()); assertEquals(v1.hashCode(), v2.hashCode());
} }
} }
public static class ToStringMethodTest { public static class ToStringMethodTest {
@Test @Test
public void shouldReturnStringRepresentation() { public void shouldReturnStringRepresentation() {
String value = "beta.abc.def"; String value = "beta.abc.def";

View File

@ -34,9 +34,9 @@ import org.junit.runner.RunWith;
*/ */
@RunWith(Enclosed.class) @RunWith(Enclosed.class)
public class NormalVersionTest { public class NormalVersionTest {
public static class CoreFunctionalityTest { public static class CoreFunctionalityTest {
@Test @Test
public void mustConsistOfMajorMinorAndPatchVersions() { public void mustConsistOfMajorMinorAndPatchVersions() {
NormalVersion v = new NormalVersion(1, 2, 3); NormalVersion v = new NormalVersion(1, 2, 3);
@ -44,13 +44,13 @@ public class NormalVersionTest {
assertEquals(2, v.getMinor()); assertEquals(2, v.getMinor());
assertEquals(3, v.getPatch()); assertEquals(3, v.getPatch());
} }
@Test @Test
public void mustTakeTheFormOfXDotYDotZWhereXyzAreNonNegativeIntegers() { public void mustTakeTheFormOfXDotYDotZWhereXyzAreNonNegativeIntegers() {
NormalVersion v = new NormalVersion(1, 2, 3); NormalVersion v = new NormalVersion(1, 2, 3);
assertEquals("1.2.3", v.toString()); assertEquals("1.2.3", v.toString());
} }
@Test @Test
public void shouldAcceptOnlyNonNegativeMajorMinorAndPatchVersions() { public void shouldAcceptOnlyNonNegativeMajorMinorAndPatchVersions() {
int[][] invalidVersions = {{-1, 2, 3}, {1, -2, 3}, {1, 2, -3}}; int[][] invalidVersions = {{-1, 2, 3}, {1, -2, 3}, {1, 2, -3}};
@ -67,7 +67,7 @@ public class NormalVersionTest {
fail("Major, minor and patch versions MUST be non-negative integers."); fail("Major, minor and patch versions MUST be non-negative integers.");
} }
} }
@Test @Test
public void mustIncreaseEachElementNumericallyByIncrementsOfOne() { public void mustIncreaseEachElementNumericallyByIncrementsOfOne() {
int major = 1, minor = 2, patch = 3; int major = 1, minor = 2, patch = 3;
@ -79,7 +79,7 @@ public class NormalVersionTest {
v.incrementMajor(); v.incrementMajor();
assertEquals(major + 1, v.getMajor()); assertEquals(major + 1, v.getMajor());
} }
@Test @Test
public void mustResetMinorAndPatchToZeroWhenMajorIsIncremented() { public void mustResetMinorAndPatchToZeroWhenMajorIsIncremented() {
NormalVersion v = new NormalVersion(1, 2, 3); NormalVersion v = new NormalVersion(1, 2, 3);
@ -88,7 +88,7 @@ public class NormalVersionTest {
assertEquals(0, v.getMinor()); assertEquals(0, v.getMinor());
assertEquals(0, v.getPatch()); assertEquals(0, v.getPatch());
} }
@Test @Test
public void mustResetPatchToZeroWhenMinorIsIncremented() { public void mustResetPatchToZeroWhenMinorIsIncremented() {
NormalVersion v = new NormalVersion(1, 2, 3); NormalVersion v = new NormalVersion(1, 2, 3);
@ -97,7 +97,7 @@ public class NormalVersionTest {
assertEquals(3, v.getMinor()); assertEquals(3, v.getMinor());
assertEquals(0, v.getPatch()); assertEquals(0, v.getPatch());
} }
@Test @Test
public void mustCompareMajorMinorAndPatchNumerically() { public void mustCompareMajorMinorAndPatchNumerically() {
NormalVersion v = new NormalVersion(1, 2, 3); NormalVersion v = new NormalVersion(1, 2, 3);
@ -105,7 +105,7 @@ public class NormalVersionTest {
assertTrue(0 == v.compareTo(new NormalVersion(1, 2, 3))); assertTrue(0 == v.compareTo(new NormalVersion(1, 2, 3)));
assertTrue(0 > v.compareTo(new NormalVersion(1, 2, 4))); assertTrue(0 > v.compareTo(new NormalVersion(1, 2, 4)));
} }
@Test @Test
public void shouldOverrideEqualsMethod() { public void shouldOverrideEqualsMethod() {
NormalVersion v1 = new NormalVersion(1, 2, 3); NormalVersion v1 = new NormalVersion(1, 2, 3);
@ -114,7 +114,7 @@ public class NormalVersionTest {
assertTrue(v1.equals(v2)); assertTrue(v1.equals(v2));
assertFalse(v1.equals(v3)); assertFalse(v1.equals(v3));
} }
@Test @Test
public void shouldHaveStaticFactoryMethod() { public void shouldHaveStaticFactoryMethod() {
NormalVersion v = NormalVersion.valueOf("1.2.3"); NormalVersion v = NormalVersion.valueOf("1.2.3");
@ -123,15 +123,15 @@ public class NormalVersionTest {
assertEquals(3, v.getPatch()); assertEquals(3, v.getPatch());
} }
} }
public static class EqualsMethodTest { public static class EqualsMethodTest {
@Test @Test
public void shouldBeReflexive() { public void shouldBeReflexive() {
NormalVersion v = new NormalVersion(1, 2, 3); NormalVersion v = new NormalVersion(1, 2, 3);
assertTrue(v.equals(v)); assertTrue(v.equals(v));
} }
@Test @Test
public void shouldBeSymmetric() { public void shouldBeSymmetric() {
NormalVersion v1 = new NormalVersion(1, 2, 3); NormalVersion v1 = new NormalVersion(1, 2, 3);
@ -172,9 +172,9 @@ public class NormalVersionTest {
assertFalse(v1.equals(v2)); assertFalse(v1.equals(v2));
} }
} }
public static class HashCodeMethodTest { public static class HashCodeMethodTest {
@Test @Test
public void shouldReturnSameHashCodeIfVersionsAreEqual() { public void shouldReturnSameHashCodeIfVersionsAreEqual() {
NormalVersion v1 = new NormalVersion(1, 2, 3); NormalVersion v1 = new NormalVersion(1, 2, 3);
@ -183,9 +183,9 @@ public class NormalVersionTest {
assertEquals(v1.hashCode(), v2.hashCode()); assertEquals(v1.hashCode(), v2.hashCode());
} }
} }
public static class ToStringMethodTest { public static class ToStringMethodTest {
@Test @Test
public void shouldReturnStringRepresentation() { public void shouldReturnStringRepresentation() {
NormalVersion v = new NormalVersion(1, 2, 3); NormalVersion v = new NormalVersion(1, 2, 3);

View File

@ -34,9 +34,9 @@ import org.junit.runner.RunWith;
*/ */
@RunWith(Enclosed.class) @RunWith(Enclosed.class)
public class VersionTest { public class VersionTest {
public static class CoreFunctionalityTest { public static class CoreFunctionalityTest {
@Test @Test
public void mayHavePreReleaseFollowingPatchAppendedWithHyphen() { public void mayHavePreReleaseFollowingPatchAppendedWithHyphen() {
Version v = Version.valueOf("1.2.3-alpha"); Version v = Version.valueOf("1.2.3-alpha");
@ -121,16 +121,16 @@ public class VersionTest {
@Test @Test
public void shouldCorrectlyCompareAllVersionsFromSpecification() { public void shouldCorrectlyCompareAllVersionsFromSpecification() {
String[] versions = { String[] versions = {
"1.0.0-alpha", "1.0.0-alpha",
"1.0.0-alpha.1", "1.0.0-alpha.1",
"1.0.0-beta.2", "1.0.0-beta.2",
"1.0.0-beta.11", "1.0.0-beta.11",
"1.0.0-rc.1", "1.0.0-rc.1",
"1.0.0-rc.1+build.1", "1.0.0-rc.1+build.1",
"1.0.0", "1.0.0",
"1.0.0+0.3.7", "1.0.0+0.3.7",
"1.3.7+build", "1.3.7+build",
"1.3.7+build.2.b8f12d7", "1.3.7+build.2.b8f12d7",
"1.3.7+build.11.e0f985a" "1.3.7+build.11.e0f985a"
}; };
for (int i = 1; i < versions.length; i++) { for (int i = 1; i < versions.length; i++) {
@ -139,7 +139,7 @@ public class VersionTest {
assertTrue(v1.lessThan(v2)); assertTrue(v1.lessThan(v2));
} }
} }
@Test @Test
public void shouldHaveStaticFactoryMethod() { public void shouldHaveStaticFactoryMethod() {
Version v = Version.valueOf("1.0.0-rc.1+build.1"); Version v = Version.valueOf("1.0.0-rc.1+build.1");
@ -151,9 +151,9 @@ public class VersionTest {
assertEquals("build.1", v.getBuildVersion()); assertEquals("build.1", v.getBuildVersion());
} }
} }
public static class EqualsMethodTest { public static class EqualsMethodTest {
@Test @Test
public void shouldBeReflexive() { public void shouldBeReflexive() {
Version v1 = Version.valueOf("2.3.7"); Version v1 = Version.valueOf("2.3.7");
@ -200,9 +200,9 @@ public class VersionTest {
assertFalse(v1.equals(v2)); assertFalse(v1.equals(v2));
} }
} }
public static class HashCodeMethodTest { public static class HashCodeMethodTest {
@Test @Test
public void shouldReturnSameHashCodeIfVersionsAreEqual() { public void shouldReturnSameHashCodeIfVersionsAreEqual() {
Version v1 = Version.valueOf("2.3.7"); Version v1 = Version.valueOf("2.3.7");
@ -211,9 +211,9 @@ public class VersionTest {
assertEquals(v1.hashCode(), v2.hashCode()); assertEquals(v1.hashCode(), v2.hashCode());
} }
} }
public static class ToStringMethodTest { public static class ToStringMethodTest {
@Test @Test
public void shouldReturnStringRepresentation() { public void shouldReturnStringRepresentation() {
String value = "1.2.3-beta+build"; String value = "1.2.3-beta+build";