isAutosensModeEnabled reactor & tests

This commit is contained in:
Milos Kozak 2018-03-19 22:36:08 +01:00
parent f6fdef7986
commit f8a3b7aee7
9 changed files with 33 additions and 19 deletions

View file

@ -29,6 +29,10 @@ public class ConstraintChecker implements ConstraintsInterface {
return isClosedLoopAllowed(new Constraint<>(true));
}
public Constraint<Boolean> isAutosensModeEnabled() {
return isAutosensModeEnabled(new Constraint<>(true));
}
@Override
public Constraint<Boolean> isLoopInvokationAllowed(Constraint<Boolean> value) {
@ -54,16 +58,15 @@ public class ConstraintChecker implements ConstraintsInterface {
}
@Override
public boolean isAutosensModeEnabled() {
boolean result = true;
public Constraint<Boolean> isAutosensModeEnabled(Constraint<Boolean> value) {
ArrayList<PluginBase> constraintsPlugins = mainApp.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p;
ConstraintsInterface constraint = (ConstraintsInterface) p;
if (!p.isEnabled(PluginBase.CONSTRAINTS)) continue;
result = result && constrain.isAutosensModeEnabled();
constraint.isAutosensModeEnabled(value);
}
return result;
return value;
}
@Override

View file

@ -9,7 +9,7 @@ public interface ConstraintsInterface {
Constraint<Boolean> isClosedLoopAllowed(Constraint<Boolean> value);
boolean isAutosensModeEnabled();
Constraint<Boolean> isAutosensModeEnabled(Constraint<Boolean> value);
boolean isAMAModeEnabled();

View file

@ -313,8 +313,10 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
}
@Override
public boolean isAutosensModeEnabled() {
return objectives.get(5).started.getTime() > 0;
public Constraint<Boolean> isAutosensModeEnabled(Constraint<Boolean> value) {
if (objectives.get(5).started.getTime() == 0)
value.set(false, String.format(MainApp.gs(R.string.objectivenotstarted), 6));
return value;
}
@Override

View file

@ -114,8 +114,8 @@ public class SafetyPlugin implements PluginBase, ConstraintsInterface {
}
@Override
public boolean isAutosensModeEnabled() {
return true;
public Constraint<Boolean> isAutosensModeEnabled(Constraint<Boolean> value) {
return value;
}
@Override

View file

@ -1438,8 +1438,8 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
}
@Override
public boolean isAutosensModeEnabled() {
return true;
public Constraint<Boolean> isAutosensModeEnabled(Constraint<Boolean> value) {
return value;
}
@Override

View file

@ -444,8 +444,8 @@ public abstract class AbstractDanaRPlugin implements PluginBase, PumpInterface,
}
@Override
public boolean isAutosensModeEnabled() {
return true;
public Constraint<Boolean> isAutosensModeEnabled(Constraint<Boolean> value) {
return value;
}
@Override

View file

@ -284,8 +284,8 @@ public class DanaRSPlugin implements PluginBase, PumpInterface, DanaRInterface,
}
@Override
public boolean isAutosensModeEnabled() {
return true;
public Constraint<Boolean> isAutosensModeEnabled(Constraint<Boolean> value) {
return value;
}
@Override

View file

@ -1090,8 +1090,8 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints
}
@Override
public boolean isAutosensModeEnabled() {
return true;
public Constraint<Boolean> isAutosensModeEnabled(Constraint<Boolean> value) {
return value;
}
@Override

View file

@ -41,7 +41,6 @@ public class ConstraintsCheckerTest {
ConfigBuilderPlugin configBuilderPlugin = mock(ConfigBuilderPlugin.class);
MainApp mainApp = mock(MainApp.class);
MockedBus bus = new MockedBus();
//PumpDescription pumpDescription = new PumpDescription();
SafetyPlugin safetyPlugin;
ObjectivesPlugin objectivesPlugin;
@ -108,6 +107,16 @@ public class ConstraintsCheckerTest {
Assert.assertEquals(Boolean.FALSE, c.get());
}
// isAutosensModeEnabled tests
@Test
public void notStartedObjective6ShouldLimitAutosensMode() throws Exception {
objectivesPlugin.objectives.get(5).setStarted(new Date(0));
Constraint<Boolean> c = constraintChecker.isAutosensModeEnabled();
Assert.assertEquals(true, c.getReasons().contains("Objective 6 not started"));
Assert.assertEquals(Boolean.FALSE, c.get());
}
@Before
public void prepareMock() throws Exception {
PowerMockito.mockStatic(ConfigBuilderPlugin.class);