File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
main/java/org/scm4j/commons
test/java/org/scm4j/commons Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments