IobTotal implements DataPointWithLabelInterface { public JSONObject json() { JSONObject json = new JSONObject(); try { json.put("iob", iob); json.put("basaliob", basaliob); json.put("activity", activity); json.put("time", DateUtil.toISOString(new Date())); } catch (JSONException e) { log.error("Unhandled exception", e); } return json; } IobTotal(long time); IobTotal copy(); IobTotal plus(IobTotal other); static IobTotal combine(IobTotal bolusIOB, IobTotal basalIob); IobTotal round(); JSONObject json(); JSONObject determineBasalJson(); @Override double getX(); @Override double getY(); @Override void setY(double y); @Override String getLabel(); @Override long getDuration(); @Override PointsWithLabelGraphSeries.Shape getShape(); @Override float getSize(); @Override int getColor(); IobTotal setColor(int color); public double iob; public double activity; public double bolussnooze; public double basaliob; public double netbasalinsulin; public double hightempinsulin; public long lastBolusTime; public IobTotal iobWithZeroTemp; public double netInsulin; public double netRatio; public double extendedBolusInsulin; }
@Test public void jsonTest() { IobTotal a = new IobTotal(now); a.iob = 10; a.activity = 11; a.bolussnooze = 12; a.basaliob = 13; a.netbasalinsulin = 14; a.hightempinsulin = 15; a.netInsulin = 16; a.extendedBolusInsulin = 17; try { JSONObject j = a.json(); Assert.assertEquals(a.iob, j.getDouble("iob"), 0.0000001d); Assert.assertEquals(a.basaliob, j.getDouble("basaliob"), 0.0000001d); Assert.assertEquals(a.activity, j.getDouble("activity"), 0.0000001d); Assert.assertEquals(now, DateUtil.fromISODateString(j.getString("time")).getTime(), 1000); } catch (Exception e) { Assert.fail("Exception: " + e.getMessage()); } }