shared-tests #13

This commit is contained in:
Milos Kozak 2023-09-04 09:33:33 +02:00
parent a2fb04c5fe
commit 22c1f8f166
34 changed files with 589 additions and 710 deletions

View file

@ -43,6 +43,7 @@ dependencies {
api "androidx.room:room-rxjava3:$room_version" api "androidx.room:room-rxjava3:$room_version"
kapt "androidx.room:room-compiler:$room_version" kapt "androidx.room:room-compiler:$room_version"
testImplementation project(':app-wear-shared:shared-tests')
// optional - Test helpers // optional - Test helpers
testImplementation("androidx.room:room-testing:$room_version") testImplementation("androidx.room:room-testing:$room_version")
} }

View file

@ -1,37 +0,0 @@
package info.nightscout.androidaps
import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.TestAapsSchedulers
import info.nightscout.rx.logging.AAPSLoggerTest
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.Mockito
import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.junit.jupiter.MockitoSettings
import org.mockito.quality.Strictness
import java.util.Locale
@ExtendWith(MockitoExtension::class)
@MockitoSettings(strictness = Strictness.LENIENT)
open class TestBase {
val aapsLogger = AAPSLoggerTest()
val aapsSchedulers: AapsSchedulers = TestAapsSchedulers()
@BeforeEach
fun setupLocale() {
Locale.setDefault(Locale.ENGLISH)
System.setProperty("disableFirebase", "true")
}
// Workaround for Kotlin nullability.
// https://medium.com/@elye.project/befriending-kotlin-and-mockito-1c2e7b0ef791
// https://stackoverflow.com/questions/30305217/is-it-possible-to-use-mockito-in-kotlin
fun <T> anyObject(): T {
Mockito.any<T>()
return uninitialized()
}
@Suppress("Unchecked_Cast")
fun <T> uninitialized(): T = null as T
}

View file

