aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-10-27 21:56:10 +0000
committerGodin <mandrikov@gmail.com>2010-10-27 21:56:10 +0000
commit91493e94947de67103dea121e894b89fda37f767 (patch)
tree66abc73d22666c9e369ee7a334c353e6230ed49a
parent0b86ed2749b5f39f655255327f8af28de0b1889b (diff)
downloadsonarqube-91493e94947de67103dea121e894b89fda37f767.tar.gz
sonarqube-91493e94947de67103dea121e894b89fda37f767.zip
Assume that snapshot and release candidate are the same as release
-rw-r--r--subprojects/sonar-update-center/sonar-update-center-common/src/main/java/org/sonar/updatecenter/common/Version.java9
-rw-r--r--subprojects/sonar-update-center/sonar-update-center-common/src/test/java/org/sonar/updatecenter/common/VersionTest.java35
2 files changed, 32 insertions, 12 deletions
diff --git a/subprojects/sonar-update-center/sonar-update-center-common/src/main/java/org/sonar/updatecenter/common/Version.java b/subprojects/sonar-update-center/sonar-update-center-common/src/main/java/org/sonar/updatecenter/common/Version.java
index 74a45335ce4..f80d797cc6f 100644
--- a/subprojects/sonar-update-center/sonar-update-center-common/src/main/java/org/sonar/updatecenter/common/Version.java
+++ b/subprojects/sonar-update-center/sonar-update-center-common/src/main/java/org/sonar/updatecenter/common/Version.java
@@ -35,6 +35,7 @@ public class Version implements Comparable<Version> {
private Version(String version) {
this.name = StringUtils.trimToEmpty(version);
+ this.name = StringUtils.substringBefore(this.name, "-"); // we don't care about snapshots and RCs for now
String[] split = StringUtils.split(name, '.');
if (split.length >= 1) {
major = split[0];
@@ -88,16 +89,16 @@ public class Version implements Comparable<Version> {
}
Version version = (Version) o;
- if (!normalizedMajor.equals(version.normalizedMajor)) {
+ if ( !normalizedMajor.equals(version.normalizedMajor)) {
return false;
}
- if (!normalizedMinor.equals(version.normalizedMinor)) {
+ if ( !normalizedMinor.equals(version.normalizedMinor)) {
return false;
}
- if (!normalizedPatch.equals(version.normalizedPatch)) {
+ if ( !normalizedPatch.equals(version.normalizedPatch)) {
return false;
}
- if (!normalizedPatch2.equals(version.normalizedPatch2)) {
+ if ( !normalizedPatch2.equals(version.normalizedPatch2)) {
return false;
}
return true;
diff --git a/subprojects/sonar-update-center/sonar-update-center-common/src/test/java/org/sonar/updatecenter/common/VersionTest.java b/subprojects/sonar-update-center/sonar-update-center-common/src/test/java/org/sonar/updatecenter/common/VersionTest.java
index 8059f223fdc..9a78aecf5e8 100644
--- a/subprojects/sonar-update-center/sonar-update-center-common/src/test/java/org/sonar/updatecenter/common/VersionTest.java
+++ b/subprojects/sonar-update-center/sonar-update-center-common/src/test/java/org/sonar/updatecenter/common/VersionTest.java
@@ -19,15 +19,15 @@
*/
package org.sonar.updatecenter.common;
-import org.junit.Ignore;
-import org.junit.Test;
-
import static junit.framework.Assert.assertTrue;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.number.OrderingComparisons.greaterThan;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
+import org.junit.Ignore;
+import org.junit.Test;
+
public class VersionTest {
@Test
@@ -39,8 +39,8 @@ public class VersionTest {
assertThat(version12.compareTo(version12), is(0));
assertThat(version121.compareTo(version121), is(0));
- assertTrue(version121.compareTo(version12)>0);
- assertTrue(version12.compareTo(version121)<0);
+ assertTrue(version121.compareTo(version12) > 0);
+ assertTrue(version12.compareTo(version121) < 0);
}
@Test
@@ -53,8 +53,25 @@ public class VersionTest {
}
@Test
+ public void snapshotEqualToRelease() {
+ Version version12 = Version.create("1.2");
+ Version version12SNAPSHOT = Version.create("1.2-SNAPSHOT");
+
+ assertThat(version12.compareTo(version12SNAPSHOT), is(0));
+ }
+
+ @Test
+ public void releaseCandidateEqualToRelease() {
+ Version version12 = Version.create("1.2");
+ Version version12RC = Version.create("1.2-RC1");
+
+ assertThat(version12.compareTo(version12RC), is(0));
+ }
+
+ @Test
public void testTrim() {
Version version12 = Version.create(" 1.2 ");
+
assertThat(version12.getName(), is("1.2"));
assertTrue(version12.equals(Version.create("1.2")));
}
@@ -63,24 +80,25 @@ public class VersionTest {
public void testDefaultNumberIsZero() {
Version version12 = Version.create("1.2");
Version version120 = Version.create("1.2.0");
+
assertTrue(version12.equals(version120));
assertTrue(version120.equals(version12));
}
-
@Test
public void testCompareOnTwoDigits() {
Version version1dot10 = Version.create("1.10");
Version version1dot1 = Version.create("1.1");
Version version1dot9 = Version.create("1.9");
- assertTrue(version1dot10.compareTo(version1dot1)>0);
- assertTrue(version1dot10.compareTo(version1dot9)>0);
+ assertTrue(version1dot10.compareTo(version1dot1) > 0);
+ assertTrue(version1dot10.compareTo(version1dot9) > 0);
}
@Test
public void testFields() {
Version version = Version.create("1.10.2");
+
assertThat(version.getName(), is("1.10.2"));
assertThat(version.toString(), is("1.10.2"));
assertThat(version.getMajor(), is("1"));
@@ -92,6 +110,7 @@ public class VersionTest {
@Test
public void testPatchFields() {
Version version = Version.create("1.2.3.4");
+
assertThat(version.getPatch(), is("3"));
assertThat(version.getPatch2(), is("4"));