TriggerLocation extends Trigger { @Override Trigger fromJSON(String data) { try { JSONObject d = new JSONObject(data); latitude.setValue(JsonHelper.safeGetDouble(d, "latitude")); longitude.setValue(JsonHelper.safeGetDouble(d, "longitude")); distance.setValue(JsonHelper.safeGetDouble(d, "distance")); name.setValue(JsonHelper.safeGetString(d, "name")); modeSelected.setValue(InputLocationMode.Mode.valueOf(JsonHelper.safeGetString(d, "mode"))); if (modeSelected.getValue() == GOING_OUT) lastMode = OUTSIDE; lastRun = DateUtil.now(); } catch (Exception e) { log.error("Unhandled exception", e); } return this; } TriggerLocation(); private  TriggerLocation(TriggerLocation triggerLocation); @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 { TriggerLocation t = new TriggerLocation(); t.latitude.setValue(213); t.longitude.setValue(212); t.distance.setValue(2); t.modeSelected.setValue(InputLocationMode.Mode.INSIDE); TriggerLocation t2 = (TriggerLocation) Trigger.instantiate(new JSONObject(t.toJSON())); Assert.assertEquals(t.latitude.getValue(), t2.latitude.getValue(), 0.01d); Assert.assertEquals(t.longitude.getValue(), t2.longitude.getValue(), 0.01d); Assert.assertEquals(t.distance.getValue(), t2.distance.getValue(), 0.01d); Assert.assertEquals(t.modeSelected.getValue(), t2.modeSelected.getValue()); }