Skip to content

Commit

Permalink
Minor tweaking post #1050
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 18, 2023
1 parent cd513f4 commit 321ef00
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 23 deletions.
4 changes: 4 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,7 @@ Jonas Konrad (yawkat@github)
Carter Kozak (carterkozak@github)
* Contributed #1015: `JsonFactory` implementations should respect `CANONICALIZE_FIELD_NAMES`
(2.15.1)

Armin Samii (artoonie@github)
* Contributed #1050: Compare `_snapshotInfo` in `Version`
(2.16.0)
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ a pure JSON library.
#1041: Start using AssertJ in unit tests
#1042: Allow configuring spaces before and/or after the colon in `DefaultPrettyPrinter`
(contributed by @digulla)
#1050: Compare `_snapshotInfo` in `Version`
(contributed by @artoonie)

2.15.2 (30-May-2023)

Expand Down
20 changes: 11 additions & 9 deletions src/main/java/com/fasterxml/jackson/core/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,17 @@ public int compareTo(Version other)
if (diff == 0) {
diff = _patchLevel - other._patchLevel;
if (diff == 0) {
if (isSnapshot() && other.isSnapshot()) {
diff = _snapshotInfo.compareTo(other._snapshotInfo);
} else if (isSnapshot() && !other.isSnapshot()) {
diff = -1;
} else if (!isSnapshot() && other.isSnapshot()) {
diff = 1;
} else {
diff = 0;
}
if (isSnapshot()) {
if (other.isSnapshot()) {
diff = _snapshotInfo.compareTo(other._snapshotInfo);
} else {
diff = -1;
}
} else if (other.isSnapshot()) {
diff = 1;
} else {
diff = 0;
}
}
}
}
Expand Down
36 changes: 25 additions & 11 deletions src/test/java/com/fasterxml/jackson/core/VersionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@
* Unit tests for class {@link Version}.
*
**/
public class VersionTest{
public class VersionTest
{
@Test
public void testEqualsAndHashCode() {
Version version1 = new Version(1, 2, 3, "", "", "");
Version version2 = new Version(1, 2, 3, "", "", "");

assertEquals(version1, version2);
assertEquals(version2, version1);

assertEquals(version1.hashCode(), version2.hashCode());
}

@Test
public void testCompareToOne() {
Expand Down Expand Up @@ -54,33 +65,36 @@ public void testCompareToAndCreatesVersionTaking6ArgumentsAndUnknownVersion() {

@Test
public void testCompareToSnapshotSame() {
Version version = new Version(0, 0, 0, "alpha");
Version versionTwo = new Version(0, 0, 0, "alpha");
Version version = new Version(0, 0, 0, "alpha", "com.fasterxml", "bogus");
Version versionTwo = new Version(0, 0, 0, "alpha", "com.fasterxml", "bogus");

assertEquals(0, version.compareTo(versionTwo));
}

@Test
public void testCompareToSnapshotDifferent() {
Version version = new Version(0, 0, 0, "alpha");
Version versionTwo = new Version(0, 0, 0, "beta");
Version version = new Version(0, 0, 0, "alpha", "com.fasterxml", "bogus");
Version versionTwo = new Version(0, 0, 0, "beta", "com.fasterxml", "bogus");

assertTrue(version.compareTo(versionTwo) < 0);
assertTrue(versionTwo.compareTo(version) > 0);
}

@Test
public void testCompareWhenOnlyFirstHasSnapshot() {
Version version = new Version(0, 0, 0, "beta");
Version versionTwo = new Version(0, 0, 0, null);
Version version = new Version(0, 0, 0, "beta", "com.fasterxml", "bogus");
Version versionTwo = new Version(0, 0, 0, null, "com.fasterxml", "bogus");

assertEquals(-1, version.compareTo(versionTwo));
assertTrue(version.compareTo(versionTwo) < 0);
assertTrue(versionTwo.compareTo(version) > 0);
}

@Test
public void testCompareWhenOnlySecondHasSnapshot() {
Version version = new Version(0, 0, 0, "");
Version versionTwo = new Version(0, 0, 0, "beta");
Version version = new Version(0, 0, 0, "", "com.fasterxml", "bogus");
Version versionTwo = new Version(0, 0, 0, "beta", "com.fasterxml", "bogus");

assertEquals(1, version.compareTo(versionTwo));
assertTrue(version.compareTo(versionTwo) > 0);
assertTrue(versionTwo.compareTo(version) < 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
/**
* Unit tests for class {@link VersionUtil}.
*
* @date 2017-07-31
* @see VersionUtil
**/
public class VersionUtilTest {
*/
public class VersionUtilTest
{
@Test
public void testParseVersionSimple() {
Version v = VersionUtil.parseVersion("1.2.3-SNAPSHOT", "group", "artifact");
assertEquals("group/artifact/1.2.3-SNAPSHOT", v.toFullString());
}

@Test
public void testParseVersionPartReturningPositive() {
Expand Down

0 comments on commit 321ef00

Please sign in to comment.