MsgBolusProgress extends MessageBase { @Override public void handleMessage(byte[] bytes) { progress = intFromBuff(bytes, 0, 2); lastReceive = System.currentTimeMillis(); Double done = (amount * 100 - progress) / 100d; t.insulin = done; EventOverviewBolusProgress bolusingEvent = EventOverviewBolusProgress.INSTANCE; bolusingEvent.setStatus(String.format(MainApp.gs(R.string.bolusdelivering), done)); bolusingEvent.setT(t); bolusingEvent.setPercent(Math.min((int) (done / amount * 100), 100)); if (L.isEnabled(L.PUMPCOMM)) { log.debug("Bolus remaining: " + progress + " delivered: " + done); } RxBus.INSTANCE.send(bolusingEvent); } MsgBolusProgress();  MsgBolusProgress(double amount, Treatment t); @Override void handleMessage(byte[] bytes); static long lastReceive; public int progress; }
@Test public void runTest() { AAPSMocker.mockMainApp(); AAPSMocker.mockApplicationContext(); AAPSMocker.mockSP(); AAPSMocker.mockL(); AAPSMocker.mockStrings(); Treatment t = new Treatment(); MsgBolusProgress packet = new MsgBolusProgress(3D, t); packet.handleMessage(createArray(34, (byte) 1)); int valueRequested = (((byte) 1 << 8) + ((byte) 1 + 0)); assertEquals(valueRequested, packet.progress,0d); }