unavailable data and IS_NOT_AVAILABLE case

This commit is contained in:
Roumen Georgiev 2019-05-20 11:21:51 +03:00
parent ccd66d498c
commit 27eb11e5df
2 changed files with 10 additions and 2 deletions

View file

@ -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<Integer> icon() {
return Optional.of(R.drawable.as);
return Optional.of(R.drawable.as);
}
@Override

View file

@ -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());