ActionProfileSwitchPercent extends Action { @Override public String toJSON() { JSONObject o = new JSONObject(); try { o.put("type", ActionProfileSwitchPercent.class.getName()); JSONObject data = new JSONObject(); data.put("percentage", pct.getValue()); data.put("durationInMinutes", duration.getMinutes()); o.put("data", data); } catch (JSONException e) { log.error("Unhandled exception", e); } return o.toString(); } ActionProfileSwitchPercent(); @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() { actionProfileSwitchPercent = new ActionProfileSwitchPercent(); actionProfileSwitchPercent.pct = new InputPercent().setValue(100); actionProfileSwitchPercent.duration = new InputDuration(30, InputDuration.TimeUnit.MINUTES); Assert.assertEquals("{\"data\":{\"percentage\":100,\"durationInMinutes\":30},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionProfileSwitchPercent\"}", actionProfileSwitchPercent.toJSON()); }