From 27eb11e5df9bd611707473d98a4a117f9e84019f Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Mon, 20 May 2019 11:21:51 +0300 Subject: [PATCH] unavailable data and IS_NOT_AVAILABLE case --- .../general/automation/triggers/TriggerAutosensValue.java | 7 +++++-- .../automation/triggers/TriggerAutosensValueTest.java | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAutosensValue.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAutosensValue.java index 270b344a20..1dfdd5e95e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAutosensValue.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAutosensValue.java @@ -59,7 +59,10 @@ public class TriggerAutosensValue extends Trigger { public synchronized boolean shouldRun() { AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensData("Automation trigger"); if (autosensData == null) - return false; + if (comparator.getValue() == Comparator.Compare.IS_NOT_AVAILABLE) + return true; + else + return false; if (lastRun > DateUtil.now() - T.mins(5).msecs()) return false; @@ -120,7 +123,7 @@ public class TriggerAutosensValue extends Trigger { @Override public Optional icon() { - return Optional.of(R.drawable.as); + return Optional.of(R.drawable.as); } @Override diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAutosensValueTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAutosensValueTest.java index 12594557b1..41ec343e0b 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAutosensValueTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAutosensValueTest.java @@ -66,6 +66,11 @@ public class TriggerAutosensValueTest { t = new TriggerAutosensValue().comparator(Comparator.Compare.IS_NOT_AVAILABLE); Assert.assertTrue(t.shouldRun()); + // Test autosensData == null and Comparator == IS_NOT_AVAILABLE + when(IobCobCalculatorPlugin.getPlugin().getLastAutosensData("Automation trigger")).thenReturn(null); + t = new TriggerAutosensValue().comparator(Comparator.Compare.IS_NOT_AVAILABLE); + Assert.assertTrue(t.shouldRun()); + t = new TriggerAutosensValue().setValue(214).comparator(Comparator.Compare.IS_EQUAL).lastRun(now - 1); Assert.assertFalse(t.shouldRun());