TriggerIob extends Trigger { @Override public synchronized boolean shouldRun() { Profile profile = ProfileFunctions.getInstance().getProfile(); if (profile == null) return false; IobTotal iob = IobCobCalculatorPlugin.getPlugin().calculateFromTreatmentsAndTempsSynchronized(DateUtil.now(), profile); if (lastRun > DateUtil.now() - T.mins(5).msecs()) return false; boolean doRun = comparator.getValue().check(iob.iob, getValue()); if (doRun) { if (L.isEnabled(L.AUTOMATION)) log.debug("Ready for execution: " + friendlyDescription()); return true; } return false; } TriggerIob(); private  TriggerIob(TriggerIob triggerIob); double getValue(); Comparator getComparator(); @Override synchronized boolean shouldRun(); @Override synchronized String toJSON(); @Override int friendlyName(); @Override String friendlyDescription(); @Override Optional<Integer> icon(); @Override Trigger duplicate(); @Override void generateDialog(LinearLayout root, FragmentManager fragmentManager);  }
@Test public void shouldRunTest() { PowerMockito.when(iobCobCalculatorPlugin.calculateFromTreatmentsAndTempsSynchronized(anyLong(), any(Profile.class))).thenReturn(generateIobRecordData()); TriggerIob t = new TriggerIob().setValue(1.1d).comparator(Comparator.Compare.IS_EQUAL); Assert.assertFalse(t.shouldRun()); t = new TriggerIob().setValue(1d).comparator(Comparator.Compare.IS_EQUAL); Assert.assertTrue(t.shouldRun()); t = new TriggerIob().setValue(0.8d).comparator(Comparator.Compare.IS_GREATER); Assert.assertTrue(t.shouldRun()); t = new TriggerIob().setValue(0.8d).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER); Assert.assertTrue(t.shouldRun()); t = new TriggerIob().setValue(0.9d).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER); Assert.assertTrue(t.shouldRun()); t = new TriggerIob().setValue(1.2d).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER); Assert.assertTrue(t.shouldRun()); t = new TriggerIob().setValue(1.1d).comparator(Comparator.Compare.IS_EQUAL); Assert.assertFalse(t.shouldRun()); t = new TriggerIob().setValue(1d).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER); Assert.assertTrue(t.shouldRun()); t = new TriggerIob().setValue(0.9d).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER); Assert.assertFalse(t.shouldRun()); t = new TriggerIob().setValue(1d).comparator(Comparator.Compare.IS_EQUAL).lastRun(now - 1); Assert.assertFalse(t.shouldRun()); }