commit
fe532598c4
2 changed files with 59 additions and 44 deletions
|
@ -19,11 +19,13 @@ import info.nightscout.androidaps.data.ConstraintChecker;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.data.ProfileStore;
|
import info.nightscout.androidaps.data.ProfileStore;
|
||||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||||
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Treatments.TreatmentService;
|
import info.nightscout.androidaps.plugins.Treatments.TreatmentService;
|
||||||
import info.nightscout.androidaps.queue.CommandQueue;
|
import info.nightscout.androidaps.queue.CommandQueue;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.anyLong;
|
import static org.mockito.ArgumentMatchers.anyLong;
|
||||||
|
@ -122,6 +124,11 @@ public class AAPSMocker {
|
||||||
when(SP.getInt(anyInt(), anyInt())).thenReturn(0);
|
when(SP.getInt(anyInt(), anyInt())).thenReturn(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void mockL() {
|
||||||
|
PowerMockito.mockStatic(L.class);
|
||||||
|
when(L.isEnabled(any())).thenReturn(true);
|
||||||
|
}
|
||||||
|
|
||||||
public static void mockApplicationContext() {
|
public static void mockApplicationContext() {
|
||||||
Context context = mock(Context.class);
|
Context context = mock(Context.class);
|
||||||
when(MainApp.instance().getApplicationContext()).thenReturn(context);
|
when(MainApp.instance().getApplicationContext()).thenReturn(context);
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
|
package info.nightscout.androidaps.plugins.PumpDanaRS.comm;
|
||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
|
@ -10,77 +8,87 @@ import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
import info.AAPSMocker;
|
import info.AAPSMocker;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
import info.nightscout.utils.ToastUtils;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 20.11.2017.
|
* Created by mike on 20.11.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@PrepareForTest({MainApp.class, SP.class})
|
@PrepareForTest({MainApp.class, SP.class, L.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
|
@Test
|
||||||
public void runTest() {
|
public void runTest() {
|
||||||
AAPSMocker.mockMainApp();
|
AAPSMocker.mockMainApp();
|
||||||
AAPSMocker.mockApplicationContext();
|
AAPSMocker.mockApplicationContext();
|
||||||
AAPSMocker.mockSP();
|
AAPSMocker.mockSP();
|
||||||
|
AAPSMocker.mockL();
|
||||||
|
|
||||||
// under 100% should last 30 min
|
// under 100% should last 30 min
|
||||||
setParams(0);
|
DanaRS_Packet_APS_Basal_Set_Temporary_Basal packet = new DanaRS_Packet_APS_Basal_Set_Temporary_Basal();
|
||||||
assertEquals(0, temporaryBasalRatio);
|
packet.setParams(0);
|
||||||
assertEquals(PARAM30MIN, temporaryBasalDuration);
|
assertEquals(0, packet.temporaryBasalRatio);
|
||||||
|
assertEquals(packet.PARAM30MIN, packet.temporaryBasalDuration);
|
||||||
|
//constructor with param
|
||||||
|
packet = new DanaRS_Packet_APS_Basal_Set_Temporary_Basal(10);
|
||||||
|
assertEquals(10, packet.temporaryBasalRatio);
|
||||||
|
assertEquals(packet.PARAM30MIN, packet.temporaryBasalDuration);
|
||||||
|
packet = new DanaRS_Packet_APS_Basal_Set_Temporary_Basal(20, true, false);
|
||||||
|
assertEquals(20, packet.temporaryBasalRatio);
|
||||||
|
assertEquals(packet.PARAM15MIN, packet.temporaryBasalDuration);
|
||||||
// over 100% should last 15 min
|
// over 100% should last 15 min
|
||||||
setParams(150);
|
packet.setParams(150);
|
||||||
assertEquals(150, temporaryBasalRatio);
|
assertEquals(150, packet.temporaryBasalRatio);
|
||||||
assertEquals(PARAM15MIN, temporaryBasalDuration);
|
assertEquals(packet.PARAM15MIN, packet.temporaryBasalDuration);
|
||||||
// test low hard limit
|
// test low hard limit
|
||||||
setParams(-1);
|
packet.setParams(-1);
|
||||||
assertEquals(0, temporaryBasalRatio);
|
assertEquals(0, packet.temporaryBasalRatio);
|
||||||
assertEquals(PARAM30MIN, temporaryBasalDuration);
|
assertEquals(packet.PARAM30MIN, packet.temporaryBasalDuration);
|
||||||
// test high hard limit
|
// test high hard limit
|
||||||
setParams(550);
|
packet.setParams(550);
|
||||||
assertEquals(500, temporaryBasalRatio);
|
assertEquals(500, packet.temporaryBasalRatio);
|
||||||
assertEquals(PARAM15MIN, temporaryBasalDuration);
|
assertEquals(packet.PARAM15MIN, packet.temporaryBasalDuration);
|
||||||
// test setting 15 min
|
// test setting 15 min
|
||||||
setParams(50, true, false);
|
packet.setParams(50, true, false);
|
||||||
assertEquals(50, temporaryBasalRatio);
|
assertEquals(50, packet.temporaryBasalRatio);
|
||||||
assertEquals(PARAM15MIN, temporaryBasalDuration);
|
assertEquals(packet.PARAM15MIN, packet.temporaryBasalDuration);
|
||||||
// test setting 30 min
|
// test setting 30 min
|
||||||
setParams(50, false, true);
|
packet.setParams(50, false, true);
|
||||||
assertEquals(50, temporaryBasalRatio);
|
assertEquals(50, packet.temporaryBasalRatio);
|
||||||
assertEquals(PARAM30MIN, temporaryBasalDuration);
|
assertEquals(packet.PARAM30MIN, packet.temporaryBasalDuration);
|
||||||
// over 200% set always 15 min
|
// over 200% set always 15 min
|
||||||
setParams(250, false, true);
|
packet.setParams(250, false, true);
|
||||||
assertEquals(250, temporaryBasalRatio);
|
assertEquals(250, packet.temporaryBasalRatio);
|
||||||
assertEquals(PARAM15MIN, temporaryBasalDuration);
|
assertEquals(packet.PARAM15MIN, packet.temporaryBasalDuration);
|
||||||
// test low hard limit
|
// test low hard limit
|
||||||
setParams(-1, false, true);
|
packet.setParams(-1, false, true);
|
||||||
assertEquals(0, temporaryBasalRatio);
|
assertEquals(0, packet.temporaryBasalRatio);
|
||||||
assertEquals(PARAM30MIN, temporaryBasalDuration);
|
assertEquals(packet.PARAM30MIN, packet.temporaryBasalDuration);
|
||||||
// test high hard limit
|
// test high hard limit
|
||||||
setParams(550, false,true);
|
packet.setParams(550, false, true);
|
||||||
assertEquals(500, temporaryBasalRatio);
|
assertEquals(500, packet.temporaryBasalRatio);
|
||||||
assertEquals(PARAM15MIN, temporaryBasalDuration);
|
assertEquals(packet.PARAM15MIN, packet.temporaryBasalDuration);
|
||||||
|
|
||||||
// test message generation
|
// test message generation
|
||||||
setParams(260, true, false);
|
packet.setParams(260, true, false);
|
||||||
byte[] generatedCode = getRequestParams();
|
byte[] generatedCode = packet.getRequestParams();
|
||||||
assertEquals(3 , generatedCode.length);
|
assertEquals(3, generatedCode.length);
|
||||||
assertEquals((byte)4 , generatedCode[0]);
|
assertEquals((byte) 4, generatedCode[0]);
|
||||||
assertEquals((byte)1 , generatedCode[1]);
|
assertEquals((byte) 1, generatedCode[1]);
|
||||||
assertEquals((byte)PARAM15MIN, generatedCode[2]);
|
assertEquals((byte) packet.PARAM15MIN, generatedCode[2]);
|
||||||
|
|
||||||
// test message decoding
|
// test message decoding
|
||||||
handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 0});
|
packet.handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 0});
|
||||||
assertEquals(false, failed);
|
assertEquals(false, packet.failed);
|
||||||
handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 1});
|
packet.handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 1});
|
||||||
assertEquals(true, failed);
|
assertEquals(true, packet.failed);
|
||||||
|
|
||||||
assertEquals("BASAL__APS_SET_TEMPORARY_BASAL", getFriendlyName());
|
assertEquals("BASAL__APS_SET_TEMPORARY_BASAL", packet.getFriendlyName());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue