SafetyPlugin extends PluginBase implements ConstraintsInterface { @Override public Constraint<Integer> applyCarbsConstraints(Constraint<Integer> carbs) { carbs.setIfGreater(0, String.format(MainApp.gs(R.string.limitingcarbs), 0, MainApp.gs(R.string.itmustbepositivevalue)), this); Integer maxCarbs = SP.getInt(R.string.key_treatmentssafety_maxcarbs, 48); carbs.setIfSmaller(maxCarbs, String.format(MainApp.gs(R.string.limitingcarbs), maxCarbs, MainApp.gs(R.string.maxvalueinpreferences)), this); return carbs; } 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 carbsAmountShouldBeLimited() { when(SP.getInt(R.string.key_treatmentssafety_maxcarbs, 48)).thenReturn(48); Constraint<Integer> i = new Constraint<>(-22); safetyPlugin.applyCarbsConstraints(i); Assert.assertEquals((Integer) 0, i.value()); Assert.assertEquals("Safety: Limiting carbs to 0 g because of it must be positive value", i.getReasons()); i = safetyPlugin.applyCarbsConstraints(new Constraint<>(Constants.REALLYHIGHCARBS)); Assert.assertEquals((Integer) 48, i.value()); Assert.assertEquals("Safety: Limiting carbs to 48 g because of max value in preferences", i.getReasons()); }