Merge pull request #2824 from ryanhaining/use_kotlin_test

Uses kotlin.test.assertFailsWith
This commit is contained in:
Milos Kozak 2023-09-24 10:33:35 +02:00 committed by GitHub
commit 0b08f618cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 26 deletions

View file

@ -1,5 +1,6 @@
dependencies {
//testImplementation "junit:junit:$junit_version"
testImplementation 'org.jetbrains.kotlin:kotlin-test:1.9.10'
testImplementation "org.junit.jupiter:junit-jupiter:$junit_jupiter_version"
testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_jupiter_version"
testImplementation "org.json:json:$json_version"

View file

@ -17,6 +17,7 @@ import org.mockito.ArgumentMatchers
import org.mockito.Mock
import org.mockito.Mockito
import java.io.File
import kotlin.test.assertFailsWith
// https://stackoverflow.com/questions/52344522/joseexception-couldnt-create-aes-gcm-nopadding-cipher-illegal-key-size
// https://stackoverflow.com/questions/47708951/can-aes-256-work-on-android-devices-with-api-level-26
@ -208,7 +209,7 @@ open class EncryptedPrefsFormatTest : TestBase() {
@Test
fun garbageInputTest() {
Assertions.assertThrows(PrefFormatError::class.java) {
assertFailsWith<PrefFormatError> {
val frozenPrefs = "whatever man, i duno care"
val storage = SingleStringStorage(frozenPrefs)
@ -219,7 +220,7 @@ open class EncryptedPrefsFormatTest : TestBase() {
@Test
fun unknownFormatTest() {
Assertions.assertThrows(PrefFormatError::class.java) {
assertFailsWith<PrefFormatError> {
val frozenPrefs = "{\n" +
" \"metadata\": {},\n" +
" \"security\": {\n" +

View file

@ -1,9 +1,10 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.util
import com.google.common.truth.Truth.assertThat
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.BasalProgram
import info.nightscout.interfaces.profile.Profile
import info.nightscout.interfaces.profile.Profile.ProfileValue
import org.junit.Assert
import kotlin.test.assertFailsWith
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.mockito.Mockito
@ -44,12 +45,10 @@ class FunctionsTest {
`when`(profile.getBasalValues()).thenReturn(emptyArray())
Assert.assertThrows(
"Basal values should contain values",
java.lang.IllegalArgumentException::class.java
) {
val exception = assertFailsWith<IllegalArgumentException> {
mapProfileToBasalProgram(profile)
}
assertThat(exception.message).isEqualTo("Basal values should contain values")
}
@Test fun invalidProfileNonZeroOffset() {
@ -59,12 +58,10 @@ class FunctionsTest {
arrayOf(ProfileValue(1800, 0.5))
)
Assert.assertThrows(
"First basal segment start time should be 0",
java.lang.IllegalArgumentException::class.java
) {
val exception = assertFailsWith<IllegalArgumentException> {
mapProfileToBasalProgram(profile)
}
assertThat(exception.message).isEqualTo("First basal segment start time should be 0")
}
@Test fun invalidProfileMoreThan24Hours() {
@ -77,12 +74,10 @@ class FunctionsTest {
)
)
Assert.assertThrows(
"Basal segment start time can not be greater than 86400",
java.lang.IllegalArgumentException::class.java
) {
val exception = assertFailsWith<IllegalArgumentException> {
mapProfileToBasalProgram(profile)
}
assertThat(exception.message).isEqualTo("Basal segment start time can not be greater than 86400")
}
@Test fun invalidProfileNegativeOffset() {
@ -92,9 +87,10 @@ class FunctionsTest {
arrayOf(ProfileValue(-1, 0.5))
)
Assert.assertThrows("Basal segment start time can not be less than 0", IllegalArgumentException::class.java) {
val exception = assertFailsWith<IllegalArgumentException> {
mapProfileToBasalProgram(profile)
}
assertThat(exception.message).isEqualTo("Basal segment start time can not be less than 0")
}
@Test fun roundsToSupportedPrecision() {

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communicatio
import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodErosManager
import info.nightscout.interfaces.profile.Profile
import info.nightscout.interfaces.profile.Profile.ProfileValue
import kotlin.test.assertFailsWith
import org.joda.time.Duration
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
@ -34,11 +35,11 @@ internal class AapsOmnipodErosManagerTest {
}
@Test fun invalidProfileNullProfile() {
Assertions.assertThrows(IllegalArgumentException::class.java) { AapsOmnipodErosManager.mapProfileToBasalSchedule(null) }
assertFailsWith<IllegalArgumentException> { AapsOmnipodErosManager.mapProfileToBasalSchedule(null) }
}
@Test fun invalidProfileNullEntries() {
Assertions.assertThrows(IllegalArgumentException::class.java) {
assertFailsWith<IllegalArgumentException> {
AapsOmnipodErosManager.mapProfileToBasalSchedule(Mockito.mock(Profile::class.java))
}
}
@ -46,7 +47,7 @@ internal class AapsOmnipodErosManagerTest {
@Test fun invalidProfileZeroEntries() {
val profile = Mockito.mock(Profile::class.java)
Mockito.`when`(profile.getBasalValues()).thenReturn(emptyArray())
Assertions.assertThrows(IllegalArgumentException::class.java) { AapsOmnipodErosManager.mapProfileToBasalSchedule(profile) }
assertFailsWith<IllegalArgumentException> { AapsOmnipodErosManager.mapProfileToBasalSchedule(profile) }
}
@Test fun invalidProfileNonZeroOffset() {
@ -56,7 +57,7 @@ internal class AapsOmnipodErosManagerTest {
ProfileValue(1800, 0.5)
)
)
Assertions.assertThrows(IllegalArgumentException::class.java) { AapsOmnipodErosManager.mapProfileToBasalSchedule(profile) }
assertFailsWith<IllegalArgumentException> { AapsOmnipodErosManager.mapProfileToBasalSchedule(profile) }
}
@Test fun invalidProfileMoreThan24Hours() {
@ -67,7 +68,7 @@ internal class AapsOmnipodErosManagerTest {
ProfileValue(86400, 0.5)
)
)
Assertions.assertThrows(IllegalArgumentException::class.java) { AapsOmnipodErosManager.mapProfileToBasalSchedule(profile) }
assertFailsWith<IllegalArgumentException> { AapsOmnipodErosManager.mapProfileToBasalSchedule(profile) }
}
@Test fun invalidProfileNegativeOffset() {
@ -77,7 +78,7 @@ internal class AapsOmnipodErosManagerTest {
ProfileValue(-1, 0.5)
)
)
Assertions.assertThrows(IllegalArgumentException::class.java) { AapsOmnipodErosManager.mapProfileToBasalSchedule(profile) }
assertFailsWith<IllegalArgumentException> { AapsOmnipodErosManager.mapProfileToBasalSchedule(profile) }
}
@Test fun roundsToSupportedPrecision() {
@ -91,4 +92,4 @@ internal class AapsOmnipodErosManagerTest {
val basalScheduleEntry = basalSchedule.entries[0]
Assertions.assertEquals(0.05, basalScheduleEntry.rate, 0.000001)
}
}
}

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.response.podinfo
import com.google.common.truth.Truth.assertThat
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.PodInfoType
import info.nightscout.pump.common.utils.ByteUtil
import org.junit.jupiter.api.Assertions
@ -31,8 +32,6 @@ internal class PodInfoResponseTest {
@Test fun testInvalidPodInfoTypeMessageDecoding() {
val podInfoResponse = PodInfoResponse(ByteUtil.fromHexString("0216020d0000000000ab6a038403ff03860000285708030d"))
Assertions.assertEquals(PodInfoType.DETAILED_STATUS, podInfoResponse.subType)
Assertions.assertThrows(ClassCastException::class.java) {
@Suppress("UNUSED_VARIABLE") val podInfo = podInfoResponse.podInfo as PodInfoActiveAlerts
}
assertThat(podInfoResponse.podInfo).isNotInstanceOf(PodInfoActiveAlerts::class.java)
}
}