Skip to content

Commit ed30316

Browse files
committed
toSnapshot() and its test added
1 parent e6199d0 commit ed30316

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ public String toSnapshotString() {
144144
return prefix + minor + (patch.isEmpty() ? "" : "." + patch) + SNAPSHOT;
145145
}
146146

147+
public Version toSnapshot() {
148+
return new Version(toSnapshotString());
149+
}
150+
147151
public String toReleaseString() {
148152
if (!StringUtils.isNumeric(minor)) {
149153
return verStr;

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
package org.scm4j.commons;
22

3-
import static org.junit.Assert.assertEquals;
4-
import static org.junit.Assert.assertFalse;
5-
import static org.junit.Assert.assertThat;
6-
import static org.junit.Assert.assertTrue;
7-
import static org.junit.Assert.fail;
8-
3+
import nl.jqno.equalsverifier.EqualsVerifier;
94
import org.junit.Test;
105

11-
import nl.jqno.equalsverifier.EqualsVerifier;
6+
import static org.junit.Assert.*;
127

138
public class VersionTest {
149

@@ -172,4 +167,13 @@ public void toSnapshotString() {
172167
assertEquals("11-SNAPSHOT", new Version("11").toSnapshotString());
173168
assertEquals("asd-SNAPSHOT", new Version("asd").toSnapshotString());
174169
}
170+
171+
@Test
172+
public void toSnapshot() {
173+
assertEquals(new Version("11.21.31.41-SNAPSHOT"), new Version("11.21.31.41").toSnapshot());
174+
assertEquals(new Version("11.21.31.41-SNAPSHOT"), new Version("11.21.31.41-SNAPSHOT").toSnapshot());
175+
assertEquals(new Version("-SNAPSHOT"), new Version("").toSnapshot());
176+
assertEquals(new Version("11-SNAPSHOT"), new Version("11").toSnapshot());
177+
assertEquals(new Version("asd-SNAPSHOT"), new Version("asd").toSnapshot());
178+
}
175179
}

0 commit comments

Comments
 (0)