Rewrites DefaultStatusResponseTest with matchers

Issue #2745
This commit is contained in:
Ryan Haining 2023-10-08 20:25:32 -07:00
parent 8af75ade2a
commit 6785f1a11d

View file

@ -1,30 +1,30 @@
package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response package info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.response
import com.google.common.truth.Truth.assertThat
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.AlertType import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.AlertType
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.DeliveryStatus import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.DeliveryStatus
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodStatus import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.pod.definition.PodStatus
import org.apache.commons.codec.DecoderException import org.apache.commons.codec.DecoderException
import org.apache.commons.codec.binary.Hex import org.apache.commons.codec.binary.Hex
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
class DefaultStatusResponseTest { class DefaultStatusResponseTest {
@Test @Throws(DecoderException::class) fun testValidResponse() { @Test fun testValidResponse() {
val encoded = Hex.decodeHex("1D1800A02800000463FF") val encoded = Hex.decodeHex("1D1800A02800000463FF")
val response = DefaultStatusResponse(encoded) val response = DefaultStatusResponse(encoded)
Assertions.assertArrayEquals(encoded, response.encoded) assertThat(response.encoded).asList().containsExactlyElementsIn(encoded.asList())
Assertions.assertNotSame(encoded, response.encoded) assertThat(response.encoded).isNotSameInstanceAs(encoded)
Assertions.assertEquals(ResponseType.DEFAULT_STATUS_RESPONSE, response.responseType) assertThat(response.responseType).isEqualTo(ResponseType.DEFAULT_STATUS_RESPONSE)
Assertions.assertEquals(ResponseType.DEFAULT_STATUS_RESPONSE.value, response.messageType) assertThat(response.messageType).isEqualTo(ResponseType.DEFAULT_STATUS_RESPONSE.value)
Assertions.assertEquals(DeliveryStatus.BASAL_ACTIVE, response.deliveryStatus) assertThat(response.deliveryStatus).isEqualTo(DeliveryStatus.BASAL_ACTIVE)
Assertions.assertEquals(PodStatus.RUNNING_ABOVE_MIN_VOLUME, response.podStatus) assertThat(response.podStatus).isEqualTo(PodStatus.RUNNING_ABOVE_MIN_VOLUME)
Assertions.assertEquals(320.toShort(), response.totalPulsesDelivered) assertThat(response.totalPulsesDelivered).isEqualTo(320.toShort())
Assertions.assertEquals(5.toShort(), response.sequenceNumberOfLastProgrammingCommand) assertThat(response.sequenceNumberOfLastProgrammingCommand).isEqualTo(5.toShort())
Assertions.assertEquals(0.toShort(), response.bolusPulsesRemaining) assertThat(response.bolusPulsesRemaining).isEqualTo(0.toShort())
Assertions.assertEquals(0, response.activeAlerts.size) assertThat(response.activeAlerts).isEmpty()
Assertions.assertEquals(280.toShort(), response.minutesSinceActivation) assertThat(response.minutesSinceActivation).isEqualTo(280.toShort())
Assertions.assertEquals(1023.toShort(), response.reservoirPulsesRemaining) assertThat(response.reservoirPulsesRemaining).isEqualTo(1023.toShort())
} }
/** /**
@ -49,21 +49,21 @@ class DefaultStatusResponseTest {
Alert 7 is InActive Alert 7 is InActive
Occlusion alert active false Occlusion alert active false
*/ */
@Test @Throws(DecoderException::class) fun testValidResponseBelowMin() { @Test fun testValidResponseBelowMin() {
val encoded = Hex.decodeHex("1D1905281000004387D3039A") val encoded = Hex.decodeHex("1D1905281000004387D3039A")
val response = DefaultStatusResponse(encoded) val response = DefaultStatusResponse(encoded)
Assertions.assertArrayEquals(encoded, response.encoded) assertThat(response.encoded).asList().containsExactlyElementsIn(encoded.asList()).inOrder()
Assertions.assertNotSame(encoded, response.encoded) assertThat(response.encoded).isNotSameInstanceAs(encoded)
Assertions.assertEquals(ResponseType.DEFAULT_STATUS_RESPONSE, response.responseType) assertThat(response.responseType).isEqualTo(ResponseType.DEFAULT_STATUS_RESPONSE)
Assertions.assertEquals(ResponseType.DEFAULT_STATUS_RESPONSE.value, response.messageType) assertThat(response.messageType).isEqualTo(ResponseType.DEFAULT_STATUS_RESPONSE.value)
Assertions.assertEquals(DeliveryStatus.BASAL_ACTIVE, response.deliveryStatus) assertThat(response.deliveryStatus).isEqualTo(DeliveryStatus.BASAL_ACTIVE)
Assertions.assertEquals(PodStatus.RUNNING_BELOW_MIN_VOLUME, response.podStatus) assertThat(response.podStatus).isEqualTo(PodStatus.RUNNING_BELOW_MIN_VOLUME)
Assertions.assertEquals(2.toShort(), response.sequenceNumberOfLastProgrammingCommand) assertThat(response.sequenceNumberOfLastProgrammingCommand).isEqualTo(2.toShort())
Assertions.assertEquals(0.toShort(), response.bolusPulsesRemaining) assertThat(response.bolusPulsesRemaining).isEqualTo(0.toShort())
Assertions.assertEquals(0, response.activeAlerts.size) assertThat(response.activeAlerts).isEmpty()
Assertions.assertEquals(4321.toShort(), response.minutesSinceActivation) assertThat(response.minutesSinceActivation).isEqualTo(4321.toShort())
Assertions.assertEquals(979.toShort(), response.reservoirPulsesRemaining) assertThat(response.reservoirPulsesRemaining).isEqualTo(979.toShort())
Assertions.assertEquals(2640.toShort(), response.totalPulsesDelivered) assertThat(response.totalPulsesDelivered).isEqualTo(2640.toShort())
} }
/** /**
@ -88,21 +88,21 @@ class DefaultStatusResponseTest {
Alert 7 is InActive Alert 7 is InActive
Occlusion alert active false Occlusion alert active false
*/ */
@Test @Throws(DecoderException::class) fun testValidResponseBolusPulsesRemaining() { @Test fun testValidResponseBolusPulsesRemaining() {
val encoded = Hex.decodeHex("1D180519C00E0039A7FF8085") val encoded = Hex.decodeHex("1D180519C00E0039A7FF8085")
val response = DefaultStatusResponse(encoded) val response = DefaultStatusResponse(encoded)
Assertions.assertArrayEquals(encoded, response.encoded) assertThat(response.encoded).asList().containsExactlyElementsIn(encoded.asList()).inOrder()
Assertions.assertNotSame(encoded, response.encoded) assertThat(response.encoded).isNotSameInstanceAs(encoded)
Assertions.assertEquals(ResponseType.DEFAULT_STATUS_RESPONSE, response.responseType) assertThat(response.responseType).isEqualTo(ResponseType.DEFAULT_STATUS_RESPONSE)
Assertions.assertEquals(ResponseType.DEFAULT_STATUS_RESPONSE.value, response.messageType) assertThat(response.messageType).isEqualTo(ResponseType.DEFAULT_STATUS_RESPONSE.value)
Assertions.assertEquals(DeliveryStatus.BASAL_ACTIVE, response.deliveryStatus) assertThat(response.deliveryStatus).isEqualTo(DeliveryStatus.BASAL_ACTIVE)
Assertions.assertEquals(PodStatus.RUNNING_ABOVE_MIN_VOLUME, response.podStatus) assertThat(response.podStatus).isEqualTo(PodStatus.RUNNING_ABOVE_MIN_VOLUME)
Assertions.assertEquals(8.toShort(), response.sequenceNumberOfLastProgrammingCommand) assertThat(response.sequenceNumberOfLastProgrammingCommand).isEqualTo(8.toShort())
Assertions.assertEquals(14.toShort(), response.bolusPulsesRemaining) assertThat(response.bolusPulsesRemaining).isEqualTo(14.toShort())
Assertions.assertEquals(0, response.activeAlerts.size) assertThat(response.activeAlerts).isEmpty()
Assertions.assertEquals(3689.toShort(), response.minutesSinceActivation) assertThat(response.minutesSinceActivation).isEqualTo(3689.toShort())
Assertions.assertEquals(1023.toShort(), response.reservoirPulsesRemaining) assertThat(response.reservoirPulsesRemaining).isEqualTo(1023.toShort())
Assertions.assertEquals(2611.toShort(), response.totalPulsesDelivered) assertThat(response.totalPulsesDelivered).isEqualTo(2611.toShort())
} }
/** response (hex) 1D990714201F0042ED8801DE /** response (hex) 1D990714201F0042ED8801DE
@ -118,21 +118,21 @@ class DefaultStatusResponseTest {
Full reservoir pulses remaining: 392 Full reservoir pulses remaining: 392
Time since activation: 4283 Time since activation: 4283
*/ */
@Test @Throws(DecoderException::class) fun testValidResponseReservoirPulsesRemaining() { @Test fun testValidResponseReservoirPulsesRemaining() {
val encoded = Hex.decodeHex("1D990714201F0042ED8801DE") val encoded = Hex.decodeHex("1D990714201F0042ED8801DE")
val response = DefaultStatusResponse(encoded) val response = DefaultStatusResponse(encoded)
Assertions.assertArrayEquals(encoded, response.encoded) assertThat(response.encoded).asList().containsExactlyElementsIn(encoded.asList()).inOrder()
Assertions.assertNotSame(encoded, response.encoded) assertThat(response.encoded).isNotSameInstanceAs(encoded)
Assertions.assertEquals(ResponseType.DEFAULT_STATUS_RESPONSE, response.responseType) assertThat(response.responseType).isEqualTo(ResponseType.DEFAULT_STATUS_RESPONSE)
Assertions.assertEquals(ResponseType.DEFAULT_STATUS_RESPONSE.value, response.messageType) assertThat(response.messageType).isEqualTo(ResponseType.DEFAULT_STATUS_RESPONSE.value)
Assertions.assertEquals(DeliveryStatus.UNKNOWN, response.deliveryStatus) // Extended bolus active assertThat(response.deliveryStatus).isEqualTo(DeliveryStatus.UNKNOWN) // Extended bolus active
Assertions.assertEquals(PodStatus.RUNNING_BELOW_MIN_VOLUME, response.podStatus) assertThat(response.podStatus).isEqualTo(PodStatus.RUNNING_BELOW_MIN_VOLUME)
Assertions.assertEquals(4.toShort(), response.sequenceNumberOfLastProgrammingCommand) assertThat(response.sequenceNumberOfLastProgrammingCommand).isEqualTo(4.toShort())
Assertions.assertEquals(31.toShort(), response.bolusPulsesRemaining) assertThat(response.bolusPulsesRemaining).isEqualTo(31.toShort())
Assertions.assertEquals(0, response.activeAlerts.size) assertThat(response.activeAlerts).isEmpty()
Assertions.assertEquals(4283.toShort(), response.minutesSinceActivation) assertThat(response.minutesSinceActivation).isEqualTo(4283.toShort())
Assertions.assertEquals(392.toShort(), response.reservoirPulsesRemaining) assertThat(response.reservoirPulsesRemaining).isEqualTo(392.toShort())
Assertions.assertEquals(3624.toShort(), response.totalPulsesDelivered) assertThat(response.totalPulsesDelivered).isEqualTo(3624.toShort())
} }
/** response (hex) 1d68002601f400002bff0368 /** response (hex) 1d68002601f400002bff0368
@ -148,13 +148,13 @@ class DefaultStatusResponseTest {
Full reservoir pulses remaining: 392 Full reservoir pulses remaining: 392
Time since activation: 4283 Time since activation: 4283
*/ */
@Test @Throws(DecoderException::class) fun testValidResponseBolusPulsesRemaining3() { @Test fun testValidResponseBolusPulsesRemaining3() {
val encoded = Hex.decodeHex("1d68002601f400002bff0368") val encoded = Hex.decodeHex("1d68002601f400002bff0368")
val response = DefaultStatusResponse(encoded) val response = DefaultStatusResponse(encoded)
Assertions.assertArrayEquals(encoded, response.encoded) assertThat(response.encoded).asList().containsExactlyElementsIn(encoded.asList()).inOrder()
Assertions.assertNotSame(encoded, response.encoded) assertThat(response.encoded).isNotSameInstanceAs(encoded)
Assertions.assertEquals(500.toShort(), response.bolusPulsesRemaining) assertThat(response.bolusPulsesRemaining).isEqualTo(500.toShort())
Assertions.assertEquals(0, response.activeAlerts.size) assertThat(response.activeAlerts).isEmpty()
} }
/** response (hex) 1d28002e91e400002fff8256 /** response (hex) 1d28002e91e400002fff8256
@ -170,13 +170,13 @@ class DefaultStatusResponseTest {
Full reservoir pulses remaining: 392 Full reservoir pulses remaining: 392
Time since activation: 4283 Time since activation: 4283
*/ */
@Test @Throws(DecoderException::class) fun testValidResponseBolusPulsesRemaining4() { @Test fun testValidResponseBolusPulsesRemaining4() {
val encoded = Hex.decodeHex("1d28002e91e400002fff8256") val encoded = Hex.decodeHex("1d28002e91e400002fff8256")
val response = DefaultStatusResponse(encoded) val response = DefaultStatusResponse(encoded)
Assertions.assertArrayEquals(encoded, response.encoded) assertThat(response.encoded).asList().containsExactlyElementsIn(encoded.asList()).inOrder()
Assertions.assertNotSame(encoded, response.encoded) assertThat(response.encoded).isNotSameInstanceAs(encoded)
Assertions.assertEquals(484.toShort(), response.bolusPulsesRemaining) assertThat(response.bolusPulsesRemaining).isEqualTo(484.toShort())
Assertions.assertEquals(0, response.activeAlerts.size) assertThat(response.activeAlerts).isEmpty()
} }
/* /*
@ -200,21 +200,21 @@ class DefaultStatusResponseTest {
Alert 7 is Active Alert 7 is Active
Occlusion alert active false Occlusion alert active false
*/ */
@Test @Throws(DecoderException::class) fun testValidResponseActiveAlert1() { @Test fun testValidResponseActiveAlert1() {
val encoded = Hex.decodeHex("1D980559C820404393FF83AA") val encoded = Hex.decodeHex("1D980559C820404393FF83AA")
val response = DefaultStatusResponse(encoded) val response = DefaultStatusResponse(encoded)
Assertions.assertArrayEquals(encoded, response.encoded) assertThat(response.encoded).asList().containsExactlyElementsIn(encoded.asList()).inOrder()
Assertions.assertNotSame(encoded, response.encoded) assertThat(response.encoded).isNotSameInstanceAs(encoded)
Assertions.assertEquals(ResponseType.DEFAULT_STATUS_RESPONSE, response.responseType) assertThat(response.responseType).isEqualTo(ResponseType.DEFAULT_STATUS_RESPONSE)
Assertions.assertEquals(ResponseType.DEFAULT_STATUS_RESPONSE.value, response.messageType) assertThat(response.messageType).isEqualTo(ResponseType.DEFAULT_STATUS_RESPONSE.value)
Assertions.assertEquals(DeliveryStatus.UNKNOWN, response.deliveryStatus) assertThat(response.deliveryStatus).isEqualTo(DeliveryStatus.UNKNOWN)
Assertions.assertEquals(PodStatus.RUNNING_ABOVE_MIN_VOLUME, response.podStatus) assertThat(response.podStatus).isEqualTo(PodStatus.RUNNING_ABOVE_MIN_VOLUME)
Assertions.assertEquals(9.toShort(), response.sequenceNumberOfLastProgrammingCommand) assertThat(response.sequenceNumberOfLastProgrammingCommand).isEqualTo(9.toShort())
Assertions.assertEquals(32.toShort(), response.bolusPulsesRemaining) assertThat(response.bolusPulsesRemaining).isEqualTo(32.toShort())
Assertions.assertEquals(1, response.activeAlerts.size) assertThat(response.activeAlerts).hasSize(1)
Assertions.assertEquals(4324.toShort(), response.minutesSinceActivation) assertThat(response.minutesSinceActivation).isEqualTo(4324.toShort())
Assertions.assertEquals(1023.toShort(), response.reservoirPulsesRemaining) assertThat(response.reservoirPulsesRemaining).isEqualTo(1023.toShort())
Assertions.assertEquals(2739.toShort(), response.totalPulsesDelivered) assertThat(response.totalPulsesDelivered).isEqualTo(2739.toShort())
Assertions.assertEquals(true, response.activeAlerts.contains(AlertType.EXPIRATION)) assertThat(response.activeAlerts.contains(AlertType.EXPIRATION)).isTrue()
} }
} }