From c95654c0ac96a1de73ccce1ceee6acfc6129d50b Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Sun, 8 Oct 2023 16:45:18 -0700 Subject: [PATCH] Rewrites AuthorizePacketTest with matchers Issue #2745 --- .../medtrum/comm/packets/AuthorizePacketTest.kt | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/pump/medtrum/src/test/java/info/nightscout/pump/medtrum/comm/packets/AuthorizePacketTest.kt b/pump/medtrum/src/test/java/info/nightscout/pump/medtrum/comm/packets/AuthorizePacketTest.kt index 0244392562..99e2aee435 100644 --- a/pump/medtrum/src/test/java/info/nightscout/pump/medtrum/comm/packets/AuthorizePacketTest.kt +++ b/pump/medtrum/src/test/java/info/nightscout/pump/medtrum/comm/packets/AuthorizePacketTest.kt @@ -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() } }