PumpEnactResult { public String toHtml() { String ret = "<b>" + MainApp.gs(R.string.success) + "</b>: " + success; if (queued) { ret = MainApp.gs(R.string.waitingforpumpresult); } else if (enacted) { if (bolusDelivered > 0) { ret += "<br><b>" + MainApp.gs(R.string.enacted) + "</b>: " + enacted; if (!comment.isEmpty()) ret += "<br><b>" + MainApp.gs(R.string.comment) + "</b>: " + comment; ret += "<br><b>" + MainApp.gs(R.string.smb_shortname) + "</b>: " + bolusDelivered + " " + MainApp.gs(R.string.insulin_unit_shortname); } else if (isTempCancel) { ret += "<br><b>" + MainApp.gs(R.string.enacted) + "</b>: " + enacted; ret += "<br><b>" + MainApp.gs(R.string.comment) + "</b>: " + comment + "<br>" + MainApp.gs(R.string.canceltemp); } else if (isPercent && percent != -1) { ret += "<br><b>" + MainApp.gs(R.string.enacted) + "</b>: " + enacted; if (!comment.isEmpty()) ret += "<br><b>" + MainApp.gs(R.string.comment) + "</b>: " + comment; ret += "<br><b>" + MainApp.gs(R.string.duration) + "</b>: " + duration + " min"; ret += "<br><b>" + MainApp.gs(R.string.percent) + "</b>: " + percent + "%"; } else if (absolute != -1) { ret += "<br><b>" + MainApp.gs(R.string.enacted) + "</b>: " + enacted; if (!comment.isEmpty()) ret += "<br><b>" + MainApp.gs(R.string.comment) + "</b>: " + comment; ret += "<br><b>" + MainApp.gs(R.string.duration) + "</b>: " + duration + " min"; ret += "<br><b>" + MainApp.gs(R.string.absolute) + "</b>: " + DecimalFormatter.to2Decimal(absolute) + " U/h"; } } else { ret += "<br><b>" + MainApp.gs(R.string.comment) + "</b>: " + comment; } return ret; }  PumpEnactResult success(boolean success); PumpEnactResult enacted(boolean enacted); PumpEnactResult comment(String comment); PumpEnactResult comment(int comment); PumpEnactResult duration(int duration); PumpEnactResult absolute(double absolute); PumpEnactResult percent(int percent); PumpEnactResult isPercent(boolean isPercent); PumpEnactResult isTempCancel(boolean isTempCancel); PumpEnactResult bolusDelivered(double bolusDelivered); PumpEnactResult carbsDelivered(double carbsDelivered); PumpEnactResult queued(boolean queued); String log(); String toString(); String toHtml(); JSONObject json(Profile profile); public boolean success; public boolean enacted; public String comment; public int duration; public double absolute; public int percent; public boolean isPercent; public boolean isTempCancel; public double bolusDelivered; public double carbsDelivered; public boolean queued; }
@Test public void toHtmlTest() throws Exception { per = new PumpEnactResult().enacted(true).bolusDelivered(10).comment("AAA"); Assert.assertEquals("<b>Success</b>: false<br><b>Enacted</b>: true<br><b>Comment</b>: AAA<br><b>SMB</b>: 10.0 U", per.toHtml()); per = new PumpEnactResult().enacted(true).isTempCancel(true).comment("AAA"); Assert.assertEquals("<b>Success</b>: false<br><b>Enacted</b>: true<br><b>Comment</b>: AAA<br>Cancel temp basal", per.toHtml()); per = new PumpEnactResult().enacted(true).isPercent(true).percent(90).duration(20).comment("AAA"); Assert.assertEquals("<b>Success</b>: false<br><b>Enacted</b>: true<br><b>Comment</b>: AAA<br><b>Duration</b>: 20 min<br><b>Percent</b>: 90%", per.toHtml()); per = new PumpEnactResult().enacted(true).isPercent(false).absolute(1).duration(30).comment("AAA"); Assert.assertEquals("<b>Success</b>: false<br><b>Enacted</b>: true<br><b>Comment</b>: AAA<br><b>Duration</b>: 30 min<br><b>Absolute</b>: 1.00 U/h", per.toHtml()); per = new PumpEnactResult().enacted(false).comment("AAA"); Assert.assertEquals("<b>Success</b>: false<br><b>Comment</b>: AAA", per.toHtml()); }