Skip to content

Commit 1ebbe35

Browse files
committed
Merge branch 'master' into release/2
2 parents 5cafcaf + 483695d commit 1ebbe35

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

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

+8
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,12 @@ public Version toRelease() {
204204
}
205205
return new Version(prefix + minor + (patch.isEmpty() ? "" : "." + patch));
206206
}
207+
208+
public Version setMinor(String minor) {
209+
if (!isSemantic) {
210+
throw new IllegalStateException("can not set minor for non-semantic version");
211+
}
212+
return new Version(prefix + minor + (patch.isEmpty() ? "" : "." + patch) + snapshot);
213+
214+
}
207215
}

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

+20-1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,25 @@ public void testIsExact() {
184184
assertFalse(new Version("-SNAPSHOT").isExact());
185185
assertFalse(new Version("").isExact());
186186
assertFalse(new Version("dfgdfg-SNAPSHOT").isExact());
187-
187+
}
188+
189+
@Test
190+
public void testSetMinor() {
191+
assertEquals(new Version("12.13.14.15-SNAPSHOT"), new Version("12.13.13.15-SNAPSHOT").setMinor("14"));
192+
assertEquals(new Version("12.13.abc.15-SNAPSHOT"), new Version("12.13.13.15-SNAPSHOT").setMinor("abc"));
193+
assertEquals(new Version("12.13.abc.15"), new Version("12.13.13.15").setMinor("abc"));
194+
try {
195+
new Version("-SNAPSHOT").setMinor("14");
196+
fail();
197+
} catch (IllegalStateException e) {
198+
199+
}
200+
try {
201+
new Version("").setMinor("14");
202+
fail();
203+
} catch (IllegalStateException e) {
204+
205+
}
206+
assertEquals(new Version("14-SNAPSHOT"), new Version("12-SNAPSHOT").setMinor("14"));
188207
}
189208
}

0 commit comments

Comments
 (0)