TriggerTempTarget extends Trigger { @Override public synchronized boolean shouldRun() { TempTarget tt = TreatmentsPlugin.getPlugin().getTempTargetFromHistory(); if (lastRun > DateUtil.now() - T.mins(5).msecs()) return false; if (tt == null && comparator.getValue() == ComparatorExists.Compare.NOT_EXISTS) { if (L.isEnabled(L.AUTOMATION)) log.debug("Ready for execution: " + friendlyDescription()); return true; } if (tt != null && comparator.getValue() == ComparatorExists.Compare.EXISTS) { if (L.isEnabled(L.AUTOMATION)) log.debug("Ready for execution: " + friendlyDescription()); return true; } return false; } TriggerTempTarget(); private  TriggerTempTarget(TriggerTempTarget triggerTempTarget); ComparatorExists getComparator(); @Override synchronized boolean shouldRun(); @Override synchronized String toJSON(); @Override int friendlyName(); @Override String friendlyDescription(); @Override Optional<Integer> icon(); @Override Trigger duplicate(); TriggerTempTarget comparator(ComparatorExists.Compare compare); @Override void generateDialog(LinearLayout root, FragmentManager fragmentManager);  }
@Test public void shouldRunTest() { when(treatmentsPlugin.getTempTargetFromHistory()).thenReturn(null); TriggerTempTarget t = new TriggerTempTarget().comparator(ComparatorExists.Compare.EXISTS); Assert.assertFalse(t.shouldRun()); t = new TriggerTempTarget().comparator(ComparatorExists.Compare.NOT_EXISTS); Assert.assertTrue(t.shouldRun()); when(treatmentsPlugin.getTempTargetFromHistory()).thenReturn(new TempTarget()); t = new TriggerTempTarget().comparator(ComparatorExists.Compare.NOT_EXISTS); Assert.assertFalse(t.shouldRun()); t = new TriggerTempTarget().comparator(ComparatorExists.Compare.EXISTS); Assert.assertTrue(t.shouldRun()); t = new TriggerTempTarget().comparator(ComparatorExists.Compare.EXISTS).lastRun(now - 1); Assert.assertFalse(t.shouldRun()); }