From 3a078c408497ca49c28c0fdfaa00d5fca7d86ee8 Mon Sep 17 00:00:00 2001 From: PoweRGbg Date: Fri, 14 Sep 2018 10:00:00 +0300 Subject: [PATCH] DanaR.comm tests --- .../plugins/PumpDanaR/comm/MsgError.java | 1 + .../plugins/PumpDanaR/comm/MsgHistoryAll.java | 3 + .../comm/MsgInitConnStatusBolus.java | 1 + .../comm/MsgInitConnStatusOption.java | 5 +- .../PumpDanaR/comm/MsgInitConnStatusTime.java | 3 + .../comm/MsgSetExtendedBolusStart.java | 9 ++- .../plugins/PumpDanaR/comm/MsgSetTime.java | 3 + .../comm/MsgSettingBasalProfileAll.java | 23 ++++--- .../comm/MsgStatusBolusExtended.java | 3 +- app/src/test/java/info/AAPSMocker.java | 21 ++++++- .../PumpDanaR/comm/MessageHashTableTest.java | 36 +++++++++++ .../comm/MessageOriginalNamesTest.java | 32 ++++++++++ .../PumpDanaR/comm/MsgBolusProgressTest.java | 59 ++++++++++++++++++ .../PumpDanaR/comm/MsgBolusStartTest.java | 55 ++++++++++++++++ .../comm/MsgBolusStartWithSpeedTest.java | 55 ++++++++++++++++ .../PumpDanaR/comm/MsgBolusStopTest.java | 54 ++++++++++++++++ .../PumpDanaR/comm/MsgCheckValueTest.java | 58 +++++++++++++++++ .../plugins/PumpDanaR/comm/MsgErrorTest.java | 60 ++++++++++++++++++ .../PumpDanaR/comm/MsgHistoryAlarmTest.java | 35 +++++++++++ .../PumpDanaR/comm/MsgHistoryAllDoneTest.java | 54 ++++++++++++++++ .../PumpDanaR/comm/MsgHistoryAllTest.java | 59 ++++++++++++++++++ .../comm/MsgHistoryBasalHourTest.java | 35 +++++++++++ .../PumpDanaR/comm/MsgHistoryBolusTest.java | 35 +++++++++++ .../PumpDanaR/comm/MsgHistoryCarboTest.java | 35 +++++++++++ .../comm/MsgHistoryDailyInsulinTest.java | 35 +++++++++++ .../PumpDanaR/comm/MsgHistoryDoneTest.java | 35 +++++++++++ .../PumpDanaR/comm/MsgHistoryErrorTest.java | 35 +++++++++++ .../PumpDanaR/comm/MsgHistoryGlucoseTest.java | 35 +++++++++++ .../PumpDanaR/comm/MsgHistoryNewDoneTest.java | 35 +++++++++++ .../PumpDanaR/comm/MsgHistoryNewTest.java | 35 +++++++++++ .../PumpDanaR/comm/MsgHistoryRefillTest.java | 35 +++++++++++ .../PumpDanaR/comm/MsgHistorySuspendTest.java | 35 +++++++++++ .../comm/MsgInitConnStatusBasicTest.java | 55 ++++++++++++++++ .../comm/MsgInitConnStatusBolusTest.java | 59 ++++++++++++++++++ .../comm/MsgInitConnStatusOptionTest.java | 61 ++++++++++++++++++ .../comm/MsgInitConnStatusTimeTest.java | 62 +++++++++++++++++++ .../PumpDanaR/comm/MsgPCCommStartTest.java | 44 +++++++++++++ .../PumpDanaR/comm/MsgPCCommStopTest.java | 44 +++++++++++++ .../comm/MsgSetActivateBasalProfileTest.java | 45 ++++++++++++++ .../comm/MsgSetBasalProfileTest.java | 55 ++++++++++++++++ .../PumpDanaR/comm/MsgSetCarbsEntryTest.java | 45 ++++++++++++++ .../comm/MsgSetExtendedBolusStartTest.java | 46 ++++++++++++++ .../comm/MsgSetExtendedBolusStopTest.java | 45 ++++++++++++++ .../comm/MsgSetSingleBasalProfileTest.java | 54 ++++++++++++++++ .../comm/MsgSetTempBasalStartTest.java | 45 ++++++++++++++ .../comm/MsgSetTempBasalStopTest.java | 45 ++++++++++++++ .../PumpDanaR/comm/MsgSetTimeTest.java | 47 ++++++++++++++ .../PumpDanaR/comm/MsgSetUserOptionsTest.java | 45 ++++++++++++++ .../comm/MsgSettingActiveProfileTest.java | 47 ++++++++++++++ .../comm/MsgSettingBasalProfileAllTest.java | 44 +++++++++++++ .../PumpDanaR/comm/MsgSettingBasalTest.java | 49 +++++++++++++++ .../PumpDanaR/comm/MsgSettingGlucoseTest.java | 47 ++++++++++++++ .../comm/MsgSettingMaxValuesTest.java | 47 ++++++++++++++ .../PumpDanaR/comm/MsgSettingMealTest.java | 48 ++++++++++++++ .../comm/MsgSettingProfileRatiosAllTest.java | 48 ++++++++++++++ .../comm/MsgSettingProfileRatiosTest.java | 48 ++++++++++++++ .../comm/MsgSettingPumpTimeTest.java | 60 ++++++++++++++++++ .../comm/MsgSettingShippingInfoTest.java | 48 ++++++++++++++ .../comm/MsgSettingUserOptionsTest.java | 48 ++++++++++++++ .../PumpDanaR/comm/MsgStatusBasicTest.java | 46 ++++++++++++++ .../comm/MsgStatusBolusExtendedTest.java | 57 +++++++++++++++++ .../PumpDanaR/comm/MsgStatusProfileTest.java | 48 ++++++++++++++ .../comm/MsgStatusTempBasalTest.java | 40 ++++++++++++ .../plugins/PumpDanaR/comm/MsgStatusTest.java | 46 ++++++++++++++ .../PumpDanaR/comm/RecordTypesTest.java | 16 +++++ 65 files changed, 2583 insertions(+), 15 deletions(-) create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageHashTableTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageOriginalNamesTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusProgressTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStartTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStartWithSpeedTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusStopTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgCheckValueTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgErrorTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAlarmTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAllDoneTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAllTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryBasalHourTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryBolusTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryCarboTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryDailyInsulinTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryDoneTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryErrorTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryGlucoseTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryNewDoneTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryNewTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryRefillTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistorySuspendTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusBasicTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusBolusTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusOptionTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusTimeTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgPCCommStartTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgPCCommStopTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetActivateBasalProfileTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetBasalProfileTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetCarbsEntryTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetExtendedBolusStartTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetExtendedBolusStopTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetSingleBasalProfileTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTempBasalStartTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTempBasalStopTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTimeTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetUserOptionsTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingActiveProfileTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingBasalProfileAllTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingBasalTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingGlucoseTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingMaxValuesTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingMealTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingProfileRatiosAllTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingProfileRatiosTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingPumpTimeTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingShippingInfoTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingUserOptionsTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusBasicTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusBolusExtendedTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusProfileTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusTempBasalTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/RecordTypesTest.java diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgError.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgError.java index b5d4267203..a8e67a98a0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgError.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgError.java @@ -48,6 +48,7 @@ public class MsgError extends MessageBase { MsgBolusStop.stopped = true; bolusingEvent.status = errorString; MainApp.bus().post(bolusingEvent); + failed=true; } if (L.isEnabled(L.PUMPCOMM)) log.debug("Error detected: " + errorString); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAll.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAll.java index 0bcf32d1e0..0fe64a20f5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAll.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgHistoryAll.java @@ -141,6 +141,9 @@ public class MsgHistoryAll extends MessageBase { strRecordValue = "On"; danaRHistoryRecord.stringRecordValue = strRecordValue; break; + case 17: + failed = true; + break; } MainApp.getDbHelper().createOrUpdate(danaRHistoryRecord); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusBolus.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusBolus.java index 49e00e1bbb..df9447cc45 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusBolus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusBolus.java @@ -26,6 +26,7 @@ public class MsgInitConnStatusBolus extends MessageBase { @Override public void handleMessage(byte[] bytes) { if (bytes.length - 10 > 12) { + failed = true; return; } DanaRPump pump = DanaRPump.getInstance(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusOption.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusOption.java index 8fc7cf032c..f8f82e16d0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusOption.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusOption.java @@ -39,6 +39,8 @@ public class MsgInitConnStatusOption extends MessageBase { DanaRPump.getInstance().password = intFromBuff(bytes, 9, 2) ^ 0x3463; if (L.isEnabled(L.PUMPCOMM)) log.debug("Pump password: " + DanaRPump.getInstance().password); + } else { + failed = true; } if (!DanaRPump.getInstance().isPasswordOK()) { @@ -49,7 +51,8 @@ public class MsgInitConnStatusOption extends MessageBase { } // This is last message of initial sequence - ConfigBuilderPlugin.getPlugin().getActivePump().finishHandshaking(); + if (ConfigBuilderPlugin.getPlugin().getActivePump() != null ) + ConfigBuilderPlugin.getPlugin().getActivePump().finishHandshaking(); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusTime.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusTime.java index 0bee5f84c8..e424c5dbda 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusTime.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgInitConnStatusTime.java @@ -50,7 +50,10 @@ public class MsgInitConnStatusTime extends MessageBase { MainApp.getConfigBuilder().storeSettings("ChangingDanaDriver"); MainApp.bus().post(new EventRefreshGui()); ConfigBuilderPlugin.getCommandQueue().readStatus("PumpDriverChange", null); // force new connection + failed = false; return; + } else { + failed = true; } long time = dateTimeSecFromBuff(bytes, 0); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetExtendedBolusStart.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetExtendedBolusStart.java index faefd79368..745d26f1a0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetExtendedBolusStart.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetExtendedBolusStart.java @@ -22,9 +22,12 @@ public class MsgSetExtendedBolusStart extends MessageBase { // HARDCODED LIMITS if (halfhours < 1) halfhours = 1; if (halfhours > 16) halfhours = 16; - amount = MainApp.getConstraintChecker().applyExtendedBolusConstraints(new Constraint<>(amount)).value(); - - AddParamInt((int) (amount * 100)); + Constraint constrainedAmount = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(amount)); + if (constrainedAmount != null) { + AddParamInt((int) (constrainedAmount.value() * 100)); + } else { + log.debug("constrainedAmount of insulin is null!!"); + } AddParamByte(halfhours); if (L.isEnabled(L.PUMPCOMM)) log.debug("Set extended bolus start: " + (((int) (amount * 100)) / 100d) + "U halfhours: " + (int) halfhours); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTime.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTime.java index 6d33aef8cf..6842344959 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTime.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSetTime.java @@ -26,6 +26,9 @@ public class MsgSetTime extends MessageBase { public void handleMessage(byte[] bytes) { int result = intFromBuff(bytes, 0, 1); + if (result != 1) { + failed = true; + } if (L.isEnabled(L.PUMPCOMM)) log.debug("Result of setting time: " + time + " is " + result); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingBasalProfileAll.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingBasalProfileAll.java index cca35401d9..f231412e06 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingBasalProfileAll.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgSettingBasalProfileAll.java @@ -53,17 +53,26 @@ public class MsgSettingBasalProfileAll extends MessageBase { if (L.isEnabled(L.PUMPCOMM)) { if (pump.basal48Enable) { for (int profile = 0; profile < 4; profile++) { - for (int index = 0; index < 24; index++) { - log.debug("Basal profile " + profile + ": " + String.format("%02d", index) + "h: " + pump.pumpProfiles[profile][index]); + for (int index = 0; index < 48; index++) { + try { + log.debug("Basal profile " + profile + ": " + String.format("%02d", index) + "h: " + pump.pumpProfiles[profile][index]); + } catch (Exception e){ + log.error("Unhandled exception" , e); + } } } } else { for (int profile = 0; profile < 4; profile++) { - for (int index = 0; index < 48; index++) { - log.debug("Basal profile " + profile + ": " + - String.format("%02d", (index / 2)) + - ":" + String.format("%02d", (index % 2) * 30) + " : " + - pump.pumpProfiles[profile][index]); + for (int index = 0; index < 24; index++) { + //this is absurd pump.pumpProfiles[profile][index] returns nullPointerException + try { + log.debug("Basal profile " + profile + ": " + + String.format("%02d", (index / 2)) + + ":" + String.format("%02d", (index % 2) * 30) + " : " + + pump.pumpProfiles[profile][index]); + } catch (Exception e){ + log.error("Unhandled exception" , e); + } } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusBolusExtended.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusBolusExtended.java index 975b67d09a..508b099677 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusBolusExtended.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgStatusBolusExtended.java @@ -5,8 +5,10 @@ import android.support.annotation.NonNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.db.ExtendedBolus; import info.nightscout.androidaps.db.Source; +import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.TreatmentsInterface; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump; @@ -46,7 +48,6 @@ public class MsgStatusBolusExtended extends MessageBase { pump.extendedBolusAbsoluteRate = extendedBolusAbsoluteRate; pump.extendedBolusStart = extendedBolusStart; pump.extendedBolusRemainingMinutes = extendedBolusRemainingMinutes; - updateExtendedBolusInDB(); if (L.isEnabled(L.PUMPCOMM)) { diff --git a/app/src/test/java/info/AAPSMocker.java b/app/src/test/java/info/AAPSMocker.java index 15bab41e2b..81c8b99597 100644 --- a/app/src/test/java/info/AAPSMocker.java +++ b/app/src/test/java/info/AAPSMocker.java @@ -2,6 +2,7 @@ package info; import android.content.Context; import android.content.Intent; +import android.content.res.Resources; import com.squareup.otto.Bus; @@ -25,6 +26,8 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; import info.nightscout.androidaps.plugins.Treatments.TreatmentService; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; +import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin; +import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.queue.CommandQueue; import info.nightscout.utils.SP; @@ -103,6 +106,7 @@ public class AAPSMocker { PowerMockito.mockStatic(MainApp.class); MainApp mainApp = mock(MainApp.class); when(MainApp.instance()).thenReturn(mainApp); + return mainApp; } @@ -135,13 +139,15 @@ public class AAPSMocker { when(L.isEnabled(any())).thenReturn(true); } - public static void mockNSUpload() { + public static void mockNSUpload(){ PowerMockito.mockStatic(NSUpload.class); } public static void mockApplicationContext() { - Context context = mock(Context.class); - when(MainApp.instance().getApplicationContext()).thenReturn(context); + Context mockedContext = mock(Context.class); + Resources mResources = mock(Resources.class); + when(MainApp.instance().getApplicationContext()).thenReturn(mockedContext); + when(mockedContext.getResources()).thenReturn(mResources); } public static DatabaseHelper mockDatabaseHelper() { @@ -167,6 +173,15 @@ public class AAPSMocker { PowerMockito.whenNew(TreatmentService.class).withNoArguments().thenReturn(treatmentService); } + public static DanaRPlugin mockDanaRPlugin() { + PowerMockito.mockStatic(DanaRPlugin.class); + DanaRPlugin danaRPlugin = mock(DanaRPlugin.class); + DanaRKoreanPlugin danaRKoreanPlugin = mock(DanaRKoreanPlugin.class); + when(MainApp.getSpecificPlugin(DanaRPlugin.class)).thenReturn(danaRPlugin); + when(MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).thenReturn(danaRKoreanPlugin); + return danaRPlugin; + } + public static Profile getValidProfile() { try { if (profile == null) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageHashTableTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageHashTableTest.java new file mode 100644 index 0000000000..b345a2b324 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageHashTableTest.java @@ -0,0 +1,36 @@ +package info.nightscout.androidaps.plugins.PumpDanaR.comm; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import info.AAPSMocker; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.Treatments.Treatment; +import info.nightscout.utils.SP; + +import static org.junit.Assert.*; + +/** + * Created by Rumen Georgiev on 8/31/2018. + */ + +@RunWith(PowerMockRunner.class) +@PrepareForTest({MainApp.class, SP.class, L.class}) +public class MessageHashTableTest { + + @Test + public void runTest() { + AAPSMocker.mockMainApp(); + AAPSMocker.mockSP(); + AAPSMocker.mockL(); + MessageHashTable messageHashTable = new MessageHashTable(); + MessageBase testMessage = messageHashTable.findMessage(0x41f2); + assertEquals("CMD_HISTORY_ALL", testMessage.getMessageName()); + + } + + +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageOriginalNamesTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageOriginalNamesTest.java new file mode 100644 index 0000000000..e7130e3984 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MessageOriginalNamesTest.java @@ -0,0 +1,32 @@ +package info.nightscout.androidaps.plugins.PumpDanaR.comm; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import info.AAPSMocker; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.Treatments.Treatment; +import info.nightscout.utils.SP; + +import static org.junit.Assert.*; + +/** + * Created by Rumen Georgiev on 8/28/2018. + */ + +@RunWith(PowerMockRunner.class) +@PrepareForTest({MainApp.class, SP.class, L.class}) +public class MessageOriginalNamesTest { + @Test + public void runTest() { + MessageOriginalNames packet = new MessageOriginalNames(); + String testName = packet.getName(0x41f2); + assertEquals("CMD_HISTORY_ALL", testName); + + } + + +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusProgressTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusProgressTest.java new file mode 100644 index 0000000000..062c176c9b --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/PumpDanaR/comm/MsgBolusProgressTest.java @@ -0,0 +1,59 @@ +package info.nightscout.androidaps.plugins.PumpDanaR.comm; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import info.AAPSMocker; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.logging.L; +import info.nightscout.androidaps.plugins.PumpDanaRS.comm.DanaRS_Packet_Bolus_Set_Extended_Bolus; +import info.nightscout.androidaps.plugins.Treatments.Treatment; +import info.nightscout.utils.SP; + +import static org.junit.Assert.*; + +/** + * Created by Rumen Georgiev on 8/28/2018. + */ + +@RunWith(PowerMockRunner.class) +@PrepareForTest({MainApp.class, SP.class, L.class}) +public class MsgBolusProgressTest { + @Test + public void runTest() { + AAPSMocker.mockMainApp(); + AAPSMocker.mockApplicationContext(); + AAPSMocker.mockSP(); + AAPSMocker.mockL(); + AAPSMocker.mockStrings(); + AAPSMocker.mockBus(); + Treatment t = new Treatment(); + MsgBolusProgress packet = new MsgBolusProgress(3D, t); + + // test message decoding + packet.handleMessage(createArray(34, (byte) 1)); + + int valueRequested = (((byte) 1 << 8) + ((byte) 1 + 0)); + assertEquals(valueRequested, packet.progress,0d); + + } + + byte[] createArray(int length, byte fillWith){ + byte[] ret = new byte[length]; + for(int i = 0; i