View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.core.api.util;
17  
18  import junit.framework.TestCase;
19  import org.junit.Test;
20  
21  /**
22   *
23   * Test cases for VersionHelper class
24   *
25   * @author Kuali Rice Team (rice.collab@kuali.org)
26   *
27   */
28  
29  public class VersionHelperTest extends TestCase
30  {
31  
32      @Test
33      public void testVersionHelper() {
34          String verOne[] = {"1.2.3","6.8.83.4","5.0","snapshot-2.3.5", "something-0.333.447...-nice" };
35          String verTwo[] = {"1.2.1","6.8.83","5.9","2.3-snapshot", "0.345...777" };
36          boolean results[] = {false, false, true, false, true, false};
37          int intResults[] = {1,1,-1,1,-1};
38  
39          for(int i=0;i<verOne.length;i++) {
40                assertEquals(VersionHelper.compareVersion(verOne[i],verTwo[i]), intResults[i]);
41          }
42  
43          for(int i=0;i<verOne.length;i++) {
44              assertEquals(VersionHelper.compareVersion(verTwo[i],verOne[i]), -1*intResults[i]);
45          }
46  
47  
48          //  let's check the case where the version numbers are equal
49          assertEquals(VersionHelper.compareVersion("7.7.7","7.7.7"), 0);
50      }
51  
52      @Test
53      public void testUndefined() {
54          assertEquals(VersionHelper.compareVersion("undefined", "2.1.3-snapshot"), -1);
55          assertEquals(VersionHelper.compareVersion("2.1.3", "undefined"), -1);
56  
57      }
58  
59  }