Rewrites AuthorizePacketTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-10-08 16:45:18 -07:00
parent b83e19ea6a
commit c95654c0ac

View file

@ -1,11 +1,11 @@
package info.nightscout.pump.medtrum.comm.packets
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumPump
import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.extension.toByteArray
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class AuthorizePacketTest : MedtrumTestBase() {
@ -37,8 +37,7 @@ class AuthorizePacketTest : MedtrumTestBase() {
val key = 3364239851
val type = 2
val expectedByteArray = byteArrayOf(opCode.toByte()) + type.toByte() + medtrumPump.patchSessionToken.toByteArray(4) + key.toByteArray(4)
Assertions.assertEquals(10, result.size)
Assertions.assertEquals(expectedByteArray.contentToString(), result.contentToString())
assertThat(result).asList().containsExactlyElementsIn(expectedByteArray.toList()).inOrder()
}
@Test fun handleResponseGivenResponseWhenMessageIsCorrectLengthThenResultTrue() {
@ -57,10 +56,10 @@ class AuthorizePacketTest : MedtrumTestBase() {
// Expected values
val swString = "$swVerX.$swVerY.$swVerZ"
Assertions.assertTrue(result)
Assertions.assertFalse(packet.failed)
Assertions.assertEquals(deviceType, medtrumPump.deviceType)
Assertions.assertEquals(swString, medtrumPump.swVersion)
assertThat(result).isTrue()
assertThat(packet.failed).isFalse()
assertThat(medtrumPump.deviceType).isEqualTo(deviceType)
assertThat(medtrumPump.swVersion).isEqualTo(swString)
}
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
@ -75,7 +74,7 @@ class AuthorizePacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response)
// Expected values
Assertions.assertFalse(result)
Assertions.assertTrue(packet.failed)
assertThat(result).isFalse()
assertThat(packet.failed).isTrue()
}
}