2 * Sonar, open source software quality management tool.
3 * Copyright (C) 2009 SonarSource SA
4 * mailto:contact AT sonarsource DOT com
6 * Sonar is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * Sonar is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Sonar; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
20 package org.sonar.updatecenter.common;
22 import static junit.framework.Assert.assertTrue;
23 import static org.hamcrest.core.Is.is;
24 import static org.hamcrest.number.OrderingComparisons.greaterThan;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertThat;
28 import org.junit.Ignore;
29 import org.junit.Test;
31 public class VersionTest {
34 public void testCompare() {
35 Version version12 = Version.create("1.2");
36 Version version121 = Version.create("1.2.1");
38 assertThat(version12.toString(), is("1.2"));
39 assertThat(version12.compareTo(version12), is(0));
40 assertThat(version121.compareTo(version121), is(0));
42 assertTrue(version121.compareTo(version12) > 0);
43 assertTrue(version12.compareTo(version121) < 0);
47 @Ignore("TODO : support alpha, beta, snapshot versions")
48 public void testCompareReleaseAndSnapshot() {
49 Version version12 = Version.create("1.2");
50 Version version12SNAPSHOT = Version.create("1.2-SNAPSHOT");
52 assertThat(version12.compareTo(version12SNAPSHOT), greaterThan(0));
56 public void snapshotEqualToRelease() {
57 Version version12 = Version.create("1.2");
58 Version version12SNAPSHOT = Version.create("1.2-SNAPSHOT");
60 assertThat(version12.compareTo(version12SNAPSHOT), is(0));
64 public void releaseCandidateEqualToRelease() {
65 Version version12 = Version.create("1.2");
66 Version version12RC = Version.create("1.2-RC1");
68 assertThat(version12.compareTo(version12RC), is(0));
72 public void testTrim() {
73 Version version12 = Version.create(" 1.2 ");
75 assertThat(version12.getName(), is("1.2"));
76 assertTrue(version12.equals(Version.create("1.2")));
80 public void testDefaultNumberIsZero() {
81 Version version12 = Version.create("1.2");
82 Version version120 = Version.create("1.2.0");
84 assertTrue(version12.equals(version120));
85 assertTrue(version120.equals(version12));
89 public void testCompareOnTwoDigits() {
90 Version version1dot10 = Version.create("1.10");
91 Version version1dot1 = Version.create("1.1");
92 Version version1dot9 = Version.create("1.9");
94 assertTrue(version1dot10.compareTo(version1dot1) > 0);
95 assertTrue(version1dot10.compareTo(version1dot9) > 0);
99 public void testFields() {
100 Version version = Version.create("1.10.2");
102 assertThat(version.getName(), is("1.10.2"));
103 assertThat(version.toString(), is("1.10.2"));
104 assertThat(version.getMajor(), is("1"));
105 assertThat(version.getMinor(), is("10"));
106 assertThat(version.getPatch(), is("2"));
107 assertThat(version.getPatch2(), is("0"));
111 public void testPatchFields() {
112 Version version = Version.create("1.2.3.4");
114 assertThat(version.getPatch(), is("3"));
115 assertThat(version.getPatch2(), is("4"));
117 assertTrue(version.equals(version));
118 assertTrue(version.equals(Version.create("1.2.3.4")));
119 assertFalse(version.equals(Version.create("1.2.3.5")));