@ -2,11 +2,9 @@ package info.nightscout.androidaps.plugins.pump.omnipod.eros
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil
import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database.ErosHistoryDatabase import info.nightscout.androidaps.plugins.pump.omnipod.eros.history.database.ErosHistoryDatabase
import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodErosManager import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodErosManager
import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.profile.Profile import info.nightscout.interfaces.profile.Profile
import info.nightscout.interfaces.pump.PumpEnactResult import info.nightscout.interfaces.pump.PumpEnactResult
import info.nightscout.interfaces.pump.PumpSync import info.nightscout.interfaces.pump.PumpSync
@ -17,12 +15,12 @@ import info.nightscout.pump.common.defs.TempBasalPair
import info.nightscout.rx.TestAapsSchedulers import info.nightscout.rx.TestAapsSchedulers
import info.nightscout.rx.bus.RxBus import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.sharedtests.TestBase
import org.joda.time.DateTimeZone import org.joda.time.DateTimeZone
import org.joda.time.tz.UTCProvider import org.joda.time.tz.UTCProvider
import org.junit.Assert import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.mockito.Answers
import org.mockito.ArgumentMatchers import org.mockito.ArgumentMatchers
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito import org.mockito.Mockito
@ -33,7 +31,6 @@ class OmnipodErosPumpPluginTest : TestBase() {
@Mock lateinit var injector: HasAndroidInjector @Mock lateinit var injector: HasAndroidInjector
@Mock lateinit var rh: ResourceHelper @Mock lateinit var rh: ResourceHelper
@Mock(answer = Answers.RETURNS_DEEP_STUBS) lateinit var activePlugin: ActivePlugin
@Mock lateinit var aapsOmnipodErosManager: AapsOmnipodErosManager @Mock lateinit var aapsOmnipodErosManager: AapsOmnipodErosManager
@Mock lateinit var uiInteraction: UiInteraction @Mock lateinit var uiInteraction: UiInteraction
@Mock lateinit var commandQueue: CommandQueue @Mock lateinit var commandQueue: CommandQueue
@ -101,17 +98,17 @@ class OmnipodErosPumpPluginTest : TestBase() {
val result5 = val result5 =
plugin.setTempBasalPercent(-50, 60, profile, false, PumpSync.TemporaryBasalType.NORMAL) plugin.setTempBasalPercent(-50, 60, profile, false, PumpSync.TemporaryBasalType.NORMAL)
// Then return correct values // Then return correct values
Assert.assertEquals(result1.absolute, 0.4, 0.01) Assertions.assertEquals(result1.absolute, 0.4, 0.01)
Assert.assertEquals(result1.duration, 30) Assertions.assertEquals(result1.duration, 30)
Assert.assertEquals(result2.absolute, 25.0, 0.01) Assertions.assertEquals(result2.absolute, 25.0, 0.01)
Assert.assertEquals(result2.duration, 30000) Assertions.assertEquals(result2.duration, 30000)
Assert.assertEquals(result3.absolute, 0.0, 0.01) Assertions.assertEquals(result3.absolute, 0.0, 0.01)
Assert.assertEquals(result3.duration, 30) Assertions.assertEquals(result3.duration, 30)
Assert.assertEquals(result4.absolute, -1.0, 0.01) Assertions.assertEquals(result4.absolute, -1.0, 0.01)
Assert.assertEquals(result4.duration, -1) Assertions.assertEquals(result4.duration, -1)
// this is validated downstream, see TempBasalExtraCommand // this is validated downstream, see TempBasalExtraCommand
Assert.assertEquals(result5.absolute, -0.25, 0.01) Assertions.assertEquals(result5.absolute, -0.25, 0.01)
Assert.assertEquals(result5.duration, 60) Assertions.assertEquals(result5.duration, 60)
// Given zero basal // Given zero basal
`when`(profile.getBasal()).thenReturn(0.0) `when`(profile.getBasal()).thenReturn(0.0)
@ -121,10 +118,10 @@ class OmnipodErosPumpPluginTest : TestBase() {
result2 = result2 =
plugin.setTempBasalPercent(0, 0, profile, false, PumpSync.TemporaryBasalType.NORMAL) plugin.setTempBasalPercent(0, 0, profile, false, PumpSync.TemporaryBasalType.NORMAL)
// Then return zero values // Then return zero values
Assert.assertEquals(result1.absolute, 0.0, 0.01) Assertions.assertEquals(result1.absolute, 0.0, 0.01)
Assert.assertEquals(result1.duration, 90) Assertions.assertEquals(result1.duration, 90)
Assert.assertEquals(result2.absolute, -1.0, 0.01) Assertions.assertEquals(result2.absolute, -1.0, 0.01)
Assert.assertEquals(result2.duration, -1) Assertions.assertEquals(result2.duration, -1)
// Given unhealthy basal // Given unhealthy basal
`when`(profile.getBasal()).thenReturn(500.0) `when`(profile.getBasal()).thenReturn(500.0)
@ -132,12 +129,12 @@ class OmnipodErosPumpPluginTest : TestBase() {
result1 = result1 =
plugin.setTempBasalPercent(80, 30, profile, false, PumpSync.TemporaryBasalType.NORMAL) plugin.setTempBasalPercent(80, 30, profile, false, PumpSync.TemporaryBasalType.NORMAL)
// Then return sane values // Then return sane values
Assert.assertEquals( Assertions.assertEquals(
result1.absolute, result1.absolute,
PumpType.OMNIPOD_EROS.determineCorrectBasalSize(500.0 * 0.8), PumpType.OMNIPOD_EROS.determineCorrectBasalSize(500.0 * 0.8),
0.01 0.01
) )
Assert.assertEquals(result1.duration, 30) Assertions.assertEquals(result1.duration, 30)
// Given weird basal // Given weird basal
`when`(profile.getBasal()).thenReturn(1.234567) `when`(profile.getBasal()).thenReturn(1.234567)
@ -145,8 +142,8 @@ class OmnipodErosPumpPluginTest : TestBase() {
result1 = result1 =
plugin.setTempBasalPercent(280, 600, profile, false, PumpSync.TemporaryBasalType.NORMAL) plugin.setTempBasalPercent(280, 600, profile, false, PumpSync.TemporaryBasalType.NORMAL)
// Then return sane values // Then return sane values
Assert.assertEquals(result1.absolute, 3.4567876, 0.01) Assertions.assertEquals(result1.absolute, 3.4567876, 0.01)
Assert.assertEquals(result1.duration, 600) Assertions.assertEquals(result1.duration, 600)
// Given negative basal // Given negative basal
`when`(profile.getBasal()).thenReturn(-1.234567) `when`(profile.getBasal()).thenReturn(-1.234567)
@ -154,7 +151,7 @@ class OmnipodErosPumpPluginTest : TestBase() {
result1 = result1 =
plugin.setTempBasalPercent(280, 510, profile, false, PumpSync.TemporaryBasalType.NORMAL) plugin.setTempBasalPercent(280, 510, profile, false, PumpSync.TemporaryBasalType.NORMAL)
// Then return negative value (this is validated further downstream, see TempBasalExtraCommand) // Then return negative value (this is validated further downstream, see TempBasalExtraCommand)
Assert.assertEquals(result1.absolute, -3.4567876, 0.01) Assertions.assertEquals(result1.absolute, -3.4567876, 0.01)
Assert.assertEquals(result1.duration, 510) Assertions.assertEquals(result1.duration, 510)
} }
} }

View file

@ -1,114 +0,0 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.joda.time.Duration;
import org.junit.jupiter.api.Test;
import java.util.List;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.schedule.BasalSchedule;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.schedule.BasalScheduleEntry;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodErosManager;
import info.nightscout.interfaces.profile.Profile;
public class AapsOmnipodErosManagerTest {
@Test
public void validProfile() {
Profile profile = mock(Profile.class);
when(profile.getBasalValues()).thenReturn(new Profile.ProfileValue[]{
new Profile.ProfileValue(0, 0.5),
new Profile.ProfileValue(18000, 1.0),
new Profile.ProfileValue(50400, 3.05)
});
BasalSchedule basalSchedule = AapsOmnipodErosManager.mapProfileToBasalSchedule(profile);
List<BasalScheduleEntry> entries = basalSchedule.getEntries();
assertEquals(3, entries.size());
BasalScheduleEntry entry1 = entries.get(0);
assertEquals(Duration.standardSeconds(0), entry1.getStartTime());
assertEquals(0.5D, entry1.getRate(), 0.000001);
BasalScheduleEntry entry2 = entries.get(1);
assertEquals(Duration.standardSeconds(18000), entry2.getStartTime());
assertEquals(1.0D, entry2.getRate(), 0.000001);
BasalScheduleEntry entry3 = entries.get(2);
assertEquals(Duration.standardSeconds(50400), entry3.getStartTime());
assertEquals(3.05D, entry3.getRate(), 0.000001);
}
@Test
public void invalidProfileNullProfile() {
assertThrows("Profile can not be null", IllegalArgumentException.class, () -> AapsOmnipodErosManager.mapProfileToBasalSchedule(null));
}
@Test
public void invalidProfileNullEntries() {
assertThrows("Basal values can not be null", IllegalArgumentException.class, () -> AapsOmnipodErosManager.mapProfileToBasalSchedule(mock(Profile.class)));
}
@Test
public void invalidProfileZeroEntries() {
Profile profile = mock(Profile.class);
when(profile.getBasalValues()).thenReturn(new Profile.ProfileValue[0]);
assertThrows("Entries can not be empty", IllegalArgumentException.class, () -> AapsOmnipodErosManager.mapProfileToBasalSchedule(profile));
}
@Test
public void invalidProfileNonZeroOffset() {
Profile profile = mock(Profile.class);
when(profile.getBasalValues()).thenReturn(new Profile.ProfileValue[]{
new Profile.ProfileValue(1800, 0.5)
});
assertThrows("First basal schedule entry should have 0 offset", IllegalArgumentException.class, () -> AapsOmnipodErosManager.mapProfileToBasalSchedule(profile));
}
@Test
public void invalidProfileMoreThan24Hours() {
Profile profile = mock(Profile.class);
when(profile.getBasalValues()).thenReturn(new Profile.ProfileValue[]{
new Profile.ProfileValue(0, 0.5),
new Profile.ProfileValue(86400, 0.5)
});
assertThrows("Invalid start time", IllegalArgumentException.class, () -> AapsOmnipodErosManager.mapProfileToBasalSchedule(profile));
}
@Test
public void invalidProfileNegativeOffset() {
Profile profile = mock(Profile.class);
when(profile.getBasalValues()).thenReturn(new Profile.ProfileValue[]{
new Profile.ProfileValue(-1, 0.5)
});
assertThrows("Invalid start time", IllegalArgumentException.class, () -> AapsOmnipodErosManager.mapProfileToBasalSchedule(profile));
}
@Test
public void roundsToSupportedPrecision() {
Profile profile = mock(Profile.class);
when(profile.getBasalValues()).thenReturn(new Profile.ProfileValue[]{
new Profile.ProfileValue(0, 0.04),
});
BasalSchedule basalSchedule = AapsOmnipodErosManager.mapProfileToBasalSchedule(profile);
BasalScheduleEntry basalScheduleEntry = basalSchedule.getEntries().get(0);
assertEquals(0.05D, basalScheduleEntry.getRate(), 0.000001);
}
}

View file

@ -0,0 +1,94 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication
import info.nightscout.androidaps.plugins.pump.omnipod.eros.manager.AapsOmnipodErosManager
import info.nightscout.interfaces.profile.Profile
import info.nightscout.interfaces.profile.Profile.ProfileValue
import org.joda.time.Duration
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.mockito.Mockito
internal class AapsOmnipodErosManagerTest {
@Test fun validProfile() {
val profile = Mockito.mock(Profile::class.java)
Mockito.`when`(profile.getBasalValues()).thenReturn(
arrayOf(
ProfileValue(0, 0.5),
ProfileValue(18000, 1.0),
ProfileValue(50400, 3.05)
)
)
val basalSchedule = AapsOmnipodErosManager.mapProfileToBasalSchedule(profile)
val entries = basalSchedule.entries
Assertions.assertEquals(3, entries.size)
val entry1 = entries[0]
Assertions.assertEquals(Duration.standardSeconds(0), entry1.startTime)
Assertions.assertEquals(0.5, entry1.rate, 0.000001)
val entry2 = entries[1]
Assertions.assertEquals(Duration.standardSeconds(18000), entry2.startTime)
Assertions.assertEquals(1.0, entry2.rate, 0.000001)
val entry3 = entries[2]
Assertions.assertEquals(Duration.standardSeconds(50400), entry3.startTime)
Assertions.assertEquals(3.05, entry3.rate, 0.000001)
}
@Test fun invalidProfileNullProfile() {
Assertions.assertThrows(IllegalArgumentException::class.java) { AapsOmnipodErosManager.mapProfileToBasalSchedule(null) }
}
@Test fun invalidProfileNullEntries() {
Assertions.assertThrows(IllegalArgumentException::class.java) {
AapsOmnipodErosManager.mapProfileToBasalSchedule(Mockito.mock(Profile::class.java))
}
}
@Test fun invalidProfileZeroEntries() {
val profile = Mockito.mock(Profile::class.java)
Mockito.`when`(profile.getBasalValues()).thenReturn(emptyArray())
Assertions.assertThrows(IllegalArgumentException::class.java) { AapsOmnipodErosManager.mapProfileToBasalSchedule(profile) }
}
@Test fun invalidProfileNonZeroOffset() {
val profile = Mockito.mock(Profile::class.java)
Mockito.`when`(profile.getBasalValues()).thenReturn(
arrayOf(
ProfileValue(1800, 0.5)
)
)
Assertions.assertThrows(IllegalArgumentException::class.java) { AapsOmnipodErosManager.mapProfileToBasalSchedule(profile) }
}
@Test fun invalidProfileMoreThan24Hours() {
val profile = Mockito.mock(Profile::class.java)
Mockito.`when`(profile.getBasalValues()).thenReturn(
arrayOf(
ProfileValue(0, 0.5),
ProfileValue(86400, 0.5)
)
)
Assertions.assertThrows(IllegalArgumentException::class.java) { AapsOmnipodErosManager.mapProfileToBasalSchedule(profile) }
}
@Test fun invalidProfileNegativeOffset() {
val profile = Mockito.mock(Profile::class.java)
Mockito.`when`(profile.getBasalValues()).thenReturn(
arrayOf(
ProfileValue(-1, 0.5)
)
)
Assertions.assertThrows(IllegalArgumentException::class.java) { AapsOmnipodErosManager.mapProfileToBasalSchedule(profile) }
}
@Test fun roundsToSupportedPrecision() {
val profile = Mockito.mock(Profile::class.java)
Mockito.`when`(profile.getBasalValues()).thenReturn(
arrayOf(
ProfileValue(0, 0.04)
)
)
val basalSchedule = AapsOmnipodErosManager.mapProfileToBasalSchedule(profile)
val basalScheduleEntry = basalSchedule.entries[0]
Assertions.assertEquals(0.05, basalScheduleEntry.rate, 0.000001)
}
}

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command;
import static org.junit.Assert.assertArrayEquals; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.Arrays; import java.util.Arrays;
@ -10,15 +9,15 @@ import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.Al
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.AlertSlot; import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.AlertSlot;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.MessageBlockType; import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.MessageBlockType;
public class AcknowledgeAlertsCommandTest { class AcknowledgeAlertsCommandTest {
@Test @Test
public void testEncodingMultipleAlerts() { void testEncodingMultipleAlerts() {
AlertSet alerts = new AlertSet(Arrays.asList(AlertSlot.SLOT0, AlertSlot.SLOT5)); AlertSet alerts = new AlertSet(Arrays.asList(AlertSlot.SLOT0, AlertSlot.SLOT5));
AcknowledgeAlertsCommand acknowledgeAlertsCommand = new AcknowledgeAlertsCommand(0x10203040, alerts); AcknowledgeAlertsCommand acknowledgeAlertsCommand = new AcknowledgeAlertsCommand(0x10203040, alerts);
byte[] rawData = acknowledgeAlertsCommand.getRawData(); byte[] rawData = acknowledgeAlertsCommand.getRawData();
assertArrayEquals(new byte[]{ Assertions.assertArrayEquals(new byte[]{
MessageBlockType.ACKNOWLEDGE_ALERT.getValue(), MessageBlockType.ACKNOWLEDGE_ALERT.getValue(),
5, // length 5, // length
(byte) 0x10, (byte) 0x20, (byte) 0x30, (byte) 0x40, // nonce (byte) 0x10, (byte) 0x20, (byte) 0x30, (byte) 0x40, // nonce
@ -27,10 +26,10 @@ public class AcknowledgeAlertsCommandTest {
} }
@Test @Test
public void testEncodingSingleAlert() { void testEncodingSingleAlert() {
AcknowledgeAlertsCommand acknowledgeAlertsCommand = new AcknowledgeAlertsCommand(0x10203040, AlertSlot.SLOT5); AcknowledgeAlertsCommand acknowledgeAlertsCommand = new AcknowledgeAlertsCommand(0x10203040, AlertSlot.SLOT5);
byte[] rawData = acknowledgeAlertsCommand.getRawData(); byte[] rawData = acknowledgeAlertsCommand.getRawData();
assertArrayEquals(new byte[]{ Assertions.assertArrayEquals(new byte[]{
MessageBlockType.ACKNOWLEDGE_ALERT.getValue(), MessageBlockType.ACKNOWLEDGE_ALERT.getValue(),
5, // length 5, // length
(byte) 0x10, (byte) 0x20, (byte) 0x30, (byte) 0x40, // nonce (byte) 0x10, (byte) 0x20, (byte) 0x30, (byte) 0x40, // nonce

View file

@ -1,21 +1,17 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command;
import static org.junit.Assert.assertEquals; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
public class AssignAddressCommandTest { class AssignAddressCommandTest {
@Test @Test
public void testEncoding() { void testEncoding() {
AssignAddressCommand assignAddressCommand = new AssignAddressCommand(0x11223344); AssignAddressCommand assignAddressCommand = new AssignAddressCommand(0x11223344);
byte[] rawData = assignAddressCommand.getRawData(); byte[] rawData = assignAddressCommand.getRawData();
assertEquals(0x11, rawData[2]); Assertions.assertEquals(0x11, rawData[2]);
assertEquals(0x22, rawData[3]); Assertions.assertEquals(0x22, rawData[3]);
assertEquals(0x33, rawData[4]); Assertions.assertEquals(0x33, rawData[4]);
assertEquals(0x44, rawData[5]); Assertions.assertEquals(0x44, rawData[5]);
} }
// TODO add tests
} }

View file

@ -1,11 +1,7 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.joda.time.Duration; import org.joda.time.Duration;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.Arrays; import java.util.Arrays;
@ -17,9 +13,9 @@ import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.sc
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.schedule.RateEntry; import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.schedule.RateEntry;
import info.nightscout.pump.core.utils.ByteUtil; import info.nightscout.pump.core.utils.ByteUtil;
public class BasalScheduleExtraCommandTest { class BasalScheduleExtraCommandTest {
@Test @Test
public void testEncodingFromRateEntries() { void testEncodingFromRateEntries() {
List<RateEntry> rateEntries = RateEntry.createEntries(3.0, Duration.standardHours(24)); List<RateEntry> rateEntries = RateEntry.createEntries(3.0, Duration.standardHours(24));
BasalScheduleExtraCommand basalScheduleExtraCommand = new BasalScheduleExtraCommand( // BasalScheduleExtraCommand basalScheduleExtraCommand = new BasalScheduleExtraCommand( //
false, // false, //
@ -30,13 +26,13 @@ public class BasalScheduleExtraCommandTest {
20D, // 20D, //
rateEntries); rateEntries);
assertArrayEquals( // Assertions.assertArrayEquals( //
ByteUtil.createByteArrayFromHexString("130e40001aea01312d003840005b8d80"), // From https://github.com/openaps/openomni/wiki/Bolus ByteUtil.createByteArrayFromHexString("130e40001aea01312d003840005b8d80"), // From https://github.com/openaps/openomni/wiki/Bolus
basalScheduleExtraCommand.getRawData()); basalScheduleExtraCommand.getRawData());
} }
@Test @Test
public void testParametersCorrectFromBasalSchedule() { void testParametersCorrectFromBasalSchedule() {
BasalSchedule basalSchedule = new BasalSchedule(Collections.singletonList(new BasalScheduleEntry(0.05, Duration.ZERO))); BasalSchedule basalSchedule = new BasalSchedule(Collections.singletonList(new BasalScheduleEntry(0.05, Duration.ZERO)));
BasalScheduleExtraCommand basalScheduleExtraCommand = new BasalScheduleExtraCommand( // BasalScheduleExtraCommand basalScheduleExtraCommand = new BasalScheduleExtraCommand( //
basalSchedule, // basalSchedule, //
@ -45,25 +41,25 @@ public class BasalScheduleExtraCommandTest {
true, // true, //
Duration.standardMinutes(1)); Duration.standardMinutes(1));
assertFalse(basalScheduleExtraCommand.isAcknowledgementBeep()); Assertions.assertFalse(basalScheduleExtraCommand.isAcknowledgementBeep());
assertTrue(basalScheduleExtraCommand.isCompletionBeep()); Assertions.assertTrue(basalScheduleExtraCommand.isCompletionBeep());
assertEquals(0, basalScheduleExtraCommand.getCurrentEntryIndex()); Assertions.assertEquals(0, basalScheduleExtraCommand.getCurrentEntryIndex());
assertEquals(180D, basalScheduleExtraCommand.getDelayUntilNextTenthOfPulseInSeconds(), 0.00001); Assertions.assertEquals(180D, basalScheduleExtraCommand.getDelayUntilNextTenthOfPulseInSeconds(), 0.00001);
assertEquals(60, basalScheduleExtraCommand.getProgramReminderInterval().getStandardSeconds()); Assertions.assertEquals(60, basalScheduleExtraCommand.getProgramReminderInterval().getStandardSeconds());
assertEquals(15.8, basalScheduleExtraCommand.getRemainingPulses(), 0.01); Assertions.assertEquals(15.8, basalScheduleExtraCommand.getRemainingPulses(), 0.01);
List<RateEntry> rateEntries = basalScheduleExtraCommand.getRateEntries(); List<RateEntry> rateEntries = basalScheduleExtraCommand.getRateEntries();
assertEquals(1, rateEntries.size()); Assertions.assertEquals(1, rateEntries.size());
RateEntry rateEntry = rateEntries.get(0); RateEntry rateEntry = rateEntries.get(0);
assertEquals(3600.0, rateEntry.getDelayBetweenPulsesInSeconds(), 0.00000001); Assertions.assertEquals(3600.0, rateEntry.getDelayBetweenPulsesInSeconds(), 0.00000001);
assertEquals(24, rateEntry.getTotalPulses(), 0.001); Assertions.assertEquals(24, rateEntry.getTotalPulses(), 0.001);
} }
@Test @Test
public void testEncodingFromBasalScheduleWithThreeEntries() { void testEncodingFromBasalScheduleWithThreeEntries() {
BasalSchedule schedule = new BasalSchedule(Arrays.asList( // BasalSchedule schedule = new BasalSchedule(Arrays.asList( //
new BasalScheduleEntry(1.05, Duration.ZERO), // new BasalScheduleEntry(1.05, Duration.ZERO), //
new BasalScheduleEntry(0.9, Duration.standardHours(10).plus(Duration.standardMinutes(30))), // new BasalScheduleEntry(0.9, Duration.standardHours(10).plus(Duration.standardMinutes(30))), //
@ -72,12 +68,12 @@ public class BasalScheduleExtraCommandTest {
BasalScheduleExtraCommand basalScheduleExtraCommand = new BasalScheduleExtraCommand(schedule, Duration.standardMinutes((0x2e + 1) * 30).minus(Duration.standardSeconds(0x1be8 / 8)), BasalScheduleExtraCommand basalScheduleExtraCommand = new BasalScheduleExtraCommand(schedule, Duration.standardMinutes((0x2e + 1) * 30).minus(Duration.standardSeconds(0x1be8 / 8)),
false, true, Duration.ZERO); false, true, Duration.ZERO);
assertArrayEquals(ByteUtil.fromHexString("131a4002009600a7d8c0089d0105944905a001312d00044c0112a880"), Assertions.assertArrayEquals(ByteUtil.fromHexString("131a4002009600a7d8c0089d0105944905a001312d00044c0112a880"),
basalScheduleExtraCommand.getRawData()); basalScheduleExtraCommand.getRawData());
} }
@Test @Test
public void testEncodingFromBasalScheduleWithSingleEntry() { void testEncodingFromBasalScheduleWithSingleEntry() {
BasalSchedule basalSchedule = new BasalSchedule(Arrays.asList(new BasalScheduleEntry(1.05, Duration.ZERO))); BasalSchedule basalSchedule = new BasalSchedule(Arrays.asList(new BasalScheduleEntry(1.05, Duration.ZERO)));
BasalScheduleExtraCommand basalScheduleExtraCommand = new BasalScheduleExtraCommand(basalSchedule, BasalScheduleExtraCommand basalScheduleExtraCommand = new BasalScheduleExtraCommand(basalSchedule,
Duration.standardMinutes((0x20 + 1) * 30).minus(Duration.standardSeconds(0x33c0 / 8)), Duration.standardMinutes((0x20 + 1) * 30).minus(Duration.standardSeconds(0x33c0 / 8)),
@ -87,7 +83,7 @@ public class BasalScheduleExtraCommandTest {
} }
@Test @Test
public void testSegmentMerging() { void testSegmentMerging() {
List<BasalScheduleEntry> entries = Arrays.asList( List<BasalScheduleEntry> entries = Arrays.asList(
new BasalScheduleEntry(0.8, Duration.ZERO), new BasalScheduleEntry(0.8, Duration.ZERO),
new BasalScheduleEntry(0.9, Duration.standardMinutes(180)), // new BasalScheduleEntry(0.9, Duration.standardMinutes(180)), //
@ -113,7 +109,7 @@ public class BasalScheduleExtraCommandTest {
} }
@Test @Test
public void testEncodingFromBasalScheduleWithThirteenEntries() { void testEncodingFromBasalScheduleWithThirteenEntries() {
List<BasalScheduleEntry> entries = Arrays.asList( List<BasalScheduleEntry> entries = Arrays.asList(
new BasalScheduleEntry(1.30, Duration.ZERO), // new BasalScheduleEntry(1.30, Duration.ZERO), //
new BasalScheduleEntry(0.05, Duration.standardMinutes(30)), // new BasalScheduleEntry(0.05, Duration.standardMinutes(30)), //
@ -140,7 +136,7 @@ public class BasalScheduleExtraCommandTest {
} }
@Test @Test
public void testBasalScheduleExtraCommandRoundsToNearestSecond() { void testBasalScheduleExtraCommandRoundsToNearestSecond() {
BasalSchedule basalSchedule = new BasalSchedule(Arrays.asList(new BasalScheduleEntry(1.00, Duration.ZERO))); BasalSchedule basalSchedule = new BasalSchedule(Arrays.asList(new BasalScheduleEntry(1.00, Duration.ZERO)));
BasalScheduleExtraCommand basalScheduleExtraCommand = new BasalScheduleExtraCommand(basalSchedule, BasalScheduleExtraCommand basalScheduleExtraCommand = new BasalScheduleExtraCommand(basalSchedule,
@ -158,13 +154,13 @@ public class BasalScheduleExtraCommandTest {
byte[] expected = ByteUtil.fromHexString(expectedHexString); byte[] expected = ByteUtil.fromHexString(expectedHexString);
assertEquals(extractDelayUntilNextPulseInSeconds(expected), extractDelayUntilNextPulseInSeconds(actual), 0.0001); Assertions.assertEquals(extractDelayUntilNextPulseInSeconds(expected), extractDelayUntilNextPulseInSeconds(actual), 0.0001);
// Discard the last byte of the integer so that we can compare the other bytes of the message // Discard the last byte of the integer so that we can compare the other bytes of the message
expected[9] = 0; expected[9] = 0;
actual[9] = 0; actual[9] = 0;
assertArrayEquals(expected, actual); Assertions.assertArrayEquals(expected, actual);
} }
private double extractDelayUntilNextPulseInSeconds(byte[] message) { private double extractDelayUntilNextPulseInSeconds(byte[] message) {

View file

@ -1,27 +1,26 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command;
import static org.junit.Assert.assertArrayEquals;
import org.joda.time.Duration; import org.joda.time.Duration;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.BeepConfigType; import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.BeepConfigType;
import info.nightscout.pump.core.utils.ByteUtil; import info.nightscout.pump.core.utils.ByteUtil;
public class BeepConfigCommandTest { class BeepConfigCommandTest {
@Test @Test
public void testConfidenceReminders() { void testConfidenceReminders() {
BeepConfigCommand beepConfigCommand = new BeepConfigCommand(BeepConfigType.BIP_BEEP_BIP_BEEP_BIP_BEEP_BIP_BEEP, true, BeepConfigCommand beepConfigCommand = new BeepConfigCommand(BeepConfigType.BIP_BEEP_BIP_BEEP_BIP_BEEP_BIP_BEEP, true,
Duration.ZERO, true, Duration.ZERO, Duration.ZERO, true, Duration.ZERO,
true, Duration.ZERO); true, Duration.ZERO);
assertArrayEquals(ByteUtil.fromHexString("1e0402404040"), beepConfigCommand.getRawData()); Assertions.assertArrayEquals(ByteUtil.fromHexString("1e0402404040"), beepConfigCommand.getRawData());
} }
@Test @Test
public void testProgramReminders() { void testProgramReminders() {
BeepConfigCommand beepConfigCommand = new BeepConfigCommand(BeepConfigType.NO_BEEP, true, BeepConfigCommand beepConfigCommand = new BeepConfigCommand(BeepConfigType.NO_BEEP, true,
Duration.ZERO, false, Duration.standardMinutes(60), Duration.ZERO, false, Duration.standardMinutes(60),
false, Duration.standardMinutes(60)); false, Duration.standardMinutes(60));
assertArrayEquals(ByteUtil.fromHexString("1e040f403c3c"), beepConfigCommand.getRawData()); Assertions.assertArrayEquals(ByteUtil.fromHexString("1e040f403c3c"), beepConfigCommand.getRawData());
} }
} }

View file

@ -1,60 +1,59 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command;
import static org.junit.Assert.assertArrayEquals;
import org.joda.time.Duration; import org.joda.time.Duration;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import info.nightscout.pump.core.utils.ByteUtil; import info.nightscout.pump.core.utils.ByteUtil;
public class BolusExtraCommandTest { class BolusExtraCommandTest {
@Test @Test
public void testBolusExtraCommand() { void testBolusExtraCommand() {
BolusExtraCommand bolusExtraCommand = new BolusExtraCommand(1.25, 0.0, BolusExtraCommand bolusExtraCommand = new BolusExtraCommand(1.25, 0.0,
Duration.ZERO, false, true, Duration.standardHours(1), Duration.ZERO, false, true, Duration.standardHours(1),
Duration.standardSeconds(2)); Duration.standardSeconds(2));
assertArrayEquals( // Assertions.assertArrayEquals( //
ByteUtil.createByteArrayFromHexString("170d7c00fa00030d40000000000000"), // From https://github.com/openaps/openomni/wiki/Bolus ByteUtil.createByteArrayFromHexString("170d7c00fa00030d40000000000000"), // From https://github.com/openaps/openomni/wiki/Bolus
bolusExtraCommand.getRawData()); bolusExtraCommand.getRawData());
} }
@Test @Test
public void testTypicalPrime() { void testTypicalPrime() {
BolusExtraCommand bolusExtraCommand = new BolusExtraCommand(2.6, Duration.standardSeconds(1), false, false); BolusExtraCommand bolusExtraCommand = new BolusExtraCommand(2.6, Duration.standardSeconds(1), false, false);
assertArrayEquals(ByteUtil.fromHexString("170d000208000186a0000000000000"), // Assertions.assertArrayEquals(ByteUtil.fromHexString("170d000208000186a0000000000000"), //
bolusExtraCommand.getRawData()); bolusExtraCommand.getRawData());
} }
@Test @Test
public void testBolusExtraCommandWithExtraOddPulseCount() { void testBolusExtraCommandWithExtraOddPulseCount() {
BolusExtraCommand bolusExtraCommand = new BolusExtraCommand(1.25, 0D, Duration.ZERO, // BolusExtraCommand bolusExtraCommand = new BolusExtraCommand(1.25, 0D, Duration.ZERO, //
false, true, Duration.standardHours(1), Duration.standardSeconds(2)); false, true, Duration.standardHours(1), Duration.standardSeconds(2));
assertArrayEquals(ByteUtil.fromHexString("170d7c00fa00030d40000000000000"), // Assertions.assertArrayEquals(ByteUtil.fromHexString("170d7c00fa00030d40000000000000"), //
bolusExtraCommand.getRawData()); bolusExtraCommand.getRawData());
} }
@Test @Test
public void testBolusExtraCommandWithExtraOddPulseCount2() { void testBolusExtraCommandWithExtraOddPulseCount2() {
BolusExtraCommand bolusExtraCommand = new BolusExtraCommand(2.05, 0D, Duration.ZERO, // BolusExtraCommand bolusExtraCommand = new BolusExtraCommand(2.05, 0D, Duration.ZERO, //
false, false, Duration.standardHours(1), Duration.standardSeconds(2)); false, false, Duration.standardHours(1), Duration.standardSeconds(2));
assertArrayEquals(ByteUtil.fromHexString("170d3c019a00030d40000000000000"), // Assertions.assertArrayEquals(ByteUtil.fromHexString("170d3c019a00030d40000000000000"), //
bolusExtraCommand.getRawData()); bolusExtraCommand.getRawData());
} }
@Test @Test
public void testLargeBolus() { void testLargeBolus() {
BolusExtraCommand bolusExtraCommand = new BolusExtraCommand(30D, 0, Duration.ZERO, // BolusExtraCommand bolusExtraCommand = new BolusExtraCommand(30D, 0, Duration.ZERO, //
false, true, Duration.standardHours(1), Duration.standardSeconds(2)); false, true, Duration.standardHours(1), Duration.standardSeconds(2));
assertArrayEquals(ByteUtil.fromHexString("170d7c177000030d40000000000000"), // Assertions.assertArrayEquals(ByteUtil.fromHexString("170d7c177000030d40000000000000"), //
bolusExtraCommand.getRawData()); bolusExtraCommand.getRawData());
} }
@Test @Test
public void testLargeBolus2() { void testLargeBolus2() {
BolusExtraCommand bolusExtraCommand = new BolusExtraCommand(29.95, 0, Duration.ZERO, // BolusExtraCommand bolusExtraCommand = new BolusExtraCommand(29.95, 0, Duration.ZERO, //
false, true, Duration.standardHours(1), Duration.standardSeconds(2)); false, true, Duration.standardHours(1), Duration.standardSeconds(2));
assertArrayEquals(ByteUtil.fromHexString("170d7c176600030d40000000000000"), // Assertions.assertArrayEquals(ByteUtil.fromHexString("170d7c176600030d40000000000000"), //
bolusExtraCommand.getRawData()); bolusExtraCommand.getRawData());
} }

View file

@ -1,7 +1,6 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command;
import static org.junit.Assert.assertArrayEquals; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.EnumSet; import java.util.EnumSet;
@ -10,36 +9,37 @@ import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.Be
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.DeliveryType; import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.DeliveryType;
import info.nightscout.pump.core.utils.ByteUtil; import info.nightscout.pump.core.utils.ByteUtil;
public class CancelDeliveryCommandTest { /** @noinspection SpellCheckingInspection*/
class CancelDeliveryCommandTest {
@Test @Test
public void testCancelBolusAndBasalWithBeep() { void testCancelBolusAndBasalWithBeep() {
CancelDeliveryCommand command = new CancelDeliveryCommand(0x10203040, BeepType.BIP_BIP, EnumSet.of(DeliveryType.BASAL, DeliveryType.BOLUS)); CancelDeliveryCommand command = new CancelDeliveryCommand(0x10203040, BeepType.BIP_BIP, EnumSet.of(DeliveryType.BASAL, DeliveryType.BOLUS));
byte[] expected = ByteUtil.fromHexString("1F051020304035"); byte[] expected = ByteUtil.fromHexString("1F051020304035");
assertArrayEquals(expected, command.getRawData()); Assertions.assertArrayEquals(expected, command.getRawData());
} }
@Test @Test
public void testCancelBolusWithBeep() { void testCancelBolusWithBeep() {
CancelDeliveryCommand command = new CancelDeliveryCommand(0x4d91f8ff, BeepType.BEEEEEEP, DeliveryType.BOLUS); CancelDeliveryCommand command = new CancelDeliveryCommand(0x4d91f8ff, BeepType.BEEEEEEP, DeliveryType.BOLUS);
byte[] expected = ByteUtil.fromHexString("1f054d91f8ff64"); byte[] expected = ByteUtil.fromHexString("1f054d91f8ff64");
assertArrayEquals(expected, command.getRawData()); Assertions.assertArrayEquals(expected, command.getRawData());
} }
@Test @Test
public void testSuspendBasalCommandWithoutBeep() { void testSuspendBasalCommandWithoutBeep() {
CancelDeliveryCommand command = new CancelDeliveryCommand(0x6fede14a, BeepType.NO_BEEP, DeliveryType.BASAL); CancelDeliveryCommand command = new CancelDeliveryCommand(0x6fede14a, BeepType.NO_BEEP, DeliveryType.BASAL);
byte[] expected = ByteUtil.fromHexString("1f056fede14a01"); byte[] expected = ByteUtil.fromHexString("1f056fede14a01");
assertArrayEquals(expected, command.getRawData()); Assertions.assertArrayEquals(expected, command.getRawData());
} }
@Test @Test
public void testCancelTempBasalWithoutBeep() { void testCancelTempBasalWithoutBeep() {
CancelDeliveryCommand cancelDeliveryCommand = new CancelDeliveryCommand(0xf76d34c4, BeepType.NO_BEEP, DeliveryType.TEMP_BASAL); CancelDeliveryCommand cancelDeliveryCommand = new CancelDeliveryCommand(0xf76d34c4, BeepType.NO_BEEP, DeliveryType.TEMP_BASAL);
assertArrayEquals(ByteUtil.fromHexString("1f05f76d34c402"), cancelDeliveryCommand.getRawData()); Assertions.assertArrayEquals(ByteUtil.fromHexString("1f05f76d34c402"), cancelDeliveryCommand.getRawData());
} }
} }

View file

@ -1,8 +1,7 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command;
import static org.junit.Assert.assertArrayEquals;
import org.joda.time.Duration; import org.joda.time.Duration;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.Arrays; import java.util.Arrays;
@ -17,9 +16,9 @@ import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.Ti
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.UnitsRemainingAlertTrigger; import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.UnitsRemainingAlertTrigger;
import info.nightscout.pump.core.utils.ByteUtil; import info.nightscout.pump.core.utils.ByteUtil;
public class ConfigureAlertsCommandTest { class ConfigureAlertsCommandTest {
@Test @Test
public void testEncoding() { void testEncoding() {
Duration softExpirationTime = Duration.standardHours(72).minus(Duration.standardMinutes(1)); Duration softExpirationTime = Duration.standardHours(72).minus(Duration.standardMinutes(1));
AlertConfiguration alertConfiguration1 = new AlertConfiguration( // AlertConfiguration alertConfiguration1 = new AlertConfiguration( //
AlertType.EXPIRATION_ADVISORY_ALERT, AlertType.EXPIRATION_ADVISORY_ALERT,
@ -31,7 +30,7 @@ public class ConfigureAlertsCommandTest {
BeepType.BEEP_BEEP_BEEP, // BeepType.BEEP_BEEP_BEEP, //
BeepRepeat.EVERY_MINUTE_FOR_15_MINUTES); BeepRepeat.EVERY_MINUTE_FOR_15_MINUTES);
assertArrayEquals( // Assertions.assertArrayEquals( //
ByteUtil.fromHexString("79a410df0205"), // ByteUtil.fromHexString("79a410df0205"), //
alertConfiguration1.getRawData()); alertConfiguration1.getRawData());
@ -46,7 +45,7 @@ public class ConfigureAlertsCommandTest {
BeepType.BEEEEEEP, // BeepType.BEEEEEEP, //
BeepRepeat.EVERY_MINUTE_FOR_15_MINUTES); BeepRepeat.EVERY_MINUTE_FOR_15_MINUTES);
assertArrayEquals( // Assertions.assertArrayEquals( //
ByteUtil.fromHexString("280012830206"), // ByteUtil.fromHexString("280012830206"), //
alertConfiguration2.getRawData()); alertConfiguration2.getRawData());
@ -60,7 +59,7 @@ public class ConfigureAlertsCommandTest {
BeepType.BIP_BEEP_BIP_BEEP_BIP_BEEP_BIP_BEEP, // BeepType.BIP_BEEP_BIP_BEEP_BIP_BEEP_BIP_BEEP, //
BeepRepeat.EVERY_MINUTE_FOR_15_MINUTES); BeepRepeat.EVERY_MINUTE_FOR_15_MINUTES);
assertArrayEquals( // Assertions.assertArrayEquals( //
ByteUtil.fromHexString("020f00000202"), // ByteUtil.fromHexString("020f00000202"), //
alertConfiguration3.getRawData()); alertConfiguration3.getRawData());
@ -68,13 +67,13 @@ public class ConfigureAlertsCommandTest {
0xfeb6268b, // 0xfeb6268b, //
Arrays.asList(alertConfiguration1, alertConfiguration2, alertConfiguration3)); Arrays.asList(alertConfiguration1, alertConfiguration2, alertConfiguration3));
assertArrayEquals( // Assertions.assertArrayEquals( //
ByteUtil.fromHexString("1916feb6268b79a410df0205280012830206020f00000202"), // ByteUtil.fromHexString("1916feb6268b79a410df0205280012830206020f00000202"), //
configureAlertsCommand.getRawData()); configureAlertsCommand.getRawData());
} }
@Test @Test
public void testLowReservoirAlert() { void testLowReservoirAlert() {
AlertConfiguration alertConfiguration = new AlertConfiguration(// AlertConfiguration alertConfiguration = new AlertConfiguration(//
AlertType.LOW_RESERVOIR_ALERT, // AlertType.LOW_RESERVOIR_ALERT, //
AlertSlot.SLOT4, // AlertSlot.SLOT4, //
@ -89,7 +88,7 @@ public class ConfigureAlertsCommandTest {
0xae01a66c, // 0xae01a66c, //
Collections.singletonList(alertConfiguration)); Collections.singletonList(alertConfiguration));
assertArrayEquals( Assertions.assertArrayEquals(
ByteUtil.fromHexString("190aae01a66c4c0000640102"), // ByteUtil.fromHexString("190aae01a66c4c0000640102"), //
configureAlertsCommand.getRawData()); configureAlertsCommand.getRawData());
} }

View file

@ -1,18 +1,17 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command;
import static org.junit.Assert.assertArrayEquals; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.MessageBlockType; import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.MessageBlockType;
public class DeactivatePodCommandTest { class DeactivatePodCommandTest {
@Test @Test
public void testEncoding() { void testEncoding() {
DeactivatePodCommand deactivatePodCommand = new DeactivatePodCommand(0x10203040); DeactivatePodCommand deactivatePodCommand = new DeactivatePodCommand(0x10203040);
byte[] rawData = deactivatePodCommand.getRawData(); byte[] rawData = deactivatePodCommand.getRawData();
assertArrayEquals(new byte[]{ Assertions.assertArrayEquals(new byte[]{
MessageBlockType.DEACTIVATE_POD.getValue(), MessageBlockType.DEACTIVATE_POD.getValue(),
4, // length 4, // length
(byte) 0x10, (byte) 0x20, (byte) 0x30, (byte) 0x40 // nonce (byte) 0x10, (byte) 0x20, (byte) 0x30, (byte) 0x40 // nonce

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command;
/** @noinspection unused*/
public class FaultConfigCommandTest { public class FaultConfigCommandTest {
// TODO add tests (obtain captures first) // TODO add tests (obtain captures first)
} }

View file

@ -1,31 +1,30 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command;
import static org.junit.Assert.assertArrayEquals; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.PodInfoType; import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.PodInfoType;
import info.nightscout.pump.core.utils.ByteUtil; import info.nightscout.pump.core.utils.ByteUtil;
public class GetStatusCommandTest { class GetStatusCommandTest {
@Test @Test
public void testPodInfoTypeNormal() { void testPodInfoTypeNormal() {
GetStatusCommand getStatusCommand = new GetStatusCommand(PodInfoType.NORMAL); GetStatusCommand getStatusCommand = new GetStatusCommand(PodInfoType.NORMAL);
assertArrayEquals(ByteUtil.fromHexString("0e0100"), getStatusCommand.getRawData()); Assertions.assertArrayEquals(ByteUtil.fromHexString("0e0100"), getStatusCommand.getRawData());
} }
@Test @Test
public void testPodInfoTypeConfiguredAlerts() { void testPodInfoTypeConfiguredAlerts() {
GetStatusCommand getStatusCommand = new GetStatusCommand(PodInfoType.ACTIVE_ALERTS); GetStatusCommand getStatusCommand = new GetStatusCommand(PodInfoType.ACTIVE_ALERTS);
assertArrayEquals(ByteUtil.fromHexString("0e0101"), getStatusCommand.getRawData()); Assertions.assertArrayEquals(ByteUtil.fromHexString("0e0101"), getStatusCommand.getRawData());
} }
@Test @Test
public void testPodInfoTypeFaultEvents() { void testPodInfoTypeFaultEvents() {
GetStatusCommand getStatusCommand = new GetStatusCommand(PodInfoType.DETAILED_STATUS); GetStatusCommand getStatusCommand = new GetStatusCommand(PodInfoType.DETAILED_STATUS);
assertArrayEquals(ByteUtil.fromHexString("0e0102"), getStatusCommand.getRawData()); Assertions.assertArrayEquals(ByteUtil.fromHexString("0e0102"), getStatusCommand.getRawData());
} }
} }

View file

@ -1,8 +1,7 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command;
import static org.junit.Assert.assertArrayEquals;
import org.joda.time.Duration; import org.joda.time.Duration;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.Arrays; import java.util.Arrays;
@ -14,17 +13,17 @@ import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.sc
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.schedule.BolusDeliverySchedule; import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.schedule.BolusDeliverySchedule;
import info.nightscout.pump.core.utils.ByteUtil; import info.nightscout.pump.core.utils.ByteUtil;
public class SetInsulinScheduleCommandTest { class SetInsulinScheduleCommandTest {
@Test @Test
public void testTemporaryBasalScheduleAlternatingSegmentFlag() { void testTemporaryBasalScheduleAlternatingSegmentFlag() {
SetInsulinScheduleCommand setInsulinScheduleCommand = new SetInsulinScheduleCommand(0x9746c65b, // SetInsulinScheduleCommand setInsulinScheduleCommand = new SetInsulinScheduleCommand(0x9746c65b, //
0.05, Duration.standardMinutes(30)); 0.05, Duration.standardMinutes(30));
assertArrayEquals(ByteUtil.fromHexString("1a0e9746c65b01007901384000000000"), // Assertions.assertArrayEquals(ByteUtil.fromHexString("1a0e9746c65b01007901384000000000"), //
setInsulinScheduleCommand.getRawData()); setInsulinScheduleCommand.getRawData());
SetInsulinScheduleCommand setInsulinScheduleCommand2 = new SetInsulinScheduleCommand(0x9746c65b, // SetInsulinScheduleCommand setInsulinScheduleCommand2 = new SetInsulinScheduleCommand(0x9746c65b, //
0.05, Duration.standardHours(8).plus(Duration.standardMinutes(30))); 0.05, Duration.standardHours(8).plus(Duration.standardMinutes(30)));
assertArrayEquals(ByteUtil.fromHexString("1a109746c65b0100911138400000f8000000"), // Assertions.assertArrayEquals(ByteUtil.fromHexString("1a109746c65b0100911138400000f8000000"), //
setInsulinScheduleCommand2.getRawData()); setInsulinScheduleCommand2.getRawData());
// Test passed before introducing a maximum temp basal duration of 12 hours // Test passed before introducing a maximum temp basal duration of 12 hours
@ -35,47 +34,47 @@ public class SetInsulinScheduleCommandTest {
} }
@Test @Test
public void testTemporaryBasalScheduleMessage() { void testTemporaryBasalScheduleMessage() {
SetInsulinScheduleCommand setInsulinScheduleCommand = new SetInsulinScheduleCommand(0xea2d0a3b, // SetInsulinScheduleCommand setInsulinScheduleCommand = new SetInsulinScheduleCommand(0xea2d0a3b, //
0.2, Duration.standardMinutes(30)); 0.2, Duration.standardMinutes(30));
assertArrayEquals( // Assertions.assertArrayEquals( //
ByteUtil.fromHexString("1a0eea2d0a3b01007d01384000020002"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/TempBasalTests.swift ByteUtil.fromHexString("1a0eea2d0a3b01007d01384000020002"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/TempBasalTests.swift
setInsulinScheduleCommand.getRawData()); setInsulinScheduleCommand.getRawData());
} }
@Test @Test
public void testTemporaryBasalScheduleMessageWithAlternatingPulse() { void testTemporaryBasalScheduleMessageWithAlternatingPulse() {
SetInsulinScheduleCommand setInsulinScheduleCommand = new SetInsulinScheduleCommand(0x4e2c2717, // SetInsulinScheduleCommand setInsulinScheduleCommand = new SetInsulinScheduleCommand(0x4e2c2717, //
0.05, Duration.standardMinutes(150)); 0.05, Duration.standardMinutes(150));
assertArrayEquals( // Assertions.assertArrayEquals( //
ByteUtil.fromHexString("1a0e4e2c271701007f05384000004800"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/TempBasalTests.swift ByteUtil.fromHexString("1a0e4e2c271701007f05384000004800"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/TempBasalTests.swift
setInsulinScheduleCommand.getRawData()); setInsulinScheduleCommand.getRawData());
} }
@Test @Test
public void testLargerTemporaryBasalScheduleMessage() { void testLargerTemporaryBasalScheduleMessage() {
SetInsulinScheduleCommand setInsulinScheduleCommand = new SetInsulinScheduleCommand(0x87e8d03a, // SetInsulinScheduleCommand setInsulinScheduleCommand = new SetInsulinScheduleCommand(0x87e8d03a, //
2D, Duration.standardMinutes(90)); 2D, Duration.standardMinutes(90));
assertArrayEquals( // Assertions.assertArrayEquals( //
ByteUtil.fromHexString("1a0e87e8d03a0100cb03384000142014"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/TempBasalTests.swift ByteUtil.fromHexString("1a0e87e8d03a0100cb03384000142014"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/TempBasalTests.swift
setInsulinScheduleCommand.getRawData()); setInsulinScheduleCommand.getRawData());
} }
@Test @Test
public void testExtremelyLargeTemporaryBasalScheduleMessage() { void testExtremelyLargeTemporaryBasalScheduleMessage() {
SetInsulinScheduleCommand setInsulinScheduleCommand = new SetInsulinScheduleCommand(0xa958c5ad, // SetInsulinScheduleCommand setInsulinScheduleCommand = new SetInsulinScheduleCommand(0xa958c5ad, //
30D, Duration.standardHours(12)); 30D, Duration.standardHours(12));
assertArrayEquals( // Assertions.assertArrayEquals( //
ByteUtil.fromHexString("1a10a958c5ad0104f5183840012cf12c712c"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/TempBasalTests.swift ByteUtil.fromHexString("1a10a958c5ad0104f5183840012cf12c712c"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/TempBasalTests.swift
setInsulinScheduleCommand.getRawData()); setInsulinScheduleCommand.getRawData());
} }
@Test @Test
public void testBasalScheduleSingleEntry() { void testBasalScheduleSingleEntry() {
BasalSchedule basalSchedule = new BasalSchedule(Collections.singletonList(new BasalScheduleEntry(0.05, Duration.ZERO))); BasalSchedule basalSchedule = new BasalSchedule(Collections.singletonList(new BasalScheduleEntry(0.05, Duration.ZERO)));
SetInsulinScheduleCommand setInsulinScheduleCommand = new SetInsulinScheduleCommand( // SetInsulinScheduleCommand setInsulinScheduleCommand = new SetInsulinScheduleCommand( //
@ -83,13 +82,13 @@ public class SetInsulinScheduleCommandTest {
basalSchedule, // basalSchedule, //
Duration.standardHours(8).plus(Duration.standardMinutes(15))); Duration.standardHours(8).plus(Duration.standardMinutes(15)));
assertArrayEquals( // Assertions.assertArrayEquals( //
ByteUtil.fromHexString("1a1201020304000064101c200000f800f800f800"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/BasalScheduleTests.swift ByteUtil.fromHexString("1a1201020304000064101c200000f800f800f800"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/BasalScheduleTests.swift
setInsulinScheduleCommand.getRawData()); setInsulinScheduleCommand.getRawData());
} }
@Test @Test
public void testBasalScheduleWithTwelveEntries() { void testBasalScheduleWithTwelveEntries() {
List<BasalScheduleEntry> entries = Arrays.asList( List<BasalScheduleEntry> entries = Arrays.asList(
new BasalScheduleEntry(1.30, Duration.ZERO), // new BasalScheduleEntry(1.30, Duration.ZERO), //
new BasalScheduleEntry(0.05, Duration.standardMinutes(30)), // new BasalScheduleEntry(0.05, Duration.standardMinutes(30)), //
@ -111,13 +110,13 @@ public class SetInsulinScheduleCommandTest {
basalSchedule, // basalSchedule, //
Duration.standardMinutes((0x03 + 1) * 30).minus(Duration.standardSeconds(0x0ae8 / 8))); Duration.standardMinutes((0x03 + 1) * 30).minus(Duration.standardSeconds(0x0ae8 / 8)));
assertArrayEquals( // Assertions.assertArrayEquals( //
ByteUtil.fromHexString("1a2af36a23a3000291030ae80000000d280000111809700a180610052806100600072806001128100009e808"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/BasalScheduleTests.swift ByteUtil.fromHexString("1a2af36a23a3000291030ae80000000d280000111809700a180610052806100600072806001128100009e808"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/BasalScheduleTests.swift
setInsulinScheduleCommand.getRawData()); setInsulinScheduleCommand.getRawData());
} }
@Test @Test
public void testBasalScheduleWithThirteenEntries() { void testBasalScheduleWithThirteenEntries() {
List<BasalScheduleEntry> entries = Arrays.asList( List<BasalScheduleEntry> entries = Arrays.asList(
new BasalScheduleEntry(1.30, Duration.ZERO), // new BasalScheduleEntry(1.30, Duration.ZERO), //
new BasalScheduleEntry(0.05, Duration.standardMinutes(30)), // new BasalScheduleEntry(0.05, Duration.standardMinutes(30)), //
@ -140,13 +139,13 @@ public class SetInsulinScheduleCommandTest {
basalSchedule, // basalSchedule, //
Duration.standardMinutes((0x27 + 1) * 30).minus(Duration.standardSeconds(0x1518 / 8))); Duration.standardMinutes((0x27 + 1) * 30).minus(Duration.standardSeconds(0x1518 / 8)));
assertArrayEquals( // Assertions.assertArrayEquals( //
ByteUtil.fromHexString("1a2a851072aa0001dd2715180003000d280000111809700a180610052806100600072806001118101801e808"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/BasalScheduleTests.swift ByteUtil.fromHexString("1a2a851072aa0001dd2715180003000d280000111809700a180610052806100600072806001118101801e808"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/BasalScheduleTests.swift
setInsulinScheduleCommand.getRawData()); setInsulinScheduleCommand.getRawData());
} }
@Test @Test
public void testBasalScheduleRounding() { void testBasalScheduleRounding() {
List<BasalScheduleEntry> entries = Arrays.asList( List<BasalScheduleEntry> entries = Arrays.asList(
new BasalScheduleEntry(2.75, Duration.ZERO), new BasalScheduleEntry(2.75, Duration.ZERO),
new BasalScheduleEntry(20.25, Duration.standardMinutes(60)), // new BasalScheduleEntry(20.25, Duration.standardMinutes(60)), //
@ -163,13 +162,13 @@ public class SetInsulinScheduleCommandTest {
basalSchedule, // basalSchedule, //
Duration.standardMinutes((0x28 + 1) * 30).minus(Duration.standardSeconds(0x1af0 / 8))); Duration.standardMinutes((0x28 + 1) * 30).minus(Duration.standardSeconds(0x1af0 / 8)));
assertArrayEquals( // Assertions.assertArrayEquals( //
ByteUtil.fromHexString("1a1ec2a32da800053a281af00010181b00ca003200650001f8008800f0230023"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/BasalScheduleTests.swift ByteUtil.fromHexString("1a1ec2a32da800053a281af00010181b00ca003200650001f8008800f0230023"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/BasalScheduleTests.swift
setInsulinScheduleCommand.getRawData()); setInsulinScheduleCommand.getRawData());
} }
@Test @Test
public void testBasalScheduleRounding2() { void testBasalScheduleRounding2() {
List<BasalScheduleEntry> entries = Arrays.asList( List<BasalScheduleEntry> entries = Arrays.asList(
new BasalScheduleEntry(0.6, Duration.ZERO), new BasalScheduleEntry(0.6, Duration.ZERO),
new BasalScheduleEntry(0.65, Duration.standardMinutes(450)), // new BasalScheduleEntry(0.65, Duration.standardMinutes(450)), //
@ -186,13 +185,13 @@ public class SetInsulinScheduleCommandTest {
basalSchedule, // basalSchedule, //
Duration.standardMinutes((0x2c + 1) * 30).minus(Duration.standardSeconds(0x2190 / 8))); Duration.standardMinutes((0x2c + 1) * 30).minus(Duration.standardSeconds(0x2190 / 8)));
assertArrayEquals( // Assertions.assertArrayEquals( //
ByteUtil.fromHexString("1a18851072aa00021b2c21900004f00600071005b8061801e008"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/BasalScheduleTests.swift ByteUtil.fromHexString("1a18851072aa00021b2c21900004f00600071005b8061801e008"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/BasalScheduleTests.swift
setInsulinScheduleCommand.getRawData()); setInsulinScheduleCommand.getRawData());
} }
@Test @Test
public void testBasalScheduleSegmentMerging() { void testBasalScheduleSegmentMerging() {
List<BasalScheduleEntry> entries = Arrays.asList( List<BasalScheduleEntry> entries = Arrays.asList(
new BasalScheduleEntry(0.8, Duration.ZERO), new BasalScheduleEntry(0.8, Duration.ZERO),
new BasalScheduleEntry(0.9, Duration.standardMinutes(180)), // new BasalScheduleEntry(0.9, Duration.standardMinutes(180)), //
@ -211,37 +210,37 @@ public class SetInsulinScheduleCommandTest {
basalSchedule, // basalSchedule, //
Duration.standardMinutes((0x2a + 1) * 30).minus(Duration.standardSeconds(0x1e50 / 8))); Duration.standardMinutes((0x2a + 1) * 30).minus(Duration.standardSeconds(0x1e50 / 8)));
assertArrayEquals( // Assertions.assertArrayEquals( //
ByteUtil.fromHexString("1a1a851072aa0002422a1e50000650083009f808380850073009700b"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/BasalScheduleTests.swift ByteUtil.fromHexString("1a1a851072aa0002422a1e50000650083009f808380850073009700b"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/BasalScheduleTests.swift
setInsulinScheduleCommand.getRawData()); setInsulinScheduleCommand.getRawData());
} }
@Test @Test
public void testBolus() { void testBolus() {
BolusDeliverySchedule bolusDeliverySchedule = new BolusDeliverySchedule(2.6, Duration.standardSeconds(1)); BolusDeliverySchedule bolusDeliverySchedule = new BolusDeliverySchedule(2.6, Duration.standardSeconds(1));
SetInsulinScheduleCommand setInsulinScheduleCommand = new SetInsulinScheduleCommand(0xbed2e16b, bolusDeliverySchedule); SetInsulinScheduleCommand setInsulinScheduleCommand = new SetInsulinScheduleCommand(0xbed2e16b, bolusDeliverySchedule);
assertArrayEquals( // Assertions.assertArrayEquals( //
ByteUtil.createByteArrayFromHexString("1a0ebed2e16b02010a0101a000340034"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/BolusTests.swift ByteUtil.createByteArrayFromHexString("1a0ebed2e16b02010a0101a000340034"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/BolusTests.swift
setInsulinScheduleCommand.getRawData()); setInsulinScheduleCommand.getRawData());
} }
@Test @Test
public void testBolusExtraCommandWithExtraOddPulseCount() { void testBolusExtraCommandWithExtraOddPulseCount() {
BolusDeliverySchedule bolusDeliverySchedule = new BolusDeliverySchedule(2.05, Duration.standardSeconds(2)); BolusDeliverySchedule bolusDeliverySchedule = new BolusDeliverySchedule(2.05, Duration.standardSeconds(2));
SetInsulinScheduleCommand setInsulinScheduleCommand = new SetInsulinScheduleCommand(0xcf9e81ac, bolusDeliverySchedule); SetInsulinScheduleCommand setInsulinScheduleCommand = new SetInsulinScheduleCommand(0xcf9e81ac, bolusDeliverySchedule);
assertArrayEquals( // Assertions.assertArrayEquals( //
ByteUtil.createByteArrayFromHexString("1a0ecf9e81ac0200e501029000290029"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/BolusTests.swift ByteUtil.createByteArrayFromHexString("1a0ecf9e81ac0200e501029000290029"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/BolusTests.swift
setInsulinScheduleCommand.getRawData()); setInsulinScheduleCommand.getRawData());
} }
@Test @Test
public void testLargeBolus() { void testLargeBolus() {
BolusDeliverySchedule bolusDeliverySchedule = new BolusDeliverySchedule(29.95, Duration.standardSeconds(2)); BolusDeliverySchedule bolusDeliverySchedule = new BolusDeliverySchedule(29.95, Duration.standardSeconds(2));
SetInsulinScheduleCommand setInsulinScheduleCommand = new SetInsulinScheduleCommand(0x31204ba7, bolusDeliverySchedule); SetInsulinScheduleCommand setInsulinScheduleCommand = new SetInsulinScheduleCommand(0x31204ba7, bolusDeliverySchedule);
assertArrayEquals( // Assertions.assertArrayEquals( //
ByteUtil.createByteArrayFromHexString("1a0e31204ba702014801257002570257"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/BolusTests.swift ByteUtil.createByteArrayFromHexString("1a0e31204ba702014801257002570257"), // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/BolusTests.swift
setInsulinScheduleCommand.getRawData()); setInsulinScheduleCommand.getRawData());
} }

View file

@ -1,22 +1,21 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command;
import static org.junit.Assert.assertArrayEquals;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import info.nightscout.pump.core.utils.ByteUtil; import info.nightscout.pump.core.utils.ByteUtil;
public class SetupPodCommandTest { class SetupPodCommandTest {
@Test @Test
public void testEncoding() { void testEncoding() {
SetupPodCommand setupPodCommand = new SetupPodCommand( // SetupPodCommand setupPodCommand = new SetupPodCommand( //
0x1f00ee87, // 0x1f00ee87, //
new DateTime(2013, 4, 5, 22, 52, 0), // new DateTime(2013, 4, 5, 22, 52, 0), //
41847, // 41847, //
240439); 240439);
assertArrayEquals( // Assertions.assertArrayEquals( //
ByteUtil.fromHexString("03131f00ee87140404050d16340000a3770003ab37"), // From https://github.com/openaps/openomni/wiki/Command-03-Setup-Pod ByteUtil.fromHexString("03131f00ee87140404050d16340000a3770003ab37"), // From https://github.com/openaps/openomni/wiki/Command-03-Setup-Pod
setupPodCommand.getRawData()); setupPodCommand.getRawData());
} }

View file

@ -1,75 +1,74 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.command;
import static org.junit.Assert.assertArrayEquals;
import org.joda.time.Duration; import org.joda.time.Duration;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import info.nightscout.pump.core.utils.ByteUtil; import info.nightscout.pump.core.utils.ByteUtil;
public class TempBasalExtraCommandTest { class TempBasalExtraCommandTest {
@Test @Test
public void testTempBasalExtraCommand() { void testTempBasalExtraCommand() {
TempBasalExtraCommand tempBasalExtraCommand = new TempBasalExtraCommand(30D, Duration.standardMinutes(30), TempBasalExtraCommand tempBasalExtraCommand = new TempBasalExtraCommand(30D, Duration.standardMinutes(30),
false, true, Duration.standardHours(1)); false, true, Duration.standardHours(1));
assertArrayEquals(ByteUtil.fromHexString("160e7c000bb8000927c00bb8000927c0"), Assertions.assertArrayEquals(ByteUtil.fromHexString("160e7c000bb8000927c00bb8000927c0"),
tempBasalExtraCommand.getRawData()); tempBasalExtraCommand.getRawData());
} }
@Test @Test
public void testBasalExtraCommandForOddPulseCountRate() { void testBasalExtraCommandForOddPulseCountRate() {
TempBasalExtraCommand tempBasalExtraCommand = new TempBasalExtraCommand(0.05, Duration.standardMinutes(30), TempBasalExtraCommand tempBasalExtraCommand = new TempBasalExtraCommand(0.05, Duration.standardMinutes(30),
false, true, Duration.standardHours(1)); false, true, Duration.standardHours(1));
assertArrayEquals(ByteUtil.fromHexString("160e7c00000515752a00000515752a00"), Assertions.assertArrayEquals(ByteUtil.fromHexString("160e7c00000515752a00000515752a00"),
tempBasalExtraCommand.getRawData()); tempBasalExtraCommand.getRawData());
TempBasalExtraCommand tempBasalExtraCommand2 = new TempBasalExtraCommand(2.05, Duration.standardMinutes(30), TempBasalExtraCommand tempBasalExtraCommand2 = new TempBasalExtraCommand(2.05, Duration.standardMinutes(30),
false, false, Duration.standardHours(1)); false, false, Duration.standardHours(1));
assertArrayEquals(ByteUtil.fromHexString("160e3c0000cd0085fac700cd0085fac7"), Assertions.assertArrayEquals(ByteUtil.fromHexString("160e3c0000cd0085fac700cd0085fac7"),
tempBasalExtraCommand2.getRawData()); tempBasalExtraCommand2.getRawData());
TempBasalExtraCommand tempBasalExtraCommand3 = new TempBasalExtraCommand(2.10, Duration.standardMinutes(30), TempBasalExtraCommand tempBasalExtraCommand3 = new TempBasalExtraCommand(2.10, Duration.standardMinutes(30),
false, false, Duration.standardHours(1)); false, false, Duration.standardHours(1));
assertArrayEquals(ByteUtil.fromHexString("160e3c0000d20082ca2400d20082ca24"), Assertions.assertArrayEquals(ByteUtil.fromHexString("160e3c0000d20082ca2400d20082ca24"),
tempBasalExtraCommand3.getRawData()); tempBasalExtraCommand3.getRawData());
TempBasalExtraCommand tempBasalExtraCommand4 = new TempBasalExtraCommand(2.15, Duration.standardMinutes(30), TempBasalExtraCommand tempBasalExtraCommand4 = new TempBasalExtraCommand(2.15, Duration.standardMinutes(30),
false, false, Duration.standardHours(1)); false, false, Duration.standardHours(1));
assertArrayEquals(ByteUtil.fromHexString("160e3c0000d7007fbf7d00d7007fbf7d"), Assertions.assertArrayEquals(ByteUtil.fromHexString("160e3c0000d7007fbf7d00d7007fbf7d"),
tempBasalExtraCommand4.getRawData()); tempBasalExtraCommand4.getRawData());
} }
@Test @Test
public void testBasalExtraCommandPulseCount() { void testBasalExtraCommandPulseCount() {
TempBasalExtraCommand tempBasalExtraCommand = new TempBasalExtraCommand(27.35, Duration.standardHours(12), TempBasalExtraCommand tempBasalExtraCommand = new TempBasalExtraCommand(27.35, Duration.standardHours(12),
false, false, Duration.ZERO); false, false, Duration.ZERO);
assertArrayEquals(ByteUtil.fromHexString("16140000f5b9000a0ad7f5b9000a0ad70aaf000a0ad7"), Assertions.assertArrayEquals(ByteUtil.fromHexString("16140000f5b9000a0ad7f5b9000a0ad70aaf000a0ad7"),
tempBasalExtraCommand.getRawData()); tempBasalExtraCommand.getRawData());
} }
@Test @Test
public void testTempBasalExtraCommandExtremeValues() { void testTempBasalExtraCommandExtremeValues() {
TempBasalExtraCommand tempBasalExtraCommand2 = new TempBasalExtraCommand(29.95, Duration.standardHours(12), TempBasalExtraCommand tempBasalExtraCommand2 = new TempBasalExtraCommand(29.95, Duration.standardHours(12),
false, false, Duration.standardHours(1)); false, false, Duration.standardHours(1));
assertArrayEquals(ByteUtil.fromHexString("16143c00f5af00092ba9f5af00092ba9231900092ba9"), Assertions.assertArrayEquals(ByteUtil.fromHexString("16143c00f5af00092ba9f5af00092ba9231900092ba9"),
tempBasalExtraCommand2.getRawData()); tempBasalExtraCommand2.getRawData());
TempBasalExtraCommand tempBasalExtraCommand = new TempBasalExtraCommand(30D, Duration.standardHours(12), TempBasalExtraCommand tempBasalExtraCommand = new TempBasalExtraCommand(30D, Duration.standardHours(12),
false, false, Duration.standardHours(1)); false, false, Duration.standardHours(1));
assertArrayEquals(ByteUtil.fromHexString("16143c00f618000927c0f618000927c02328000927c0"), Assertions.assertArrayEquals(ByteUtil.fromHexString("16143c00f618000927c0f618000927c02328000927c0"),
tempBasalExtraCommand.getRawData()); tempBasalExtraCommand.getRawData());
} }
@Test @Test
public void testTempBasalExtraCommandZeroBasal() { void testTempBasalExtraCommandZeroBasal() {
TempBasalExtraCommand tempBasalExtraCommand = new TempBasalExtraCommand(0D, Duration.standardMinutes(30), TempBasalExtraCommand tempBasalExtraCommand = new TempBasalExtraCommand(0D, Duration.standardMinutes(30),
false, true, Duration.standardHours(1)); false, true, Duration.standardHours(1));
assertArrayEquals(ByteUtil.fromHexString("160e7c0000006b49d20000006b49d200"), Assertions.assertArrayEquals(ByteUtil.fromHexString("160e7c0000006b49d20000006b49d200"),
tempBasalExtraCommand.getRawData()); tempBasalExtraCommand.getRawData());
TempBasalExtraCommand tempBasalExtraCommand2 = new TempBasalExtraCommand(0D, Duration.standardHours(3), TempBasalExtraCommand tempBasalExtraCommand2 = new TempBasalExtraCommand(0D, Duration.standardHours(3),
false, true, Duration.standardHours(1)); false, true, Duration.standardHours(1));
assertArrayEquals(ByteUtil.fromHexString("162c7c0000006b49d20000006b49d20000006b49d20000006b49d20000006b49d20000006b49d20000006b49d200"), Assertions.assertArrayEquals(ByteUtil.fromHexString("162c7c0000006b49d20000006b49d20000006b49d20000006b49d20000006b49d20000006b49d20000006b49d200"),
tempBasalExtraCommand2.getRawData()); tempBasalExtraCommand2.getRawData());
} }
} }

View file

@ -1,21 +1,20 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.defs.schedule; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.defs.schedule;
import static org.junit.Assert.assertEquals; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.schedule.BasalTableEntry; import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.schedule.BasalTableEntry;
public class BasalTableEntryTest { class BasalTableEntryTest {
@Test @Test
public void testChecksum() { void testChecksum() {
BasalTableEntry basalTableEntry = new BasalTableEntry(2, 300, false); BasalTableEntry basalTableEntry = new BasalTableEntry(2, 300, false);
assertEquals(0x5a, basalTableEntry.getChecksum()); Assertions.assertEquals(0x5a, basalTableEntry.getChecksum());
} }
@Test @Test
public void testChecksumWithAlternatePulses() { void testChecksumWithAlternatePulses() {
BasalTableEntry basalTableEntry = new BasalTableEntry(2, 260, true); BasalTableEntry basalTableEntry = new BasalTableEntry(2, 260, true);
assertEquals(0x0b, basalTableEntry.getChecksum()); Assertions.assertEquals(0x0b, basalTableEntry.getChecksum());
} }
} }

View file

@ -1,52 +1,49 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.response; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.response;
import static org.junit.Assert.assertArrayEquals; import org.junit.jupiter.api.Assertions;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.FaultEventCode; import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.FaultEventCode;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.PodProgressStatus; import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.PodProgressStatus;
import info.nightscout.pump.core.utils.ByteUtil; import info.nightscout.pump.core.utils.ByteUtil;
public class ErrorResponseTest { class ErrorResponseTest {
@Test @Test
public void testGetRawData() { void testGetRawData() {
byte[] encodedData = ByteUtil.fromHexString("060314fa92"); byte[] encodedData = ByteUtil.fromHexString("060314fa92");
ErrorResponse errorResponse = new ErrorResponse(encodedData); ErrorResponse errorResponse = new ErrorResponse(encodedData);
assertArrayEquals(encodedData, errorResponse.getRawData()); Assertions.assertArrayEquals(encodedData, errorResponse.getRawData());
} }
@Test @Test
public void testGetRawDataWithLongerMessage() { void testGetRawDataWithLongerMessage() {
byte[] encodedData = ByteUtil.fromHexString("060314fa9201"); byte[] encodedData = ByteUtil.fromHexString("060314fa9201");
byte[] expected = ByteUtil.fromHexString("060314fa92"); byte[] expected = ByteUtil.fromHexString("060314fa92");
ErrorResponse errorResponse = new ErrorResponse(encodedData); ErrorResponse errorResponse = new ErrorResponse(encodedData);
assertArrayEquals(expected, errorResponse.getRawData()); Assertions.assertArrayEquals(expected, errorResponse.getRawData());
} }
@Test @Test
public void testBadNonce() { void testBadNonce() {
byte[] encodedData = ByteUtil.fromHexString("060314fa92"); byte[] encodedData = ByteUtil.fromHexString("060314fa92");
ErrorResponse errorResponse = new ErrorResponse(encodedData); ErrorResponse errorResponse = new ErrorResponse(encodedData);
assertEquals(ErrorResponse.ERROR_RESPONSE_CODE_BAD_NONCE, errorResponse.getErrorResponseCode()); Assertions.assertEquals(ErrorResponse.ERROR_RESPONSE_CODE_BAD_NONCE, errorResponse.getErrorResponseCode());
// TODO add assertion on nonce search key (obtain captures first) // TODO add assertion on nonce search key (obtain captures first)
assertNull(errorResponse.getFaultEventCode()); Assertions.assertNull(errorResponse.getFaultEventCode());
assertNull(errorResponse.getPodProgressStatus()); Assertions.assertNull(errorResponse.getPodProgressStatus());
} }
@Test @Test
public void testOtherError() { void testOtherError() {
ErrorResponse errorResponse = new ErrorResponse(ByteUtil.fromHexString("0603101308")); ErrorResponse errorResponse = new ErrorResponse(ByteUtil.fromHexString("0603101308"));
assertEquals(0x10, errorResponse.getErrorResponseCode()); Assertions.assertEquals(0x10, errorResponse.getErrorResponseCode());
assertEquals(FaultEventCode.MESSAGE_LENGTH_TOO_LONG, errorResponse.getFaultEventCode()); Assertions.assertEquals(FaultEventCode.MESSAGE_LENGTH_TOO_LONG, errorResponse.getFaultEventCode());
assertEquals(PodProgressStatus.ABOVE_FIFTY_UNITS, errorResponse.getPodProgressStatus()); Assertions.assertEquals(PodProgressStatus.ABOVE_FIFTY_UNITS, errorResponse.getPodProgressStatus());
assertNull(errorResponse.getNonceSearchKey()); Assertions.assertNull(errorResponse.getNonceSearchKey());
} }
} }

View file

@ -1,11 +1,7 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.response; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.response;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.joda.time.Duration; import org.joda.time.Duration;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.AlertSlot; import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.AlertSlot;
@ -14,96 +10,95 @@ 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.androidaps.plugins.pump.omnipod.eros.driver.definition.PodProgressStatus;
import info.nightscout.pump.core.utils.ByteUtil; import info.nightscout.pump.core.utils.ByteUtil;
public class StatusResponseTest { class StatusResponseTest {
// TODO add /extend tests
@Test @Test
public void testRawData() { void testRawData() {
byte[] encodedData = ByteUtil.fromHexString("1d080000000038800000"); byte[] encodedData = ByteUtil.fromHexString("1d080000000038800000");
StatusResponse statusResponse = new StatusResponse(encodedData); StatusResponse statusResponse = new StatusResponse(encodedData);
assertArrayEquals(encodedData, statusResponse.getRawData()); Assertions.assertArrayEquals(encodedData, statusResponse.getRawData());
} }
@Test @Test
public void testRawDataWithLongerMessage() { void testRawDataWithLongerMessage() {
byte[] encodedData = ByteUtil.fromHexString("1d08000000003880000001"); byte[] encodedData = ByteUtil.fromHexString("1d08000000003880000001");
byte[] expected = ByteUtil.fromHexString("1d080000000038800000"); byte[] expected = ByteUtil.fromHexString("1d080000000038800000");
StatusResponse statusResponse = new StatusResponse(encodedData); StatusResponse statusResponse = new StatusResponse(encodedData);
assertArrayEquals(expected, statusResponse.getRawData()); Assertions.assertArrayEquals(expected, statusResponse.getRawData());
} }
@Test @Test
public void testWithSampleCapture() { void testWithSampleCapture() {
byte[] bytes = ByteUtil.fromHexString("1d180258f80000146fff"); // From https://github.com/openaps/openomni/wiki/Command-1D-Status-response byte[] bytes = ByteUtil.fromHexString("1d180258f80000146fff"); // From https://github.com/openaps/openomni/wiki/Command-1D-Status-response
StatusResponse statusResponse = new StatusResponse(bytes); StatusResponse statusResponse = new StatusResponse(bytes);
assertEquals(DeliveryStatus.NORMAL, statusResponse.getDeliveryStatus()); Assertions.assertEquals(DeliveryStatus.NORMAL, statusResponse.getDeliveryStatus());
assertEquals(PodProgressStatus.ABOVE_FIFTY_UNITS, statusResponse.getPodProgressStatus()); Assertions.assertEquals(PodProgressStatus.ABOVE_FIFTY_UNITS, statusResponse.getPodProgressStatus());
assertNull("Reservoir level should be null", statusResponse.getReservoirLevel()); Assertions.assertNull(statusResponse.getReservoirLevel());
assertEquals(Duration.standardMinutes(1307).getMillis(), statusResponse.getTimeActive().getMillis()); Assertions.assertEquals(Duration.standardMinutes(1307).getMillis(), statusResponse.getTimeActive().getMillis());
assertEquals(1201, statusResponse.getTicksDelivered()); Assertions.assertEquals(1201, statusResponse.getTicksDelivered());
assertEquals(60.05, statusResponse.getInsulinDelivered(), 0.000001); Assertions.assertEquals(60.05, statusResponse.getInsulinDelivered(), 0.000001);
assertEquals(15, statusResponse.getPodMessageCounter()); Assertions.assertEquals(15, statusResponse.getPodMessageCounter());
assertEquals(0, statusResponse.getBolusNotDelivered(), 0.000001); Assertions.assertEquals(0, statusResponse.getBolusNotDelivered(), 0.000001);
assertEquals(0, statusResponse.getUnacknowledgedAlerts().getAlertSlots().size()); Assertions.assertEquals(0, statusResponse.getUnacknowledgedAlerts().getAlertSlots().size());
assertArrayEquals(ByteUtil.fromHexString("1d180258f80000146fff"), statusResponse.getRawData()); Assertions.assertArrayEquals(ByteUtil.fromHexString("1d180258f80000146fff"), statusResponse.getRawData());
} }
@Test @Test
public void testWithSampleCaptureWithChangePodSoonAlert() { void testWithSampleCaptureWithChangePodSoonAlert() {
byte[] bytes = ByteUtil.fromHexString("1d19061f6800044295e8"); // From https://github.com/openaps/openomni/wiki/Status-Response-1D-long-run-%28Lytrix%29 byte[] bytes = ByteUtil.fromHexString("1d19061f6800044295e8"); // From https://github.com/openaps/openomni/wiki/Status-Response-1D-long-run-%28Lytrix%29
StatusResponse statusResponse = new StatusResponse(bytes); StatusResponse statusResponse = new StatusResponse(bytes);
assertEquals(DeliveryStatus.NORMAL, statusResponse.getDeliveryStatus()); Assertions.assertEquals(DeliveryStatus.NORMAL, statusResponse.getDeliveryStatus());
assertEquals(PodProgressStatus.FIFTY_OR_LESS_UNITS, statusResponse.getPodProgressStatus()); Assertions.assertEquals(PodProgressStatus.FIFTY_OR_LESS_UNITS, statusResponse.getPodProgressStatus());
assertEquals(24.4, statusResponse.getReservoirLevel(), 0.000001); Assertions.assertEquals(24.4, statusResponse.getReservoirLevel(), 0.000001);
assertEquals(Duration.standardMinutes(4261).getMillis(), statusResponse.getTimeActive().getMillis()); Assertions.assertEquals(Duration.standardMinutes(4261).getMillis(), statusResponse.getTimeActive().getMillis());
assertEquals(3134, statusResponse.getTicksDelivered()); Assertions.assertEquals(3134, statusResponse.getTicksDelivered());
assertEquals(156.7, statusResponse.getInsulinDelivered(), 0.000001); Assertions.assertEquals(156.7, statusResponse.getInsulinDelivered(), 0.000001);
assertEquals(13, statusResponse.getPodMessageCounter()); Assertions.assertEquals(13, statusResponse.getPodMessageCounter());
assertEquals(0, statusResponse.getBolusNotDelivered(), 0.000001); Assertions.assertEquals(0, statusResponse.getBolusNotDelivered(), 0.000001);
assertEquals(1, statusResponse.getUnacknowledgedAlerts().getAlertSlots().size()); Assertions.assertEquals(1, statusResponse.getUnacknowledgedAlerts().getAlertSlots().size());
assertEquals(AlertSlot.SLOT3, statusResponse.getUnacknowledgedAlerts().getAlertSlots().get(0)); Assertions.assertEquals(AlertSlot.SLOT3, statusResponse.getUnacknowledgedAlerts().getAlertSlots().get(0));
assertArrayEquals(ByteUtil.fromHexString("1d19061f6800044295e8"), statusResponse.getRawData()); Assertions.assertArrayEquals(ByteUtil.fromHexString("1d19061f6800044295e8"), statusResponse.getRawData());
} }
@Test @Test
public void testLargeValues() { void testLargeValues() {
byte[] bytes = ByteUtil.fromHexString("1d11ffffffffffffffff"); byte[] bytes = ByteUtil.fromHexString("1d11ffffffffffffffff");
StatusResponse statusResponse = new StatusResponse(bytes); StatusResponse statusResponse = new StatusResponse(bytes);
assertEquals(Duration.standardMinutes(8191).getMillis(), statusResponse.getTimeActive().getMillis()); Assertions.assertEquals(Duration.standardMinutes(8191).getMillis(), statusResponse.getTimeActive().getMillis());
assertEquals(OmnipodConstants.POD_PULSE_SIZE * 1023, statusResponse.getBolusNotDelivered(), 0.000001); Assertions.assertEquals(OmnipodConstants.POD_PULSE_SIZE * 1023, statusResponse.getBolusNotDelivered(), 0.000001);
assertNull("Reservoir level should be null", statusResponse.getReservoirLevel()); Assertions.assertNull(statusResponse.getReservoirLevel());
assertEquals(OmnipodConstants.POD_PULSE_SIZE * 8191, statusResponse.getInsulinDelivered(), 0.0000001); Assertions.assertEquals(OmnipodConstants.POD_PULSE_SIZE * 8191, statusResponse.getInsulinDelivered(), 0.0000001);
assertEquals(8191, statusResponse.getTicksDelivered()); Assertions.assertEquals(8191, statusResponse.getTicksDelivered());
assertEquals(OmnipodConstants.POD_PULSE_SIZE * 8191, statusResponse.getInsulinDelivered(), 0.0000001); Assertions.assertEquals(OmnipodConstants.POD_PULSE_SIZE * 8191, statusResponse.getInsulinDelivered(), 0.0000001);
assertEquals(15, statusResponse.getPodMessageCounter()); Assertions.assertEquals(15, statusResponse.getPodMessageCounter());
assertEquals(8, statusResponse.getUnacknowledgedAlerts().getAlertSlots().size()); Assertions.assertEquals(8, statusResponse.getUnacknowledgedAlerts().getAlertSlots().size());
assertArrayEquals(ByteUtil.fromHexString("1d11ffffffffffffffff"), statusResponse.getRawData()); Assertions.assertArrayEquals(ByteUtil.fromHexString("1d11ffffffffffffffff"), statusResponse.getRawData());
} }
@Test @Test
public void testWithReservoirLevel() { void testWithReservoirLevel() {
byte[] bytes = ByteUtil.fromHexString("1d19050ec82c08376f98"); byte[] bytes = ByteUtil.fromHexString("1d19050ec82c08376f98");
StatusResponse statusResponse = new StatusResponse(bytes); StatusResponse statusResponse = new StatusResponse(bytes);
assertTrue(Duration.standardMinutes(3547).isEqual(statusResponse.getTimeActive())); Assertions.assertTrue(Duration.standardMinutes(3547).isEqual(statusResponse.getTimeActive()));
assertEquals(DeliveryStatus.NORMAL, statusResponse.getDeliveryStatus()); Assertions.assertEquals(DeliveryStatus.NORMAL, statusResponse.getDeliveryStatus());
assertEquals(PodProgressStatus.FIFTY_OR_LESS_UNITS, statusResponse.getPodProgressStatus()); Assertions.assertEquals(PodProgressStatus.FIFTY_OR_LESS_UNITS, statusResponse.getPodProgressStatus());
assertEquals(2589, statusResponse.getTicksDelivered()); Assertions.assertEquals(2589, statusResponse.getTicksDelivered());
assertEquals(129.45, statusResponse.getInsulinDelivered(), 0.00001); Assertions.assertEquals(129.45, statusResponse.getInsulinDelivered(), 0.00001);
assertEquals(46.00, statusResponse.getReservoirLevel(), 0.00001); Assertions.assertEquals(46.00, statusResponse.getReservoirLevel(), 0.00001);
assertEquals(2.2, statusResponse.getBolusNotDelivered(), 0.0001); Assertions.assertEquals(2.2, statusResponse.getBolusNotDelivered(), 0.0001);
assertEquals(9, statusResponse.getPodMessageCounter()); Assertions.assertEquals(9, statusResponse.getPodMessageCounter());
assertArrayEquals(ByteUtil.fromHexString("1d19050ec82c08376f98"), statusResponse.getRawData()); Assertions.assertArrayEquals(ByteUtil.fromHexString("1d19050ec82c08376f98"), statusResponse.getRawData());
} }
} }

View file

@ -1,81 +1,75 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.response; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.response;
import static org.junit.Assert.assertArrayEquals; import org.junit.jupiter.api.Assertions;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.PodProgressStatus; import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.PodProgressStatus;
import info.nightscout.pump.core.utils.ByteUtil; import info.nightscout.pump.core.utils.ByteUtil;
public class VersionResponseTest { class VersionResponseTest {
@Test @Test
public void testRawDataAssignAddressVersionResponse() { void testRawDataAssignAddressVersionResponse() {
byte[] encodedData = ByteUtil.fromHexString("011502070002070002020000a64000097c279c1f08ced2"); byte[] encodedData = ByteUtil.fromHexString("011502070002070002020000a64000097c279c1f08ced2");
VersionResponse versionResponse = new VersionResponse(encodedData); VersionResponse versionResponse = new VersionResponse(encodedData);
assertArrayEquals(encodedData, versionResponse.getRawData()); Assertions.assertArrayEquals(encodedData, versionResponse.getRawData());
} }
@Test @Test
public void testRawDataAssignAddressVersionResponseWithLongerMessage() { void testRawDataAssignAddressVersionResponseWithLongerMessage() {
byte[] encodedData = ByteUtil.fromHexString("011502070002070002020000a64000097c279c1f08ced201"); byte[] encodedData = ByteUtil.fromHexString("011502070002070002020000a64000097c279c1f08ced201");
byte[] expected = ByteUtil.fromHexString("011502070002070002020000a64000097c279c1f08ced2"); byte[] expected = ByteUtil.fromHexString("011502070002070002020000a64000097c279c1f08ced2");
VersionResponse versionResponse = new VersionResponse(encodedData); VersionResponse versionResponse = new VersionResponse(encodedData);
assertArrayEquals(expected, versionResponse.getRawData()); Assertions.assertArrayEquals(expected, versionResponse.getRawData());
} }
@Test @Test
public void testRawDataSetupPodVersionResponse() { void testRawDataSetupPodVersionResponse() {
byte[] encodedData = ByteUtil.fromHexString("011b13881008340a5002070002070002030000a3770003ab371f00ee87"); byte[] encodedData = ByteUtil.fromHexString("011b13881008340a5002070002070002030000a3770003ab371f00ee87");
VersionResponse versionResponse = new VersionResponse(encodedData); VersionResponse versionResponse = new VersionResponse(encodedData);
assertArrayEquals(encodedData, versionResponse.getRawData()); Assertions.assertArrayEquals(encodedData, versionResponse.getRawData());
} }
@Test @Test
public void testRawDataSetupPodVersionResponseWithLongerMessage() { void testRawDataSetupPodVersionResponseWithLongerMessage() {
byte[] encodedData = ByteUtil.fromHexString("011b13881008340a5002070002070002030000a3770003ab371f00ee8701"); byte[] encodedData = ByteUtil.fromHexString("011b13881008340a5002070002070002030000a3770003ab371f00ee8701");
byte[] expected = ByteUtil.fromHexString("011b13881008340a5002070002070002030000a3770003ab371f00ee87"); byte[] expected = ByteUtil.fromHexString("011b13881008340a5002070002070002030000a3770003ab371f00ee87");
VersionResponse versionResponse = new VersionResponse(encodedData); VersionResponse versionResponse = new VersionResponse(encodedData);
assertArrayEquals(expected, versionResponse.getRawData()); Assertions.assertArrayEquals(expected, versionResponse.getRawData());
} }
@Test @Test
public void testAssignAddressVersionResponse() { void testAssignAddressVersionResponse() {
VersionResponse versionResponse = new VersionResponse(ByteUtil.fromHexString("011502070002070002020000a64000097c279c1f08ced2")); VersionResponse versionResponse = new VersionResponse(ByteUtil.fromHexString("011502070002070002020000a64000097c279c1f08ced2"));
assertTrue(versionResponse.isAssignAddressVersionResponse()); Assertions.assertTrue(versionResponse.isAssignAddressVersionResponse());
assertFalse(versionResponse.isSetupPodVersionResponse()); Assertions.assertFalse(versionResponse.isSetupPodVersionResponse());
assertEquals(0x1f08ced2, versionResponse.getAddress()); Assertions.assertEquals(0x1f08ced2, versionResponse.getAddress());
assertEquals(42560, versionResponse.getLot()); Assertions.assertEquals(42560, versionResponse.getLot());
assertEquals(621607, versionResponse.getTid()); Assertions.assertEquals(621607, versionResponse.getTid());
assertEquals("2.7.0", versionResponse.getPiVersion().toString()); Assertions.assertEquals("2.7.0", versionResponse.getPiVersion().toString());
assertEquals("2.7.0", versionResponse.getPmVersion().toString()); Assertions.assertEquals("2.7.0", versionResponse.getPmVersion().toString());
assertNotNull(versionResponse.getRssi()); Assertions.assertNotNull(versionResponse.getRssi());
assertNotNull(versionResponse.getGain()); Assertions.assertNotNull(versionResponse.getGain());
} }
@Test @Test
public void testSetupPodVersionResponse() { void testSetupPodVersionResponse() {
VersionResponse versionResponse = new VersionResponse(ByteUtil.fromHexString("011b13881008340a5002070002070002030000a3770003ab371f00ee87")); VersionResponse versionResponse = new VersionResponse(ByteUtil.fromHexString("011b13881008340a5002070002070002030000a3770003ab371f00ee87"));
assertFalse(versionResponse.isAssignAddressVersionResponse()); Assertions.assertFalse(versionResponse.isAssignAddressVersionResponse());
assertTrue(versionResponse.isSetupPodVersionResponse()); Assertions.assertTrue(versionResponse.isSetupPodVersionResponse());
assertEquals(0x1f00ee87, versionResponse.getAddress()); Assertions.assertEquals(0x1f00ee87, versionResponse.getAddress());
assertEquals(41847, versionResponse.getLot()); Assertions.assertEquals(41847, versionResponse.getLot());
assertEquals(240439, versionResponse.getTid()); Assertions.assertEquals(240439, versionResponse.getTid());
assertEquals(PodProgressStatus.PAIRING_COMPLETED, versionResponse.getPodProgressStatus()); Assertions.assertEquals(PodProgressStatus.PAIRING_COMPLETED, versionResponse.getPodProgressStatus());
assertEquals("2.7.0", versionResponse.getPiVersion().toString()); Assertions.assertEquals("2.7.0", versionResponse.getPiVersion().toString());
assertEquals("2.7.0", versionResponse.getPmVersion().toString()); Assertions.assertEquals("2.7.0", versionResponse.getPmVersion().toString());
assertNull(versionResponse.getRssi()); Assertions.assertNull(versionResponse.getRssi());
assertNull(versionResponse.getGain()); Assertions.assertNull(versionResponse.getGain());
} }
} }

View file

@ -1,35 +1,33 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.response.podinfo; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.response.podinfo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.joda.time.Duration; import org.joda.time.Duration;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.List; import java.util.List;
import info.nightscout.pump.core.utils.ByteUtil; import info.nightscout.pump.core.utils.ByteUtil;
public class PodInfoActiveAlertsTest { class PodInfoActiveAlertsTest {
@Test @Test
public void testNoActiveAlerts() { void testNoActiveAlerts() {
byte[] encodedMessage = ByteUtil.fromHexString("01000000000000000000000000000000000000"); // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/PodInfoTests.swift byte[] encodedMessage = ByteUtil.fromHexString("01000000000000000000000000000000000000"); // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/PodInfoTests.swift
PodInfoActiveAlerts podInfoActiveAlerts = new PodInfoActiveAlerts(encodedMessage); PodInfoActiveAlerts podInfoActiveAlerts = new PodInfoActiveAlerts(encodedMessage);
List<PodInfoActiveAlerts.AlertActivation> alertActivations = podInfoActiveAlerts.getAlertActivations(); List<PodInfoActiveAlerts.AlertActivation> alertActivations = podInfoActiveAlerts.getAlertActivations();
assertEquals(0, alertActivations.size()); Assertions.assertEquals(0, alertActivations.size());
} }
@Test @Test
public void testChangePodAfter3Days() { void testChangePodAfter3Days() {
byte[] encodedMessage = ByteUtil.fromHexString("010000000000000000000000000000000010e1"); // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/PodInfoTests.swift byte[] encodedMessage = ByteUtil.fromHexString("010000000000000000000000000000000010e1"); // from https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/PodInfoTests.swift
PodInfoActiveAlerts podInfoActiveAlerts = new PodInfoActiveAlerts(encodedMessage); PodInfoActiveAlerts podInfoActiveAlerts = new PodInfoActiveAlerts(encodedMessage);
List<PodInfoActiveAlerts.AlertActivation> alertActivations = podInfoActiveAlerts.getAlertActivations(); List<PodInfoActiveAlerts.AlertActivation> alertActivations = podInfoActiveAlerts.getAlertActivations();
assertEquals(1, alertActivations.size()); Assertions.assertEquals(1, alertActivations.size());
PodInfoActiveAlerts.AlertActivation alertActivation = alertActivations.get(0); PodInfoActiveAlerts.AlertActivation alertActivation = alertActivations.get(0);
Duration expectedDuration = Duration.standardHours(72).plus(Duration.standardMinutes(1)); Duration expectedDuration = Duration.standardHours(72).plus(Duration.standardMinutes(1));
assertTrue(expectedDuration.isEqual(alertActivation.getValueAsDuration())); Assertions.assertTrue(expectedDuration.isEqual(alertActivation.getValueAsDuration()));
} }
} }

View file

@ -1,23 +1,21 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.response.podinfo; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.response.podinfo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.joda.time.Duration; import org.joda.time.Duration;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.FaultEventCode; import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.FaultEventCode;
import info.nightscout.pump.core.utils.ByteUtil; import info.nightscout.pump.core.utils.ByteUtil;
public class PodInfoDataLogTest { class PodInfoDataLogTest {
@Test @Test
public void testDecoding() { void testDecoding() {
PodInfoDataLog podInfoDataLog = new PodInfoDataLog(ByteUtil.fromHexString("030100010001043c"), 8); // From https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/PodInfoTests.swift PodInfoDataLog podInfoDataLog = new PodInfoDataLog(ByteUtil.fromHexString("030100010001043c"), 8); // From https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/PodInfoTests.swift
assertEquals(FaultEventCode.FAILED_FLASH_ERASE, podInfoDataLog.getFaultEventCode()); Assertions.assertEquals(FaultEventCode.FAILED_FLASH_ERASE, podInfoDataLog.getFaultEventCode());
assertTrue(Duration.standardMinutes(1).isEqual(podInfoDataLog.getTimeFaultEvent())); Assertions.assertTrue(Duration.standardMinutes(1).isEqual(podInfoDataLog.getTimeFaultEvent()));
assertTrue(Duration.standardMinutes(1).isEqual(podInfoDataLog.getTimeSinceActivation())); Assertions.assertTrue(Duration.standardMinutes(1).isEqual(podInfoDataLog.getTimeSinceActivation()));
assertEquals(4, podInfoDataLog.getDataChunkSize()); Assertions.assertEquals(4, podInfoDataLog.getDataChunkSize());
assertEquals(60, podInfoDataLog.getMaximumNumberOfDwords()); Assertions.assertEquals(60, podInfoDataLog.getMaximumNumberOfDwords());
} }
} }

View file

@ -1,11 +1,7 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.response.podinfo; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.response.podinfo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.joda.time.Duration; import org.joda.time.Duration;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.DeliveryStatus; import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.DeliveryStatus;
@ -14,149 +10,151 @@ import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.Fa
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.PodProgressStatus; import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.PodProgressStatus;
import info.nightscout.pump.core.utils.ByteUtil; import info.nightscout.pump.core.utils.ByteUtil;
// From https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/PodInfoTests.swift /**
public class PodInfoDetailedStatusTest { * @noinspection SpellCheckingInspection
*/ // From https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/PodInfoTests.swift
class PodInfoDetailedStatusTest {
@Test @Test
public void testPodInfoFaultEventNoFaultAlerts() { void testPodInfoFaultEventNoFaultAlerts() {
PodInfoDetailedStatus podInfoDetailedStatus = new PodInfoDetailedStatus(ByteUtil.fromHexString("02080100000a003800000003ff008700000095ff0000")); PodInfoDetailedStatus podInfoDetailedStatus = new PodInfoDetailedStatus(ByteUtil.fromHexString("02080100000a003800000003ff008700000095ff0000"));
assertEquals(PodProgressStatus.ABOVE_FIFTY_UNITS, podInfoDetailedStatus.getPodProgressStatus()); Assertions.assertEquals(PodProgressStatus.ABOVE_FIFTY_UNITS, podInfoDetailedStatus.getPodProgressStatus());
assertEquals(DeliveryStatus.NORMAL, podInfoDetailedStatus.getDeliveryStatus()); Assertions.assertEquals(DeliveryStatus.NORMAL, podInfoDetailedStatus.getDeliveryStatus());
assertEquals(0, podInfoDetailedStatus.getBolusNotDelivered(), 0.000001); Assertions.assertEquals(0, podInfoDetailedStatus.getBolusNotDelivered(), 0.000001);
assertEquals(0x0a, podInfoDetailedStatus.getPodMessageCounter()); Assertions.assertEquals(0x0a, podInfoDetailedStatus.getPodMessageCounter());
assertNull(podInfoDetailedStatus.getFaultEventCode()); Assertions.assertNull(podInfoDetailedStatus.getFaultEventCode());
assertTrue(Duration.ZERO.isEqual(podInfoDetailedStatus.getFaultEventTime())); Assertions.assertTrue(Duration.ZERO.isEqual(podInfoDetailedStatus.getFaultEventTime()));
assertNull(podInfoDetailedStatus.getReservoirLevel()); Assertions.assertNull(podInfoDetailedStatus.getReservoirLevel());
assertTrue(Duration.standardSeconds(8100).isEqual(podInfoDetailedStatus.getTimeActive())); Assertions.assertTrue(Duration.standardSeconds(8100).isEqual(podInfoDetailedStatus.getTimeActive()));
assertEquals(0, podInfoDetailedStatus.getUnacknowledgedAlerts().getRawValue()); Assertions.assertEquals(0, podInfoDetailedStatus.getUnacknowledgedAlerts().getRawValue());
assertFalse(podInfoDetailedStatus.isFaultAccessingTables()); Assertions.assertFalse(podInfoDetailedStatus.isFaultAccessingTables());
ErrorEventInfo errorEventInfo = podInfoDetailedStatus.getErrorEventInfo(); ErrorEventInfo errorEventInfo = podInfoDetailedStatus.getErrorEventInfo();
assertNull(errorEventInfo); Assertions.assertNull(errorEventInfo);
assertNull(podInfoDetailedStatus.getPreviousPodProgressStatus()); Assertions.assertNull(podInfoDetailedStatus.getPreviousPodProgressStatus());
assertEquals(2, podInfoDetailedStatus.getReceiverLowGain()); Assertions.assertEquals(2, podInfoDetailedStatus.getReceiverLowGain());
assertEquals(21, podInfoDetailedStatus.getRadioRSSI()); Assertions.assertEquals(21, podInfoDetailedStatus.getRadioRSSI());
} }
@Test @Test
public void testPodInfoFaultEventDeliveryErrorDuringPriming() { void testPodInfoFaultEventDeliveryErrorDuringPriming() {
PodInfoDetailedStatus podInfoDetailedStatus = new PodInfoDetailedStatus(ByteUtil.fromHexString("020f0000000900345c000103ff0001000005ae056029")); PodInfoDetailedStatus podInfoDetailedStatus = new PodInfoDetailedStatus(ByteUtil.fromHexString("020f0000000900345c000103ff0001000005ae056029"));
assertEquals(PodProgressStatus.INACTIVE, podInfoDetailedStatus.getPodProgressStatus()); Assertions.assertEquals(PodProgressStatus.INACTIVE, podInfoDetailedStatus.getPodProgressStatus());
assertEquals(DeliveryStatus.SUSPENDED, podInfoDetailedStatus.getDeliveryStatus()); Assertions.assertEquals(DeliveryStatus.SUSPENDED, podInfoDetailedStatus.getDeliveryStatus());
assertEquals(0, podInfoDetailedStatus.getBolusNotDelivered(), 0.000001); Assertions.assertEquals(0, podInfoDetailedStatus.getBolusNotDelivered(), 0.000001);
assertEquals(0x09, podInfoDetailedStatus.getPodMessageCounter()); Assertions.assertEquals(0x09, podInfoDetailedStatus.getPodMessageCounter());
assertEquals(FaultEventCode.PRIME_OPEN_COUNT_TOO_LOW, podInfoDetailedStatus.getFaultEventCode()); Assertions.assertEquals(FaultEventCode.PRIME_OPEN_COUNT_TOO_LOW, podInfoDetailedStatus.getFaultEventCode());
assertTrue(Duration.standardSeconds(60).isEqual(podInfoDetailedStatus.getFaultEventTime())); Assertions.assertTrue(Duration.standardSeconds(60).isEqual(podInfoDetailedStatus.getFaultEventTime()));
assertNull(podInfoDetailedStatus.getReservoirLevel()); Assertions.assertNull(podInfoDetailedStatus.getReservoirLevel());
assertTrue(Duration.standardSeconds(60).isEqual(podInfoDetailedStatus.getTimeActive())); Assertions.assertTrue(Duration.standardSeconds(60).isEqual(podInfoDetailedStatus.getTimeActive()));
assertEquals(0, podInfoDetailedStatus.getUnacknowledgedAlerts().getRawValue()); Assertions.assertEquals(0, podInfoDetailedStatus.getUnacknowledgedAlerts().getRawValue());
assertFalse(podInfoDetailedStatus.isFaultAccessingTables()); Assertions.assertFalse(podInfoDetailedStatus.isFaultAccessingTables());
ErrorEventInfo errorEventInfo = podInfoDetailedStatus.getErrorEventInfo(); ErrorEventInfo errorEventInfo = podInfoDetailedStatus.getErrorEventInfo();
assertFalse(errorEventInfo.isInsulinStateTableCorruption()); Assertions.assertFalse(errorEventInfo.isInsulinStateTableCorruption());
assertEquals(0x00, errorEventInfo.getInternalVariable()); Assertions.assertEquals(0x00, errorEventInfo.getInternalVariable());
assertFalse(errorEventInfo.isImmediateBolusInProgress()); Assertions.assertFalse(errorEventInfo.isImmediateBolusInProgress());
assertEquals(PodProgressStatus.PRIMING_COMPLETED, errorEventInfo.getPodProgressStatus()); Assertions.assertEquals(PodProgressStatus.PRIMING_COMPLETED, errorEventInfo.getPodProgressStatus());
assertEquals(PodProgressStatus.PRIMING_COMPLETED, podInfoDetailedStatus.getPreviousPodProgressStatus()); Assertions.assertEquals(PodProgressStatus.PRIMING_COMPLETED, podInfoDetailedStatus.getPreviousPodProgressStatus());
assertEquals(2, podInfoDetailedStatus.getReceiverLowGain()); Assertions.assertEquals(2, podInfoDetailedStatus.getReceiverLowGain());
assertEquals(46, podInfoDetailedStatus.getRadioRSSI()); Assertions.assertEquals(46, podInfoDetailedStatus.getRadioRSSI());
} }
@Test @Test
public void testPodInfoFaultEventErrorShuttingDown() { void testPodInfoFaultEventErrorShuttingDown() {
PodInfoDetailedStatus podInfoDetailedStatus = new PodInfoDetailedStatus(ByteUtil.fromHexString("020d0000000407f28609ff03ff0a0200000823080000")); PodInfoDetailedStatus podInfoDetailedStatus = new PodInfoDetailedStatus(ByteUtil.fromHexString("020d0000000407f28609ff03ff0a0200000823080000"));
assertEquals(PodProgressStatus.FAULT_EVENT_OCCURRED, podInfoDetailedStatus.getPodProgressStatus()); Assertions.assertEquals(PodProgressStatus.FAULT_EVENT_OCCURRED, podInfoDetailedStatus.getPodProgressStatus());
assertEquals(DeliveryStatus.SUSPENDED, podInfoDetailedStatus.getDeliveryStatus()); Assertions.assertEquals(DeliveryStatus.SUSPENDED, podInfoDetailedStatus.getDeliveryStatus());
assertEquals(2034, podInfoDetailedStatus.getTicksDelivered()); Assertions.assertEquals(2034, podInfoDetailedStatus.getTicksDelivered());
assertEquals(101.7, podInfoDetailedStatus.getInsulinDelivered(), 0.000001); Assertions.assertEquals(101.7, podInfoDetailedStatus.getInsulinDelivered(), 0.000001);
assertEquals(0, podInfoDetailedStatus.getBolusNotDelivered(), 0.000001); Assertions.assertEquals(0, podInfoDetailedStatus.getBolusNotDelivered(), 0.000001);
assertEquals(0x04, podInfoDetailedStatus.getPodMessageCounter()); Assertions.assertEquals(0x04, podInfoDetailedStatus.getPodMessageCounter());
assertEquals(FaultEventCode.BASAL_OVER_INFUSION_PULSE, podInfoDetailedStatus.getFaultEventCode()); Assertions.assertEquals(FaultEventCode.BASAL_OVER_INFUSION_PULSE, podInfoDetailedStatus.getFaultEventCode());
assertTrue(Duration.standardMinutes(2559).isEqual(podInfoDetailedStatus.getFaultEventTime())); Assertions.assertTrue(Duration.standardMinutes(2559).isEqual(podInfoDetailedStatus.getFaultEventTime()));
assertNull(podInfoDetailedStatus.getReservoirLevel()); Assertions.assertNull(podInfoDetailedStatus.getReservoirLevel());
assertEquals(0, podInfoDetailedStatus.getUnacknowledgedAlerts().getRawValue()); Assertions.assertEquals(0, podInfoDetailedStatus.getUnacknowledgedAlerts().getRawValue());
assertFalse(podInfoDetailedStatus.isFaultAccessingTables()); Assertions.assertFalse(podInfoDetailedStatus.isFaultAccessingTables());
ErrorEventInfo errorEventInfo = podInfoDetailedStatus.getErrorEventInfo(); ErrorEventInfo errorEventInfo = podInfoDetailedStatus.getErrorEventInfo();
assertFalse(errorEventInfo.isInsulinStateTableCorruption()); Assertions.assertFalse(errorEventInfo.isInsulinStateTableCorruption());
assertEquals(0x00, errorEventInfo.getInternalVariable()); Assertions.assertEquals(0x00, errorEventInfo.getInternalVariable());
assertFalse(errorEventInfo.isImmediateBolusInProgress()); Assertions.assertFalse(errorEventInfo.isImmediateBolusInProgress());
assertEquals(PodProgressStatus.ABOVE_FIFTY_UNITS, errorEventInfo.getPodProgressStatus()); Assertions.assertEquals(PodProgressStatus.ABOVE_FIFTY_UNITS, errorEventInfo.getPodProgressStatus());
assertEquals(PodProgressStatus.ABOVE_FIFTY_UNITS, podInfoDetailedStatus.getPreviousPodProgressStatus()); Assertions.assertEquals(PodProgressStatus.ABOVE_FIFTY_UNITS, podInfoDetailedStatus.getPreviousPodProgressStatus());
assertEquals(0, podInfoDetailedStatus.getReceiverLowGain()); Assertions.assertEquals(0, podInfoDetailedStatus.getReceiverLowGain());
assertEquals(35, podInfoDetailedStatus.getRadioRSSI()); Assertions.assertEquals(35, podInfoDetailedStatus.getRadioRSSI());
} }
@Test @Test
public void testPodInfoFaultEventInsulinNotDelivered() { void testPodInfoFaultEventInsulinNotDelivered() {
PodInfoDetailedStatus podInfoDetailedStatus = new PodInfoDetailedStatus(ByteUtil.fromHexString("020f0000010200ec6a026803ff026b000028a7082023")); PodInfoDetailedStatus podInfoDetailedStatus = new PodInfoDetailedStatus(ByteUtil.fromHexString("020f0000010200ec6a026803ff026b000028a7082023"));
assertEquals(PodProgressStatus.INACTIVE, podInfoDetailedStatus.getPodProgressStatus()); Assertions.assertEquals(PodProgressStatus.INACTIVE, podInfoDetailedStatus.getPodProgressStatus());
assertEquals(DeliveryStatus.SUSPENDED, podInfoDetailedStatus.getDeliveryStatus()); Assertions.assertEquals(DeliveryStatus.SUSPENDED, podInfoDetailedStatus.getDeliveryStatus());
assertEquals(236, podInfoDetailedStatus.getTicksDelivered()); Assertions.assertEquals(236, podInfoDetailedStatus.getTicksDelivered());
assertEquals(11.8, podInfoDetailedStatus.getInsulinDelivered(), 0.000001); Assertions.assertEquals(11.8, podInfoDetailedStatus.getInsulinDelivered(), 0.000001);
assertEquals(0.05, podInfoDetailedStatus.getBolusNotDelivered(), 0.000001); Assertions.assertEquals(0.05, podInfoDetailedStatus.getBolusNotDelivered(), 0.000001);
assertEquals(0x02, podInfoDetailedStatus.getPodMessageCounter()); Assertions.assertEquals(0x02, podInfoDetailedStatus.getPodMessageCounter());
assertEquals(FaultEventCode.OCCLUSION_CHECK_ABOVE_THRESHOLD, podInfoDetailedStatus.getFaultEventCode()); Assertions.assertEquals(FaultEventCode.OCCLUSION_CHECK_ABOVE_THRESHOLD, podInfoDetailedStatus.getFaultEventCode());
assertTrue(Duration.standardMinutes(616).isEqual(podInfoDetailedStatus.getFaultEventTime())); Assertions.assertTrue(Duration.standardMinutes(616).isEqual(podInfoDetailedStatus.getFaultEventTime()));
assertNull(podInfoDetailedStatus.getReservoirLevel()); Assertions.assertNull(podInfoDetailedStatus.getReservoirLevel());
assertEquals(0, podInfoDetailedStatus.getUnacknowledgedAlerts().getRawValue()); Assertions.assertEquals(0, podInfoDetailedStatus.getUnacknowledgedAlerts().getRawValue());
assertFalse(podInfoDetailedStatus.isFaultAccessingTables()); Assertions.assertFalse(podInfoDetailedStatus.isFaultAccessingTables());
ErrorEventInfo errorEventInfo = podInfoDetailedStatus.getErrorEventInfo(); ErrorEventInfo errorEventInfo = podInfoDetailedStatus.getErrorEventInfo();
assertFalse(errorEventInfo.isInsulinStateTableCorruption()); Assertions.assertFalse(errorEventInfo.isInsulinStateTableCorruption());
assertEquals(0x01, errorEventInfo.getInternalVariable()); Assertions.assertEquals(0x01, errorEventInfo.getInternalVariable());
assertFalse(errorEventInfo.isImmediateBolusInProgress()); Assertions.assertFalse(errorEventInfo.isImmediateBolusInProgress());
assertEquals(PodProgressStatus.ABOVE_FIFTY_UNITS, errorEventInfo.getPodProgressStatus()); Assertions.assertEquals(PodProgressStatus.ABOVE_FIFTY_UNITS, errorEventInfo.getPodProgressStatus());
assertEquals(PodProgressStatus.ABOVE_FIFTY_UNITS, podInfoDetailedStatus.getPreviousPodProgressStatus()); Assertions.assertEquals(PodProgressStatus.ABOVE_FIFTY_UNITS, podInfoDetailedStatus.getPreviousPodProgressStatus());
assertEquals(2, podInfoDetailedStatus.getReceiverLowGain()); Assertions.assertEquals(2, podInfoDetailedStatus.getReceiverLowGain());
assertEquals(39, podInfoDetailedStatus.getRadioRSSI()); Assertions.assertEquals(39, podInfoDetailedStatus.getRadioRSSI());
} }
@Test @Test
public void testPodInfoFaultEventMaxBolusNotDelivered() { void testPodInfoFaultEventMaxBolusNotDelivered() {
PodInfoDetailedStatus podInfoDetailedStatus = new PodInfoDetailedStatus(ByteUtil.fromHexString("020f00ffff0200ec6a026803ff026b000028a7082023")); PodInfoDetailedStatus podInfoDetailedStatus = new PodInfoDetailedStatus(ByteUtil.fromHexString("020f00ffff0200ec6a026803ff026b000028a7082023"));
assertEquals(PodProgressStatus.INACTIVE, podInfoDetailedStatus.getPodProgressStatus()); Assertions.assertEquals(PodProgressStatus.INACTIVE, podInfoDetailedStatus.getPodProgressStatus());
assertEquals(DeliveryStatus.SUSPENDED, podInfoDetailedStatus.getDeliveryStatus()); Assertions.assertEquals(DeliveryStatus.SUSPENDED, podInfoDetailedStatus.getDeliveryStatus());
assertEquals(236, podInfoDetailedStatus.getTicksDelivered()); Assertions.assertEquals(236, podInfoDetailedStatus.getTicksDelivered());
assertEquals(11.8, podInfoDetailedStatus.getInsulinDelivered(), 0.000001); Assertions.assertEquals(11.8, podInfoDetailedStatus.getInsulinDelivered(), 0.000001);
assertEquals(3276.75, podInfoDetailedStatus.getBolusNotDelivered(), 0.000001); // Insane and will not happen, but this verifies that we convert it to an unsigned int Assertions.assertEquals(3276.75, podInfoDetailedStatus.getBolusNotDelivered(), 0.000001); // Insane and will not happen, but this verifies that we convert it to an unsigned int
assertEquals(0x02, podInfoDetailedStatus.getPodMessageCounter()); Assertions.assertEquals(0x02, podInfoDetailedStatus.getPodMessageCounter());
assertEquals(FaultEventCode.OCCLUSION_CHECK_ABOVE_THRESHOLD, podInfoDetailedStatus.getFaultEventCode()); Assertions.assertEquals(FaultEventCode.OCCLUSION_CHECK_ABOVE_THRESHOLD, podInfoDetailedStatus.getFaultEventCode());
assertTrue(Duration.standardMinutes(616).isEqual(podInfoDetailedStatus.getFaultEventTime())); Assertions.assertTrue(Duration.standardMinutes(616).isEqual(podInfoDetailedStatus.getFaultEventTime()));
assertNull(podInfoDetailedStatus.getReservoirLevel()); Assertions.assertNull(podInfoDetailedStatus.getReservoirLevel());
assertEquals(0, podInfoDetailedStatus.getUnacknowledgedAlerts().getRawValue()); Assertions.assertEquals(0, podInfoDetailedStatus.getUnacknowledgedAlerts().getRawValue());
assertFalse(podInfoDetailedStatus.isFaultAccessingTables()); Assertions.assertFalse(podInfoDetailedStatus.isFaultAccessingTables());
ErrorEventInfo errorEventInfo = podInfoDetailedStatus.getErrorEventInfo(); ErrorEventInfo errorEventInfo = podInfoDetailedStatus.getErrorEventInfo();
assertFalse(errorEventInfo.isInsulinStateTableCorruption()); Assertions.assertFalse(errorEventInfo.isInsulinStateTableCorruption());
assertEquals(0x01, errorEventInfo.getInternalVariable()); Assertions.assertEquals(0x01, errorEventInfo.getInternalVariable());
assertFalse(errorEventInfo.isImmediateBolusInProgress()); Assertions.assertFalse(errorEventInfo.isImmediateBolusInProgress());
assertEquals(PodProgressStatus.ABOVE_FIFTY_UNITS, errorEventInfo.getPodProgressStatus()); Assertions.assertEquals(PodProgressStatus.ABOVE_FIFTY_UNITS, errorEventInfo.getPodProgressStatus());
assertEquals(PodProgressStatus.ABOVE_FIFTY_UNITS, podInfoDetailedStatus.getPreviousPodProgressStatus()); Assertions.assertEquals(PodProgressStatus.ABOVE_FIFTY_UNITS, podInfoDetailedStatus.getPreviousPodProgressStatus());
assertEquals(2, podInfoDetailedStatus.getReceiverLowGain()); Assertions.assertEquals(2, podInfoDetailedStatus.getReceiverLowGain());
assertEquals(39, podInfoDetailedStatus.getRadioRSSI()); Assertions.assertEquals(39, podInfoDetailedStatus.getRadioRSSI());
} }
@Test @Test
public void testPodInfoFaultEventInsulinStateTableCorruptionFoundDuringErrorLogging() { void testPodInfoFaultEventInsulinStateTableCorruptionFoundDuringErrorLogging() {
PodInfoDetailedStatus podInfoDetailedStatus = new PodInfoDetailedStatus(ByteUtil.fromHexString("020D00000000000012FFFF03FF00160000879A070000")); PodInfoDetailedStatus podInfoDetailedStatus = new PodInfoDetailedStatus(ByteUtil.fromHexString("020D00000000000012FFFF03FF00160000879A070000"));
assertEquals(PodProgressStatus.FAULT_EVENT_OCCURRED, podInfoDetailedStatus.getPodProgressStatus()); Assertions.assertEquals(PodProgressStatus.FAULT_EVENT_OCCURRED, podInfoDetailedStatus.getPodProgressStatus());
assertEquals(DeliveryStatus.SUSPENDED, podInfoDetailedStatus.getDeliveryStatus()); Assertions.assertEquals(DeliveryStatus.SUSPENDED, podInfoDetailedStatus.getDeliveryStatus());
assertEquals(0, podInfoDetailedStatus.getBolusNotDelivered(), 0.000001); Assertions.assertEquals(0, podInfoDetailedStatus.getBolusNotDelivered(), 0.000001);
assertEquals(0x00, podInfoDetailedStatus.getPodMessageCounter()); Assertions.assertEquals(0x00, podInfoDetailedStatus.getPodMessageCounter());
assertEquals(FaultEventCode.RESET_DUE_TO_LVD, podInfoDetailedStatus.getFaultEventCode()); Assertions.assertEquals(FaultEventCode.RESET_DUE_TO_LVD, podInfoDetailedStatus.getFaultEventCode());
assertTrue(Duration.ZERO.isEqual(podInfoDetailedStatus.getFaultEventTime())); Assertions.assertTrue(Duration.ZERO.isEqual(podInfoDetailedStatus.getFaultEventTime()));
assertNull(podInfoDetailedStatus.getReservoirLevel()); Assertions.assertNull(podInfoDetailedStatus.getReservoirLevel());
assertTrue(Duration.standardSeconds(1320).isEqual(podInfoDetailedStatus.getTimeActive())); Assertions.assertTrue(Duration.standardSeconds(1320).isEqual(podInfoDetailedStatus.getTimeActive()));
assertEquals(0, podInfoDetailedStatus.getUnacknowledgedAlerts().getRawValue()); Assertions.assertEquals(0, podInfoDetailedStatus.getUnacknowledgedAlerts().getRawValue());
assertFalse(podInfoDetailedStatus.isFaultAccessingTables()); Assertions.assertFalse(podInfoDetailedStatus.isFaultAccessingTables());
ErrorEventInfo errorEventInfo = podInfoDetailedStatus.getErrorEventInfo(); ErrorEventInfo errorEventInfo = podInfoDetailedStatus.getErrorEventInfo();
assertTrue(errorEventInfo.isInsulinStateTableCorruption()); Assertions.assertTrue(errorEventInfo.isInsulinStateTableCorruption());
assertEquals(0x00, errorEventInfo.getInternalVariable()); Assertions.assertEquals(0x00, errorEventInfo.getInternalVariable());
assertFalse(errorEventInfo.isImmediateBolusInProgress()); Assertions.assertFalse(errorEventInfo.isImmediateBolusInProgress());
assertEquals(PodProgressStatus.INSERTING_CANNULA, errorEventInfo.getPodProgressStatus()); Assertions.assertEquals(PodProgressStatus.INSERTING_CANNULA, errorEventInfo.getPodProgressStatus());
assertEquals(PodProgressStatus.INSERTING_CANNULA, podInfoDetailedStatus.getPreviousPodProgressStatus()); Assertions.assertEquals(PodProgressStatus.INSERTING_CANNULA, podInfoDetailedStatus.getPreviousPodProgressStatus());
assertEquals(2, podInfoDetailedStatus.getReceiverLowGain()); Assertions.assertEquals(2, podInfoDetailedStatus.getReceiverLowGain());
assertEquals(26, podInfoDetailedStatus.getRadioRSSI()); Assertions.assertEquals(26, podInfoDetailedStatus.getRadioRSSI());
} }
} }

View file

@ -1,29 +1,26 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.response.podinfo; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.response.podinfo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.Duration; import org.joda.time.Duration;
import org.junit.Assert; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.FaultEventCode; import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.FaultEventCode;
import info.nightscout.pump.core.utils.ByteUtil; import info.nightscout.pump.core.utils.ByteUtil;
public class PodInfoFaultAndInitializationTimeTest { class PodInfoFaultAndInitializationTimeTest {
@Test @Test
public void testDecoding() { void testDecoding() {
PodInfoFaultAndInitializationTime podInfoFaultAndInitializationTime = new PodInfoFaultAndInitializationTime(ByteUtil.fromHexString("059200010000000000000000091912170e")); // From https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/PodInfoTests.swift PodInfoFaultAndInitializationTime podInfoFaultAndInitializationTime = new PodInfoFaultAndInitializationTime(ByteUtil.fromHexString("059200010000000000000000091912170e")); // From https://github.com/ps2/rileylink_ios/blob/omnipod-testing/OmniKitTests/PodInfoTests.swift
assertEquals(FaultEventCode.BAD_PUMP_REQ_2_STATE, podInfoFaultAndInitializationTime.getFaultEventCode()); Assertions.assertEquals(FaultEventCode.BAD_PUMP_REQ_2_STATE, podInfoFaultAndInitializationTime.getFaultEventCode());
assertTrue(Duration.standardMinutes(1).isEqual(podInfoFaultAndInitializationTime.getTimeFaultEvent())); Assertions.assertTrue(Duration.standardMinutes(1).isEqual(podInfoFaultAndInitializationTime.getTimeFaultEvent()));
DateTime dateTime = podInfoFaultAndInitializationTime.getInitializationTime(); DateTime dateTime = podInfoFaultAndInitializationTime.getInitializationTime();
Assert.assertEquals(2018, dateTime.getYear()); Assertions.assertEquals(2018, dateTime.getYear());
Assert.assertEquals(9, dateTime.getMonthOfYear()); Assertions.assertEquals(9, dateTime.getMonthOfYear());
Assert.assertEquals(25, dateTime.getDayOfMonth()); Assertions.assertEquals(25, dateTime.getDayOfMonth());
Assert.assertEquals(23, dateTime.getHourOfDay()); Assertions.assertEquals(23, dateTime.getHourOfDay());
Assert.assertEquals(14, dateTime.getMinuteOfHour()); Assertions.assertEquals(14, dateTime.getMinuteOfHour());
} }
} }

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.response.podinfo; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.response.podinfo;
/** @noinspection unused*/
public class PodInfoOlderPulseLogTest { public class PodInfoOlderPulseLogTest {
// TODO // TODO
} }

View file

@ -1,16 +1,15 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.response.podinfo; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.response.podinfo;
import static org.junit.Assert.assertEquals; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import info.nightscout.pump.core.utils.ByteUtil; import info.nightscout.pump.core.utils.ByteUtil;
public class PodInfoRecentPulseLogTest { class PodInfoRecentPulseLogTest {
@Test @Test
public void testDecoding() { void testDecoding() {
PodInfoRecentPulseLog podInfoRecentPulseLog = new PodInfoRecentPulseLog(ByteUtil.fromHexString("3d313b004030350045303a00483033004d313a005031310054313f00583038805d302d806030368001313b800c3033801130388014313480193138801c313280213039802431360029313d002c31390031303f0034313900393140003c31390041313e00443137004905723a80087335800d733a801073358015733a80187235801d7338802073338025733a00287235002d723b003072360035703b00383134"), 160); PodInfoRecentPulseLog podInfoRecentPulseLog = new PodInfoRecentPulseLog(ByteUtil.fromHexString("3d313b004030350045303a00483033004d313a005031310054313f00583038805d302d806030368001313b800c3033801130388014313480193138801c313280213039802431360029313d002c31390031303f0034313900393140003c31390041313e00443137004905723a80087335800d733a801073358015733a80187235801d7338802073338025733a00287235002d723b003072360035703b00383134"), 160);
assertEquals(39, podInfoRecentPulseLog.getDwords().size()); Assertions.assertEquals(39, podInfoRecentPulseLog.getDwords().size());
} }
} }

View file

@ -1,54 +0,0 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.response.podinfo;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.PodInfoType;
import info.nightscout.pump.core.utils.ByteUtil;
public class PodInfoResponseTest {
@Test
public void testRawData() {
byte[] encodedData = ByteUtil.fromHexString("0216020d0000000000ab6a038403ff03860000285708030d");
PodInfoResponse podInfoResponse = new PodInfoResponse(encodedData);
assertArrayEquals(encodedData, podInfoResponse.getRawData());
}
@Test
public void testRawDataWithLongerMessage() {
byte[] encodedData = ByteUtil.fromHexString("0216020d0000000000ab6a038403ff03860000285708030d01");
byte[] expected = ByteUtil.fromHexString("0216020d0000000000ab6a038403ff03860000285708030d");
PodInfoResponse podInfoResponse = new PodInfoResponse(encodedData);
assertArrayEquals(expected, podInfoResponse.getRawData());
}
@Test
public void testMessageDecoding() {
PodInfoResponse podInfoResponse = new PodInfoResponse(ByteUtil.fromHexString("0216020d0000000000ab6a038403ff03860000285708030d"));
assertEquals(PodInfoType.DETAILED_STATUS, podInfoResponse.getSubType());
PodInfoDetailedStatus podInfo = (PodInfoDetailedStatus) podInfoResponse.getPodInfo();
assertFalse(podInfo.isFaultAccessingTables());
assertEquals(0x01, podInfo.getErrorEventInfo().getInternalVariable());
}
@Test
public void testInvalidPodInfoTypeMessageDecoding() {
PodInfoResponse podInfoResponse = new PodInfoResponse(ByteUtil.fromHexString("0216020d0000000000ab6a038403ff03860000285708030d"));
assertEquals(PodInfoType.DETAILED_STATUS, podInfoResponse.getSubType());
Assert.assertThrows("Expect throw", ClassCastException.class, () -> {
PodInfoActiveAlerts podInfo = (PodInfoActiveAlerts) podInfoResponse.getPodInfo();
});
}
}

View file

@ -0,0 +1,38 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.communication.message.response.podinfo
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.PodInfoType
import info.nightscout.pump.core.utils.ByteUtil
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
internal class PodInfoResponseTest {
@Test fun testRawData() {
val encodedData = ByteUtil.fromHexString("0216020d0000000000ab6a038403ff03860000285708030d")
val podInfoResponse = PodInfoResponse(encodedData)
Assertions.assertArrayEquals(encodedData, podInfoResponse.rawData)
}
@Test fun testRawDataWithLongerMessage() {
val encodedData = ByteUtil.fromHexString("0216020d0000000000ab6a038403ff03860000285708030d01")
val expected = ByteUtil.fromHexString("0216020d0000000000ab6a038403ff03860000285708030d")
val podInfoResponse = PodInfoResponse(encodedData)
Assertions.assertArrayEquals(expected, podInfoResponse.rawData)
}
@Test fun testMessageDecoding() {
val podInfoResponse = PodInfoResponse(ByteUtil.fromHexString("0216020d0000000000ab6a038403ff03860000285708030d"))
Assertions.assertEquals(PodInfoType.DETAILED_STATUS, podInfoResponse.subType)
val podInfo = podInfoResponse.podInfo as PodInfoDetailedStatus
Assertions.assertFalse(podInfo.isFaultAccessingTables)
Assertions.assertEquals(0x01, podInfo.errorEventInfo.internalVariable.toInt())
}
@Test fun testInvalidPodInfoTypeMessageDecoding() {
val podInfoResponse = PodInfoResponse(ByteUtil.fromHexString("0216020d0000000000ab6a038403ff03860000285708030d"))
Assertions.assertEquals(PodInfoType.DETAILED_STATUS, podInfoResponse.subType)
Assertions.assertThrows(ClassCastException::class.java) {
@Suppress("UNUSED_VARIABLE") val podInfo = podInfoResponse.podInfo as PodInfoActiveAlerts
}
}
}

View file

@ -1,22 +1,20 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition;
import static org.junit.Assert.assertEquals; import org.junit.jupiter.api.Assertions;
import static org.junit.Assert.assertNotEquals;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
public class AlertSetTest { class AlertSetTest {
@Test @Test
public void testEquality() { void testEquality() {
AlertSet set1 = new AlertSet(Arrays.asList(AlertSlot.SLOT0, AlertSlot.SLOT1)); AlertSet set1 = new AlertSet(Arrays.asList(AlertSlot.SLOT0, AlertSlot.SLOT1));
AlertSet set2 = new AlertSet(Arrays.asList(AlertSlot.SLOT0, AlertSlot.SLOT1)); AlertSet set2 = new AlertSet(Arrays.asList(AlertSlot.SLOT0, AlertSlot.SLOT1));
AlertSet set3 = new AlertSet(Collections.singletonList(AlertSlot.SLOT1)); AlertSet set3 = new AlertSet(Collections.singletonList(AlertSlot.SLOT1));
assertEquals(set1, set2); Assertions.assertEquals(set1, set2);
assertNotEquals(set1, set3); Assertions.assertNotEquals(set1, set3);
assertNotEquals(set2, set3); Assertions.assertNotEquals(set2, set3);
} }
} }

View file

@ -1,17 +1,15 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.schedule; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.schedule;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import org.joda.time.Duration; import org.joda.time.Duration;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class BasalScheduleTest { class BasalScheduleTest {
@Test @Test
public void testRateAt() { void testRateAt() {
List<BasalScheduleEntry> entries = new ArrayList<>(); List<BasalScheduleEntry> entries = new ArrayList<>();
entries.add(new BasalScheduleEntry(1.0d, Duration.ZERO)); entries.add(new BasalScheduleEntry(1.0d, Duration.ZERO));
entries.add(new BasalScheduleEntry(2.0d, Duration.standardHours(6))); entries.add(new BasalScheduleEntry(2.0d, Duration.standardHours(6)));
@ -19,20 +17,20 @@ public class BasalScheduleTest {
entries.add(new BasalScheduleEntry(4.0d, Duration.standardHours(20))); entries.add(new BasalScheduleEntry(4.0d, Duration.standardHours(20)));
BasalSchedule schedule = new BasalSchedule(entries); BasalSchedule schedule = new BasalSchedule(entries);
assertEquals(1.0d, schedule.rateAt(Duration.ZERO), 0.00001); Assertions.assertEquals(1.0d, schedule.rateAt(Duration.ZERO), 0.00001);
assertEquals(1.0d, schedule.rateAt(Duration.standardHours(6).minus(Duration.standardSeconds(1))), 0.00001); Assertions.assertEquals(1.0d, schedule.rateAt(Duration.standardHours(6).minus(Duration.standardSeconds(1))), 0.00001);
assertEquals(2.0d, schedule.rateAt(Duration.standardHours(6)), 0.00001); Assertions.assertEquals(2.0d, schedule.rateAt(Duration.standardHours(6)), 0.00001);
assertEquals(2.0d, schedule.rateAt(Duration.standardHours(6).plus(Duration.standardMinutes(30))), 0.00001); Assertions.assertEquals(2.0d, schedule.rateAt(Duration.standardHours(6).plus(Duration.standardMinutes(30))), 0.00001);
assertEquals(2.0d, schedule.rateAt(Duration.standardHours(7).minus(Duration.standardSeconds(1))), 0.00001); Assertions.assertEquals(2.0d, schedule.rateAt(Duration.standardHours(7).minus(Duration.standardSeconds(1))), 0.00001);
assertEquals(3.0d, schedule.rateAt(Duration.standardHours(7)), 0.00001); Assertions.assertEquals(3.0d, schedule.rateAt(Duration.standardHours(7)), 0.00001);
assertEquals(3.0d, schedule.rateAt(Duration.standardHours(19)), 0.00001); Assertions.assertEquals(3.0d, schedule.rateAt(Duration.standardHours(19)), 0.00001);
assertEquals(3.0d, schedule.rateAt(Duration.standardHours(20).minus(Duration.standardSeconds(1))), 0.00001); Assertions.assertEquals(3.0d, schedule.rateAt(Duration.standardHours(20).minus(Duration.standardSeconds(1))), 0.00001);
assertEquals(4.0d, schedule.rateAt(Duration.standardHours(20)), 0.00001); Assertions.assertEquals(4.0d, schedule.rateAt(Duration.standardHours(20)), 0.00001);
assertEquals(4.0d, schedule.rateAt(Duration.standardHours(24).minus(Duration.standardSeconds(1))), 0.00001); Assertions.assertEquals(4.0d, schedule.rateAt(Duration.standardHours(24).minus(Duration.standardSeconds(1))), 0.00001);
} }
@Test @Test
public void testEquals() { void testEquals() {
List<BasalScheduleEntry> entries = new ArrayList<>(); List<BasalScheduleEntry> entries = new ArrayList<>();
entries.add(new BasalScheduleEntry(1.0d, Duration.ZERO)); entries.add(new BasalScheduleEntry(1.0d, Duration.ZERO));
entries.add(new BasalScheduleEntry(2.0d, Duration.standardHours(6))); entries.add(new BasalScheduleEntry(2.0d, Duration.standardHours(6)));
@ -45,13 +43,13 @@ public class BasalScheduleTest {
otherEntries.add(new BasalScheduleEntry(2.0d, Duration.standardHours(6))); otherEntries.add(new BasalScheduleEntry(2.0d, Duration.standardHours(6)));
otherEntries.add(new BasalScheduleEntry(3.0d, Duration.standardHours(7))); otherEntries.add(new BasalScheduleEntry(3.0d, Duration.standardHours(7)));
otherEntries.add(new BasalScheduleEntry(4.0d, Duration.standardHours(20))); otherEntries.add(new BasalScheduleEntry(4.0d, Duration.standardHours(20)));
BasalSchedule otherschedule = new BasalSchedule(otherEntries); BasalSchedule otherSchedule = new BasalSchedule(otherEntries);
assertEquals(schedule, otherschedule); Assertions.assertEquals(schedule, otherSchedule);
} }
@Test @Test
public void testNotEquals() { void testNotEquals() {
List<BasalScheduleEntry> entries = new ArrayList<>(); List<BasalScheduleEntry> entries = new ArrayList<>();
entries.add(new BasalScheduleEntry(1.0d, Duration.ZERO)); entries.add(new BasalScheduleEntry(1.0d, Duration.ZERO));
entries.add(new BasalScheduleEntry(2.0d, Duration.standardHours(6))); entries.add(new BasalScheduleEntry(2.0d, Duration.standardHours(6)));
@ -64,13 +62,13 @@ public class BasalScheduleTest {
otherEntries.add(new BasalScheduleEntry(2.0d, Duration.standardHours(6))); otherEntries.add(new BasalScheduleEntry(2.0d, Duration.standardHours(6)));
otherEntries.add(new BasalScheduleEntry(3.0d, Duration.standardHours(7))); otherEntries.add(new BasalScheduleEntry(3.0d, Duration.standardHours(7)));
otherEntries.add(new BasalScheduleEntry(4.1d, Duration.standardHours(20))); otherEntries.add(new BasalScheduleEntry(4.1d, Duration.standardHours(20)));
BasalSchedule otherschedule = new BasalSchedule(otherEntries); BasalSchedule otherSchedule = new BasalSchedule(otherEntries);
assertNotEquals(schedule, otherschedule); Assertions.assertNotEquals(schedule, otherSchedule);
} }
@Test @Test
public void testNotEquals2() { void testNotEquals2() {
List<BasalScheduleEntry> entries = new ArrayList<>(); List<BasalScheduleEntry> entries = new ArrayList<>();
entries.add(new BasalScheduleEntry(1.0d, Duration.ZERO)); entries.add(new BasalScheduleEntry(1.0d, Duration.ZERO));
entries.add(new BasalScheduleEntry(2.0d, Duration.standardHours(6))); entries.add(new BasalScheduleEntry(2.0d, Duration.standardHours(6)));
@ -82,9 +80,9 @@ public class BasalScheduleTest {
otherEntries.add(new BasalScheduleEntry(1.0d, Duration.ZERO)); otherEntries.add(new BasalScheduleEntry(1.0d, Duration.ZERO));
otherEntries.add(new BasalScheduleEntry(2.0d, Duration.standardHours(6))); otherEntries.add(new BasalScheduleEntry(2.0d, Duration.standardHours(6)));
otherEntries.add(new BasalScheduleEntry(3.0d, Duration.standardHours(7))); otherEntries.add(new BasalScheduleEntry(3.0d, Duration.standardHours(7)));
BasalSchedule otherschedule = new BasalSchedule(otherEntries); BasalSchedule otherSchedule = new BasalSchedule(otherEntries);
assertNotEquals(schedule, otherschedule); Assertions.assertNotEquals(schedule, otherSchedule);
} }
} }

View file

@ -1,52 +1,50 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.util; package info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.DateTimeZone; import org.joda.time.DateTimeZone;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
public class TimeUtilTest { class TimeUtilTest {
@BeforeEach @BeforeEach
public void setUp() { void setUp() {
DateTimeZone.setDefault(DateTimeZone.forID("Europe/Amsterdam")); DateTimeZone.setDefault(DateTimeZone.forID("Europe/Amsterdam"));
} }
@Test @Test
public void testDateTimeToDuration() { void testDateTimeToDuration() {
DateTime dateTime = new DateTime(1991, 8, 13, 23, 5, 1); DateTime dateTime = new DateTime(1991, 8, 13, 23, 5, 1);
assertEquals(83101, TimeUtil.toDuration(dateTime).getStandardSeconds()); Assertions.assertEquals(83101, TimeUtil.toDuration(dateTime).getStandardSeconds());
} }
@Test @Test
public void testDateTimeToDurationAtDstChange() { void testDateTimeToDurationAtDstChange() {
DateTime dateTime = new DateTime(2020, 10, 25, 23, 5, 1); DateTime dateTime = new DateTime(2020, 10, 25, 23, 5, 1);
assertEquals(83101, TimeUtil.toDuration(dateTime).getStandardSeconds()); Assertions.assertEquals(83101, TimeUtil.toDuration(dateTime).getStandardSeconds());
} }
@Test @Test
public void testDateTimeToDurationAtDstReverseChange() { void testDateTimeToDurationAtDstReverseChange() {
DateTime dateTime = new DateTime(2020, 3, 29, 23, 5, 1); DateTime dateTime = new DateTime(2020, 3, 29, 23, 5, 1);
assertEquals(83101, TimeUtil.toDuration(dateTime).getStandardSeconds()); Assertions.assertEquals(83101, TimeUtil.toDuration(dateTime).getStandardSeconds());
} }
@Test @Test
public void testDateTimeInOtherZone() { void testDateTimeInOtherZone() {
DateTime dateTime = new DateTime(2020, 3, 29, 23, 5, 1, DateTimeZone.forID("America/Los_Angeles")); DateTime dateTime = new DateTime(2020, 3, 29, 23, 5, 1, DateTimeZone.forID("America/Los_Angeles"));
assertEquals(83101, TimeUtil.toDuration(dateTime).getStandardSeconds()); Assertions.assertEquals(83101, TimeUtil.toDuration(dateTime).getStandardSeconds());
} }
@Test @Test
public void testDateTimeToDurationWithNullDateTime() { void testDateTimeToDurationWithNullDateTime() {
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> TimeUtil.toDuration(null)); IllegalArgumentException ex = Assertions.assertThrows(IllegalArgumentException.class, () -> TimeUtil.toDuration(null));
assertEquals("dateTime can not be null", ex.getMessage()); Assertions.assertEquals("dateTime can not be null", ex.getMessage());
} }
} }

View file

@ -1,17 +1,17 @@
package info.nightscout.androidaps.plugins.pump.omnipod.eros.manager package info.nightscout.androidaps.plugins.pump.omnipod.eros.manager
import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.FirmwareVersion import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.FirmwareVersion
import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.PodProgressStatus import info.nightscout.androidaps.plugins.pump.omnipod.eros.driver.definition.PodProgressStatus
import info.nightscout.rx.TestAapsSchedulers import info.nightscout.rx.TestAapsSchedulers
import info.nightscout.rx.bus.RxBus import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.sharedtests.TestBase
import org.joda.time.DateTime import org.joda.time.DateTime
import org.joda.time.DateTimeUtils import org.joda.time.DateTimeUtils
import org.joda.time.DateTimeZone import org.joda.time.DateTimeZone
import org.joda.time.Duration import org.joda.time.Duration
import org.junit.Assert
import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.mockito.Mock import org.mockito.Mock
@ -32,8 +32,8 @@ class AapsErosPodStateManagerTest : TestBase() {
0, 0, FirmwareVersion(1, 1, 1), 0, 0, FirmwareVersion(1, 1, 1),
FirmwareVersion(2, 2, 2), timeZone, PodProgressStatus.ABOVE_FIFTY_UNITS FirmwareVersion(2, 2, 2), timeZone, PodProgressStatus.ABOVE_FIFTY_UNITS
) )
Assert.assertEquals(now, podStateManager.time) Assertions.assertEquals(now, podStateManager.time)
Assert.assertEquals( Assertions.assertEquals(
Duration.standardHours(1) Duration.standardHours(1)
.plus(Duration.standardMinutes(2).plus(Duration.standardSeconds(3))), .plus(Duration.standardMinutes(2).plus(Duration.standardSeconds(3))),
podStateManager.scheduleOffset podStateManager.scheduleOffset
@ -56,8 +56,8 @@ class AapsErosPodStateManagerTest : TestBase() {
// The system time zone has been updated, but the pod session state's time zone hasn't // The system time zone has been updated, but the pod session state's time zone hasn't
// So the pods time should not have been changed // So the pods time should not have been changed
Assert.assertEquals(now, podStateManager.time) Assertions.assertEquals(now, podStateManager.time)
Assert.assertEquals( Assertions.assertEquals(
Duration.standardHours(1) Duration.standardHours(1)
.plus(Duration.standardMinutes(2).plus(Duration.standardSeconds(3))), .plus(Duration.standardMinutes(2).plus(Duration.standardSeconds(3))),
podStateManager.scheduleOffset podStateManager.scheduleOffset
@ -81,8 +81,8 @@ class AapsErosPodStateManagerTest : TestBase() {
// Both the system time zone have been updated // Both the system time zone have been updated
// So the pods time should have been changed (to +2 hours) // So the pods time should have been changed (to +2 hours)
Assert.assertEquals(now.withZone(newTimeZone), podStateManager.time) Assertions.assertEquals(now.withZone(newTimeZone), podStateManager.time)
Assert.assertEquals( Assertions.assertEquals(
Duration.standardHours(3) Duration.standardHours(3)
.plus(Duration.standardMinutes(2).plus(Duration.standardSeconds(3))), .plus(Duration.standardMinutes(2).plus(Duration.standardSeconds(3))),
podStateManager.scheduleOffset podStateManager.scheduleOffset