WineryVersion implements Comparable<WineryVersion> { @Override @ADR(19) public int compareTo(WineryVersion o) { if (Objects.isNull(o)) { return 1; } int cVersion = this.componentVersion.compareToIgnoreCase(o.componentVersion); if (cVersion < 0) { return -1; } else if (cVersion > 0) { return 1; } if (this.wineryVersion < o.wineryVersion) { return -1; } else if (this.wineryVersion > o.wineryVersion) { return 1; } if (this.wineryVersion > 0 && this.workInProgressVersion == 0) { return 1; } else if (o.wineryVersion > 0 && o.workInProgressVersion == 0) { return -1; } if (this.workInProgressVersion < o.workInProgressVersion) { return -1; } else if (this.workInProgressVersion > o.workInProgressVersion) { return 1; } return 0; } WineryVersion();  WineryVersion(String componentVersion, int wineryVersion, int workInProgressVersion); String getComponentVersion(); void setComponentVersion(String componentVersion); int getWineryVersion(); void setWineryVersion(int wineryVersion); int getWorkInProgressVersion(); void setWorkInProgressVersion(int workInProgressVersion); boolean isCurrentVersion(); void setCurrentVersion(boolean currentVersion); boolean isLatestVersion(); void setLatestVersion(boolean latestVersion); boolean isEditable(); void setEditable(boolean editable); boolean isReleasable(); void setReleasable(boolean releasable); @JsonIgnore boolean isVersionedInWinery(); @Override @ADR(19) int compareTo(WineryVersion o); @Override String toString(); static String WINERY_NAME_FROM_VERSION_SEPARATOR; static String WINERY_VERSION_SEPARATOR; static String WINERY_VERSION_PREFIX; static String WINERY_WIP_VERSION_PREFIX; }
@Test public void testCompareToSmallerComponentVersion() { WineryVersion smaller = new WineryVersion("1.0.0", 1, 1); WineryVersion greater = new WineryVersion("1.0.1", 1, 1); assertEquals(1, greater.compareTo(smaller)); }
@Test public void testCompareToSmallerWineryVersion() { WineryVersion smaller = new WineryVersion("1.0.0", 1, 1); WineryVersion greater = new WineryVersion("1.0.0", 2, 1); assertEquals(1, greater.compareTo(smaller)); }
@Test public void testCompareToSmallerWipVersion() { WineryVersion smaller = new WineryVersion("1.0.0", 1, 1); WineryVersion greater = new WineryVersion("1.0.0", 1, 5); assertEquals(1, greater.compareTo(smaller)); }
@Test public void testCompareToGreaterComponentVersion() { WineryVersion smaller = new WineryVersion("1.0.0", 7, 1); WineryVersion greater = new WineryVersion("1.0.1", 1, 6); assertEquals(-1, smaller.compareTo(greater)); }
@Test public void testCompareToGreaterWineryVersion() { WineryVersion smaller = new WineryVersion("1.0.0", 1, 1); WineryVersion greater = new WineryVersion("1.0.0", 9, 5); assertEquals(-1, smaller.compareTo(greater)); }
@Test public void testCompareToGreaterWipVersion() { WineryVersion smaller = new WineryVersion("1.0.0", 1, 1); WineryVersion greater = new WineryVersion("1.0.0", 6, 6); assertEquals(-1, smaller.compareTo(greater)); }
@Test public void testCompareToEqualVersion() { WineryVersion smaller = new WineryVersion("1.6.3", 4, 8); WineryVersion greater = new WineryVersion("1.6.3", 4, 8); assertEquals(0, smaller.compareTo(greater)); }
@Test public void testCompareToWipVersionShouldBeLessThanActualWineryRelease() { WineryVersion smaller = new WineryVersion("1.0.0", 6, 6); WineryVersion greater = new WineryVersion("1.0.0", 6, 0); assertEquals(-1, smaller.compareTo(greater)); assertEquals(1, greater.compareTo(smaller)); }