1 package org.kuali.common.util; 2 3 import org.junit.Assert; 4 import org.junit.Test; 5 6 public class VersionUtilsTest { 7 8 @Test 9 public void testIsSnapshot() { 10 Assert.assertTrue(VersionUtils.isSnapshot("1.0.0-SNAPSHOT")); 11 Assert.assertTrue(VersionUtils.isSnapshot("1.0-SNAPSHOT")); 12 Assert.assertTrue(VersionUtils.isSnapshot("1.0.0-sNAPSHOt")); 13 Assert.assertTrue(VersionUtils.isSnapshot("1.0.0-snapshot")); 14 Assert.assertFalse(VersionUtils.isSnapshot("1.0.0SNAPSHOT")); 15 Assert.assertFalse(VersionUtils.isSnapshot("SNAPSHOT")); 16 } 17 18 @Test 19 public void testTrimSnapshot() { 20 Assert.assertEquals("1.0.0", VersionUtils.trimSnapshot("1.0.0-SNAPSHOT")); 21 Assert.assertEquals("1.0.0", VersionUtils.trimSnapshot("1.0.0")); 22 Assert.assertEquals("1.0.0-SNAPSHO", VersionUtils.trimSnapshot("1.0.0-SNAPSHO")); 23 } 24 25 @Test 26 public void testGetVersionNormal() { 27 Version version = VersionUtils.getVersion("1.0.0-SNAPSHOT"); 28 Assert.assertTrue(version.isSnapshot()); 29 Assert.assertEquals("1", version.getMajor()); 30 Assert.assertEquals("0", version.getMinor()); 31 Assert.assertEquals("0", version.getIncremental()); 32 Assert.assertEquals("1.0.0", version.getTrimmed()); 33 Assert.assertNull(version.getQualifier()); 34 } 35 36 @Test 37 public void testGetVersion2Digits() { 38 Version version = VersionUtils.getVersion("1.0-SNAPSHOT"); 39 Assert.assertTrue(version.isSnapshot()); 40 Assert.assertEquals("1", version.getMajor()); 41 Assert.assertEquals("0", version.getMinor()); 42 Assert.assertNull(version.getIncremental()); 43 Assert.assertEquals("1.0", version.getTrimmed()); 44 Assert.assertNull(version.getQualifier()); 45 } 46 47 @Test 48 public void testGetVersion1Digit() { 49 Version version = VersionUtils.getVersion("1-SNAPSHOT"); 50 Assert.assertTrue(version.isSnapshot()); 51 Assert.assertEquals("1", version.getMajor()); 52 Assert.assertNull(version.getMinor()); 53 Assert.assertNull(version.getIncremental()); 54 Assert.assertEquals("1", version.getTrimmed()); 55 Assert.assertNull(version.getQualifier()); 56 } 57 58 @Test 59 public void testGetVersionSpring() { 60 Version version = VersionUtils.getVersion("3.1.3.RELEASE"); 61 Assert.assertFalse(version.isSnapshot()); 62 Assert.assertEquals("3", version.getMajor()); 63 Assert.assertEquals("1", version.getMinor()); 64 Assert.assertEquals("3", version.getIncremental()); 65 Assert.assertEquals("3.1.3.RELEASE", version.getTrimmed()); 66 Assert.assertEquals("RELEASE", version.getQualifier()); 67 } 68 69 @Test 70 public void testGetVersionWithQualifier() { 71 Version version = VersionUtils.getVersion("1.0.0-M4-SNAPSHOT"); 72 Assert.assertTrue(version.isSnapshot()); 73 Assert.assertEquals("1", version.getMajor()); 74 Assert.assertEquals("0", version.getMinor()); 75 Assert.assertEquals("0", version.getIncremental()); 76 Assert.assertEquals("1.0.0-M4", version.getTrimmed()); 77 Assert.assertEquals("M4", version.getQualifier()); 78 } 79 80 @Test 81 public void testGetVersionWithDoubleQualifier() { 82 Version version = VersionUtils.getVersion("1.0.0-beta-1-SNAPSHOT"); 83 Assert.assertTrue(version.isSnapshot()); 84 Assert.assertEquals("1", version.getMajor()); 85 Assert.assertEquals("0", version.getMinor()); 86 Assert.assertEquals("0", version.getIncremental()); 87 Assert.assertEquals("1.0.0-beta-1", version.getTrimmed()); 88 Assert.assertEquals("beta-1", version.getQualifier()); 89 } 90 91 }