ActionStartTempTarget extends Action { @Override public String toJSON() { JSONObject o = new JSONObject(); try { o.put("type", ActionStartTempTarget.class.getName()); JSONObject data = new JSONObject(); data.put("reason", reason); data.put("value", value.getValue()); data.put("units", value.getUnits()); data.put("durationInMinutes", duration.getMinutes()); o.put("data", data); } catch (JSONException e) { log.error("Unhandled exception", e); } return o.toString(); } 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 toJSONTest() { actionStartTempTarget = new ActionStartTempTarget(); actionStartTempTarget.reason = "Test"; actionStartTempTarget.value = new InputTempTarget().setValue(100).setUnits(Constants.MGDL); actionStartTempTarget.duration = new InputDuration(30, InputDuration.TimeUnit.MINUTES); Assert.assertEquals("{\"data\":{\"reason\":\"Test\",\"durationInMinutes\":30,\"units\":\"mg/dl\",\"value\":100},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionStartTempTarget\"}", actionStartTempTarget.toJSON()); }