Skip to content

Commit 321ef00

Browse files
committed
Minor tweaking post #1050
1 parent cd513f4 commit 321ef00

File tree

5 files changed

+50
-23
lines changed

5 files changed

+50
-23
lines changed

release-notes/CREDITS-2.x

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,7 @@ Jonas Konrad (yawkat@github)
376376
Carter Kozak (carterkozak@github)
377377
* Contributed #1015: `JsonFactory` implementations should respect `CANONICALIZE_FIELD_NAMES`
378378
(2.15.1)
379+
380+
Armin Samii (artoonie@github)
381+
* Contributed #1050: Compare `_snapshotInfo` in `Version`
382+
(2.16.0)

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ a pure JSON library.
3131
#1041: Start using AssertJ in unit tests
3232
#1042: Allow configuring spaces before and/or after the colon in `DefaultPrettyPrinter`
3333
(contributed by @digulla)
34+
#1050: Compare `_snapshotInfo` in `Version`
35+
(contributed by @artoonie)
3436

3537
2.15.2 (30-May-2023)
3638

src/main/java/com/fasterxml/jackson/core/Version.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,17 @@ public int compareTo(Version other)
148148
if (diff == 0) {
149149
diff = _patchLevel - other._patchLevel;
150150
if (diff == 0) {
151-
if (isSnapshot() && other.isSnapshot()) {
152-
diff = _snapshotInfo.compareTo(other._snapshotInfo);
153-
} else if (isSnapshot() && !other.isSnapshot()) {
154-
diff = -1;
155-
} else if (!isSnapshot() && other.isSnapshot()) {
156-
diff = 1;
157-
} else {
158-
diff = 0;
159-
}
151+
if (isSnapshot()) {
152+
if (other.isSnapshot()) {
153+
diff = _snapshotInfo.compareTo(other._snapshotInfo);
154+
} else {
155+
diff = -1;
156+
}
157+
} else if (other.isSnapshot()) {
158+
diff = 1;
159+
} else {
160+
diff = 0;
161+
}
160162
}
161163
}
162164
}

src/test/java/com/fasterxml/jackson/core/VersionTest.java

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,18 @@
77
* Unit tests for class {@link Version}.
88
*
99
**/
10-
public class VersionTest{
10+
public class VersionTest
11+
{
12+
@Test
13+
public void testEqualsAndHashCode() {
14+
Version version1 = new Version(1, 2, 3, "", "", "");
15+
Version version2 = new Version(1, 2, 3, "", "", "");
16+
17+
assertEquals(version1, version2);
18+
assertEquals(version2, version1);
19+
20+
assertEquals(version1.hashCode(), version2.hashCode());
21+
}
1122

1223
@Test
1324
public void testCompareToOne() {
@@ -54,33 +65,36 @@ public void testCompareToAndCreatesVersionTaking6ArgumentsAndUnknownVersion() {
5465

5566
@Test
5667
public void testCompareToSnapshotSame() {
57-
Version version = new Version(0, 0, 0, "alpha");
58-
Version versionTwo = new Version(0, 0, 0, "alpha");
68+
Version version = new Version(0, 0, 0, "alpha", "com.fasterxml", "bogus");
69+
Version versionTwo = new Version(0, 0, 0, "alpha", "com.fasterxml", "bogus");
5970

6071
assertEquals(0, version.compareTo(versionTwo));
6172
}
6273

6374
@Test
6475
public void testCompareToSnapshotDifferent() {
65-
Version version = new Version(0, 0, 0, "alpha");
66-
Version versionTwo = new Version(0, 0, 0, "beta");
76+
Version version = new Version(0, 0, 0, "alpha", "com.fasterxml", "bogus");
77+
Version versionTwo = new Version(0, 0, 0, "beta", "com.fasterxml", "bogus");
6778

6879
assertTrue(version.compareTo(versionTwo) < 0);
80+
assertTrue(versionTwo.compareTo(version) > 0);
6981
}
7082

7183
@Test
7284
public void testCompareWhenOnlyFirstHasSnapshot() {
73-
Version version = new Version(0, 0, 0, "beta");
74-
Version versionTwo = new Version(0, 0, 0, null);
85+
Version version = new Version(0, 0, 0, "beta", "com.fasterxml", "bogus");
86+
Version versionTwo = new Version(0, 0, 0, null, "com.fasterxml", "bogus");
7587

76-
assertEquals(-1, version.compareTo(versionTwo));
88+
assertTrue(version.compareTo(versionTwo) < 0);
89+
assertTrue(versionTwo.compareTo(version) > 0);
7790
}
7891

7992
@Test
8093
public void testCompareWhenOnlySecondHasSnapshot() {
81-
Version version = new Version(0, 0, 0, "");
82-
Version versionTwo = new Version(0, 0, 0, "beta");
94+
Version version = new Version(0, 0, 0, "", "com.fasterxml", "bogus");
95+
Version versionTwo = new Version(0, 0, 0, "beta", "com.fasterxml", "bogus");
8396

84-
assertEquals(1, version.compareTo(versionTwo));
97+
assertTrue(version.compareTo(versionTwo) > 0);
98+
assertTrue(versionTwo.compareTo(version) < 0);
8599
}
86100
}

src/test/java/com/fasterxml/jackson/core/util/VersionUtilTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@
88
/**
99
* Unit tests for class {@link VersionUtil}.
1010
*
11-
* @date 2017-07-31
1211
* @see VersionUtil
13-
**/
14-
public class VersionUtilTest {
12+
*/
13+
public class VersionUtilTest
14+
{
15+
@Test
16+
public void testParseVersionSimple() {
17+
Version v = VersionUtil.parseVersion("1.2.3-SNAPSHOT", "group", "artifact");
18+
assertEquals("group/artifact/1.2.3-SNAPSHOT", v.toFullString());
19+
}
1520

1621
@Test
1722
public void testParseVersionPartReturningPositive() {

0 commit comments

Comments
 (0)