TriggerDelta extends Trigger { @Override Trigger fromJSON(String data) { try { JSONObject d = new JSONObject(data); units = JsonHelper.safeGetString(d, "units"); deltaType = DeltaType.valueOf(JsonHelper.safeGetString(d, "deltaType", "")); value.setValue(JsonHelper.safeGetDouble(d, "value"), deltaType); lastRun = JsonHelper.safeGetLong(d, "lastRun"); comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator"))); } catch (Exception e) { log.error("Unhandled exception", e); } return this; } TriggerDelta(); private  TriggerDelta(TriggerDelta triggerDelta); double getValue(); DeltaType getType(); String getUnits(); 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 fromJSONTest() throws JSONException { TriggerDelta t = new TriggerDelta().setUnits(Constants.MMOL).setValue(4.1d, DeltaType.DELTA).comparator(Comparator.Compare.IS_EQUAL); TriggerDelta t2 = (TriggerDelta) Trigger.instantiate(new JSONObject(t.toJSON())); Assert.assertEquals(Comparator.Compare.IS_EQUAL, t2.getComparator().getValue()); Assert.assertEquals(4.1d, t2.getValue(), 0.01d); Assert.assertEquals(Constants.MMOL, t2.getUnits()); Assert.assertEquals(DeltaType.DELTA, t2.getType()); }