ActionProfileSwitchPercent extends Action { @Override public Action fromJSON(String data) { try { JSONObject d = new JSONObject(data); pct.setValue(JsonHelper.safeGetInt(d, "percentage")); duration.setMinutes(JsonHelper.safeGetInt(d, "durationInMinutes")); } catch (JSONException e) { log.error("Unhandled exception", e); } return this; } 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 fromJSONTest() { actionProfileSwitchPercent = new ActionProfileSwitchPercent(); actionProfileSwitchPercent.fromJSON("{\"percentage\":100,\"durationInMinutes\":30}"); Assert.assertEquals(100, actionProfileSwitchPercent.pct.getValue(), 0.001d); Assert.assertEquals(30, actionProfileSwitchPercent.duration.getMinutes(), 0.001); }