View Javadoc
1   /**
2    * Copyright 2010-2014 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.common.util;
17  
18  import org.junit.Assert;
19  import org.junit.Test;
20  
21  public class VersionUtilsTest {
22  
23  	@Test
24  	public void testIsSnapshot() {
25  		Assert.assertTrue(VersionUtils.isSnapshot("1.0.0-SNAPSHOT"));
26  		Assert.assertTrue(VersionUtils.isSnapshot("1.0-SNAPSHOT"));
27  		Assert.assertTrue(VersionUtils.isSnapshot("1.0.0-sNAPSHOt"));
28  		Assert.assertTrue(VersionUtils.isSnapshot("1.0.0-snapshot"));
29  		Assert.assertFalse(VersionUtils.isSnapshot("1.0.0SNAPSHOT"));
30  		Assert.assertFalse(VersionUtils.isSnapshot("SNAPSHOT"));
31  	}
32  
33  	@Test
34  	public void testTrimSnapshot() {
35  		Assert.assertEquals("1.0.0", VersionUtils.trimSnapshot("1.0.0-SNAPSHOT"));
36  		Assert.assertEquals("1.0.0", VersionUtils.trimSnapshot("1.0.0"));
37  		Assert.assertEquals("1.0.0-SNAPSHO", VersionUtils.trimSnapshot("1.0.0-SNAPSHO"));
38  	}
39  
40  	@Test
41  	public void testGetVersionNormal() {
42  		Version version = VersionUtils.getVersion("1.0.0-SNAPSHOT");
43  		Assert.assertTrue(version.isSnapshot());
44  		Assert.assertEquals("1", version.getMajor());
45  		Assert.assertEquals("0", version.getMinor());
46  		Assert.assertEquals("0", version.getIncremental());
47  		Assert.assertEquals("1.0.0", version.getTrimmed());
48  		Assert.assertNull(version.getQualifier());
49  	}
50  
51  	@Test
52  	public void testGetVersion2Digits() {
53  		Version version = VersionUtils.getVersion("1.0-SNAPSHOT");
54  		Assert.assertTrue(version.isSnapshot());
55  		Assert.assertEquals("1", version.getMajor());
56  		Assert.assertEquals("0", version.getMinor());
57  		Assert.assertNull(version.getIncremental());
58  		Assert.assertEquals("1.0", version.getTrimmed());
59  		Assert.assertNull(version.getQualifier());
60  	}
61  
62  	@Test
63  	public void testGetVersion1Digit() {
64  		Version version = VersionUtils.getVersion("1-SNAPSHOT");
65  		Assert.assertTrue(version.isSnapshot());
66  		Assert.assertEquals("1", version.getMajor());
67  		Assert.assertNull(version.getMinor());
68  		Assert.assertNull(version.getIncremental());
69  		Assert.assertEquals("1", version.getTrimmed());
70  		Assert.assertNull(version.getQualifier());
71  	}
72  
73  	@Test
74  	public void testGetVersionSpring() {
75  		Version version = VersionUtils.getVersion("3.1.3.RELEASE");
76  		Assert.assertFalse(version.isSnapshot());
77  		Assert.assertEquals("3", version.getMajor());
78  		Assert.assertEquals("1", version.getMinor());
79  		Assert.assertEquals("3", version.getIncremental());
80  		Assert.assertEquals("3.1.3.RELEASE", version.getTrimmed());
81  		Assert.assertEquals("RELEASE", version.getQualifier());
82  	}
83  
84  	@Test
85  	public void testGetVersionWithQualifier() {
86  		Version version = VersionUtils.getVersion("1.0.0-M4-SNAPSHOT");
87  		Assert.assertTrue(version.isSnapshot());
88  		Assert.assertEquals("1", version.getMajor());
89  		Assert.assertEquals("0", version.getMinor());
90  		Assert.assertEquals("0", version.getIncremental());
91  		Assert.assertEquals("1.0.0-M4", version.getTrimmed());
92  		Assert.assertEquals("M4", version.getQualifier());
93  	}
94  
95  	@Test
96  	public void testGetVersionWithDoubleQualifier() {
97  		Version version = VersionUtils.getVersion("1.0.0-beta-1-SNAPSHOT");
98  		Assert.assertTrue(version.isSnapshot());
99  		Assert.assertEquals("1", version.getMajor());
100 		Assert.assertEquals("0", version.getMinor());
101 		Assert.assertEquals("0", version.getIncremental());
102 		Assert.assertEquals("1.0.0-beta-1", version.getTrimmed());
103 		Assert.assertEquals("beta-1", version.getQualifier());
104 	}
105 
106 }