View Javadoc
1   package org.nuiton.version;
2   
3   /*
4    * #%L
5    * Nuiton Version
6    * %%
7    * Copyright (C) 2016 CodeLutin, Tony Chemit
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Lesser Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Lesser Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22   * #L%
23   */
24  
25  import org.junit.Assert;
26  import org.junit.Test;
27  
28  /**
29   * Created on 7/11/14.
30   *
31   * @author Tony Chemit - chemit@codelutin.com
32   * @since 3.0
33   */
34  public class VersionComparatorTest {
35  
36      @Test
37      public void testCompareVersions() {
38  
39          VersionComparator comparator = new VersionComparator();
40  
41          Version[] versions = new Version[]{
42                  VersionBuilder.create().setSnapshot(true).build(),
43                  VersionBuilder.create().build(),
44                  VersionBuilder.create("1").build(),
45                  VersionBuilder.create("1.1-alpha-1").build(),
46                  VersionBuilder.create("1.1-alpha-2").build(),
47                  VersionBuilder.create("1.1-beta-1").build(),
48                  VersionBuilder.create("1.1-rc-1-SNAPSHOT").build(),
49                  VersionBuilder.create("1.1-rc-1").build(),
50                  VersionBuilder.create("1.1-rc2").build(),
51                  VersionBuilder.create("1.1").build(),
52                  VersionBuilder.create("1.1.1").build(),
53                  VersionBuilder.create("1.1.1-blablah").build(),
54                  VersionBuilder.create("1.1.1-blablah1-SNAPSHOT").build(),
55                  VersionBuilder.create("1.1.1-blablah1").build(),
56                  VersionBuilder.create("1.1.1-blablah1a").build(),
57                  VersionBuilder.create("1.1.1-blablah1b").build(),
58                  VersionBuilder.create("2-rc-1").build(),
59                  VersionBuilder.create("2").build(),
60                  VersionBuilder.create("2-aa-1").build(),
61          };
62  
63          for (int i = 0, l = versions.length - 1; i < l; i++) {
64  
65              Version v0 = versions[i];
66              Version v1 = versions[i + 1];
67              Assert.assertTrue(v0 + " < " + v1, comparator.compare(v0, v1) < 0);
68  
69          }
70  
71      }
72  
73  }