SmsCommunicatorPluginTest 3
This commit is contained in:
parent
a212ba7156
commit
bb5cec95ea
|
@ -50,6 +50,10 @@ public class ConstraintChecker implements ConstraintsInterface {
|
||||||
return isAdvancedFilteringEnabled(new Constraint<>(true));
|
return isAdvancedFilteringEnabled(new Constraint<>(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Constraint<Boolean> isSuperBolusEnabled() {
|
||||||
|
return isSuperBolusEnabled(new Constraint<>(true));
|
||||||
|
}
|
||||||
|
|
||||||
public Constraint<Double> getMaxBasalAllowed(Profile profile) {
|
public Constraint<Double> getMaxBasalAllowed(Profile profile) {
|
||||||
return applyBasalConstraints(new Constraint<>(Constants.REALLYHIGHBASALRATE), profile);
|
return applyBasalConstraints(new Constraint<>(Constants.REALLYHIGHBASALRATE), profile);
|
||||||
}
|
}
|
||||||
|
@ -157,6 +161,17 @@ public class ConstraintChecker implements ConstraintsInterface {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Constraint<Boolean> isSuperBolusEnabled(Constraint<Boolean> value) {
|
||||||
|
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
||||||
|
for (PluginBase p : constraintsPlugins) {
|
||||||
|
ConstraintsInterface constraint = (ConstraintsInterface) p;
|
||||||
|
if (!p.isEnabled(PluginType.CONSTRAINTS)) continue;
|
||||||
|
constraint.isSuperBolusEnabled(value);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Constraint<Double> applyBasalConstraints(Constraint<Double> absoluteRate, Profile profile) {
|
public Constraint<Double> applyBasalConstraints(Constraint<Double> absoluteRate, Profile profile) {
|
||||||
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
|
||||||
|
|
|
@ -35,6 +35,10 @@ public interface ConstraintsInterface {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default Constraint<Boolean> isSuperBolusEnabled(Constraint<Boolean> value) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
default Constraint<Double> applyBasalConstraints(Constraint<Double> absoluteRate, Profile profile) {
|
default Constraint<Double> applyBasalConstraints(Constraint<Double> absoluteRate, Profile profile) {
|
||||||
return absoluteRate;
|
return absoluteRate;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.interfaces.APSInterface;
|
import info.nightscout.androidaps.interfaces.APSInterface;
|
||||||
import info.nightscout.androidaps.interfaces.Constraint;
|
import info.nightscout.androidaps.interfaces.Constraint;
|
||||||
|
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PluginType;
|
import info.nightscout.androidaps.interfaces.PluginType;
|
||||||
|
@ -38,7 +39,7 @@ import info.nightscout.androidaps.utils.ToastUtils;
|
||||||
/**
|
/**
|
||||||
* Created by mike on 05.08.2016.
|
* Created by mike on 05.08.2016.
|
||||||
*/
|
*/
|
||||||
public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
|
public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, ConstraintsInterface {
|
||||||
private static Logger log = LoggerFactory.getLogger(L.APS);
|
private static Logger log = LoggerFactory.getLogger(L.APS);
|
||||||
|
|
||||||
private static OpenAPSSMBPlugin openAPSSMBPlugin;
|
private static OpenAPSSMBPlugin openAPSSMBPlugin;
|
||||||
|
@ -266,4 +267,9 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
|
||||||
return newvalue;
|
return newvalue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Constraint<Boolean> isSuperBolusEnabled(Constraint<Boolean> value) {
|
||||||
|
value.set(false);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,6 +110,10 @@ public class AAPSMocker {
|
||||||
when(MainApp.gs(R.string.sms_iob)).thenReturn("IOB:");
|
when(MainApp.gs(R.string.sms_iob)).thenReturn("IOB:");
|
||||||
when(MainApp.gs(R.string.sms_lastbg)).thenReturn("Last BG:");
|
when(MainApp.gs(R.string.sms_lastbg)).thenReturn("Last BG:");
|
||||||
when(MainApp.gs(R.string.sms_minago)).thenReturn("%1$dmin ago");
|
when(MainApp.gs(R.string.sms_minago)).thenReturn("%1$dmin ago");
|
||||||
|
when(MainApp.gs(R.string.smscommunicator_remotecommandnotallowed)).thenReturn("Remote command is not allowed");
|
||||||
|
when(MainApp.gs(R.string.loopsuspendedfor)).thenReturn("Suspended (%1$d m)");
|
||||||
|
when(MainApp.gs(R.string.smscommunicator_loopisdisabled)).thenReturn("Loop is disabled");
|
||||||
|
when(MainApp.gs(R.string.smscommunicator_loopisenabled)).thenReturn("Loop is enabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MainApp mockMainApp() {
|
public static MainApp mockMainApp() {
|
||||||
|
|
|
@ -54,6 +54,7 @@ public class ConstraintsCheckerTest {
|
||||||
DanaRPlugin danaRPlugin;
|
DanaRPlugin danaRPlugin;
|
||||||
DanaRSPlugin danaRSPlugin;
|
DanaRSPlugin danaRSPlugin;
|
||||||
LocalInsightPlugin insightPlugin;
|
LocalInsightPlugin insightPlugin;
|
||||||
|
OpenAPSSMBPlugin openAPSSMBPlugin;
|
||||||
|
|
||||||
boolean notificationSent = false;
|
boolean notificationSent = false;
|
||||||
|
|
||||||
|
@ -119,6 +120,13 @@ public class ConstraintsCheckerTest {
|
||||||
Assert.assertEquals(Boolean.FALSE, c.value());
|
Assert.assertEquals(Boolean.FALSE, c.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isSuperBolusEnabledTest() throws Exception {
|
||||||
|
|
||||||
|
Constraint<Boolean> c = constraintChecker.isSuperBolusEnabled();
|
||||||
|
Assert.assertEquals(Boolean.FALSE, c.value()); // SMB should limit
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isSMBModeEnabledTest() throws Exception {
|
public void isSMBModeEnabledTest() throws Exception {
|
||||||
objectivesPlugin.objectives.get(7).setStartedOn(null);
|
objectivesPlugin.objectives.get(7).setStartedOn(null);
|
||||||
|
@ -288,6 +296,7 @@ public class ConstraintsCheckerTest {
|
||||||
danaRPlugin = DanaRPlugin.getPlugin();
|
danaRPlugin = DanaRPlugin.getPlugin();
|
||||||
danaRSPlugin = DanaRSPlugin.getPlugin();
|
danaRSPlugin = DanaRSPlugin.getPlugin();
|
||||||
insightPlugin = LocalInsightPlugin.getPlugin();
|
insightPlugin = LocalInsightPlugin.getPlugin();
|
||||||
|
openAPSSMBPlugin = OpenAPSSMBPlugin.getPlugin();
|
||||||
ArrayList<PluginBase> constraintsPluginsList = new ArrayList<>();
|
ArrayList<PluginBase> constraintsPluginsList = new ArrayList<>();
|
||||||
constraintsPluginsList.add(safetyPlugin);
|
constraintsPluginsList.add(safetyPlugin);
|
||||||
constraintsPluginsList.add(objectivesPlugin);
|
constraintsPluginsList.add(objectivesPlugin);
|
||||||
|
@ -295,6 +304,7 @@ public class ConstraintsCheckerTest {
|
||||||
constraintsPluginsList.add(danaRPlugin);
|
constraintsPluginsList.add(danaRPlugin);
|
||||||
constraintsPluginsList.add(danaRSPlugin);
|
constraintsPluginsList.add(danaRSPlugin);
|
||||||
constraintsPluginsList.add(insightPlugin);
|
constraintsPluginsList.add(insightPlugin);
|
||||||
|
constraintsPluginsList.add(openAPSSMBPlugin);
|
||||||
when(mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class)).thenReturn(constraintsPluginsList);
|
when(mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class)).thenReturn(constraintsPluginsList);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.interfaces.PluginType;
|
import info.nightscout.androidaps.interfaces.PluginType;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||||
|
@ -35,6 +36,7 @@ import static org.powermock.api.mockito.PowerMockito.when;
|
||||||
public class SmsCommunicatorPluginTest {
|
public class SmsCommunicatorPluginTest {
|
||||||
|
|
||||||
SmsCommunicatorPlugin smsCommunicatorPlugin;
|
SmsCommunicatorPlugin smsCommunicatorPlugin;
|
||||||
|
LoopPlugin loopPlugin;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void processSettingsTest() {
|
public void processSettingsTest() {
|
||||||
|
@ -60,14 +62,53 @@ public class SmsCommunicatorPluginTest {
|
||||||
Assert.assertTrue(sms.ignored);
|
Assert.assertTrue(sms.ignored);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "aText");
|
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "aText");
|
||||||
|
|
||||||
|
// test remote control disabled
|
||||||
|
when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(false);
|
||||||
|
smsCommunicatorPlugin.messages = new ArrayList<>();
|
||||||
|
sms = new Sms("1234", "LOOP STATUS");
|
||||||
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
|
Assert.assertFalse(sms.ignored);
|
||||||
|
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "LOOP STATUS");
|
||||||
|
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("Remote command is not allowed"));
|
||||||
|
|
||||||
|
// enable remote control for next tests
|
||||||
|
when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true);
|
||||||
|
|
||||||
//BG
|
//BG
|
||||||
smsCommunicatorPlugin.messages = new ArrayList<>();
|
smsCommunicatorPlugin.messages = new ArrayList<>();
|
||||||
sms = new Sms("1234", "BG");
|
sms = new Sms("1234", "BG");
|
||||||
smsCommunicatorPlugin.processSms(sms);
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
Assert.assertFalse(sms.ignored);
|
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "BG");
|
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "BG");
|
||||||
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("IOB:"));
|
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("IOB:"));
|
||||||
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("Last BG: 100"));
|
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("Last BG: 100"));
|
||||||
|
|
||||||
|
//LOOP STATUS : disabled
|
||||||
|
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(false);
|
||||||
|
smsCommunicatorPlugin.messages = new ArrayList<>();
|
||||||
|
sms = new Sms("1234", "LOOP STATUS");
|
||||||
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
|
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "LOOP STATUS");
|
||||||
|
Assert.assertEquals(smsCommunicatorPlugin.messages.get(1).text, "Loop is disabled");
|
||||||
|
|
||||||
|
//LOOP STATUS : suspended
|
||||||
|
when(loopPlugin.minutesToEndOfSuspend()).thenReturn(10);
|
||||||
|
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
|
||||||
|
when(loopPlugin.isSuspended()).thenReturn(true);
|
||||||
|
smsCommunicatorPlugin.messages = new ArrayList<>();
|
||||||
|
sms = new Sms("1234", "LOOP STATUS");
|
||||||
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
|
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "LOOP STATUS");
|
||||||
|
Assert.assertEquals(smsCommunicatorPlugin.messages.get(1).text, "Suspended (10 m)");
|
||||||
|
|
||||||
|
//LOOP STATUS : enabled
|
||||||
|
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
|
||||||
|
when(loopPlugin.isSuspended()).thenReturn(false);
|
||||||
|
smsCommunicatorPlugin.messages = new ArrayList<>();
|
||||||
|
sms = new Sms("1234", "LOOP STATUS");
|
||||||
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
|
Assert.assertFalse(sms.ignored);
|
||||||
|
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "LOOP STATUS");
|
||||||
|
Assert.assertEquals(smsCommunicatorPlugin.messages.get(1).text, "Loop is enabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@ -96,6 +137,9 @@ public class SmsCommunicatorPluginTest {
|
||||||
when(SP.getString(R.string.key_smscommunicator_allowednumbers, "")).thenReturn("1234;5678");
|
when(SP.getString(R.string.key_smscommunicator_allowednumbers, "")).thenReturn("1234;5678");
|
||||||
smsCommunicatorPlugin = new SmsCommunicatorPlugin();
|
smsCommunicatorPlugin = new SmsCommunicatorPlugin();
|
||||||
smsCommunicatorPlugin.setPluginEnabled(PluginType.GENERAL, true);
|
smsCommunicatorPlugin.setPluginEnabled(PluginType.GENERAL, true);
|
||||||
|
|
||||||
|
loopPlugin = mock(LoopPlugin.class);
|
||||||
|
when(MainApp.getSpecificPlugin(LoopPlugin.class)).thenReturn(loopPlugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue