DanaRS tests

This commit is contained in:
Milos Kozak 2020-03-01 22:05:28 +01:00
parent 40aa3cc60e
commit 09176a1b9e
40 changed files with 547 additions and 866 deletions

View file

@ -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();

View file

@ -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

View file

@ -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")

View file

@ -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");

View file

@ -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<Double> 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<Integer> 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();
}
}

View file

@ -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)
}
}

View file

@ -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))
}
}

View file

@ -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());
}
}

View file

@ -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)
}
}

View file

@ -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());
}
}

View file

@ -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)
}
}

View file

@ -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());
}
}

View file

@ -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)
}
}

View file

@ -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());
}
}

View file

@ -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)
}
}

View file

@ -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());
}
}

View file

@ -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)
}
}

View file

@ -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());
}
}

View file

@ -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)
}
}

View file

@ -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());
}
}

View file

@ -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)
}
}

View file

@ -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());
}
}

View file

@ -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)
}
}

View file

@ -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());
}
}

View file

@ -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)
}
}

View file

@ -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<length; i++){
ret[i] = fillWith;
}
return ret;
}
double[] createArray(int length, double fillWith){
double[] ret = new double[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
}

View file

@ -0,0 +1,38 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
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.powermock.api.mockito.PowerMockito
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
@PrepareForTest(NSUpload::class)
class DanaRS_Packet_Notify_AlarmTest : DanaRSTestBase() {
@Mock lateinit var resourceHelper: ResourceHelper
@Test fun runTest() {
val packet = DanaRS_Packet_Notify_Alarm(aapsLogger, resourceHelper)
// test params
Assert.assertEquals(null, packet.requestParams)
// test message decoding
// handlemessage testing fails on non-eror byte because of NSUpload not properly mocked
packet.handleMessage(createArray(17, 0x01.toByte()))
Assert.assertEquals(false, packet.failed)
// no error
packet.handleMessage(createArray(17, 0.toByte()))
Assert.assertEquals(true, packet.failed)
Assert.assertEquals("NOTIFY__ALARM", packet.friendlyName)
}
@Before
fun mock() {
PowerMockito.mockStatic(NSUpload::class.java)
}
}

View file

@ -1,31 +1,42 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm
import android.content.Context
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.AAPSMocker
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
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.Treatment
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.DefaultValueHelper
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
import org.mockito.Mock
import org.mockito.Mockito.`when`
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
@PrepareForTest(MainApp::class, SP::class, L::class)
class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest {
@PrepareForTest(ConstraintChecker::class, RxBusWrapper::class)
class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest : DanaRSTestBase() {
@Mock lateinit var defaultValueHelper: DefaultValueHelper
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin
@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
private var treatmentInjector: HasAndroidInjector = HasAndroidInjector {
AndroidInjector {
@ -39,12 +50,9 @@ class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest {
}
@Test fun runTest() {
AAPSMocker.mockMainApp()
AAPSMocker.mockApplicationContext()
AAPSMocker.mockSP()
AAPSMocker.mockL()
AAPSMocker.mockStrings()
val packet = DanaRS_Packet_Notify_Delivery_Rate_Display(1.0, Treatment(treatmentInjector))
`when`(resourceHelper.gs(ArgumentMatchers.anyInt(), anyObject())).thenReturn("SomeString")
// val packet = DanaRS_Packet_Notify_Delivery_Rate_Display(1.0, Treatment(treatmentInjector))
val packet = DanaRS_Packet_Notify_Delivery_Rate_Display(aapsLogger, rxBus, resourceHelper, danaRSPlugin)
// test params
Assert.assertEquals(null, packet.requestParams)
// test message decoding
@ -57,19 +65,9 @@ class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest {
Assert.assertEquals("NOTIFY__DELIVERY_RATE_DISPLAY", packet.friendlyName)
}
fun createArray(length: Int, fillWith: Byte): ByteArray {
val ret = ByteArray(length)
for (i in 0 until length) {
ret[i] = fillWith
}
return ret
}
fun createArray(length: Int, fillWith: Double): DoubleArray {
val ret = DoubleArray(length)
for (i in 0 until length) {
ret[i] = fillWith
}
return ret
@Before
fun mock() {
danaRSPlugin = DanaRSPlugin(aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump)
danaRSPlugin.bolusingTreatment = Treatment(treatmentInjector)
}
}

View file

@ -1,61 +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_Notify_Missed_Bolus_AlarmTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
DanaRS_Packet_Notify_Missed_Bolus_Alarm packet = new DanaRS_Packet_Notify_Missed_Bolus_Alarm();
// test params
assertEquals(null, packet.getRequestParams());
// test message decoding
packet.handleMessage(createArray(6, (byte) 0));
assertEquals(false, packet.failed);
// everything ok :)
packet.handleMessage(createArray(6, (byte) 1));
assertEquals(true, packet.failed);
assertEquals("NOTIFY__MISSED_BOLUS_ALARM", packet.getFriendlyName());
}
byte[] createArray(int length, byte fillWith){
byte[] ret = new byte[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
double[] createArray(int length, double fillWith){
double[] ret = new double[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
}

View file

@ -0,0 +1,25 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
@PrepareForTest()
class DanaRS_Packet_Notify_Missed_Bolus_AlarmTest : DanaRSTestBase() {
@Test fun runTest() {
val packet = DanaRS_Packet_Notify_Missed_Bolus_Alarm(aapsLogger)
// test params
Assert.assertEquals(null, packet.requestParams)
// test message decoding
packet.handleMessage(createArray(6, 0.toByte()))
Assert.assertEquals(false, packet.failed)
// everything ok :)
packet.handleMessage(createArray(6, 1.toByte()))
Assert.assertEquals(true, packet.failed)
Assert.assertEquals("NOTIFY__MISSED_BOLUS_ALARM", packet.friendlyName)
}
}

View file

@ -1,61 +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_Option_Get_Pump_TimeTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
DanaRS_Packet_Option_Get_Pump_Time packet = new DanaRS_Packet_Option_Get_Pump_Time();
// test params
assertEquals(null, packet.getRequestParams());
// test message decoding
packet.handleMessage(createArray(8, (byte) 0));
assertEquals(false, packet.failed);
// this should fail
packet.handleMessage(createArray(8, (byte) 1));
assertEquals(true, packet.failed);
assertEquals("OPTION__GET_PUMP_TIME", packet.getFriendlyName());
}
byte[] createArray(int length, byte fillWith){
byte[] ret = new byte[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
double[] createArray(int length, double fillWith){
double[] ret = new double[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
}

View file

@ -0,0 +1,25 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
@PrepareForTest()
class DanaRS_Packet_Option_Get_Pump_TimeTest : DanaRSTestBase() {
@Test fun runTest() {
val packet = DanaRS_Packet_Option_Get_Pump_Time(aapsLogger, danaRPump)
// test params
Assert.assertEquals(null, packet.requestParams)
// test message decoding
packet.handleMessage(createArray(8, 0.toByte()))
Assert.assertEquals(false, packet.failed)
// this should fail
packet.handleMessage(createArray(8, 1.toByte()))
Assert.assertEquals(true, packet.failed)
Assert.assertEquals("OPTION__GET_PUMP_TIME", packet.friendlyName)
}
}

View file

@ -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.pump.danaR.DanaRPump;
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_Option_Get_User_OptionTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
DanaRS_Packet_Option_Get_User_Option packet = new DanaRS_Packet_Option_Get_User_Option();
// test params
assertEquals(null, packet.getRequestParams());
// test message decoding
packet.handleMessage(createArray(20, (byte) 0));
assertEquals(true, packet.failed);
// everything ok :)
packet.handleMessage(createArray(20, (byte) 5));
DanaRPump pump = DanaRPump.getInstance();
assertEquals(5, pump.lcdOnTimeSec);
assertEquals(false, packet.failed);
assertEquals("OPTION__GET_USER_OPTION", packet.getFriendlyName());
}
byte[] createArray(int length, byte fillWith){
byte[] ret = new byte[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
double[] createArray(int length, double fillWith){
double[] ret = new double[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
}

View file

@ -0,0 +1,26 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
@PrepareForTest()
class DanaRS_Packet_Option_Get_User_OptionTest : DanaRSTestBase() {
@Test fun runTest() {
val packet = DanaRS_Packet_Option_Get_User_Option(aapsLogger, danaRPump)
// test params
Assert.assertEquals(null, packet.requestParams)
// test message decoding
packet.handleMessage(createArray(20, 0.toByte()))
Assert.assertEquals(true, packet.failed)
// everything ok :)
packet.handleMessage(createArray(20, 5.toByte()))
Assert.assertEquals(5, danaRPump.lcdOnTimeSec)
Assert.assertEquals(false, packet.failed)
Assert.assertEquals("OPTION__GET_USER_OPTION", packet.friendlyName)
}
}

View file

@ -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 java.util.Date;
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_Option_Set_Pump_TimeTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
DanaRS_Packet_Option_Set_Pump_Time packet = new DanaRS_Packet_Option_Set_Pump_Time(new Date());
// test params
byte[] params = packet.getRequestParams();
assertEquals((byte) (new Date().getDate() & 0xff) , params[2]);
// test message decoding
packet.handleMessage(createArray(3, (byte) 0));
assertEquals(false, packet.failed);
// everything ok :)
packet.handleMessage(createArray(17, (byte) 1));
assertEquals(true, packet.failed);
assertEquals("OPTION__SET_PUMP_TIME", packet.getFriendlyName());
}
byte[] createArray(int length, byte fillWith){
byte[] ret = new byte[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
double[] createArray(int length, double fillWith){
double[] ret = new double[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
}

View file

@ -0,0 +1,28 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.utils.DateUtil
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
import java.util.*
@RunWith(PowerMockRunner::class)
@PrepareForTest()
class DanaRS_Packet_Option_Set_Pump_TimeTest : DanaRSTestBase() {
@Test fun runTest() {
val packet = DanaRS_Packet_Option_Set_Pump_Time(aapsLogger, DateUtil.now())
// test params
val params = packet.requestParams
Assert.assertEquals((Date().date and 0xff).toByte(), params[2])
// test message decoding
packet.handleMessage(createArray(3, 0.toByte()))
Assert.assertEquals(false, packet.failed)
// everything ok :)
packet.handleMessage(createArray(17, 1.toByte()))
Assert.assertEquals(true, packet.failed)
Assert.assertEquals("OPTION__SET_PUMP_TIME", packet.friendlyName)
}
}

View file

@ -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.pump.danaR.DanaRPump;
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_Option_Set_User_OptionTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
DanaRS_Packet_Option_Set_User_Option packet = new DanaRS_Packet_Option_Set_User_Option();
// test params
byte[] params = packet.getRequestParams();
DanaRPump pump = DanaRPump.getInstance();
assertEquals((byte) (pump.lcdOnTimeSec & 0xff) ,params[3]);
// test message decoding
packet.handleMessage(createArray(3, (byte) 0));
assertEquals(false, packet.failed);
// everything ok :)
packet.handleMessage(createArray(17, (byte) 1));
assertEquals(true, packet.failed);
assertEquals("OPTION__SET_USER_OPTION", packet.getFriendlyName());
}
byte[] createArray(int length, byte fillWith){
byte[] ret = new byte[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
double[] createArray(int length, double fillWith){
double[] ret = new double[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
}

View file

@ -0,0 +1,26 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
@PrepareForTest()
class DanaRS_Packet_Option_Set_User_OptionTest : DanaRSTestBase() {
@Test fun runTest() {
val packet = DanaRS_Packet_Option_Set_User_Option(aapsLogger, danaRPump)
// test params
val params = packet.requestParams
Assert.assertEquals((danaRPump.lcdOnTimeSec and 0xff).toByte(), params[3])
// test message decoding
packet.handleMessage(createArray(3, 0.toByte()))
Assert.assertEquals(false, packet.failed)
// everything ok :)
packet.handleMessage(createArray(17, 1.toByte()))
Assert.assertEquals(true, packet.failed)
Assert.assertEquals("OPTION__SET_USER_OPTION", packet.friendlyName)
}
}

View file

@ -1,61 +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_Review_Bolus_AvgTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
DanaRS_Packet_Review_Bolus_Avg packet = new DanaRS_Packet_Review_Bolus_Avg();
// test params
assertEquals(null, packet.getRequestParams());
// test message decoding
packet.handleMessage(createArray(12, (byte) 0));
assertEquals(false, packet.failed);
// every average equals 1
packet.handleMessage(createArray(12, (byte) 1));
assertEquals(true, packet.failed);
assertEquals("REVIEW__BOLUS_AVG", packet.getFriendlyName());
}
byte[] createArray(int length, byte fillWith){
byte[] ret = new byte[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
double[] createArray(int length, double fillWith){
double[] ret = new double[length];
for(int i = 0; i<length; i++){
ret[i] = fillWith;
}
return ret;
}
}

View file

@ -0,0 +1,25 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
@PrepareForTest()
class DanaRS_Packet_Review_Bolus_AvgTest : DanaRSTestBase() {
@Test fun runTest() {
val packet = DanaRS_Packet_Review_Bolus_Avg(aapsLogger)
// test params
Assert.assertEquals(null, packet.requestParams)
// test message decoding
packet.handleMessage(createArray(12, 0.toByte()))
Assert.assertEquals(false, packet.failed)
// every average equals 1
packet.handleMessage(createArray(12, 1.toByte()))
Assert.assertEquals(true, packet.failed)
Assert.assertEquals("REVIEW__BOLUS_AVG", packet.friendlyName)
}
}