fix test coverage

This commit is contained in:
Milos Kozak 2018-08-02 15:53:36 +02:00
parent ce0730793f
commit 12883a407e

View file

@ -1,8 +1,6 @@
package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
import android.content.Context;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -10,9 +8,7 @@ import org.powermock.modules.junit4.PowerMockRunner;
import info.AAPSMocker;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.utils.SP;
import info.nightscout.utils.ToastUtils;
import static org.junit.Assert.assertEquals;
@ -22,7 +18,7 @@ import static org.junit.Assert.assertEquals;
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class})
public class DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest extends DanaRS_Packet_APS_Basal_Set_Temporary_Basal {
public class DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest {
@Test
public void runTest() {
@ -30,57 +26,58 @@ public class DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest extends DanaRS_Pack
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
// under 100% should last 30 min
setParams(0);
assertEquals(0, temporaryBasalRatio);
assertEquals(PARAM30MIN, temporaryBasalDuration);
DanaRS_Packet_APS_Basal_Set_Temporary_Basal packet = new DanaRS_Packet_APS_Basal_Set_Temporary_Basal();
packet.setParams(0);
assertEquals(0, packet.temporaryBasalRatio);
assertEquals(packet.PARAM30MIN, packet.temporaryBasalDuration);
// over 100% should last 15 min
setParams(150);
assertEquals(150, temporaryBasalRatio);
assertEquals(PARAM15MIN, temporaryBasalDuration);
packet.setParams(150);
assertEquals(150, packet.temporaryBasalRatio);
assertEquals(packet.PARAM15MIN, packet.temporaryBasalDuration);
// test low hard limit
setParams(-1);
assertEquals(0, temporaryBasalRatio);
assertEquals(PARAM30MIN, temporaryBasalDuration);
packet.setParams(-1);
assertEquals(0, packet.temporaryBasalRatio);
assertEquals(packet.PARAM30MIN, packet.temporaryBasalDuration);
// test high hard limit
setParams(550);
assertEquals(500, temporaryBasalRatio);
assertEquals(PARAM15MIN, temporaryBasalDuration);
packet.setParams(550);
assertEquals(500, packet.temporaryBasalRatio);
assertEquals(packet.PARAM15MIN, packet.temporaryBasalDuration);
// test setting 15 min
setParams(50, true, false);
assertEquals(50, temporaryBasalRatio);
assertEquals(PARAM15MIN, temporaryBasalDuration);
packet.setParams(50, true, false);
assertEquals(50, packet.temporaryBasalRatio);
assertEquals(packet.PARAM15MIN, packet.temporaryBasalDuration);
// test setting 30 min
setParams(50, false, true);
assertEquals(50, temporaryBasalRatio);
assertEquals(PARAM30MIN, temporaryBasalDuration);
packet.setParams(50, false, true);
assertEquals(50, packet.temporaryBasalRatio);
assertEquals(packet.PARAM30MIN, packet.temporaryBasalDuration);
// over 200% set always 15 min
setParams(250, false, true);
assertEquals(250, temporaryBasalRatio);
assertEquals(PARAM15MIN, temporaryBasalDuration);
packet.setParams(250, false, true);
assertEquals(250, packet.temporaryBasalRatio);
assertEquals(packet.PARAM15MIN, packet.temporaryBasalDuration);
// test low hard limit
setParams(-1, false, true);
assertEquals(0, temporaryBasalRatio);
assertEquals(PARAM30MIN, temporaryBasalDuration);
packet.setParams(-1, false, true);
assertEquals(0, packet.temporaryBasalRatio);
assertEquals(packet.PARAM30MIN, packet.temporaryBasalDuration);
// test high hard limit
setParams(550, false,true);
assertEquals(500, temporaryBasalRatio);
assertEquals(PARAM15MIN, temporaryBasalDuration);
packet.setParams(550, false, true);
assertEquals(500, packet.temporaryBasalRatio);
assertEquals(packet.PARAM15MIN, packet.temporaryBasalDuration);
// test message generation
setParams(260, true, false);
byte[] generatedCode = getRequestParams();
assertEquals(3 , generatedCode.length);
assertEquals((byte)4 , generatedCode[0]);
assertEquals((byte)1 , generatedCode[1]);
assertEquals((byte)PARAM15MIN, generatedCode[2]);
packet.setParams(260, true, false);
byte[] generatedCode = packet.getRequestParams();
assertEquals(3, generatedCode.length);
assertEquals((byte) 4, generatedCode[0]);
assertEquals((byte) 1, generatedCode[1]);
assertEquals((byte) packet.PARAM15MIN, generatedCode[2]);
// test message decoding
handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 0});
assertEquals(false, failed);
handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 1});
assertEquals(true, failed);
packet.handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 0});
assertEquals(false, packet.failed);
packet.handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 1});
assertEquals(true, packet.failed);
assertEquals("BASAL__APS_SET_TEMPORARY_BASAL", getFriendlyName());
assertEquals("BASAL__APS_SET_TEMPORARY_BASAL", packet.getFriendlyName());
}
}