TriggerCOB extends Trigger { @Override public synchronized boolean shouldRun() { CobInfo cobInfo = IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "AutomationTriggerCOB"); if (cobInfo == null) if (comparator.getValue() == Comparator.Compare.IS_NOT_AVAILABLE) return true; else return false; if (lastRun > DateUtil.now() - T.mins(5).msecs()) return false; boolean doRun = comparator.getValue().check((cobInfo.displayCob), getValue()); if (doRun) { if (L.isEnabled(L.AUTOMATION)) log.debug("Ready for execution: " + friendlyDescription()); return true; } return false; } TriggerCOB(); private  TriggerCOB(TriggerCOB triggerCOB); 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.getPlugin().getCobInfo(false, "AutomationTriggerCOB")).thenReturn(new CobInfo(6d, 2d)); TriggerCOB t = new TriggerCOB().setValue(1).comparator(Comparator.Compare.IS_EQUAL); Assert.assertFalse(t.shouldRun()); t = new TriggerCOB().setValue(6).comparator(Comparator.Compare.IS_EQUAL); Assert.assertTrue(t.shouldRun()); t = new TriggerCOB().setValue(5).comparator(Comparator.Compare.IS_GREATER); Assert.assertTrue(t.shouldRun()); t = new TriggerCOB().setValue(5).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER); Assert.assertTrue(t.shouldRun()); t = new TriggerCOB().setValue(6).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER); Assert.assertTrue(t.shouldRun()); t = new TriggerCOB().setValue(1).comparator(Comparator.Compare.IS_EQUAL); Assert.assertFalse(t.shouldRun()); t = new TriggerCOB().setValue(10).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER); Assert.assertTrue(t.shouldRun()); t = new TriggerCOB().setValue(5).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER); Assert.assertFalse(t.shouldRun()); t = new TriggerCOB().setValue(1).comparator(Comparator.Compare.IS_EQUAL).lastRun(now - 1); Assert.assertFalse(t.shouldRun()); }