Skip to content

Commit

Permalink
Merge pull request #1 from tobiasdiez/ignore-version-in-dev-mode
Browse files Browse the repository at this point in the history
More test cases
  • Loading branch information
tobiasdiez authored Jun 29, 2016
2 parents a4f79ad + 550973a commit 5bea79e
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 21 deletions.
37 changes: 18 additions & 19 deletions src/main/java/net/sf/jabref/logic/util/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ public class Version {
private boolean isDevelopmentVersion = false;

/**
* @param version must be in form of X.X (eg 3.3; 3.4dev)
* @param version must be in form of X.X (e.g., 3.3; 3.4dev)
*/
public Version(String version) {
if (version == null || "".equals(version) || version.equals(BuildInfo.UNKNOWN_VERSION)) {
if ((version == null) || "".equals(version) || version.equals(BuildInfo.UNKNOWN_VERSION)) {
return;
}

Expand All @@ -65,9 +65,6 @@ public Version(String version) {

/**
* Grabs the latest release version from the JabRef GitHub repository
*
* @return
* @throws IOException
*/
public static Version getLatestVersion() throws IOException {
URLConnection connection = new URL(JABREF_GITHUB_URL).openConnection();
Expand All @@ -78,33 +75,29 @@ public static Version getLatestVersion() throws IOException {
}

/**
* @return true if this version is newer than the passed one
* @return true iff this version is newer than the passed one
*/
public boolean isNewerThan(Version otherVersion) {
Objects.requireNonNull(otherVersion);
if (Objects.equals(this, otherVersion)) {
return false;
}
if (this.getFullVersion().equals(BuildInfo.UNKNOWN_VERSION)) {
} else if (this.getFullVersion().equals(BuildInfo.UNKNOWN_VERSION)) {
return false;
}
if (otherVersion.getFullVersion().equals(BuildInfo.UNKNOWN_VERSION)) {
} else if (otherVersion.getFullVersion().equals(BuildInfo.UNKNOWN_VERSION)) {
return false;
}

if (this.getMajor() > otherVersion.getMajor()) {
} else if (this.getMajor() > otherVersion.getMajor()) {
return true;
}
if (this.getMajor() == otherVersion.getMajor()) {
} else if (this.getMajor() == otherVersion.getMajor()) {
if (this.getMinor() > otherVersion.getMinor()) {
return true;
}
if (this.getMinor() == otherVersion.getMinor() && this.getPatch() > otherVersion.getPatch()) {
} else if ((this.getMinor() == otherVersion.getMinor()) && (this.getPatch() > otherVersion.getPatch())) {
return true;
} else {
return false;
}
} else {
return false;
}

return false;
}

public String getFullVersion() {
Expand Down Expand Up @@ -150,8 +143,14 @@ public boolean equals(Object other) {
return this.getFullVersion().equals(otherVersion.getFullVersion());
}

@Override
public int hashCode() {
return getFullVersion().hashCode();
}

@Override
public String toString() {
return this.getFullVersion();
}

}
75 changes: 73 additions & 2 deletions src/test/java/net/sf/jabref/logic/util/version/VersionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,23 @@
public class VersionTest {

@Test
public void unknownVersion() {
Version version = new Version(BuildInfo.UNKNOWN_VERSION);
public void unknownVersionAsString() {
String versionText = BuildInfo.UNKNOWN_VERSION;
Version version = new Version(versionText);
assertEquals(BuildInfo.UNKNOWN_VERSION, version.getFullVersion());
}

@Test
public void unknownVersionAsNull() {
String versionText = null;
Version version = new Version(versionText);
assertEquals(BuildInfo.UNKNOWN_VERSION, version.getFullVersion());
}

@Test
public void unknownVersionAsEmptyString() {
String versionText = "";
Version version = new Version(versionText);
assertEquals(BuildInfo.UNKNOWN_VERSION, version.getFullVersion());
}

Expand Down Expand Up @@ -105,6 +120,27 @@ public void versionNewerThan() {
assertTrue(newerVersion.isNewerThan(olderVersion));
}

@Test
public void versionNotNewerThanSameVersion() {
Version version1 = new Version("4.2");
Version version2 = new Version("4.2");
assertFalse(version1.isNewerThan(version2));
}

@Test
public void concreteVersionNewerThanUnknownVersion() {
Version concreteVersion = new Version("4.2");
Version unknownVersion = new Version(BuildInfo.UNKNOWN_VERSION);
assertTrue(concreteVersion.isNewerThan(unknownVersion));
}

@Test
public void unknownVersionNotNewerThanConceteVersion() {
Version concreteVersion = new Version("4.2");
Version unknownVersion = new Version(BuildInfo.UNKNOWN_VERSION);
assertTrue(unknownVersion.isNewerThan(concreteVersion));
}

@Test
public void versionNewerThanDevTwoDigits() {
Version older = new Version("4.2");
Expand All @@ -126,6 +162,20 @@ public void versionNewerPatch() {
assertTrue(newer.isNewerThan(older));
}

@Test
public void versionNotNewerPatch() {
Version older = new Version("4.2.1");
Version newer = new Version("4.2.2");
assertFalse(older.isNewerThan(newer));
}

@Test
public void equalVersionsNotNewer() {
Version version1 = new Version("4.2.2");
Version version2 = new Version("4.2.2");
assertTrue(version1.isNewerThan(version2));
}

@Test
public void changelogWithTwoDigits(){
Version version = new Version("3.4");
Expand All @@ -138,4 +188,25 @@ public void changelogWithThreeDigits(){
assertEquals("https://github.com/JabRef/jabref/blob/v3.4.1/CHANGELOG.md", version.getChangelogUrl());
}

@Test
public void versionNotReplaced() {
String versionText = "${version}";
Version version = new Version(versionText);
assertEquals(BuildInfo.UNKNOWN_VERSION, version.getFullVersion());
}

@Test
public void versionNull() {
String versionText = null;
Version version = new Version(versionText);
assertEquals(BuildInfo.UNKNOWN_VERSION, version.getFullVersion());
}

@Test
public void versionEmpty() {
String versionText = "";
Version version = new Version(versionText);
assertEquals(BuildInfo.UNKNOWN_VERSION, version.getFullVersion());
}

}

0 comments on commit 5bea79e

Please sign in to comment.