TriggerAutosensValue extends Trigger { @Override Trigger fromJSON(String data) { try { JSONObject d = new JSONObject(data); value.setValue(JsonHelper.safeGetDouble(d, "value")); lastRun = JsonHelper.safeGetLong(d, "lastRun"); comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator"))); } catch (Exception e) { log.error("Unhandled exception", e); } return this; } TriggerAutosensValue(); private  TriggerAutosensValue(TriggerAutosensValue triggerAutosensValue); 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 fromJSONTest() throws JSONException { TriggerAutosensValue t = new TriggerAutosensValue().setValue(410).comparator(Comparator.Compare.IS_EQUAL); TriggerAutosensValue t2 = (TriggerAutosensValue) Trigger.instantiate(new JSONObject(t.toJSON())); Assert.assertEquals(Comparator.Compare.IS_EQUAL, t2.getComparator().getValue()); Assert.assertEquals(410, t2.getValue(), 0.01d); }