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
import com.google.common.truth.Truth.assertThat
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.pump.medtrum.MedtrumTestBase
import info.nightscout.pump.medtrum.extension.toByteArray
import info.nightscout.pump.medtrum.util.MedtrumTimeUtil
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class GetTimePacketTest : MedtrumTestBase() {
@ -30,8 +30,7 @@ class GetTimePacketTest : MedtrumTestBase() {
val result = packet.getRequest()
// Expected values
Assertions.assertEquals(1, result.size)
Assertions.assertEquals(opCode.toByte(), result[0])
assertThat(result).asList().containsExactly(opCode.toByte())
}
@Test fun handleResponseGivenResponseWhenMessageIsCorrectLengthThenResultTrue() {
@ -46,9 +45,9 @@ class GetTimePacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response)
// Expected values
Assertions.assertEquals(true, result)
Assertions.assertEquals(false, packet.failed)
Assertions.assertEquals(MedtrumTimeUtil().convertPumpTimeToSystemTimeMillis(time), medtrumPump.lastTimeReceivedFromPump)
assertThat(result).isTrue()
assertThat(packet.failed).isFalse()
assertThat(medtrumPump.lastTimeReceivedFromPump).isEqualTo(MedtrumTimeUtil().convertPumpTimeToSystemTimeMillis(time))
}
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
@ -63,8 +62,8 @@ class GetTimePacketTest : MedtrumTestBase() {
val result = packet.handleResponse(response.sliceArray(0..response.size - 2))
// Expected values
Assertions.assertEquals(false, result)
Assertions.assertEquals(true, packet.failed)
Assertions.assertEquals(0, medtrumPump.lastTimeReceivedFromPump)
assertThat(result).isFalse()
assertThat(packet.failed).isTrue()
assertThat(medtrumPump.lastTimeReceivedFromPump).isEqualTo(0)
}
}