Skip to content

Commit 11aaf86

Browse files
committed
setPacth() method added
1 parent f251b20 commit 11aaf86

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/main/java/org/scm4j/commons/Version.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,11 @@ public Version setMinor(String minor) {
212212
return new Version(prefix + minor + (patch.isEmpty() ? "" : "." + patch) + snapshot);
213213

214214
}
215+
216+
public Version setPatch(String patch) {
217+
if (!isSemantic) {
218+
throw new IllegalStateException("can not set patch for non-semantic version");
219+
}
220+
return new Version(prefix + minor + (patch.isEmpty() ? "" : "." + patch) + snapshot);
221+
}
215222
}

src/test/java/org/scm4j/commons/VersionTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,25 @@ public void testSetMinor() {
205205
}
206206
assertEquals(new Version("14-SNAPSHOT"), new Version("12-SNAPSHOT").setMinor("14"));
207207
}
208+
209+
@Test
210+
public void testSetPatch() {
211+
assertEquals("12.13.14.0-SNAPSHOT", new Version("12.13.14.15-SNAPSHOT").setPatch("0").toString());
212+
assertEquals("12.13.14.0", new Version("12.13.14.15").setPatch("0").toString());
213+
assertEquals("12.13.0", new Version("12.13.14").setPatch("0").toString());
214+
assertEquals("12.0", new Version("12.13").setPatch("0").toString());
215+
assertEquals("12.0", new Version("12").setPatch("0").toString());
216+
try {
217+
new Version("").setPatch("0");
218+
fail();
219+
} catch (IllegalStateException e) {
220+
}
221+
try {
222+
new Version("non semantic").setPatch("0");
223+
fail();
224+
} catch (IllegalStateException e) {
225+
}
226+
227+
228+
}
208229
}

0 commit comments

Comments
 (0)