Implement fluent interface for Version.Builder
This commit is contained in:
parent
988059b444
commit
371d100065
|
@ -106,27 +106,33 @@ public class Version implements Comparable<Version> {
|
|||
* Sets the normal version.
|
||||
*
|
||||
* @param normal the string representation of the normal version
|
||||
* @return this builder instance
|
||||
*/
|
||||
public void setNormalVersion(String normal) {
|
||||
public Builder setNormalVersion(String normal) {
|
||||
this.normal = normal;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the pre-release version.
|
||||
*
|
||||
* @param preRelease the string representation of the pre-release version
|
||||
* @return this builder instance
|
||||
*/
|
||||
public void setPreReleaseVersion(String preRelease) {
|
||||
public Builder setPreReleaseVersion(String preRelease) {
|
||||
this.preRelease = preRelease;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the build metadata.
|
||||
*
|
||||
* @param build the string representation of the build metadata
|
||||
* @return this builder instance
|
||||
*/
|
||||
public void setBuildMetadata(String build) {
|
||||
public Builder setBuildMetadata(String build) {
|
||||
this.build = build;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -429,6 +429,17 @@ public class VersionTest {
|
|||
builder.setBuildMetadata("build");
|
||||
assertEquals(Version.valueOf("1.0.0-alpha+build"), builder.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldImplementFluentInterface() {
|
||||
Version.Builder builder = new Version.Builder();
|
||||
Version version = builder
|
||||
.setNormalVersion("1.0.0")
|
||||
.setPreReleaseVersion("alpha")
|
||||
.setBuildMetadata("build")
|
||||
.build();
|
||||
assertEquals(Version.valueOf("1.0.0-alpha+build"), version);
|
||||
}
|
||||
}
|
||||
|
||||
public static class BuildAwareOrderTest {
|
||||
|
|
Loading…
Reference in New Issue
Block a user