diff --git a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.java b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.java index 8958ffa25d..52de2d12c5 100644 --- a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.java +++ b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.java @@ -58,11 +58,11 @@ public class ConstraintsCheckerTest { boolean notificationSent = false; - public ConstraintsCheckerTest() throws JSONException { + public ConstraintsCheckerTest() { } @Test - public void isLoopInvokationAllowedTest() throws Exception { + public void isLoopInvokationAllowedTest() { comboPlugin.setPluginEnabled(PluginType.PUMP, true); comboPlugin.setValidBasalRateProfileSelectedOnPump(false); @@ -73,9 +73,9 @@ public class ConstraintsCheckerTest { } @Test - public void isClosedLoopAllowedTest() throws Exception { + public void isClosedLoopAllowedTest() { when(SP.getString(R.string.key_aps_mode, "open")).thenReturn("closed"); - objectivesPlugin.getObjectives().get(ObjectivesPlugin.CLOSED_LOOP_OBJECTIVE).setStartedOn(null); + objectivesPlugin.getObjectives().get(ObjectivesPlugin.INSTANCE.getMAXIOB_ZERO_CL_OBJECTIVE()).setStartedOn(0); Constraint c = constraintChecker.isClosedLoopAllowed(); Assert.assertEquals(true, c.getReasonList().size() == 2); // Safety & Objectives @@ -90,8 +90,8 @@ public class ConstraintsCheckerTest { } @Test - public void isAutosensModeEnabledTest() throws Exception { - objectivesPlugin.getObjectives().get(ObjectivesPlugin.Companion.getAUTOSENS_OBJECTIVE()).setStartedOn(null); + public void isAutosensModeEnabledTest() { + objectivesPlugin.getObjectives().get(ObjectivesPlugin.INSTANCE.getAUTOSENS_OBJECTIVE()).setStartedOn(0); when(SP.getBoolean(R.string.key_openapsama_useautosens, false)).thenReturn(false); Constraint c = constraintChecker.isAutosensModeEnabled(); @@ -101,8 +101,8 @@ public class ConstraintsCheckerTest { } @Test - public void isAMAModeEnabledTest() throws Exception { - objectivesPlugin.getObjectives().get(ObjectivesPlugin.Companion.getAMA_OBJECTIVE()).setStartedOn(null); + public void isAMAModeEnabledTest() { + objectivesPlugin.getObjectives().get(ObjectivesPlugin.INSTANCE.getAMA_OBJECTIVE()).setStartedOn(0); Constraint c = constraintChecker.isAMAModeEnabled(); Assert.assertEquals(true, c.getReasonList().size() == 1); // Objectives @@ -111,7 +111,7 @@ public class ConstraintsCheckerTest { } @Test - public void isAdvancedFilteringEnabledTest() throws Exception { + public void isAdvancedFilteringEnabledTest() { when(ConfigBuilderPlugin.getPlugin().getActiveBgSource()).thenReturn(SourceGlimpPlugin.getPlugin()); Constraint c = constraintChecker.isAdvancedFilteringEnabled(); @@ -130,7 +130,7 @@ public class ConstraintsCheckerTest { @Test public void isSMBModeEnabledTest() throws Exception { - objectivesPlugin.getObjectives().get(ObjectivesPlugin.Companion.getSMB_OBJECTIVE()).setStartedOn(null); + objectivesPlugin.getObjectives().get(ObjectivesPlugin.INSTANCE.getSMB_OBJECTIVE()).setStartedOn(0); when(SP.getBoolean(R.string.key_use_smb, false)).thenReturn(false); when(MainApp.getConstraintChecker().isClosedLoopAllowed()).thenReturn(new Constraint<>(true)); @@ -294,7 +294,7 @@ public class ConstraintsCheckerTest { constraintChecker = new ConstraintChecker(); safetyPlugin = SafetyPlugin.getPlugin(); - objectivesPlugin = ObjectivesPlugin.Companion.getPlugin(); + objectivesPlugin = ObjectivesPlugin.INSTANCE; comboPlugin = ComboPlugin.getPlugin(); danaRPlugin = DanaRPlugin.getPlugin(); danaRSPlugin = DanaRSPlugin.getPlugin(); diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.java index 2425e3852d..7c9514629d 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.java @@ -14,6 +14,7 @@ import info.AAPSMocker; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; +import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.SP; /** @@ -27,53 +28,53 @@ public class ObjectivesPluginTest { ObjectivesPlugin objectivesPlugin; @Test - public void notStartedObjectivesShouldLimitLoopInvocation() throws Exception { - objectivesPlugin.getObjectives().get(ObjectivesPlugin.Companion.getFIRST_OBJECTIVE()).setStartedOn(null); + public void notStartedObjectivesShouldLimitLoopInvocation() { + objectivesPlugin.getObjectives().get(ObjectivesPlugin.INSTANCE.getFIRST_OBJECTIVE()).setStartedOn(0); Constraint c = new Constraint<>(true); c = objectivesPlugin.isLoopInvocationAllowed(c); Assert.assertEquals("Objectives: Objective 1 not started", c.getReasons()); Assert.assertEquals(Boolean.FALSE, c.value()); - objectivesPlugin.getObjectives().get(ObjectivesPlugin.Companion.getFIRST_OBJECTIVE()).setStartedOn(new Date()); + objectivesPlugin.getObjectives().get(ObjectivesPlugin.INSTANCE.getFIRST_OBJECTIVE()).setStartedOn(DateUtil.now()); } @Test - public void notStartedObjective4ShouldLimitClosedLoop() throws Exception { - objectivesPlugin.getObjectives().get(ObjectivesPlugin.CLOSED_LOOP_OBJECTIVE).setStartedOn(null); + public void notStartedObjective6ShouldLimitClosedLoop() { + objectivesPlugin.getObjectives().get(ObjectivesPlugin.INSTANCE.getMAXIOB_ZERO_CL_OBJECTIVE()).setStartedOn(0); Constraint c = new Constraint<>(true); c = objectivesPlugin.isClosedLoopAllowed(c); - Assert.assertEquals(true, c.getReasons().contains("Objective 4 not started")); - Assert.assertEquals(Boolean.FALSE, c.value()); - } - - @Test - public void notStartedObjective6ShouldLimitAutosensMode() throws Exception { - objectivesPlugin.getObjectives().get(ObjectivesPlugin.Companion.getAUTOSENS_OBJECTIVE()).setStartedOn(null); - - Constraint c = new Constraint<>(true); - c = objectivesPlugin.isAutosensModeEnabled(c); Assert.assertEquals(true, c.getReasons().contains("Objective 6 not started")); Assert.assertEquals(Boolean.FALSE, c.value()); } @Test - public void notStartedObjective7ShouldLimitAMAMode() throws Exception { - objectivesPlugin.getObjectives().get(ObjectivesPlugin.Companion.getAMA_OBJECTIVE()).setStartedOn(null); + public void notStartedObjective8ShouldLimitAutosensMode() { + objectivesPlugin.getObjectives().get(ObjectivesPlugin.INSTANCE.getAUTOSENS_OBJECTIVE()).setStartedOn(0); Constraint c = new Constraint<>(true); - c = objectivesPlugin.isAMAModeEnabled(c); - Assert.assertEquals(true, c.getReasons().contains("Objective 7 not started")); + c = objectivesPlugin.isAutosensModeEnabled(c); + Assert.assertEquals(true, c.getReasons().contains("Objective 8 not started")); Assert.assertEquals(Boolean.FALSE, c.value()); } @Test - public void notStartedObjective8ShouldLimitSMBMode() throws Exception { - objectivesPlugin.getObjectives().get(ObjectivesPlugin.Companion.getSMB_OBJECTIVE()).setStartedOn(null); + public void notStartedObjective9ShouldLimitAMAMode() { + objectivesPlugin.getObjectives().get(ObjectivesPlugin.INSTANCE.getAMA_OBJECTIVE()).setStartedOn(0); + + Constraint c = new Constraint<>(true); + c = objectivesPlugin.isAMAModeEnabled(c); + Assert.assertEquals(true, c.getReasons().contains("Objective 9 not started")); + Assert.assertEquals(Boolean.FALSE, c.value()); + } + + @Test + public void notStartedObjective10ShouldLimitSMBMode() { + objectivesPlugin.getObjectives().get(ObjectivesPlugin.INSTANCE.getSMB_OBJECTIVE()).setStartedOn(0); Constraint c = new Constraint<>(true); c = objectivesPlugin.isSMBModeEnabled(c); - Assert.assertEquals(true, c.getReasons().contains("Objective 8 not started")); + Assert.assertEquals(true, c.getReasons().contains("Objective 10 not started")); Assert.assertEquals(Boolean.FALSE, c.value()); } @@ -85,6 +86,6 @@ public class ObjectivesPluginTest { AAPSMocker.mockSP(); AAPSMocker.mockStrings(); - objectivesPlugin = ObjectivesPlugin.Companion.getPlugin(); + objectivesPlugin = ObjectivesPlugin.INSTANCE; } }