From ce2ee660ae4dcbe953db5193a3b211d3025af679 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Sat, 21 Dec 2019 18:56:30 +0100 Subject: [PATCH] add test for VersionUtils (#1602) * add test for VersionUtils * add nullability annotation to VersionUtils --- .../tusky/util/VersionUtils.java | 4 ++- .../tusky/util/VersionUtilsTest.kt | 36 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 app/src/test/java/com/keylesspalace/tusky/util/VersionUtilsTest.kt diff --git a/app/src/main/java/com/keylesspalace/tusky/util/VersionUtils.java b/app/src/main/java/com/keylesspalace/tusky/util/VersionUtils.java index 76dcd451..dceef0f3 100644 --- a/app/src/main/java/com/keylesspalace/tusky/util/VersionUtils.java +++ b/app/src/main/java/com/keylesspalace/tusky/util/VersionUtils.java @@ -15,6 +15,8 @@ package com.keylesspalace.tusky.util; +import androidx.annotation.NonNull; + import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -24,7 +26,7 @@ public class VersionUtils { private int minor; private int patch; - public VersionUtils(String versionString) { + public VersionUtils(@NonNull String versionString) { String regex = "([0-9]+)\\.([0-9]+)\\.([0-9]+).*"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(versionString); diff --git a/app/src/test/java/com/keylesspalace/tusky/util/VersionUtilsTest.kt b/app/src/test/java/com/keylesspalace/tusky/util/VersionUtilsTest.kt new file mode 100644 index 00000000..03ab3d94 --- /dev/null +++ b/app/src/test/java/com/keylesspalace/tusky/util/VersionUtilsTest.kt @@ -0,0 +1,36 @@ +package com.keylesspalace.tusky.util + +import org.junit.Assert.assertEquals +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.Parameterized + +@RunWith(Parameterized::class) +class VersionUtilsTest( + private val versionString: String, + private val supportsScheduledToots: Boolean +) { + + companion object { + @JvmStatic + @Parameterized.Parameters + fun data() = listOf( + arrayOf("2.0.0", false), + arrayOf("2a9a0", false), + arrayOf("1.0", false), + arrayOf("error", false), + arrayOf("", false), + arrayOf("2.6.9", false), + arrayOf("2.7.0", true), + arrayOf("2.00008.0", true), + arrayOf("2.7.2 (compatible; Pleroma 1.0.0-1168-ge18c7866-pleroma-dot-site)", true), + arrayOf("3.0.1", true) + ) + } + + @Test + fun testVersionUtils() { + assertEquals(VersionUtils(versionString).supportsScheduledToots(), supportsScheduledToots) + } + +} \ No newline at end of file