diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java index d4a5889a43..9c69e4c7d2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPlugin.java @@ -19,7 +19,6 @@ import javax.inject.Inject; import javax.inject.Singleton; import info.nightscout.androidaps.BuildConfig; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.DetailedBolusInfo; import info.nightscout.androidaps.data.Profile; @@ -70,7 +69,7 @@ import io.reactivex.schedulers.Schedulers; public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaRInterface, ConstraintsInterface { private CompositeDisposable disposable = new CompositeDisposable(); - private final MainApp mainApp; + private final Context context; private final ResourceHelper resourceHelper; private final ConstraintChecker constraintChecker; private final ProfileFunction profileFunction; @@ -102,7 +101,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR public DanaRSPlugin( AAPSLogger aapsLogger, RxBusWrapper rxBus, - MainApp maiApp, + Context context, ResourceHelper resourceHelper, ConstraintChecker constraintChecker, ProfileFunction profileFunction, @@ -120,7 +119,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR .description(R.string.description_pump_dana_rs), aapsLogger, resourceHelper, commandQueue ); - this.mainApp = maiApp; + this.context = context; this.rxBus = rxBus; this.resourceHelper = resourceHelper; this.constraintChecker = constraintChecker; @@ -143,13 +142,13 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR @Override protected void onStart() { - Intent intent = new Intent(mainApp, DanaRSService.class); - mainApp.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); + Intent intent = new Intent(context, DanaRSService.class); + context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); disposable.add(rxBus .toObservable(EventAppExit.class) .observeOn(Schedulers.io()) - .subscribe(event -> mainApp.unbindService(mConnection), exception -> FabricPrivacy.getInstance().logException(exception)) + .subscribe(event -> context.unbindService(mConnection), exception -> FabricPrivacy.getInstance().logException(exception)) ); disposable.add(rxBus .toObservable(EventDanaRSDeviceChange.class) @@ -162,7 +161,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR @Override protected void onStop() { - mainApp.unbindService(mConnection); + context.unbindService(mConnection); disposable.clear(); super.onStop(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.kt index 8bd59b3424..9705c53669 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Delivery_Rate_Display.kt @@ -28,7 +28,7 @@ class DanaRS_Packet_Notify_Delivery_Rate_Display( danaRSPlugin.bolusProgressLastTimeStamp = System.currentTimeMillis() danaRSPlugin.bolusingTreatment.insulin = deliveredInsulin val bolusingEvent = EventOverviewBolusProgress - bolusingEvent.status = String.format(resourceHelper.gs(R.string.bolusdelivering), deliveredInsulin) + bolusingEvent.status = resourceHelper.gs(R.string.bolusdelivering, deliveredInsulin) bolusingEvent.t = danaRSPlugin.bolusingTreatment bolusingEvent.percent = min((deliveredInsulin / danaRSPlugin.bolusAmountToBeDelivered * 100).toInt(), 100) failed = bolusingEvent.percent < 100 diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.kt b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.kt index 47afe018e6..ad5fdbdef6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_Missed_Bolus_Alarm.kt @@ -32,7 +32,7 @@ class DanaRS_Packet_Notify_Missed_Bolus_Alarm( dataSize = 1 endMin = byteArrayToInt(getBytes(data, dataIndex, dataSize)) if (endMin == 1 && endMin == endHour && startHour == endHour && startHour == startMin) failed = true - else failed = true + else failed = false aapsLogger.debug(LTag.PUMPCOMM, "Start hour: $startHour") aapsLogger.debug(LTag.PUMPCOMM, "Start min: $startMin") aapsLogger.debug(LTag.PUMPCOMM, "End hour: $endHour") diff --git a/app/src/test/java/info/AAPSMocker.java b/app/src/test/java/info/AAPSMocker.java index 0a11093683..544473dbaa 100644 --- a/app/src/test/java/info/AAPSMocker.java +++ b/app/src/test/java/info/AAPSMocker.java @@ -61,13 +61,11 @@ public class AAPSMocker { when(MainApp.gs(R.string.novalidbasalrate)).thenReturn("No valid basal rate read from pump"); when(MainApp.gs(R.string.autosensdisabledinpreferences)).thenReturn("Autosens disabled in preferences"); when(MainApp.gs(R.string.smbdisabledinpreferences)).thenReturn("SMB disabled in preferences"); - when(MainApp.gs(R.string.limitingbasalratio)).thenReturn("Limiting basal rate to %.2f U/h because of %s"); when(MainApp.gs(R.string.pumplimit)).thenReturn("pump limit"); when(MainApp.gs(R.string.itmustbepositivevalue)).thenReturn("it must be positive value"); when(MainApp.gs(R.string.maxvalueinpreferences)).thenReturn("max value in preferences"); when(MainApp.gs(R.string.maxbasalmultiplier)).thenReturn("max basal multiplier"); when(MainApp.gs(R.string.maxdailybasalmultiplier)).thenReturn("max daily basal multiplier"); - when(MainApp.gs(R.string.limitingpercentrate)).thenReturn("Limiting percent rate to %d%% because of %s"); when(MainApp.gs(R.string.pumplimit)).thenReturn("pump limit"); when(MainApp.gs(R.string.limitingbolus)).thenReturn("Limiting bolus to %.1f U because of %s"); when(MainApp.gs(R.string.hardlimit)).thenReturn("hard limit"); diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.java deleted file mode 100644 index 269a6a0304..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.java +++ /dev/null @@ -1,74 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.danaRS; - -import android.content.Context; - -import org.junit.Before; -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.Constants; -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.interfaces.Constraint; -import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; -import info.nightscout.androidaps.utils.SP; -import info.nightscout.androidaps.utils.ToastUtils; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.when; - -/** - * Created by mike on 23.03.2018. - */ - -@RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class, ConfigBuilderPlugin.class, ToastUtils.class, Context.class, SP.class}) -public class DanaRSPluginTest { - - DanaRSPlugin danaRSPlugin; - - @Test - public void basalRateShouldBeLimited() throws Exception { - danaRSPlugin.setPluginEnabled(PluginType.PUMP, true); - danaRSPlugin.setPluginEnabled(PluginType.PUMP, true); - DanaRPump.getInstance().maxBasal = 0.8d; - - Constraint c = new Constraint<>(Constants.REALLYHIGHBASALRATE); - danaRSPlugin.applyBasalConstraints(c, AAPSMocker.getValidProfile()); - assertEquals(Double.valueOf(0.8d), c.value()); - assertEquals("DanaRS: Limiting basal rate to 0.80 U/h because of pump limit", c.getReasons()); - assertEquals("DanaRS: Limiting basal rate to 0.80 U/h because of pump limit", c.getMostLimitedReasons()); - } - - @Test - public void percentBasalRateShouldBeLimited() throws Exception { - danaRSPlugin.setPluginEnabled(PluginType.PUMP, true); - danaRSPlugin.setPluginEnabled(PluginType.PUMP, true); - DanaRPump.getInstance().maxBasal = 0.8d; - - Constraint c = new Constraint<>(Constants.REALLYHIGHPERCENTBASALRATE); - danaRSPlugin.applyBasalPercentConstraints(c, AAPSMocker.getValidProfile()); - assertEquals((Integer) 200, c.value()); - assertEquals("DanaRS: Limiting percent rate to 200% because of pump limit", c.getReasons()); - assertEquals("DanaRS: Limiting percent rate to 200% because of pump limit", c.getMostLimitedReasons()); - } - - @Before - public void prepareMocks() throws Exception { - AAPSMocker.mockMainApp(); - AAPSMocker.mockConfigBuilder(); - AAPSMocker.mockStrings(); - AAPSMocker.mockApplicationContext(); - AAPSMocker.mockSP(); - AAPSMocker.mockCommandQueue(); - - when(SP.getString(R.string.key_danars_address, "")).thenReturn(""); - - danaRSPlugin = DanaRSPlugin.getPlugin(); - } -} diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.kt new file mode 100644 index 0000000000..8fab2d46bb --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/DanaRSPluginTest.kt @@ -0,0 +1,79 @@ +package info.nightscout.androidaps.plugins.pump.danaRS + +import android.content.Context +import info.AAPSMocker +import info.nightscout.androidaps.Constants +import info.nightscout.androidaps.MainApp +import info.nightscout.androidaps.R +import info.nightscout.androidaps.interfaces.CommandQueueProvider +import info.nightscout.androidaps.interfaces.Constraint +import info.nightscout.androidaps.interfaces.PluginType +import info.nightscout.androidaps.logging.L +import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction +import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSTestBase +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin +import info.nightscout.androidaps.utils.SP +import info.nightscout.androidaps.utils.resources.ResourceHelper +import org.junit.Assert +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.ArgumentMatchers.eq +import org.mockito.Mock +import org.mockito.Mockito +import org.powermock.core.classloader.annotations.PrepareForTest +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +@PrepareForTest(ConstraintChecker::class, RxBusWrapper::class, L::class, SP::class, MainApp::class) +class DanaRSPluginTest : DanaRSTestBase() { + + @Mock lateinit var context: Context + @Mock lateinit var resourceHelper: ResourceHelper + @Mock lateinit var constraintChecker: ConstraintChecker + @Mock lateinit var profileFunction: ProfileFunction + @Mock lateinit var treatmentsPlugin: TreatmentsPlugin + @Mock lateinit var commandQueue: CommandQueueProvider + private lateinit var danaRSPlugin: DanaRSPlugin + lateinit var rxBus: RxBusWrapper + + @Test + fun basalRateShouldBeLimited() { + danaRSPlugin.setPluginEnabled(PluginType.PUMP, true) + danaRSPlugin.setPluginEnabled(PluginType.PUMP, true) + danaRPump.maxBasal = 0.8 + val c = Constraint(Constants.REALLYHIGHBASALRATE) + danaRSPlugin.applyBasalConstraints(c, AAPSMocker.getValidProfile()) + Assert.assertEquals(java.lang.Double.valueOf(0.8), c.value(), 0.0001) + Assert.assertEquals("DanaRS: limitingbasalratio", c.reasons) + Assert.assertEquals("DanaRS: limitingbasalratio", c.mostLimitedReasons) + } + + @Test + fun percentBasalRateShouldBeLimited() { + danaRSPlugin.setPluginEnabled(PluginType.PUMP, true) + danaRSPlugin.setPluginEnabled(PluginType.PUMP, true) + danaRPump.maxBasal = 0.8 + val c = Constraint(Constants.REALLYHIGHPERCENTBASALRATE) + danaRSPlugin.applyBasalPercentConstraints(c, AAPSMocker.getValidProfile()) + Assert.assertEquals(200, c.value()) + Assert.assertEquals("DanaRS: limitingpercentrate", c.reasons) + Assert.assertEquals("DanaRS: limitingpercentrate", c.mostLimitedReasons) + } + + @Before + fun prepareMocks() { + AAPSMocker.mockMainApp() // TODO remove + AAPSMocker.mockSP() + AAPSMocker.mockL() + AAPSMocker.mockStrings() + Mockito.`when`(sp.getString(R.string.key_danars_address, "")).thenReturn("") + Mockito.`when`(resourceHelper.gs(eq(R.string.limitingbasalratio), anyObject(), anyObject())).thenReturn("limitingbasalratio") + Mockito.`when`(resourceHelper.gs(eq(R.string.limitingpercentrate), anyObject(), anyObject())).thenReturn("limitingpercentrate") + + rxBus = RxBusWrapper() + danaRSPlugin = DanaRSPlugin(aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt new file mode 100644 index 0000000000..0dcc525ef4 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest.kt @@ -0,0 +1,53 @@ +package info.nightscout.androidaps.plugins.pump.danaRS.comm + +import android.content.Context +import info.nightscout.androidaps.interfaces.CommandQueueProvider +import info.nightscout.androidaps.interfaces.Constraint +import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker +import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction +import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin +import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin +import info.nightscout.androidaps.utils.resources.ResourceHelper +import org.junit.Assert +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.Mockito +import org.powermock.core.classloader.annotations.PrepareForTest +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +@PrepareForTest(ConstraintChecker::class) +class DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest : DanaRSTestBase() { + + @Mock lateinit var resourceHelper: ResourceHelper + @Mock lateinit var profileFunction: ProfileFunction + @Mock lateinit var treatmentsPlugin: TreatmentsPlugin + @Mock lateinit var constraintChecker: ConstraintChecker + @Mock lateinit var commandQueue: CommandQueueProvider + @Mock lateinit var rxBus: RxBusWrapper + @Mock lateinit var context: Context + private lateinit var danaRSPlugin: DanaRSPlugin + + @Test fun runTest() { + val packet = DanaRS_Packet_Bolus_Set_Step_Bolus_Start(aapsLogger, danaRSPlugin, constraintChecker) + // test params + val testparams = packet.requestParams + Assert.assertEquals(0.toByte(), testparams[0]) + Assert.assertEquals(0.toByte(), testparams[2]) + // test message decoding + packet.handleMessage(byteArrayOf(0.toByte(), 0.toByte(), 0.toByte())) + Assert.assertEquals(false, packet.failed) + packet.handleMessage(byteArrayOf(1.toByte(), 1.toByte(), 1.toByte(), 1.toByte(), 1.toByte(), 1.toByte(), 1.toByte(), 1.toByte())) + Assert.assertEquals(true, packet.failed) + Assert.assertEquals("BOLUS__SET_STEP_BOLUS_START", packet.friendlyName) + } + + @Before + fun mock() { + danaRSPlugin = DanaRSPlugin(aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump) + Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0)) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BasalTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BasalTest.java deleted file mode 100644 index 32fe887b64..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BasalTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.danaRS.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.utils.SP; - -import static org.junit.Assert.assertEquals; - -/** - * Created by Rumen on 09.08.2018. - */ - -@RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class, SP.class, L.class}) -public class DanaRS_Packet_History_BasalTest { - - @Test - public void runTest() { - AAPSMocker.mockMainApp(); - AAPSMocker.mockApplicationContext(); - AAPSMocker.mockSP(); - AAPSMocker.mockL(); - DanaRS_Packet_History_Basal packet = new DanaRS_Packet_History_Basal(System.currentTimeMillis()); - - assertEquals("REVIEW__BASAL", packet.getFriendlyName()); - } - -} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BasalTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BasalTest.kt new file mode 100644 index 0000000000..702f297186 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BasalTest.kt @@ -0,0 +1,21 @@ +package info.nightscout.androidaps.plugins.pump.danaRS.comm + +import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.powermock.core.classloader.annotations.PrepareForTest +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +@PrepareForTest() +class DanaRS_Packet_History_BasalTest : DanaRSTestBase() { + + @Mock lateinit var rxBus: RxBusWrapper + + @Test fun runTest() { + val packet = DanaRS_Packet_History_Basal(aapsLogger, rxBus, System.currentTimeMillis()) + Assert.assertEquals("REVIEW__BASAL", packet.friendlyName) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_GlucoseTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_GlucoseTest.java deleted file mode 100644 index 3534cc4828..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_GlucoseTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.danaRS.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.utils.SP; - -import static org.junit.Assert.assertEquals; - -/** - * Created by Rumen on 09.08.2018. - */ - -@RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class, SP.class, L.class}) -public class DanaRS_Packet_History_Blood_GlucoseTest { - - @Test - public void runTest() { - AAPSMocker.mockMainApp(); - AAPSMocker.mockApplicationContext(); - AAPSMocker.mockSP(); - AAPSMocker.mockL(); - DanaRS_Packet_History_Blood_Glucose packet = new DanaRS_Packet_History_Blood_Glucose(System.currentTimeMillis()); - - assertEquals("REVIEW__BLOOD_GLUCOSE", packet.getFriendlyName()); - } - -} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_GlucoseTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_GlucoseTest.kt new file mode 100644 index 0000000000..8cdb489db3 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_Blood_GlucoseTest.kt @@ -0,0 +1,21 @@ +package info.nightscout.androidaps.plugins.pump.danaRS.comm + +import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.powermock.core.classloader.annotations.PrepareForTest +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +@PrepareForTest() +class DanaRS_Packet_History_Blood_GlucoseTest : DanaRSTestBase() { + + @Mock lateinit var rxBus: RxBusWrapper + + @Test fun runTest() { + val packet = DanaRS_Packet_History_Blood_Glucose(aapsLogger, rxBus, System.currentTimeMillis()) + Assert.assertEquals("REVIEW__BLOOD_GLUCOSE", packet.friendlyName) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BolusTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BolusTest.java deleted file mode 100644 index 856b43a589..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BolusTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.danaRS.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.utils.SP; - -import static org.junit.Assert.assertEquals; - -/** - * Created by Rumen Georgiev on 8/9/2018. - */ - -@RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class, SP.class, L.class}) -public class DanaRS_Packet_History_BolusTest { - - @Test - public void runTest() { - AAPSMocker.mockMainApp(); - AAPSMocker.mockApplicationContext(); - AAPSMocker.mockSP(); - AAPSMocker.mockL(); - DanaRS_Packet_History_Bolus packet = new DanaRS_Packet_History_Bolus(System.currentTimeMillis()); - - assertEquals("REVIEW__BOLUS", packet.getFriendlyName()); - } - -} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BolusTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BolusTest.kt new file mode 100644 index 0000000000..e31c42207e --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_BolusTest.kt @@ -0,0 +1,21 @@ +package info.nightscout.androidaps.plugins.pump.danaRS.comm + +import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.powermock.core.classloader.annotations.PrepareForTest +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +@PrepareForTest() +class DanaRS_Packet_History_BolusTest : DanaRSTestBase() { + + @Mock lateinit var rxBus: RxBusWrapper + + @Test fun runTest() { + val packet = DanaRS_Packet_History_Bolus(aapsLogger, rxBus, System.currentTimeMillis()) + Assert.assertEquals("REVIEW__BOLUS", packet.friendlyName) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_CarbohydrateTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_CarbohydrateTest.java deleted file mode 100644 index 876315389d..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_CarbohydrateTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.danaRS.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.utils.SP; - -import static org.junit.Assert.assertEquals; - -/** - * Created by Rumen Georgiev on 8/9/2018. - */ - -@RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class, SP.class, L.class}) -public class DanaRS_Packet_History_CarbohydrateTest { - - @Test - public void runTest() { - AAPSMocker.mockMainApp(); - AAPSMocker.mockApplicationContext(); - AAPSMocker.mockSP(); - AAPSMocker.mockL(); - DanaRS_Packet_History_Carbohydrate packet = new DanaRS_Packet_History_Carbohydrate(System.currentTimeMillis()); - - assertEquals("REVIEW__CARBOHYDRATE", packet.getFriendlyName()); - } - -} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_CarbohydrateTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_CarbohydrateTest.kt new file mode 100644 index 0000000000..2504be6824 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_CarbohydrateTest.kt @@ -0,0 +1,21 @@ +package info.nightscout.androidaps.plugins.pump.danaRS.comm + +import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.powermock.core.classloader.annotations.PrepareForTest +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +@PrepareForTest() +class DanaRS_Packet_History_CarbohydrateTest : DanaRSTestBase() { + + @Mock lateinit var rxBus: RxBusWrapper + + @Test fun runTest() { + val packet = DanaRS_Packet_History_Carbohydrate(aapsLogger, rxBus, System.currentTimeMillis()) + Assert.assertEquals("REVIEW__CARBOHYDRATE", packet.friendlyName) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_DailyTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_DailyTest.java deleted file mode 100644 index 847563e2dd..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_DailyTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.danaRS.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.utils.SP; - -import static org.junit.Assert.assertEquals; - -/** - * Created by Rumen Georgiev on 8/9/2018. - */ - -@RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class, SP.class, L.class}) -public class DanaRS_Packet_History_DailyTest { - - @Test - public void runTest() { - AAPSMocker.mockMainApp(); - AAPSMocker.mockApplicationContext(); - AAPSMocker.mockSP(); - AAPSMocker.mockL(); - DanaRS_Packet_History_Daily packet = new DanaRS_Packet_History_Daily(System.currentTimeMillis()); - - assertEquals("REVIEW__DAILY", packet.getFriendlyName()); - } - -} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_DailyTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_DailyTest.kt new file mode 100644 index 0000000000..2c6e047462 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_DailyTest.kt @@ -0,0 +1,21 @@ +package info.nightscout.androidaps.plugins.pump.danaRS.comm + +import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.powermock.core.classloader.annotations.PrepareForTest +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +@PrepareForTest() +class DanaRS_Packet_History_DailyTest : DanaRSTestBase() { + + @Mock lateinit var rxBus: RxBusWrapper + + @Test fun runTest() { + val packet = DanaRS_Packet_History_Daily(aapsLogger, rxBus, System.currentTimeMillis()) + Assert.assertEquals("REVIEW__DAILY", packet.friendlyName) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_PrimeTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_PrimeTest.java deleted file mode 100644 index db5e201b74..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_PrimeTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.danaRS.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.utils.SP; - -import static org.junit.Assert.assertEquals; - -/** - * Created by Rumen Georgiev on 8/9/2018. - */ - -@RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class, SP.class, L.class}) -public class DanaRS_Packet_History_PrimeTest { - - @Test - public void runTest() { - AAPSMocker.mockMainApp(); - AAPSMocker.mockApplicationContext(); - AAPSMocker.mockSP(); - AAPSMocker.mockL(); - DanaRS_Packet_History_Prime packet = new DanaRS_Packet_History_Prime(System.currentTimeMillis()); - - assertEquals("REVIEW__PRIME", packet.getFriendlyName()); - } - -} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_PrimeTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_PrimeTest.kt new file mode 100644 index 0000000000..1d15c66a40 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_PrimeTest.kt @@ -0,0 +1,21 @@ +package info.nightscout.androidaps.plugins.pump.danaRS.comm + +import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.powermock.core.classloader.annotations.PrepareForTest +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +@PrepareForTest() +class DanaRS_Packet_History_PrimeTest : DanaRSTestBase() { + + @Mock lateinit var rxBus: RxBusWrapper + + @Test fun runTest() { + val packet = DanaRS_Packet_History_Prime(aapsLogger, rxBus, System.currentTimeMillis()) + Assert.assertEquals("REVIEW__PRIME", packet.friendlyName) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_RefillTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_RefillTest.java deleted file mode 100644 index 7faa893bcf..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_RefillTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.danaRS.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.utils.SP; - -import static org.junit.Assert.assertEquals; - -/** - * Created by Rumen Georgiev on 8/9/2018. - */ - -@RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class, SP.class, L.class}) -public class DanaRS_Packet_History_RefillTest { - - @Test - public void runTest() { - AAPSMocker.mockMainApp(); - AAPSMocker.mockApplicationContext(); - AAPSMocker.mockSP(); - AAPSMocker.mockL(); - DanaRS_Packet_History_Refill packet = new DanaRS_Packet_History_Refill(System.currentTimeMillis()); - - assertEquals("REVIEW__REFILL", packet.getFriendlyName()); - } - -} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_RefillTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_RefillTest.kt new file mode 100644 index 0000000000..47e26cea25 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_RefillTest.kt @@ -0,0 +1,21 @@ +package info.nightscout.androidaps.plugins.pump.danaRS.comm + +import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.powermock.core.classloader.annotations.PrepareForTest +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +@PrepareForTest() +class DanaRS_Packet_History_RefillTest : DanaRSTestBase() { + + @Mock lateinit var rxBus: RxBusWrapper + + @Test fun runTest() { + val packet = DanaRS_Packet_History_Refill(aapsLogger, rxBus, System.currentTimeMillis()) + Assert.assertEquals("REVIEW__REFILL", packet.friendlyName) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_SuspendTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_SuspendTest.java deleted file mode 100644 index d8f51ffb88..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_SuspendTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.danaRS.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.utils.SP; - -import static org.junit.Assert.assertEquals; - -/** - * Created by Rumen Georgiev on 8/9/2018. - */ - -@RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class, SP.class, L.class}) -public class DanaRS_Packet_History_SuspendTest { - - @Test - public void runTest() { - AAPSMocker.mockMainApp(); - AAPSMocker.mockApplicationContext(); - AAPSMocker.mockSP(); - AAPSMocker.mockL(); - DanaRS_Packet_History_Suspend packet = new DanaRS_Packet_History_Suspend(System.currentTimeMillis()); - - assertEquals("REVIEW__SUSPEND", packet.getFriendlyName()); - } - -} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_SuspendTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_SuspendTest.kt new file mode 100644 index 0000000000..cc0157be55 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_SuspendTest.kt @@ -0,0 +1,21 @@ +package info.nightscout.androidaps.plugins.pump.danaRS.comm + +import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.powermock.core.classloader.annotations.PrepareForTest +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +@PrepareForTest() +class DanaRS_Packet_History_SuspendTest : DanaRSTestBase() { + + @Mock lateinit var rxBus: RxBusWrapper + + @Test fun runTest() { + val packet = DanaRS_Packet_History_Suspend(aapsLogger, rxBus, System.currentTimeMillis()) + Assert.assertEquals("REVIEW__SUSPEND", packet.friendlyName) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_TemporaryTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_TemporaryTest.java deleted file mode 100644 index 87fedbdb96..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_TemporaryTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.danaRS.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.utils.SP; - -import static org.junit.Assert.assertEquals; - -/** - * Created by Rumen Georgiev on 8/9/2018. - */ - -@RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class, SP.class, L.class}) -public class DanaRS_Packet_History_TemporaryTest { - - @Test - public void runTest() { - AAPSMocker.mockMainApp(); - AAPSMocker.mockApplicationContext(); - AAPSMocker.mockSP(); - AAPSMocker.mockL(); - DanaRS_Packet_History_Temporary packet = new DanaRS_Packet_History_Temporary(System.currentTimeMillis()); - - assertEquals("REVIEW__TEMPORARY", packet.getFriendlyName()); - } - -} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_TemporaryTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_TemporaryTest.kt new file mode 100644 index 0000000000..bfdac8cc05 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_History_TemporaryTest.kt @@ -0,0 +1,21 @@ +package info.nightscout.androidaps.plugins.pump.danaRS.comm + +import info.nightscout.androidaps.plugins.bus.RxBusWrapper +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.powermock.core.classloader.annotations.PrepareForTest +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +@PrepareForTest() +class DanaRS_Packet_History_TemporaryTest : DanaRSTestBase() { + + @Mock lateinit var rxBus: RxBusWrapper + + @Test fun runTest() { + val packet = DanaRS_Packet_History_Temporary(aapsLogger, rxBus, System.currentTimeMillis()) + Assert.assertEquals("REVIEW__TEMPORARY", packet.friendlyName) + } +} \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_AlarmTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_AlarmTest.java deleted file mode 100644 index 079eb7e752..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/danaRS/comm/DanaRS_Packet_Notify_AlarmTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.danaRS.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.general.nsclient.NSUpload; -import info.nightscout.androidaps.utils.SP; - -import static org.junit.Assert.assertEquals; - -/** - * Created by Rumen Georgiev on 8/9/2018. - */ - - -@RunWith(PowerMockRunner.class) -@PrepareForTest({MainApp.class, SP.class, L.class, NSUpload.class}) -public class DanaRS_Packet_Notify_AlarmTest { - - @Test - public void runTest() { - AAPSMocker.mockMainApp(); - AAPSMocker.mockApplicationContext(); - AAPSMocker.mockSP(); - AAPSMocker.mockL(); - AAPSMocker.mockNSUpload(); - DanaRS_Packet_Notify_Alarm packet = new DanaRS_Packet_Notify_Alarm(); - - // test params - assertEquals(null, packet.getRequestParams()); - - // test message decoding - // handlemessage testing fails on non-eror byte because of NSUpload not properly mocked - packet.handleMessage(createArray(17, (byte) 0x01)); - assertEquals(false, packet.failed); - // no error - packet.handleMessage(createArray(17, (byte) 0)); - assertEquals(true, packet.failed); - - assertEquals("NOTIFY__ALARM", packet.getFriendlyName()); - } - - byte[] createArray(int length, byte fillWith){ - byte[] ret = new byte[length]; - for(int i = 0; i