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