VersionTest.kt (2259B)
1 /* 2 * This file is part of GNU Taler 3 * (C) 2020 Taler Systems S.A. 4 * 5 * GNU Taler is free software; you can redistribute it and/or modify it under the 6 * terms of the GNU General Public License as published by the Free Software 7 * Foundation; either version 3, or (at your option) any later version. 8 * 9 * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY 10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 * A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License along with 14 * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 17 package net.taler.common 18 import org.junit.Assert.assertEquals 19 import org.junit.Assert.assertNull 20 import org.junit.Test 21 22 23 class VersionTest { 24 25 @Test 26 fun testParse() { 27 assertNull(Version.parse("")) 28 assertNull(Version.parse("foo")) 29 assertNull(Version.parse("foo:bar:foo")) 30 assertNull(Version.parse("0:0:0:")) 31 assertNull(Version.parse("0:0:")) 32 assertEquals(Version(0, 0, 0), Version.parse("0:0:0")) 33 assertEquals(Version(1, 2, 3), Version.parse("1:2:3")) 34 assertEquals(Version(1337, 42, 23), Version.parse("1337:42:23")) 35 } 36 37 @Test 38 fun testComparision() { 39 assertEquals( 40 Version.VersionMatchResult(true, 0), 41 Version.parse("0:0:0")!!.compare(Version.parse("0:0:0")) 42 ) 43 assertEquals( 44 Version.VersionMatchResult(true, -1), 45 Version.parse("0:0:0")!!.compare(Version.parse("1:0:1")) 46 ) 47 assertEquals( 48 Version.VersionMatchResult(true, -1), 49 Version.parse("0:0:0")!!.compare(Version.parse("1:5:1")) 50 ) 51 assertEquals( 52 Version.VersionMatchResult(false, -1), 53 Version.parse("0:0:0")!!.compare(Version.parse("1:5:0")) 54 ) 55 assertEquals( 56 Version.VersionMatchResult(false, 1), 57 Version.parse("1:0:0")!!.compare(Version.parse("0:5:0")) 58 ) 59 assertEquals( 60 Version.VersionMatchResult(true, 0), 61 Version.parse("1:0:1")!!.compare(Version.parse("1:5:1")) 62 ) 63 } 64 65 }