Rewrites SetTimeZonePacketTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-10-08 18:20:33 -07:00
parent 58dd9692de
commit d75bf0e611

View file

@ -1,11 +1,11 @@
package info.nightscout.pump.medtrum.comm.packets package info.nightscout.pump.medtrum.comm.packets
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.extension.toByteArray import info.nightscout.pump.medtrum.extension.toByteArray
import info.nightscout.pump.medtrum.util.MedtrumTimeUtil import info.nightscout.pump.medtrum.util.MedtrumTimeUtil
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
class SetTimeZonePacketTest : MedtrumTestBase() { class SetTimeZonePacketTest : MedtrumTestBase() {
@ -35,9 +35,8 @@ class SetTimeZonePacketTest : MedtrumTestBase() {
val result = packet.getRequest() val result = packet.getRequest()
// Expected values // Expected values
val expectedByteArray = byteArrayOf(opCode.toByte()) + offsetMinutes.toByteArray(2) + time.toByteArray(4) val expected = byteArrayOf(opCode.toByte()) + offsetMinutes.toByteArray(2) + time.toByteArray(4)
Assertions.assertEquals(7, result.size) assertThat(result).asList().containsExactlyElementsIn(expected.toList()).inOrder()
Assertions.assertEquals(expectedByteArray.contentToString(), result.contentToString())
} }
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() { @Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
@ -50,7 +49,7 @@ class SetTimeZonePacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response) val result = packet.handleResponse(response)
// Expected values // Expected values
Assertions.assertTrue(result) assertThat(result).isTrue()
Assertions.assertEquals(offsetMinutes, medtrumPump.pumpTimeZoneOffset) assertThat(medtrumPump.pumpTimeZoneOffset).isEqualTo(offsetMinutes)
} }
} }