Merge pull request #2824 from ryanhaining/use_kotlin_test
Uses kotlin.test.assertFailsWith
This commit is contained in:
commit
0b08f618cf
|
@ -1,5 +1,6 @@
|
||||||
dependencies {
|
dependencies {
|
||||||
//testImplementation "junit:junit:$junit_version"
|
//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:$junit_jupiter_version"
|
||||||
testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_jupiter_version"
|
testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_jupiter_version"
|
||||||
testImplementation "org.json:json:$json_version"
|
testImplementation "org.json:json:$json_version"
|
||||||
|
|
|
@ -17,6 +17,7 @@ import org.mockito.ArgumentMatchers
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
import org.mockito.Mockito
|
import org.mockito.Mockito
|
||||||
import java.io.File
|
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/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
|
// 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
|
@Test
|
||||||
fun garbageInputTest() {
|
fun garbageInputTest() {
|
||||||
Assertions.assertThrows(PrefFormatError::class.java) {
|
assertFailsWith<PrefFormatError> {
|
||||||
val frozenPrefs = "whatever man, i duno care"
|
val frozenPrefs = "whatever man, i duno care"
|
||||||
|
|
||||||
val storage = SingleStringStorage(frozenPrefs)
|
val storage = SingleStringStorage(frozenPrefs)
|
||||||
|
@ -219,7 +220,7 @@ open class EncryptedPrefsFormatTest : TestBase() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun unknownFormatTest() {
|
fun unknownFormatTest() {
|
||||||
Assertions.assertThrows(PrefFormatError::class.java) {
|
assertFailsWith<PrefFormatError> {
|
||||||
val frozenPrefs = "{\n" +
|
val frozenPrefs = "{\n" +
|
||||||
" \"metadata\": {},\n" +
|
" \"metadata\": {},\n" +
|
||||||
" \"security\": {\n" +
|
" \"security\": {\n" +
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.dash.util
|
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.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.BasalProgram
|
||||||
import info.nightscout.interfaces.profile.Profile
|
import info.nightscout.interfaces.profile.Profile
|
||||||
import info.nightscout.interfaces.profile.Profile.ProfileValue
|
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.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.mockito.Mockito
|
import org.mockito.Mockito
|
||||||
|
@ -44,12 +45,10 @@ class FunctionsTest {
|
||||||
|
|
||||||
`when`(profile.getBasalValues()).thenReturn(emptyArray())
|
`when`(profile.getBasalValues()).thenReturn(emptyArray())
|
||||||
|
|
||||||
Assert.assertThrows(
|
val exception = assertFailsWith<IllegalArgumentException> {
|
||||||
"Basal values should contain values",
|
|
||||||
java.lang.IllegalArgumentException::class.java
|
|
||||||
) {
|
|
||||||
mapProfileToBasalProgram(profile)
|
mapProfileToBasalProgram(profile)
|
||||||
}
|
}
|
||||||
|
assertThat(exception.message).isEqualTo("Basal values should contain values")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun invalidProfileNonZeroOffset() {
|
@Test fun invalidProfileNonZeroOffset() {
|
||||||
|
@ -59,12 +58,10 @@ class FunctionsTest {
|
||||||
arrayOf(ProfileValue(1800, 0.5))
|
arrayOf(ProfileValue(1800, 0.5))
|
||||||
)
|
)
|
||||||
|
|
||||||
Assert.assertThrows(
|
val exception = assertFailsWith<IllegalArgumentException> {
|
||||||
"First basal segment start time should be 0",
|
|
||||||
java.lang.IllegalArgumentException::class.java
|
|
||||||
) {
|
|
||||||
mapProfileToBasalProgram(profile)
|
mapProfileToBasalProgram(profile)
|
||||||
}
|
}
|
||||||
|
assertThat(exception.message).isEqualTo("First basal segment start time should be 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun invalidProfileMoreThan24Hours() {
|
@Test fun invalidProfileMoreThan24Hours() {
|
||||||
|
@ -77,12 +74,10 @@ class FunctionsTest {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
Assert.assertThrows(
|
val exception = assertFailsWith<IllegalArgumentException> {
|
||||||
"Basal segment start time can not be greater than 86400",
|
|
||||||
java.lang.IllegalArgumentException::class.java
|
|
||||||
) {
|
|
||||||
mapProfileToBasalProgram(profile)
|
mapProfileToBasalProgram(profile)
|
||||||
}
|
}
|
||||||
|
assertThat(exception.message).isEqualTo("Basal segment start time can not be greater than 86400")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun invalidProfileNegativeOffset() {
|
@Test fun invalidProfileNegativeOffset() {
|
||||||
|
@ -92,9 +87,10 @@ class FunctionsTest {
|
||||||
arrayOf(ProfileValue(-1, 0.5))
|
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)
|
mapProfileToBasalProgram(profile)
|
||||||
}
|
}
|
||||||
|
assertThat(exception.message).isEqualTo("Basal segment start time can not be less than 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun roundsToSupportedPrecision() {
|
@Test fun roundsToSupportedPrecision() {
|
||||||
|
|
|
@ -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.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodErosManager
|
||||||
import info.nightscout.interfaces.profile.Profile
|
import info.nightscout.interfaces.profile.Profile
|
||||||
import info.nightscout.interfaces.profile.Profile.ProfileValue
|
import info.nightscout.interfaces.profile.Profile.ProfileValue
|
||||||
|
import kotlin.test.assertFailsWith
|
||||||
import org.joda.time.Duration
|
import org.joda.time.Duration
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
@ -34,11 +35,11 @@ internal class AapsOmnipodErosManagerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun invalidProfileNullProfile() {
|
@Test fun invalidProfileNullProfile() {
|
||||||
Assertions.assertThrows(IllegalArgumentException::class.java) { AapsOmnipodErosManager.mapProfileToBasalSchedule(null) }
|
assertFailsWith<IllegalArgumentException> { AapsOmnipodErosManager.mapProfileToBasalSchedule(null) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun invalidProfileNullEntries() {
|
@Test fun invalidProfileNullEntries() {
|
||||||
Assertions.assertThrows(IllegalArgumentException::class.java) {
|
assertFailsWith<IllegalArgumentException> {
|
||||||
AapsOmnipodErosManager.mapProfileToBasalSchedule(Mockito.mock(Profile::class.java))
|
AapsOmnipodErosManager.mapProfileToBasalSchedule(Mockito.mock(Profile::class.java))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +47,7 @@ internal class AapsOmnipodErosManagerTest {
|
||||||
@Test fun invalidProfileZeroEntries() {
|
@Test fun invalidProfileZeroEntries() {
|
||||||
val profile = Mockito.mock(Profile::class.java)
|
val profile = Mockito.mock(Profile::class.java)
|
||||||
Mockito.`when`(profile.getBasalValues()).thenReturn(emptyArray())
|
Mockito.`when`(profile.getBasalValues()).thenReturn(emptyArray())
|
||||||
Assertions.assertThrows(IllegalArgumentException::class.java) { AapsOmnipodErosManager.mapProfileToBasalSchedule(profile) }
|
assertFailsWith<IllegalArgumentException> { AapsOmnipodErosManager.mapProfileToBasalSchedule(profile) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun invalidProfileNonZeroOffset() {
|
@Test fun invalidProfileNonZeroOffset() {
|
||||||
|
@ -56,7 +57,7 @@ internal class AapsOmnipodErosManagerTest {
|
||||||
ProfileValue(1800, 0.5)
|
ProfileValue(1800, 0.5)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
Assertions.assertThrows(IllegalArgumentException::class.java) { AapsOmnipodErosManager.mapProfileToBasalSchedule(profile) }
|
assertFailsWith<IllegalArgumentException> { AapsOmnipodErosManager.mapProfileToBasalSchedule(profile) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun invalidProfileMoreThan24Hours() {
|
@Test fun invalidProfileMoreThan24Hours() {
|
||||||
|
@ -67,7 +68,7 @@ internal class AapsOmnipodErosManagerTest {
|
||||||
ProfileValue(86400, 0.5)
|
ProfileValue(86400, 0.5)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
Assertions.assertThrows(IllegalArgumentException::class.java) { AapsOmnipodErosManager.mapProfileToBasalSchedule(profile) }
|
assertFailsWith<IllegalArgumentException> { AapsOmnipodErosManager.mapProfileToBasalSchedule(profile) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun invalidProfileNegativeOffset() {
|
@Test fun invalidProfileNegativeOffset() {
|
||||||
|
@ -77,7 +78,7 @@ internal class AapsOmnipodErosManagerTest {
|
||||||
ProfileValue(-1, 0.5)
|
ProfileValue(-1, 0.5)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
Assertions.assertThrows(IllegalArgumentException::class.java) { AapsOmnipodErosManager.mapProfileToBasalSchedule(profile) }
|
assertFailsWith<IllegalArgumentException> { AapsOmnipodErosManager.mapProfileToBasalSchedule(profile) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun roundsToSupportedPrecision() {
|
@Test fun roundsToSupportedPrecision() {
|
||||||
|
@ -91,4 +92,4 @@ internal class AapsOmnipodErosManagerTest {
|
||||||
val basalScheduleEntry = basalSchedule.entries[0]
|
val basalScheduleEntry = basalSchedule.entries[0]
|
||||||
Assertions.assertEquals(0.05, basalScheduleEntry.rate, 0.000001)
|
Assertions.assertEquals(0.05, basalScheduleEntry.rate, 0.000001)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.response.podinfo
|
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.androidaps.plugins.pump.omnipod.eros.driver.definition.PodInfoType
|
||||||
import info.nightscout.pump.common.utils.ByteUtil
|
import info.nightscout.pump.common.utils.ByteUtil
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions
|
||||||
|
@ -31,8 +32,6 @@ internal class PodInfoResponseTest {
|
||||||
@Test fun testInvalidPodInfoTypeMessageDecoding() {
|
@Test fun testInvalidPodInfoTypeMessageDecoding() {
|
||||||
val podInfoResponse = PodInfoResponse(ByteUtil.fromHexString("0216020d0000000000ab6a038403ff03860000285708030d"))
|
val podInfoResponse = PodInfoResponse(ByteUtil.fromHexString("0216020d0000000000ab6a038403ff03860000285708030d"))
|
||||||
Assertions.assertEquals(PodInfoType.DETAILED_STATUS, podInfoResponse.subType)
|
Assertions.assertEquals(PodInfoType.DETAILED_STATUS, podInfoResponse.subType)
|
||||||
Assertions.assertThrows(ClassCastException::class.java) {
|
assertThat(podInfoResponse.podInfo).isNotInstanceOf(PodInfoActiveAlerts::class.java)
|
||||||
@Suppress("UNUSED_VARIABLE") val podInfo = podInfoResponse.podInfo as PodInfoActiveAlerts
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue