Rewrites AllowedVersionsTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-09-23 17:59:01 -07:00
parent 99c042fb65
commit 1cfe6fbcd9

View file

@ -1,10 +1,10 @@
package info.nightscout.plugins.constraints.versionChecker package info.nightscout.plugins.constraints.versionChecker
import com.google.common.truth.Truth.assertThat
import info.nightscout.plugins.constraints.versionChecker.AllowedVersions import info.nightscout.plugins.constraints.versionChecker.AllowedVersions
import org.joda.time.LocalDate import org.joda.time.LocalDate
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONObject import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
class AllowedVersionsTest { class AllowedVersionsTest {
@ -45,14 +45,14 @@ class AllowedVersionsTest {
@Test @Test
fun generateSupportedVersionsTest() { fun generateSupportedVersionsTest() {
val definition = generateSupportedVersions() val definition = generateSupportedVersions()
Assertions.assertNull(AllowedVersions().findByApi(definition, 0)) assertThat(AllowedVersions().findByApi(definition, 0)).isNull()
Assertions.assertFalse(AllowedVersions().findByApi(definition, 1)?.has("supported") ?: true) assertThat(AllowedVersions().findByApi(definition, 1)!!.has("supported")).isFalse()
Assertions.assertFalse(AllowedVersions().findByApi(definition, 23)?.has("supported") ?: true) assertThat(AllowedVersions().findByApi(definition, 23)!!.has("supported")).isFalse()
Assertions.assertEquals("2.6.2", AllowedVersions().findByApi(definition, 24)?.getString("supported")) assertThat(AllowedVersions().findByApi(definition, 24)!!.getString("supported")).isEqualTo("2.6.2")
Assertions.assertEquals("2.6.2", AllowedVersions().findByApi(definition, 25)?.getString("supported")) assertThat(AllowedVersions().findByApi(definition, 25)!!.getString("supported")).isEqualTo("2.6.2")
Assertions.assertEquals("2.8.2", AllowedVersions().findByApi(definition, 26)?.getString("supported")) assertThat(AllowedVersions().findByApi(definition, 26)!!.getString("supported")).isEqualTo("2.8.2")
Assertions.assertEquals("2.8.2", AllowedVersions().findByApi(definition, 27)?.getString("supported")) assertThat(AllowedVersions().findByApi(definition, 27)!!.getString("supported")).isEqualTo("2.8.2")
Assertions.assertEquals("2.8.2", AllowedVersions().findByApi(definition, 28)?.getString("supported")) assertThat(AllowedVersions().findByApi(definition, 28)!!.getString("supported")).isEqualTo("2.8.2")
} }
@Test @Test
@ -62,9 +62,9 @@ class AllowedVersionsTest {
"[{\"minAndroid\":1,\"maxAndroid\":23},{\"minAndroid\":24,\"maxAndroid\":25,\"supported\":\"2.6.2\"},{\"minAndroid\":26,\"maxAndroid\":27,\"supported\":\"2.8.2\"},{\"minAndroid\":28,\"maxAndroid\":99,\"supported\":\"2.8.2\"},{\"endDate\":\"2021-11-07\",\"version\":\"2.9.0-beta1\"},{\"endDate\":\"2021-11-02\",\"version\":\"3.0-beta1\"},{\"endDate\":\"2021-11-04\",\"version\":\"3.0-beta2\"},{\"endDate\":\"2021-11-10\",\"version\":\"3.0-beta3\"},{\"endDate\":\"2021-11-14\",\"version\":\"3.0-beta4\"}\n" + "[{\"minAndroid\":1,\"maxAndroid\":23},{\"minAndroid\":24,\"maxAndroid\":25,\"supported\":\"2.6.2\"},{\"minAndroid\":26,\"maxAndroid\":27,\"supported\":\"2.8.2\"},{\"minAndroid\":28,\"maxAndroid\":99,\"supported\":\"2.8.2\"},{\"endDate\":\"2021-11-07\",\"version\":\"2.9.0-beta1\"},{\"endDate\":\"2021-11-02\",\"version\":\"3.0-beta1\"},{\"endDate\":\"2021-11-04\",\"version\":\"3.0-beta2\"},{\"endDate\":\"2021-11-10\",\"version\":\"3.0-beta3\"},{\"endDate\":\"2021-11-14\",\"version\":\"3.0-beta4\"}\n" +
" ,{\"endDate\":\"2021-11-16\",\"version\":\"3.0-beta5\"}\n" + " ,{\"endDate\":\"2021-11-16\",\"version\":\"3.0-beta5\"}\n" +
"]" "]"
Assertions.assertNull(AllowedVersions().findByVersion(definition, "2.6.0")) assertThat(AllowedVersions().findByVersion(definition, "2.6.0")).isNull()
Assertions.assertTrue(AllowedVersions().findByVersion(definition, "2.9.0-beta1")?.has("endDate") ?: false) assertThat(AllowedVersions().findByVersion(definition, "2.9.0-beta1")!!.has("endDate")).isTrue()
Assertions.assertEquals("2021-11-07", AllowedVersions().findByVersion(definition, "2.9.0-beta1")?.getString("endDate")) assertThat(AllowedVersions().findByVersion(definition, "2.9.0-beta1")!!.getString("endDate")).isEqualTo("2021-11-07")
} }
@Suppress("SpellCheckingInspection") @Suppress("SpellCheckingInspection")
@ -73,10 +73,10 @@ class AllowedVersionsTest {
val definition = generateSupportedVersions() val definition = generateSupportedVersions()
val endDate = AllowedVersions().endDateToMilliseconds(AllowedVersions().findByVersion(definition, "2.9.0-beta1")?.getString("endDate") ?: "1000/01/01") val endDate = AllowedVersions().endDateToMilliseconds(AllowedVersions().findByVersion(definition, "2.9.0-beta1")?.getString("endDate") ?: "1000/01/01")
val dateTime = LocalDate(endDate) val dateTime = LocalDate(endDate)
Assertions.assertEquals(2021, dateTime.year) assertThat(dateTime.year).isEqualTo(2021)
Assertions.assertEquals(11, dateTime.monthOfYear) assertThat(dateTime.monthOfYear).isEqualTo(11)
Assertions.assertEquals(7, dateTime.dayOfMonth) assertThat(dateTime.dayOfMonth).isEqualTo(7)
Assertions.assertNull(AllowedVersions().endDateToMilliseconds("abdef")) assertThat(AllowedVersions().endDateToMilliseconds("abdef")).isNull()
} }
} }