diff options
Diffstat (limited to 'api')
-rwxr-xr-x | api/src/main/java/org/semver/Version.java | 5 | ||||
-rwxr-xr-x | api/src/test/java/org/semver/VersionTest.java | 15 |
2 files changed, 18 insertions, 2 deletions
diff --git a/api/src/main/java/org/semver/Version.java b/api/src/main/java/org/semver/Version.java index a6871b5..b4c76ee 100755 --- a/api/src/main/java/org/semver/Version.java +++ b/api/src/main/java/org/semver/Version.java @@ -24,6 +24,7 @@ import javax.annotation.Nonnegative; import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.apache.commons.lang.StringUtils; /** * @@ -40,7 +41,7 @@ public final class Version implements Comparable<Version> { MAJOR, MINOR, PATCH, SPECIAL; } - private static final String FORMAT = "(\\d)+\\.(\\d)+(?:\\.)?(\\d)*(?:\\.|-)?([A-Za-z][0-9A-Za-z-]*)?"; + private static final String FORMAT = "(\\d+)\\.(\\d+)(?:\\.)?(\\d*)(?:\\.|-)?([A-Za-z][0-9A-Za-z-]*)?"; private static final Pattern PATTERN = Pattern.compile(Version.FORMAT); private static final String SNAPSHOT_VERSION_SUFFIX = "-SNAPSHOT"; @@ -88,7 +89,7 @@ public final class Version implements Comparable<Version> { final int minor = Integer.valueOf(matcher.group(2)); final int patch; final String patchMatch = matcher.group(3); - if (patchMatch != null) { + if (StringUtils.isNotEmpty(patchMatch)) { patch = Integer.valueOf(patchMatch); } else { patch = 0; diff --git a/api/src/test/java/org/semver/VersionTest.java b/api/src/test/java/org/semver/VersionTest.java index 9ba6e2d..a7aa0e4 100755 --- a/api/src/test/java/org/semver/VersionTest.java +++ b/api/src/test/java/org/semver/VersionTest.java @@ -72,6 +72,21 @@ public class VersionTest { } @Test + public void shouldMajorBeCorrectlyIncremented() { + Assert.assertEquals(Version.parse("10.0.0"), Version.parse("9.0.0").next(Version.Element.MAJOR)); + } + + @Test + public void shouldMinorBeCorrectlyIncremented() { + Assert.assertEquals(Version.parse("0.10.0"), Version.parse("0.9.0").next(Version.Element.MINOR)); + } + + @Test + public void shouldPatchBeCorrectlyIncremented() { + Assert.assertEquals(Version.parse("0.0.10"), Version.parse("0.0.9").next(Version.Element.PATCH)); + } + + @Test public void shouldDevelopmentBeInDevelopment() { Assert.assertTrue(Version.parse("0.1.1").isInDevelopment()); Assert.assertFalse(Version.parse("1.1.1").isInDevelopment()); |