Create setters for Pre-release version & Build metadata
This commit is contained in:
parent
5c39ab15d8
commit
98abdb4c02
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -203,15 +203,45 @@ public class VersionTest {
|
|||
assertEquals("1.2.4-beta", patch2.toString());
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user