Dana plugins tests
This commit is contained in:
parent
6f2ba7c135
commit
bc0ae1fa68
7 changed files with 260 additions and 168 deletions
|
@ -12,7 +12,6 @@ import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector;
|
import dagger.android.HasAndroidInjector;
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
@ -46,7 +45,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
||||||
private CompositeDisposable disposable = new CompositeDisposable();
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
private final AAPSLogger aapsLogger;
|
private final AAPSLogger aapsLogger;
|
||||||
private final MainApp mainApp;
|
private final Context context;
|
||||||
private final ResourceHelper resourceHelper;
|
private final ResourceHelper resourceHelper;
|
||||||
private final ConstraintChecker constraintChecker;
|
private final ConstraintChecker constraintChecker;
|
||||||
|
|
||||||
|
@ -56,7 +55,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
||||||
AAPSLogger aapsLogger,
|
AAPSLogger aapsLogger,
|
||||||
RxBusWrapper rxBus,
|
RxBusWrapper rxBus,
|
||||||
DanaRPump danaRPump,
|
DanaRPump danaRPump,
|
||||||
MainApp maiApp,
|
Context context,
|
||||||
ResourceHelper resourceHelper,
|
ResourceHelper resourceHelper,
|
||||||
ConstraintChecker constraintChecker,
|
ConstraintChecker constraintChecker,
|
||||||
TreatmentsPlugin treatmentsPlugin,
|
TreatmentsPlugin treatmentsPlugin,
|
||||||
|
@ -66,7 +65,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
||||||
) {
|
) {
|
||||||
super(injector, danaRPump, resourceHelper, constraintChecker, aapsLogger, commandQueue, rxBus, treatmentsPlugin, sp);
|
super(injector, danaRPump, resourceHelper, constraintChecker, aapsLogger, commandQueue, rxBus, treatmentsPlugin, sp);
|
||||||
this.aapsLogger = aapsLogger;
|
this.aapsLogger = aapsLogger;
|
||||||
this.mainApp = maiApp;
|
this.context = context;
|
||||||
this.resourceHelper = resourceHelper;
|
this.resourceHelper = resourceHelper;
|
||||||
this.constraintChecker = constraintChecker;
|
this.constraintChecker = constraintChecker;
|
||||||
getPluginDescription().description(R.string.description_pump_dana_r_korean);
|
getPluginDescription().description(R.string.description_pump_dana_r_korean);
|
||||||
|
@ -77,8 +76,8 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
Intent intent = new Intent(mainApp, DanaRKoreanExecutionService.class);
|
Intent intent = new Intent(context, DanaRKoreanExecutionService.class);
|
||||||
mainApp.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
||||||
disposable.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventPreferenceChange.class)
|
.toObservable(EventPreferenceChange.class)
|
||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
|
@ -96,14 +95,14 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
|
||||||
disposable.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventAppExit.class)
|
.toObservable(EventAppExit.class)
|
||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
.subscribe(event -> mainApp.unbindService(mConnection), exception -> FabricPrivacy.getInstance().logException(exception))
|
.subscribe(event -> context.unbindService(mConnection), exception -> FabricPrivacy.getInstance().logException(exception))
|
||||||
);
|
);
|
||||||
super.onStart();
|
super.onStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
mainApp.unbindService(mConnection);
|
context.unbindService(mConnection);
|
||||||
disposable.clear();
|
disposable.clear();
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector;
|
import dagger.android.HasAndroidInjector;
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
|
@ -46,7 +45,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
||||||
private CompositeDisposable disposable = new CompositeDisposable();
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
private final AAPSLogger aapsLogger;
|
private final AAPSLogger aapsLogger;
|
||||||
private final MainApp mainApp;
|
private final Context context;
|
||||||
private final ResourceHelper resourceHelper;
|
private final ResourceHelper resourceHelper;
|
||||||
private final ConstraintChecker constraintChecker;
|
private final ConstraintChecker constraintChecker;
|
||||||
private final DetailedBolusInfoStorage detailedBolusInfoStorage;
|
private final DetailedBolusInfoStorage detailedBolusInfoStorage;
|
||||||
|
@ -60,7 +59,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
||||||
HasAndroidInjector injector,
|
HasAndroidInjector injector,
|
||||||
AAPSLogger aapsLogger,
|
AAPSLogger aapsLogger,
|
||||||
RxBusWrapper rxBus,
|
RxBusWrapper rxBus,
|
||||||
MainApp maiApp,
|
Context context,
|
||||||
DanaRPump danaRPump,
|
DanaRPump danaRPump,
|
||||||
ResourceHelper resourceHelper,
|
ResourceHelper resourceHelper,
|
||||||
ConstraintChecker constraintChecker,
|
ConstraintChecker constraintChecker,
|
||||||
|
@ -71,7 +70,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
||||||
) {
|
) {
|
||||||
super(injector, danaRPump, resourceHelper, constraintChecker, aapsLogger, commandQueue, rxBus, treatmentsPlugin, sp);
|
super(injector, danaRPump, resourceHelper, constraintChecker, aapsLogger, commandQueue, rxBus, treatmentsPlugin, sp);
|
||||||
this.aapsLogger = aapsLogger;
|
this.aapsLogger = aapsLogger;
|
||||||
this.mainApp = maiApp;
|
this.context = context;
|
||||||
this.resourceHelper = resourceHelper;
|
this.resourceHelper = resourceHelper;
|
||||||
this.constraintChecker = constraintChecker;
|
this.constraintChecker = constraintChecker;
|
||||||
this.detailedBolusInfoStorage = detailedBolusInfoStorage;
|
this.detailedBolusInfoStorage = detailedBolusInfoStorage;
|
||||||
|
@ -83,20 +82,20 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
Intent intent = new Intent(mainApp, DanaRv2ExecutionService.class);
|
Intent intent = new Intent(context, DanaRv2ExecutionService.class);
|
||||||
mainApp.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
||||||
|
|
||||||
disposable.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventAppExit.class)
|
.toObservable(EventAppExit.class)
|
||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
.subscribe(event -> mainApp.unbindService(mConnection), exception -> FabricPrivacy.getInstance().logException(exception))
|
.subscribe(event -> context.unbindService(mConnection), exception -> FabricPrivacy.getInstance().logException(exception))
|
||||||
);
|
);
|
||||||
super.onStart();
|
super.onStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
mainApp.unbindService(mConnection);
|
context.unbindService(mConnection);
|
||||||
|
|
||||||
disposable.clear();
|
disposable.clear();
|
||||||
super.onStop();
|
super.onStop();
|
||||||
|
|
|
@ -1,74 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.danaR;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
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.utils.SP;
|
|
||||||
import info.nightscout.androidaps.utils.ToastUtils;
|
|
||||||
|
|
||||||
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 DanaRPluginTest {
|
|
||||||
|
|
||||||
DanaRPlugin danaRPlugin;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void basalRateShouldBeLimited() throws Exception {
|
|
||||||
danaRPlugin.setPluginEnabled(PluginType.PUMP, true);
|
|
||||||
danaRPlugin.setPluginEnabled(PluginType.PUMP, true);
|
|
||||||
DanaRPump.getInstance().maxBasal = 0.8d;
|
|
||||||
|
|
||||||
Constraint<Double> c = new Constraint<>(Constants.REALLYHIGHBASALRATE);
|
|
||||||
danaRPlugin.applyBasalConstraints(c, AAPSMocker.getValidProfile());
|
|
||||||
Assert.assertEquals(0.8d, c.value());
|
|
||||||
Assert.assertEquals("DanaR: Limiting basal rate to 0.80 U/h because of pump limit", c.getReasons());
|
|
||||||
Assert.assertEquals("DanaR: Limiting basal rate to 0.80 U/h because of pump limit", c.getMostLimitedReasons());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void percentBasalRateShouldBeLimited() throws Exception {
|
|
||||||
danaRPlugin.setPluginEnabled(PluginType.PUMP, true);
|
|
||||||
danaRPlugin.setPluginEnabled(PluginType.PUMP, true);
|
|
||||||
DanaRPump.getInstance().maxBasal = 0.8d;
|
|
||||||
|
|
||||||
Constraint<Integer> c = new Constraint<>(Constants.REALLYHIGHPERCENTBASALRATE);
|
|
||||||
danaRPlugin.applyBasalPercentConstraints(c, AAPSMocker.getValidProfile());
|
|
||||||
Assert.assertEquals((Integer) 200, c.value());
|
|
||||||
Assert.assertEquals("DanaR: Limiting percent rate to 200% because of pump limit", c.getReasons());
|
|
||||||
Assert.assertEquals("DanaR: 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("");
|
|
||||||
|
|
||||||
danaRPlugin = DanaRPlugin.getPlugin();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.danaR
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import dagger.android.AndroidInjector
|
||||||
|
import dagger.android.HasAndroidInjector
|
||||||
|
import info.TestBase
|
||||||
|
import info.nightscout.androidaps.Constants
|
||||||
|
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.AAPSLogger
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||||
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
|
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.`when`
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner::class)
|
||||||
|
@PrepareForTest(SP::class, ConstraintChecker::class)
|
||||||
|
class DanaRPluginTest : TestBase() {
|
||||||
|
|
||||||
|
@Mock lateinit var aapsLogger: AAPSLogger
|
||||||
|
@Mock lateinit var context: Context
|
||||||
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
|
@Mock lateinit var constraintChecker: ConstraintChecker
|
||||||
|
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
|
||||||
|
@Mock lateinit var sp: SP
|
||||||
|
@Mock lateinit var commandQueue: CommandQueueProvider
|
||||||
|
|
||||||
|
val rxBus = RxBusWrapper()
|
||||||
|
lateinit var danaRPump: DanaRPump
|
||||||
|
|
||||||
|
private lateinit var danaRPlugin: DanaRPlugin
|
||||||
|
|
||||||
|
val injector = HasAndroidInjector {
|
||||||
|
AndroidInjector { }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun prepareMocks() {
|
||||||
|
`when`(sp.getString(R.string.key_danars_address, "")).thenReturn("")
|
||||||
|
`when`(resourceHelper.gs(R.string.pumplimit)).thenReturn("pump limit")
|
||||||
|
`when`(resourceHelper.gs(R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s")
|
||||||
|
`when`(resourceHelper.gs(R.string.limitingpercentrate)).thenReturn("Limiting max percent rate to %1\$d%% because of %2\$s")
|
||||||
|
danaRPump = DanaRPump(aapsLogger, sp, injector)
|
||||||
|
danaRPlugin = DanaRPlugin(injector, aapsLogger, rxBus, context, resourceHelper, constraintChecker, treatmentsPlugin, sp, commandQueue, danaRPump)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test @Throws(Exception::class)
|
||||||
|
fun basalRateShouldBeLimited() {
|
||||||
|
danaRPlugin.setPluginEnabled(PluginType.PUMP, true)
|
||||||
|
danaRPlugin.setPluginEnabled(PluginType.PUMP, true)
|
||||||
|
danaRPump.maxBasal = 0.8
|
||||||
|
val c = Constraint(Constants.REALLYHIGHBASALRATE)
|
||||||
|
danaRPlugin.applyBasalConstraints(c, validProfile)
|
||||||
|
Assert.assertEquals(0.8, c.value(), 0.01)
|
||||||
|
Assert.assertEquals("DanaR: Limiting max basal rate to 0.80 U/h because of pump limit", c.getReasons(aapsLogger))
|
||||||
|
Assert.assertEquals("DanaR: Limiting max basal rate to 0.80 U/h because of pump limit", c.getMostLimitedReasons(aapsLogger))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test @Throws(Exception::class)
|
||||||
|
fun percentBasalRateShouldBeLimited() {
|
||||||
|
danaRPlugin.setPluginEnabled(PluginType.PUMP, true)
|
||||||
|
danaRPlugin.setPluginEnabled(PluginType.PUMP, true)
|
||||||
|
danaRPump.maxBasal = 0.8
|
||||||
|
val c = Constraint(Constants.REALLYHIGHPERCENTBASALRATE)
|
||||||
|
danaRPlugin.applyBasalPercentConstraints(c, validProfile)
|
||||||
|
Assert.assertEquals(200, c.value())
|
||||||
|
Assert.assertEquals("DanaR: Limiting max percent rate to 200% because of pump limit", c.getReasons(aapsLogger))
|
||||||
|
Assert.assertEquals("DanaR: Limiting max percent rate to 200% because of pump limit", c.getMostLimitedReasons(aapsLogger))
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,82 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.danaRKorean
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import dagger.android.AndroidInjector
|
||||||
|
import dagger.android.HasAndroidInjector
|
||||||
|
import info.TestBase
|
||||||
|
import info.nightscout.androidaps.Constants
|
||||||
|
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.AAPSLogger
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||||
|
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
|
||||||
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
|
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.`when`
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner::class)
|
||||||
|
@PrepareForTest(SP::class, ConstraintChecker::class)
|
||||||
|
class DanaRKoreanPluginTest : TestBase() {
|
||||||
|
|
||||||
|
@Mock lateinit var aapsLogger: AAPSLogger
|
||||||
|
@Mock lateinit var context: Context
|
||||||
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
|
@Mock lateinit var constraintChecker: ConstraintChecker
|
||||||
|
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
|
||||||
|
@Mock lateinit var sp: SP
|
||||||
|
@Mock lateinit var commandQueue: CommandQueueProvider
|
||||||
|
|
||||||
|
val rxBus = RxBusWrapper()
|
||||||
|
lateinit var danaRPump: DanaRPump
|
||||||
|
|
||||||
|
private lateinit var danaRPlugin: DanaRKoreanPlugin
|
||||||
|
|
||||||
|
val injector = HasAndroidInjector {
|
||||||
|
AndroidInjector { }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun prepareMocks() {
|
||||||
|
`when`(sp.getString(R.string.key_danars_address, "")).thenReturn("")
|
||||||
|
`when`(resourceHelper.gs(R.string.pumplimit)).thenReturn("pump limit")
|
||||||
|
`when`(resourceHelper.gs(R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s")
|
||||||
|
`when`(resourceHelper.gs(R.string.limitingpercentrate)).thenReturn("Limiting max percent rate to %1\$d%% because of %2\$s")
|
||||||
|
danaRPump = DanaRPump(aapsLogger, sp, injector)
|
||||||
|
danaRPlugin = DanaRKoreanPlugin(injector, aapsLogger, rxBus, danaRPump, context, resourceHelper, constraintChecker, treatmentsPlugin, sp, commandQueue)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test @Throws(Exception::class)
|
||||||
|
fun basalRateShouldBeLimited() {
|
||||||
|
danaRPlugin.setPluginEnabled(PluginType.PUMP, true)
|
||||||
|
danaRPlugin.setPluginEnabled(PluginType.PUMP, true)
|
||||||
|
danaRPump.maxBasal = 0.8
|
||||||
|
val c = Constraint(Constants.REALLYHIGHBASALRATE)
|
||||||
|
danaRPlugin.applyBasalConstraints(c, validProfile)
|
||||||
|
Assert.assertEquals(0.8, c.value(), 0.01)
|
||||||
|
Assert.assertEquals("DanaRKorean: Limiting max basal rate to 0.80 U/h because of pump limit", c.getReasons(aapsLogger))
|
||||||
|
Assert.assertEquals("DanaRKorean: Limiting max basal rate to 0.80 U/h because of pump limit", c.getMostLimitedReasons(aapsLogger))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test @Throws(Exception::class)
|
||||||
|
fun percentBasalRateShouldBeLimited() {
|
||||||
|
danaRPlugin.setPluginEnabled(PluginType.PUMP, true)
|
||||||
|
danaRPlugin.setPluginEnabled(PluginType.PUMP, true)
|
||||||
|
danaRPump.maxBasal = 0.8
|
||||||
|
val c = Constraint(Constants.REALLYHIGHPERCENTBASALRATE)
|
||||||
|
danaRPlugin.applyBasalPercentConstraints(c, validProfile)
|
||||||
|
Assert.assertEquals(200, c.value())
|
||||||
|
Assert.assertEquals("DanaRKorean: Limiting max percent rate to 200% because of pump limit", c.getReasons(aapsLogger))
|
||||||
|
Assert.assertEquals("DanaRKorean: Limiting max percent rate to 200% because of pump limit", c.getMostLimitedReasons(aapsLogger))
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,78 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.danaRv2;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import junit.framework.Assert;
|
|
||||||
|
|
||||||
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.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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Rumen on 01.08.2018
|
|
||||||
*/
|
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
|
||||||
@PrepareForTest({MainApp.class, ConfigBuilderPlugin.class, ToastUtils.class, Context.class, SP.class})
|
|
||||||
public class DanaRv2PluginTest {
|
|
||||||
DanaRv2Plugin danaRv2Plugin;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getPlugin() {
|
|
||||||
danaRv2Plugin.getPlugin();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void basalRateShouldBeLimited() throws Exception {
|
|
||||||
danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true);
|
|
||||||
danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true);
|
|
||||||
DanaRPump.getInstance().maxBasal = 0.8d;
|
|
||||||
|
|
||||||
Constraint<Double> c = new Constraint<>(Constants.REALLYHIGHBASALRATE);
|
|
||||||
danaRv2Plugin.applyBasalConstraints(c, AAPSMocker.getValidProfile());
|
|
||||||
Assert.assertEquals(0.8d, c.value());
|
|
||||||
Assert.assertEquals("DanaRv2: Limiting basal rate to 0.80 U/h because of pump limit", c.getReasons());
|
|
||||||
Assert.assertEquals("DanaRv2: Limiting basal rate to 0.80 U/h because of pump limit", c.getMostLimitedReasons());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void percentBasalRateShouldBeLimited() throws Exception {
|
|
||||||
danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true);
|
|
||||||
danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true);
|
|
||||||
DanaRPump.getInstance().maxBasal = 0.8d;
|
|
||||||
|
|
||||||
Constraint<Integer> c = new Constraint<>(Constants.REALLYHIGHPERCENTBASALRATE);
|
|
||||||
danaRv2Plugin.applyBasalPercentConstraints(c, AAPSMocker.getValidProfile());
|
|
||||||
Assert.assertEquals((Integer) 200, c.value());
|
|
||||||
Assert.assertEquals("DanaRv2: Limiting percent rate to 200% because of pump limit", c.getReasons());
|
|
||||||
Assert.assertEquals("DanaRv2: 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("");
|
|
||||||
|
|
||||||
danaRv2Plugin = DanaRv2Plugin.getPlugin();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.danaRv2
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import dagger.android.AndroidInjector
|
||||||
|
import dagger.android.HasAndroidInjector
|
||||||
|
import info.TestBase
|
||||||
|
import info.nightscout.androidaps.Constants
|
||||||
|
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.AAPSLogger
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||||
|
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage
|
||||||
|
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
|
||||||
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||||
|
import info.nightscout.androidaps.utils.SP
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
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(ConstraintChecker::class, SP::class, DetailedBolusInfoStorage::class)
|
||||||
|
class DanaRv2PluginTest : TestBase() {
|
||||||
|
|
||||||
|
@Mock lateinit var aapsLogger: AAPSLogger
|
||||||
|
@Mock lateinit var context: Context
|
||||||
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
|
@Mock lateinit var constraintChecker: ConstraintChecker
|
||||||
|
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
|
||||||
|
@Mock lateinit var sp: info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
|
@Mock lateinit var commandQueue: CommandQueueProvider
|
||||||
|
@Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage
|
||||||
|
|
||||||
|
val rxBus = RxBusWrapper()
|
||||||
|
lateinit var danaRPump: DanaRPump
|
||||||
|
|
||||||
|
private lateinit var danaRv2Plugin: DanaRv2Plugin
|
||||||
|
|
||||||
|
val injector = HasAndroidInjector {
|
||||||
|
AndroidInjector { }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun prepareMocks() {
|
||||||
|
`when`(sp.getString(R.string.key_danars_address, "")).thenReturn("")
|
||||||
|
`when`(resourceHelper.gs(R.string.pumplimit)).thenReturn("pump limit")
|
||||||
|
`when`(resourceHelper.gs(R.string.limitingbasalratio)).thenReturn("Limiting max basal rate to %1\$.2f U/h because of %2\$s")
|
||||||
|
`when`(resourceHelper.gs(R.string.limitingpercentrate)).thenReturn("Limiting max percent rate to %1\$d%% because of %2\$s")
|
||||||
|
danaRPump = DanaRPump(aapsLogger, sp, injector)
|
||||||
|
danaRv2Plugin = DanaRv2Plugin(injector, aapsLogger, rxBus, context, danaRPump, resourceHelper, constraintChecker, treatmentsPlugin, sp, commandQueue, detailedBolusInfoStorage)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun basalRateShouldBeLimited() {
|
||||||
|
danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true)
|
||||||
|
danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true)
|
||||||
|
danaRPump.maxBasal = 0.8
|
||||||
|
val c = Constraint(Constants.REALLYHIGHBASALRATE)
|
||||||
|
danaRv2Plugin.applyBasalConstraints(c, validProfile)
|
||||||
|
org.junit.Assert.assertEquals(0.8, c.value(), 0.01)
|
||||||
|
org.junit.Assert.assertEquals("DanaRv2: Limiting max basal rate to 0.80 U/h because of pump limit", c.getReasons(aapsLogger))
|
||||||
|
org.junit.Assert.assertEquals("DanaRv2: Limiting max basal rate to 0.80 U/h because of pump limit", c.getMostLimitedReasons(aapsLogger))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun percentBasalRateShouldBeLimited() {
|
||||||
|
danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true)
|
||||||
|
danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true)
|
||||||
|
danaRPump.maxBasal = 0.8
|
||||||
|
val c = Constraint(Constants.REALLYHIGHPERCENTBASALRATE)
|
||||||
|
danaRv2Plugin.applyBasalPercentConstraints(c, validProfile)
|
||||||
|
org.junit.Assert.assertEquals(200, c.value())
|
||||||
|
org.junit.Assert.assertEquals("DanaRv2: Limiting max percent rate to 200% because of pump limit", c.getReasons(aapsLogger))
|
||||||
|
org.junit.Assert.assertEquals("DanaRv2: Limiting max percent rate to 200% because of pump limit", c.getMostLimitedReasons(aapsLogger))
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue