Skip to content

Commit 5bea79e

Browse files
authored
Merge pull request #1 from tobiasdiez/ignore-version-in-dev-mode
More test cases
2 parents a4f79ad + 550973a commit 5bea79e

File tree

2 files changed

+91
-21
lines changed

2 files changed

+91
-21
lines changed

src/main/java/net/sf/jabref/logic/util/Version.java

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ public class Version {
4343
private boolean isDevelopmentVersion = false;
4444

4545
/**
46-
* @param version must be in form of X.X (eg 3.3; 3.4dev)
46+
* @param version must be in form of X.X (e.g., 3.3; 3.4dev)
4747
*/
4848
public Version(String version) {
49-
if (version == null || "".equals(version) || version.equals(BuildInfo.UNKNOWN_VERSION)) {
49+
if ((version == null) || "".equals(version) || version.equals(BuildInfo.UNKNOWN_VERSION)) {
5050
return;
5151
}
5252

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

6666
/**
6767
* Grabs the latest release version from the JabRef GitHub repository
68-
*
69-
* @return
70-
* @throws IOException
7168
*/
7269
public static Version getLatestVersion() throws IOException {
7370
URLConnection connection = new URL(JABREF_GITHUB_URL).openConnection();
@@ -78,33 +75,29 @@ public static Version getLatestVersion() throws IOException {
7875
}
7976

8077
/**
81-
* @return true if this version is newer than the passed one
78+
* @return true iff this version is newer than the passed one
8279
*/
8380
public boolean isNewerThan(Version otherVersion) {
8481
Objects.requireNonNull(otherVersion);
8582
if (Objects.equals(this, otherVersion)) {
8683
return false;
87-
}
88-
if (this.getFullVersion().equals(BuildInfo.UNKNOWN_VERSION)) {
84+
} else if (this.getFullVersion().equals(BuildInfo.UNKNOWN_VERSION)) {
8985
return false;
90-
}
91-
if (otherVersion.getFullVersion().equals(BuildInfo.UNKNOWN_VERSION)) {
86+
} else if (otherVersion.getFullVersion().equals(BuildInfo.UNKNOWN_VERSION)) {
9287
return false;
93-
}
94-
95-
if (this.getMajor() > otherVersion.getMajor()) {
88+
} else if (this.getMajor() > otherVersion.getMajor()) {
9689
return true;
97-
}
98-
if (this.getMajor() == otherVersion.getMajor()) {
90+
} else if (this.getMajor() == otherVersion.getMajor()) {
9991
if (this.getMinor() > otherVersion.getMinor()) {
10092
return true;
101-
}
102-
if (this.getMinor() == otherVersion.getMinor() && this.getPatch() > otherVersion.getPatch()) {
93+
} else if ((this.getMinor() == otherVersion.getMinor()) && (this.getPatch() > otherVersion.getPatch())) {
10394
return true;
95+
} else {
96+
return false;
10497
}
98+
} else {
99+
return false;
105100
}
106-
107-
return false;
108101
}
109102

110103
public String getFullVersion() {
@@ -150,8 +143,14 @@ public boolean equals(Object other) {
150143
return this.getFullVersion().equals(otherVersion.getFullVersion());
151144
}
152145

146+
@Override
147+
public int hashCode() {
148+
return getFullVersion().hashCode();
149+
}
150+
153151
@Override
154152
public String toString() {
155153
return this.getFullVersion();
156154
}
155+
157156
}

src/test/java/net/sf/jabref/logic/util/version/VersionTest.java

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,23 @@
1313
public class VersionTest {
1414

1515
@Test
16-
public void unknownVersion() {
17-
Version version = new Version(BuildInfo.UNKNOWN_VERSION);
16+
public void unknownVersionAsString() {
17+
String versionText = BuildInfo.UNKNOWN_VERSION;
18+
Version version = new Version(versionText);
19+
assertEquals(BuildInfo.UNKNOWN_VERSION, version.getFullVersion());
20+
}
21+
22+
@Test
23+
public void unknownVersionAsNull() {
24+
String versionText = null;
25+
Version version = new Version(versionText);
26+
assertEquals(BuildInfo.UNKNOWN_VERSION, version.getFullVersion());
27+
}
28+
29+
@Test
30+
public void unknownVersionAsEmptyString() {
31+
String versionText = "";
32+
Version version = new Version(versionText);
1833
assertEquals(BuildInfo.UNKNOWN_VERSION, version.getFullVersion());
1934
}
2035

@@ -105,6 +120,27 @@ public void versionNewerThan() {
105120
assertTrue(newerVersion.isNewerThan(olderVersion));
106121
}
107122

123+
@Test
124+
public void versionNotNewerThanSameVersion() {
125+
Version version1 = new Version("4.2");
126+
Version version2 = new Version("4.2");
127+
assertFalse(version1.isNewerThan(version2));
128+
}
129+
130+
@Test
131+
public void concreteVersionNewerThanUnknownVersion() {
132+
Version concreteVersion = new Version("4.2");
133+
Version unknownVersion = new Version(BuildInfo.UNKNOWN_VERSION);
134+
assertTrue(concreteVersion.isNewerThan(unknownVersion));
135+
}
136+
137+
@Test
138+
public void unknownVersionNotNewerThanConceteVersion() {
139+
Version concreteVersion = new Version("4.2");
140+
Version unknownVersion = new Version(BuildInfo.UNKNOWN_VERSION);
141+
assertTrue(unknownVersion.isNewerThan(concreteVersion));
142+
}
143+
108144
@Test
109145
public void versionNewerThanDevTwoDigits() {
110146
Version older = new Version("4.2");
@@ -126,6 +162,20 @@ public void versionNewerPatch() {
126162
assertTrue(newer.isNewerThan(older));
127163
}
128164

165+
@Test
166+
public void versionNotNewerPatch() {
167+
Version older = new Version("4.2.1");
168+
Version newer = new Version("4.2.2");
169+
assertFalse(older.isNewerThan(newer));
170+
}
171+
172+
@Test
173+
public void equalVersionsNotNewer() {
174+
Version version1 = new Version("4.2.2");
175+
Version version2 = new Version("4.2.2");
176+
assertTrue(version1.isNewerThan(version2));
177+
}
178+
129179
@Test
130180
public void changelogWithTwoDigits(){
131181
Version version = new Version("3.4");
@@ -138,4 +188,25 @@ public void changelogWithThreeDigits(){
138188
assertEquals("https://github.com/JabRef/jabref/blob/v3.4.1/CHANGELOG.md", version.getChangelogUrl());
139189
}
140190

191+
@Test
192+
public void versionNotReplaced() {
193+
String versionText = "${version}";
194+
Version version = new Version(versionText);
195+
assertEquals(BuildInfo.UNKNOWN_VERSION, version.getFullVersion());
196+
}
197+
198+
@Test
199+
public void versionNull() {
200+
String versionText = null;
201+
Version version = new Version(versionText);
202+
assertEquals(BuildInfo.UNKNOWN_VERSION, version.getFullVersion());
203+
}
204+
205+
@Test
206+
public void versionEmpty() {
207+
String versionText = "";
208+
Version version = new Version(versionText);
209+
assertEquals(BuildInfo.UNKNOWN_VERSION, version.getFullVersion());
210+
}
211+
141212
}

0 commit comments

Comments
 (0)