Rewrites MessagePacketTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-10-08 19:00:47 -07:00
parent 6bc5adfe52
commit 23a97d1dc5

View file

@ -1,9 +1,9 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message
import app.aaps.core.utils.toHex import app.aaps.core.utils.toHex
import com.google.common.truth.Truth.assertThat
import com.google.crypto.tink.subtle.Hex import com.google.crypto.tink.subtle.Hex
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.Id import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.Id
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
class MessagePacketTest { class MessagePacketTest {
@ -16,19 +16,19 @@ class MessagePacketTest {
@Test fun testParseMessagePacket() { @Test fun testParseMessagePacket() {
val msg = MessagePacket.parse(Hex.decode(payload)) val msg = MessagePacket.parse(Hex.decode(payload))
Assertions.assertEquals(msg.type, MessageType.ENCRYPTED) assertThat(msg.type).isEqualTo(MessageType.ENCRYPTED)
Assertions.assertEquals(msg.source, Id.fromLong(136326824)) assertThat(msg.source).isEqualTo(Id.fromLong(136326824))
Assertions.assertEquals(msg.destination, Id.fromLong(136326825)) assertThat(msg.destination).isEqualTo(Id.fromLong(136326825))
Assertions.assertEquals(msg.sequenceNumber, 7.toByte()) assertThat(msg.sequenceNumber).isEqualTo(7.toByte())
Assertions.assertEquals(msg.ackNumber, 0.toByte()) assertThat(msg.ackNumber).isEqualTo(0.toByte())
Assertions.assertEquals(msg.eqos, 1.toShort()) assertThat(msg.eqos).isEqualTo(1.toShort())
Assertions.assertEquals(msg.priority, false) assertThat(msg.priority).isFalse()
Assertions.assertEquals(msg.lastMessage, false) assertThat(msg.lastMessage).isFalse()
Assertions.assertEquals(msg.gateway, false) assertThat(msg.gateway).isFalse()
Assertions.assertEquals(msg.sas, true) assertThat(msg.sas).isTrue()
Assertions.assertEquals(msg.tfs, false) assertThat(msg.tfs).isFalse()
Assertions.assertEquals(msg.version, 0.toShort()) assertThat(msg.version).isEqualTo(0.toShort())
Assertions.assertEquals(msg.payload.toHex(), payload.substring(32, payload.length)) assertThat(payload.substring(32, payload.length)).isEqualTo(msg.payload.toHex())
} }
@Test fun testSerializeMessagePacket() { @Test fun testSerializeMessagePacket() {
@ -46,6 +46,6 @@ class MessagePacketTest {
tfs = false, tfs = false,
payload = Hex.decode(payload.substring(32, payload.length)) payload = Hex.decode(payload.substring(32, payload.length))
) )
Assertions.assertEquals(msg.asByteArray().toHex(), payload) assertThat(msg.asByteArray().toHex()).isEqualTo(payload)
} }
} }