SafetyPlugin extends PluginBase implements ConstraintsInterface { @Override public Constraint<Boolean> isClosedLoopAllowed(Constraint<Boolean> value) { String mode = SP.getString(R.string.key_aps_mode, "open"); if (!mode.equals("closed")) value.set(false, MainApp.gs(R.string.closedmodedisabledinpreferences), this); if (!MainApp.isEngineeringModeOrRelease()) { if (value.value()) { Notification n = new Notification(Notification.TOAST_ALARM, MainApp.gs(R.string.closed_loop_disabled_on_dev_branch), Notification.NORMAL); RxBus.INSTANCE.send(new EventNewNotification(n)); } value.set(false, MainApp.gs(R.string.closed_loop_disabled_on_dev_branch), this); } PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump(); if (pump != null && !pump.isFakingTempsByExtendedBoluses() && TreatmentsPlugin.getPlugin().isInHistoryExtendedBoluslInProgress()) { value.set(false, MainApp.gs(R.string.closed_loop_disabled_with_eb), this); } return value; } SafetyPlugin(); static SafetyPlugin getPlugin(); @Override Constraint<Boolean> isLoopInvocationAllowed(Constraint<Boolean> value); @Override Constraint<Boolean> isClosedLoopAllowed(Constraint<Boolean> value); @Override Constraint<Boolean> isAutosensModeEnabled(Constraint<Boolean> value); @Override Constraint<Boolean> isSMBModeEnabled(Constraint<Boolean> value); @Override Constraint<Boolean> isUAMEnabled(Constraint<Boolean> value); @Override Constraint<Boolean> isAdvancedFilteringEnabled(Constraint<Boolean> value); @Override Constraint<Double> applyBasalConstraints(Constraint<Double> absoluteRate, Profile profile); @Override Constraint<Integer> applyBasalPercentConstraints(Constraint<Integer> percentRate, Profile profile); @Override Constraint<Double> applyBolusConstraints(Constraint<Double> insulin); @Override Constraint<Double> applyExtendedBolusConstraints(Constraint<Double> insulin); @Override Constraint<Integer> applyCarbsConstraints(Constraint<Integer> carbs); @Override Constraint<Double> applyMaxIOBConstraints(Constraint<Double> maxIob);  }
@Test public void disabledEngineeringModeShouldLimitClosedLoop() { when(SP.getString(R.string.key_aps_mode, "open")).thenReturn("closed"); when(MainApp.isEngineeringModeOrRelease()).thenReturn(false); Constraint<Boolean> c = new Constraint<>(true); c = safetyPlugin.isClosedLoopAllowed(c); Assert.assertTrue(c.getReasons().contains("Running dev version. Closed loop is disabled.")); Assert.assertEquals(Boolean.FALSE, c.value()); }
@Test public void setOpenLoopInPreferencesShouldLimitClosedLoop() { when(SP.getString(R.string.key_aps_mode, "open")).thenReturn("open"); Constraint<Boolean> c = new Constraint<>(true); c = safetyPlugin.isClosedLoopAllowed(c); Assert.assertTrue(c.getReasons().contains("Closed loop mode disabled in preferences")); Assert.assertEquals(Boolean.FALSE, c.value()); }