ActionStartTempTarget extends Action { @Override public Action fromJSON(String data) { try { JSONObject d = new JSONObject(data); reason = JsonHelper.safeGetString(d, "reason"); value.setUnits(JsonHelper.safeGetString(d, "units")); value.setValue(JsonHelper.safeGetDouble(d, "value")); duration.setMinutes(JsonHelper.safeGetInt(d, "durationInMinutes")); } catch (JSONException e) { log.error("Unhandled exception", e); } return this; } ActionStartTempTarget(); @Override int friendlyName(); @Override String shortDescription(); @Override void doAction(Callback callback); @Override void generateDialog(LinearLayout root); @Override boolean hasDialog(); @Override String toJSON(); @Override Action fromJSON(String data); @Override Optional<Integer> icon();  }
@Test public void fromJSONTest() { actionStartTempTarget = new ActionStartTempTarget(); actionStartTempTarget.fromJSON("{\"reason\":\"Test\",\"value\":100,\"durationInMinutes\":30,\"units\":\"mg/dl\"}"); Assert.assertEquals(Constants.MGDL, actionStartTempTarget.value.getUnits()); Assert.assertEquals(100, actionStartTempTarget.value.getValue(), 0.001d); Assert.assertEquals(30, actionStartTempTarget.duration.getMinutes(), 0.001); Assert.assertEquals("Test", actionStartTempTarget.reason); }