Rewrites PodInfoResponseTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-10-05 23:10:32 -07:00
parent 89366e54b8
commit f388285ff5

View file

@ -3,35 +3,35 @@ package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communicatio
import com.google.common.truth.Truth.assertThat 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 kotlin.test.assertIsNot
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
internal class PodInfoResponseTest { internal class PodInfoResponseTest {
@Test fun testRawData() { @Test fun testRawData() {
val encodedData = ByteUtil.fromHexString("0216020d0000000000ab6a038403ff03860000285708030d") val encodedData = ByteUtil.fromHexString("0216020d0000000000ab6a038403ff03860000285708030d")!!
val podInfoResponse = PodInfoResponse(encodedData) val podInfoResponse = PodInfoResponse(encodedData)
Assertions.assertArrayEquals(encodedData, podInfoResponse.rawData) assertThat(podInfoResponse.rawData.asList()).containsExactlyElementsIn(encodedData.asIterable()).inOrder()
} }
@Test fun testRawDataWithLongerMessage() { @Test fun testRawDataWithLongerMessage() {
val encodedData = ByteUtil.fromHexString("0216020d0000000000ab6a038403ff03860000285708030d01") val encodedData = ByteUtil.fromHexString("0216020d0000000000ab6a038403ff03860000285708030d01")!!
val expected = ByteUtil.fromHexString("0216020d0000000000ab6a038403ff03860000285708030d") val expected = ByteUtil.fromHexString("0216020d0000000000ab6a038403ff03860000285708030d")!!
val podInfoResponse = PodInfoResponse(encodedData) val podInfoResponse = PodInfoResponse(encodedData)
Assertions.assertArrayEquals(expected, podInfoResponse.rawData) assertThat(podInfoResponse.rawData.asList()).containsExactlyElementsIn(expected.asIterable()).inOrder()
} }
@Test fun testMessageDecoding() { @Test fun testMessageDecoding() {
val podInfoResponse = PodInfoResponse(ByteUtil.fromHexString("0216020d0000000000ab6a038403ff03860000285708030d")) val podInfoResponse = PodInfoResponse(ByteUtil.fromHexString("0216020d0000000000ab6a038403ff03860000285708030d"))
Assertions.assertEquals(PodInfoType.DETAILED_STATUS, podInfoResponse.subType) assertThat(podInfoResponse.subType).isEqualTo(PodInfoType.DETAILED_STATUS)
val podInfo = podInfoResponse.podInfo as PodInfoDetailedStatus val podInfo = podInfoResponse.podInfo as PodInfoDetailedStatus
Assertions.assertFalse(podInfo.isFaultAccessingTables) assertThat(podInfo.isFaultAccessingTables).isFalse()
Assertions.assertEquals(0x01, podInfo.errorEventInfo.internalVariable.toInt()) assertThat(podInfo.errorEventInfo.internalVariable.toInt()).isEqualTo(0x01)
} }
@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) assertThat(podInfoResponse.subType).isEqualTo(PodInfoType.DETAILED_STATUS)
assertThat(podInfoResponse.podInfo).isNotInstanceOf(PodInfoActiveAlerts::class.java) assertIsNot<PodInfoActiveAlerts>(podInfoResponse.podInfo)
} }
} }