Rewrites GetTimePacketTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-10-08 17:18:53 -07:00
parent 568b6cbcc5
commit 764ae29e56

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 GetTimePacketTest : MedtrumTestBase() { class GetTimePacketTest : MedtrumTestBase() {
@ -30,8 +30,7 @@ class GetTimePacketTest : MedtrumTestBase() {
val result = packet.getRequest() val result = packet.getRequest()
// Expected values // Expected values
Assertions.assertEquals(1, result.size) assertThat(result).asList().containsExactly(opCode.toByte())
Assertions.assertEquals(opCode.toByte(), result[0])
} }
@Test fun handleResponseGivenResponseWhenMessageIsCorrectLengthThenResultTrue() { @Test fun handleResponseGivenResponseWhenMessageIsCorrectLengthThenResultTrue() {
@ -46,9 +45,9 @@ class GetTimePacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response) val result = packet.handleResponse(response)
// Expected values // Expected values
Assertions.assertEquals(true, result) assertThat(result).isTrue()
Assertions.assertEquals(false, packet.failed) assertThat(packet.failed).isFalse()
Assertions.assertEquals(MedtrumTimeUtil().convertPumpTimeToSystemTimeMillis(time), medtrumPump.lastTimeReceivedFromPump) assertThat(medtrumPump.lastTimeReceivedFromPump).isEqualTo(MedtrumTimeUtil().convertPumpTimeToSystemTimeMillis(time))
} }
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() { @Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
@ -63,8 +62,8 @@ class GetTimePacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response.sliceArray(0..response.size - 2)) val result = packet.handleResponse(response.sliceArray(0..response.size - 2))
// Expected values // Expected values
Assertions.assertEquals(false, result) assertThat(result).isFalse()
Assertions.assertEquals(true, packet.failed) assertThat(packet.failed).isTrue()
Assertions.assertEquals(0, medtrumPump.lastTimeReceivedFromPump) assertThat(medtrumPump.lastTimeReceivedFromPump).isEqualTo(0)
} }
} }