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() { public synchronized boolean shouldRun() {
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensData("Automation trigger"); AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensData("Automation trigger");
if (autosensData == null) 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()) if (lastRun > DateUtil.now() - T.mins(5).msecs())
return false; return false;
@ -120,7 +123,7 @@ public class TriggerAutosensValue extends Trigger {
@Override @Override
public Optional<Integer> icon() { public Optional<Integer> icon() {
return Optional.of(R.drawable.as); return Optional.of(R.drawable.as);
} }
@Override @Override

View file

@ -66,6 +66,11 @@ public class TriggerAutosensValueTest {
t = new TriggerAutosensValue().comparator(Comparator.Compare.IS_NOT_AVAILABLE); t = new TriggerAutosensValue().comparator(Comparator.Compare.IS_NOT_AVAILABLE);
Assert.assertTrue(t.shouldRun()); 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); t = new TriggerAutosensValue().setValue(214).comparator(Comparator.Compare.IS_EQUAL).lastRun(now - 1);
Assert.assertFalse(t.shouldRun()); Assert.assertFalse(t.shouldRun());