From 6606f5453eee3366e33f31d88764aaa5ef9c3895 Mon Sep 17 00:00:00 2001 From: Ryan Haining Date: Fri, 8 Sep 2023 19:48:54 -0700 Subject: [PATCH] Rewrites StatusResponseTest with matchers Issue #2745 --- .../message/response/StatusResponseTest.java | 90 +++++++++---------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/pump/omnipod-eros/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/driver/communication/message/response/StatusResponseTest.java b/pump/omnipod-eros/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/driver/communication/message/response/StatusResponseTest.java index 10d7529762..8b504f49ba 100644 --- a/pump/omnipod-eros/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/driver/communication/message/response/StatusResponseTest.java +++ b/pump/omnipod-eros/src/test/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/driver/communication/message/response/StatusResponseTest.java @@ -1,8 +1,6 @@ package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.response; -import org.joda.time.Duration; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; +import static com.google.common.truth.Truth.assertThat; import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.AlertSlot; import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.DeliveryStatus; @@ -10,6 +8,9 @@ import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.Om import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.PodProgressStatus; import info.nightscout.pump.core.utils.ByteUtil; +import org.joda.time.Duration; +import org.junit.jupiter.api.Test; + class StatusResponseTest { @Test @@ -18,7 +19,7 @@ class StatusResponseTest { StatusResponse statusResponse = new StatusResponse(encodedData); - Assertions.assertArrayEquals(encodedData, statusResponse.getRawData()); + assertThat(statusResponse.getRawData()).isEqualTo(encodedData); } @Test @@ -28,7 +29,7 @@ class StatusResponseTest { StatusResponse statusResponse = new StatusResponse(encodedData); - Assertions.assertArrayEquals(expected, statusResponse.getRawData()); + assertThat(statusResponse.getRawData()).isEqualTo(expected); } @Test @@ -36,17 +37,17 @@ class StatusResponseTest { byte[] bytes = ByteUtil.fromHexString("1d180258f80000146fff"); // From https://github.com/openaps/openomni/wiki/Command-1D-Status-response StatusResponse statusResponse = new StatusResponse(bytes); - Assertions.assertEquals(DeliveryStatus.NORMAL, statusResponse.getDeliveryStatus()); - Assertions.assertEquals(PodProgressStatus.ABOVE_FIFTY_UNITS, statusResponse.getPodProgressStatus()); - Assertions.assertNull(statusResponse.getReservoirLevel()); - Assertions.assertEquals(Duration.standardMinutes(1307).getMillis(), statusResponse.getTimeActive().getMillis()); - Assertions.assertEquals(1201, statusResponse.getTicksDelivered()); - Assertions.assertEquals(60.05, statusResponse.getInsulinDelivered(), 0.000001); - Assertions.assertEquals(15, statusResponse.getPodMessageCounter()); - Assertions.assertEquals(0, statusResponse.getBolusNotDelivered(), 0.000001); - Assertions.assertEquals(0, statusResponse.getUnacknowledgedAlerts().getAlertSlots().size()); + assertThat(statusResponse.getDeliveryStatus()).isEqualTo(DeliveryStatus.NORMAL); + assertThat(statusResponse.getPodProgressStatus()).isEqualTo(PodProgressStatus.ABOVE_FIFTY_UNITS); + assertThat(statusResponse.getReservoirLevel()).isNull(); + assertThat(statusResponse.getTimeActive().getMillis()).isEqualTo(Duration.standardMinutes(1307).getMillis()); + assertThat(statusResponse.getTicksDelivered()).isEqualTo(1201); + assertThat(statusResponse.getInsulinDelivered()).isWithin(0.000001).of(60.05); + assertThat(statusResponse.getPodMessageCounter()).isEqualTo(15); + assertThat(statusResponse.getBolusNotDelivered()).isWithin(0.000001).of(0); + assertThat(statusResponse.getUnacknowledgedAlerts().getAlertSlots()).isEmpty(); - Assertions.assertArrayEquals(ByteUtil.fromHexString("1d180258f80000146fff"), statusResponse.getRawData()); + assertThat(statusResponse.getRawData()).isEqualTo(ByteUtil.fromHexString("1d180258f80000146fff")); } @Test @@ -54,18 +55,17 @@ class StatusResponseTest { byte[] bytes = ByteUtil.fromHexString("1d19061f6800044295e8"); // From https://github.com/openaps/openomni/wiki/Status-Response-1D-long-run-%28Lytrix%29 StatusResponse statusResponse = new StatusResponse(bytes); - Assertions.assertEquals(DeliveryStatus.NORMAL, statusResponse.getDeliveryStatus()); - Assertions.assertEquals(PodProgressStatus.FIFTY_OR_LESS_UNITS, statusResponse.getPodProgressStatus()); - Assertions.assertEquals(24.4, statusResponse.getReservoirLevel(), 0.000001); - Assertions.assertEquals(Duration.standardMinutes(4261).getMillis(), statusResponse.getTimeActive().getMillis()); - Assertions.assertEquals(3134, statusResponse.getTicksDelivered()); - Assertions.assertEquals(156.7, statusResponse.getInsulinDelivered(), 0.000001); - Assertions.assertEquals(13, statusResponse.getPodMessageCounter()); - Assertions.assertEquals(0, statusResponse.getBolusNotDelivered(), 0.000001); - Assertions.assertEquals(1, statusResponse.getUnacknowledgedAlerts().getAlertSlots().size()); - Assertions.assertEquals(AlertSlot.SLOT3, statusResponse.getUnacknowledgedAlerts().getAlertSlots().get(0)); + assertThat(statusResponse.getDeliveryStatus()).isEqualTo(DeliveryStatus.NORMAL); + assertThat(statusResponse.getPodProgressStatus()).isEqualTo(PodProgressStatus.FIFTY_OR_LESS_UNITS); + assertThat(statusResponse.getReservoirLevel()).isWithin(0.000001).of(24.4); + assertThat(statusResponse.getTimeActive().getMillis()).isEqualTo(Duration.standardMinutes(4261).getMillis()); + assertThat(statusResponse.getTicksDelivered()).isEqualTo(3134); + assertThat(statusResponse.getInsulinDelivered()).isWithin(0.000001).of(156.7); + assertThat(statusResponse.getPodMessageCounter()).isEqualTo(13); + assertThat(statusResponse.getBolusNotDelivered()).isWithin(0.000001).of(0); + assertThat(statusResponse.getUnacknowledgedAlerts().getAlertSlots()).containsExactly(AlertSlot.SLOT3); - Assertions.assertArrayEquals(ByteUtil.fromHexString("1d19061f6800044295e8"), statusResponse.getRawData()); + assertThat(statusResponse.getRawData()).isEqualTo(ByteUtil.fromHexString("1d19061f6800044295e8")); } @Test @@ -73,16 +73,16 @@ class StatusResponseTest { byte[] bytes = ByteUtil.fromHexString("1d11ffffffffffffffff"); StatusResponse statusResponse = new StatusResponse(bytes); - Assertions.assertEquals(Duration.standardMinutes(8191).getMillis(), statusResponse.getTimeActive().getMillis()); - Assertions.assertEquals(OmnipodConstants.POD_PULSE_SIZE * 1023, statusResponse.getBolusNotDelivered(), 0.000001); - Assertions.assertNull(statusResponse.getReservoirLevel()); - Assertions.assertEquals(OmnipodConstants.POD_PULSE_SIZE * 8191, statusResponse.getInsulinDelivered(), 0.0000001); - Assertions.assertEquals(8191, statusResponse.getTicksDelivered()); - Assertions.assertEquals(OmnipodConstants.POD_PULSE_SIZE * 8191, statusResponse.getInsulinDelivered(), 0.0000001); - Assertions.assertEquals(15, statusResponse.getPodMessageCounter()); - Assertions.assertEquals(8, statusResponse.getUnacknowledgedAlerts().getAlertSlots().size()); + assertThat(statusResponse.getTimeActive().getMillis()).isEqualTo(Duration.standardMinutes(8191).getMillis()); + assertThat(statusResponse.getBolusNotDelivered()).isWithin(0.000001).of(OmnipodConstants.POD_PULSE_SIZE * 1023); + assertThat(statusResponse.getReservoirLevel()).isNull(); + assertThat(statusResponse.getInsulinDelivered()).isWithin(0.0000001).of(OmnipodConstants.POD_PULSE_SIZE * 8191); + assertThat(statusResponse.getTicksDelivered()).isEqualTo(8191); + assertThat(statusResponse.getInsulinDelivered()).isWithin(0.0000001).of(OmnipodConstants.POD_PULSE_SIZE * 8191); + assertThat(statusResponse.getPodMessageCounter()).isEqualTo(15); + assertThat(statusResponse.getUnacknowledgedAlerts().getAlertSlots()).hasSize(8); - Assertions.assertArrayEquals(ByteUtil.fromHexString("1d11ffffffffffffffff"), statusResponse.getRawData()); + assertThat(statusResponse.getRawData()).isEqualTo(ByteUtil.fromHexString("1d11ffffffffffffffff")); } @Test @@ -90,15 +90,15 @@ class StatusResponseTest { byte[] bytes = ByteUtil.fromHexString("1d19050ec82c08376f98"); StatusResponse statusResponse = new StatusResponse(bytes); - Assertions.assertTrue(Duration.standardMinutes(3547).isEqual(statusResponse.getTimeActive())); - Assertions.assertEquals(DeliveryStatus.NORMAL, statusResponse.getDeliveryStatus()); - Assertions.assertEquals(PodProgressStatus.FIFTY_OR_LESS_UNITS, statusResponse.getPodProgressStatus()); - Assertions.assertEquals(2589, statusResponse.getTicksDelivered()); - Assertions.assertEquals(129.45, statusResponse.getInsulinDelivered(), 0.00001); - Assertions.assertEquals(46.00, statusResponse.getReservoirLevel(), 0.00001); - Assertions.assertEquals(2.2, statusResponse.getBolusNotDelivered(), 0.0001); - Assertions.assertEquals(9, statusResponse.getPodMessageCounter()); + assertThat(statusResponse.getTimeActive()).isEqualTo(Duration.standardMinutes(3547)); + assertThat(statusResponse.getDeliveryStatus()).isEqualTo(DeliveryStatus.NORMAL); + assertThat(statusResponse.getPodProgressStatus()).isEqualTo(PodProgressStatus.FIFTY_OR_LESS_UNITS); + assertThat(statusResponse.getTicksDelivered()).isEqualTo(2589); + assertThat(statusResponse.getInsulinDelivered()).isWithin(0.00001).of(129.45); + assertThat(statusResponse.getReservoirLevel()).isWithin(0.00001).of(46.00); + assertThat(statusResponse.getBolusNotDelivered()).isWithin(0.0001).of(2.2); + assertThat(statusResponse.getPodMessageCounter()).isEqualTo(9); - Assertions.assertArrayEquals(ByteUtil.fromHexString("1d19050ec82c08376f98"), statusResponse.getRawData()); + assertThat(statusResponse.getRawData()).isEqualTo(ByteUtil.fromHexString("1d19050ec82c08376f98")); } -} \ No newline at end of file +}