v2 tests
This commit is contained in:
parent
b73cbacbf5
commit
685b9e007a
|
@ -24,6 +24,7 @@ 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.ConfigBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
|
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
||||||
import info.nightscout.androidaps.plugins.Treatments.TreatmentService;
|
import info.nightscout.androidaps.plugins.Treatments.TreatmentService;
|
||||||
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||||
|
@ -176,8 +177,10 @@ public class AAPSMocker {
|
||||||
public static DanaRPlugin mockDanaRPlugin() {
|
public static DanaRPlugin mockDanaRPlugin() {
|
||||||
PowerMockito.mockStatic(DanaRPlugin.class);
|
PowerMockito.mockStatic(DanaRPlugin.class);
|
||||||
DanaRPlugin danaRPlugin = mock(DanaRPlugin.class);
|
DanaRPlugin danaRPlugin = mock(DanaRPlugin.class);
|
||||||
|
DanaRv2Plugin danaRv2Plugin = mock(DanaRv2Plugin.class);
|
||||||
DanaRKoreanPlugin danaRKoreanPlugin = mock(DanaRKoreanPlugin.class);
|
DanaRKoreanPlugin danaRKoreanPlugin = mock(DanaRKoreanPlugin.class);
|
||||||
when(MainApp.getSpecificPlugin(DanaRPlugin.class)).thenReturn(danaRPlugin);
|
when(MainApp.getSpecificPlugin(DanaRPlugin.class)).thenReturn(danaRPlugin);
|
||||||
|
when(MainApp.getSpecificPlugin(DanaRv2Plugin.class)).thenReturn(danaRv2Plugin);
|
||||||
when(MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).thenReturn(danaRKoreanPlugin);
|
when(MainApp.getSpecificPlugin(DanaRKoreanPlugin.class)).thenReturn(danaRKoreanPlugin);
|
||||||
return danaRPlugin;
|
return danaRPlugin;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
package info.nightscout.androidaps.plugins.PumpdanaRv2;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
|
import info.AAPSMocker;
|
||||||
|
import info.nightscout.androidaps.Constants;
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.interfaces.Constraint;
|
||||||
|
import info.nightscout.androidaps.interfaces.PluginType;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
||||||
|
import info.nightscout.utils.SP;
|
||||||
|
import info.nightscout.utils.ToastUtils;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Rumen on 01.08.2018
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner.class)
|
||||||
|
@PrepareForTest({MainApp.class, ConfigBuilderPlugin.class, ToastUtils.class, Context.class, SP.class})
|
||||||
|
public class DanaRv2PluginTest {
|
||||||
|
DanaRv2Plugin danaRv2Plugin;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getPlugin() {
|
||||||
|
danaRv2Plugin.getPlugin();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void basalRateShouldBeLimited() throws Exception {
|
||||||
|
danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true);
|
||||||
|
danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true);
|
||||||
|
DanaRPump.getInstance().maxBasal = 0.8d;
|
||||||
|
|
||||||
|
Constraint<Double> c = new Constraint<>(Constants.REALLYHIGHBASALRATE);
|
||||||
|
danaRv2Plugin.applyBasalConstraints(c, AAPSMocker.getValidProfile());
|
||||||
|
Assert.assertEquals(0.8d, c.value());
|
||||||
|
Assert.assertEquals("DanaRv2: Limiting basal rate to 0.80 U/h because of pump limit", c.getReasons());
|
||||||
|
Assert.assertEquals("DanaRv2: Limiting basal rate to 0.80 U/h because of pump limit", c.getMostLimitedReasons());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void percentBasalRateShouldBeLimited() throws Exception {
|
||||||
|
danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true);
|
||||||
|
danaRv2Plugin.setPluginEnabled(PluginType.PUMP, true);
|
||||||
|
DanaRPump.getInstance().maxBasal = 0.8d;
|
||||||
|
|
||||||
|
Constraint<Integer> c = new Constraint<>(Constants.REALLYHIGHPERCENTBASALRATE);
|
||||||
|
danaRv2Plugin.applyBasalPercentConstraints(c, AAPSMocker.getValidProfile());
|
||||||
|
Assert.assertEquals((Integer) 200, c.value());
|
||||||
|
Assert.assertEquals("DanaRv2: Limiting percent rate to 200% because of pump limit", c.getReasons());
|
||||||
|
Assert.assertEquals("DanaRv2: Limiting percent rate to 200% because of pump limit", c.getMostLimitedReasons());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void prepareMocks() throws Exception {
|
||||||
|
AAPSMocker.mockMainApp();
|
||||||
|
AAPSMocker.mockConfigBuilder();
|
||||||
|
AAPSMocker.mockBus();
|
||||||
|
AAPSMocker.mockStrings();
|
||||||
|
AAPSMocker.mockApplicationContext();
|
||||||
|
AAPSMocker.mockSP();
|
||||||
|
AAPSMocker.mockCommandQueue();
|
||||||
|
|
||||||
|
// when(SP.getString(R.string.key_danars_address, "")).thenReturn("");
|
||||||
|
|
||||||
|
danaRv2Plugin = DanaRv2Plugin.getPlugin();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
package info.nightscout.androidaps.plugins.PumpdanaRv2.comm;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
|
import info.AAPSMocker;
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MessageHashTable_v2;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusAPS_v2;
|
||||||
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
/**
|
||||||
|
* Created by Rumen Georgiev on 30.10.2018.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner.class)
|
||||||
|
@PrepareForTest({MainApp.class, SP.class, L.class})
|
||||||
|
public class MessageHashTable_v2Test {
|
||||||
|
@Test
|
||||||
|
public void runTest() {
|
||||||
|
AAPSMocker.mockMainApp();
|
||||||
|
AAPSMocker.mockApplicationContext();
|
||||||
|
AAPSMocker.mockSP();
|
||||||
|
AAPSMocker.mockL();
|
||||||
|
AAPSMocker.mockBus();
|
||||||
|
|
||||||
|
MessageHashTable_v2 packet = new MessageHashTable_v2();
|
||||||
|
|
||||||
|
MessageBase forTesting = new MsgStatusAPS_v2();
|
||||||
|
MessageBase testPacket = MessageHashTable_v2.findMessage(forTesting.getCommand());
|
||||||
|
assertEquals(0xE001, testPacket.getCommand());
|
||||||
|
// try putting another command
|
||||||
|
MessageBase testMessage = new MessageBase();
|
||||||
|
testMessage.SetCommand(0xE005);
|
||||||
|
packet.put(testMessage);
|
||||||
|
assertEquals(0xE005, packet.findMessage(0xE005).getCommand());
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] createArray(int length, byte fillWith){
|
||||||
|
byte[] ret = new byte[length];
|
||||||
|
for(int i = 0; i<length; i++){
|
||||||
|
ret[i] = fillWith;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
double[] createArray(int length, double fillWith){
|
||||||
|
double[] ret = new double[length];
|
||||||
|
for(int i = 0; i<length; i++){
|
||||||
|
ret[i] = fillWith;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
package info.nightscout.androidaps.plugins.PumpdanaRv2.comm;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
|
import info.AAPSMocker;
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgCheckValue;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgCheckValue_v2;
|
||||||
|
import info.nightscout.androidaps.plugins.Treatments.Treatment;
|
||||||
|
import info.nightscout.androidaps.queue.CommandQueue;
|
||||||
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.powermock.api.mockito.PowerMockito.when;
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner.class)
|
||||||
|
@PrepareForTest({MainApp.class, SP.class, L.class, DanaRv2Plugin.class, DanaRPlugin.class, ConfigBuilderPlugin.class, CommandQueue.class})
|
||||||
|
public class MsgCheckValue_v2Test {
|
||||||
|
@Test
|
||||||
|
public void runTest() {
|
||||||
|
AAPSMocker.mockMainApp();
|
||||||
|
AAPSMocker.mockApplicationContext();
|
||||||
|
AAPSMocker.mockSP();
|
||||||
|
AAPSMocker.mockL();
|
||||||
|
AAPSMocker.mockBus();
|
||||||
|
AAPSMocker.mockDanaRPlugin();
|
||||||
|
AAPSMocker.mockConfigBuilder();
|
||||||
|
AAPSMocker.mockCommandQueue();
|
||||||
|
Treatment t = new Treatment();
|
||||||
|
MsgCheckValue_v2 packet = new MsgCheckValue_v2();
|
||||||
|
// test message decoding
|
||||||
|
packet.handleMessage(createArray(34, (byte) 3));
|
||||||
|
DanaRPump pump = DanaRPump.getInstance();
|
||||||
|
assertEquals(DanaRPump.EXPORT_MODEL, pump.model);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] createArray(int length, byte fillWith){
|
||||||
|
byte[] ret = new byte[length];
|
||||||
|
for(int i = 0; i<length; i++){
|
||||||
|
ret[i] = fillWith;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
double[] createArray(int length, double fillWith){
|
||||||
|
double[] ret = new double[length];
|
||||||
|
for(int i = 0; i<length; i++){
|
||||||
|
ret[i] = fillWith;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
package info.nightscout.androidaps.plugins.PumpdanaRv2.comm;
|
||||||
|
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
|
import info.AAPSMocker;
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgHistoryEvents_v2;
|
||||||
|
import info.nightscout.androidaps.plugins.Treatments.Treatment;
|
||||||
|
import info.nightscout.androidaps.plugins.Treatments.TreatmentService;
|
||||||
|
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
||||||
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Rumen Georgiev on 30.10.2018.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner.class)
|
||||||
|
@PrepareForTest({MainApp.class, SP.class, L.class, TreatmentsPlugin.class, TreatmentService.class})
|
||||||
|
public class MsgHistoryEvents_v2Test {
|
||||||
|
@Test
|
||||||
|
public void runTest() throws Exception {
|
||||||
|
AAPSMocker.mockMainApp();
|
||||||
|
AAPSMocker.mockApplicationContext();
|
||||||
|
AAPSMocker.mockSP();
|
||||||
|
AAPSMocker.mockL();
|
||||||
|
AAPSMocker.mockBus();
|
||||||
|
AAPSMocker.mockDatabaseHelper();
|
||||||
|
AAPSMocker.mockTreatmentPlugin();
|
||||||
|
AAPSMocker.mockTreatmentService();
|
||||||
|
MsgHistoryEvents_v2 packet = new MsgHistoryEvents_v2();
|
||||||
|
|
||||||
|
// test message decoding
|
||||||
|
//last message in history
|
||||||
|
packet.handleMessage(createArray(34, (byte) 0xFF));
|
||||||
|
assertEquals(true, packet.done);
|
||||||
|
// passing an bigger number
|
||||||
|
packet = new MsgHistoryEvents_v2();
|
||||||
|
packet.handleMessage(createArray(34, (byte) 17));
|
||||||
|
assertEquals(false, packet.done);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] createArray(int length, byte fillWith){
|
||||||
|
byte[] ret = new byte[length];
|
||||||
|
for(int i = 0; i<length; i++){
|
||||||
|
ret[i] = fillWith;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
double[] createArray(int length, double fillWith){
|
||||||
|
double[] ret = new double[length];
|
||||||
|
for(int i = 0; i<length; i++){
|
||||||
|
ret[i] = fillWith;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
package info.nightscout.androidaps.plugins.PumpdanaRv2.comm;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
|
import info.AAPSMocker;
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgSetHistoryEntry_v2;
|
||||||
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
/**
|
||||||
|
* Created by Rumen Georgiev on 30.10.2018.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner.class)
|
||||||
|
@PrepareForTest({MainApp.class, SP.class, L.class, DanaRv2Plugin.class, DanaRPlugin.class})
|
||||||
|
public class MsgSetHistoryEntry_v2Test {
|
||||||
|
@Test
|
||||||
|
public void runTest() {
|
||||||
|
AAPSMocker.mockMainApp();
|
||||||
|
AAPSMocker.mockApplicationContext();
|
||||||
|
AAPSMocker.mockSP();
|
||||||
|
AAPSMocker.mockL();
|
||||||
|
AAPSMocker.mockBus();
|
||||||
|
AAPSMocker.mockDanaRPlugin();
|
||||||
|
|
||||||
|
MsgSetHistoryEntry_v2 initializerTest = new MsgSetHistoryEntry_v2((byte) 1, System.currentTimeMillis(), 1, 0);
|
||||||
|
MsgSetHistoryEntry_v2 packet = new MsgSetHistoryEntry_v2();
|
||||||
|
// test message decoding
|
||||||
|
// != 1 fails
|
||||||
|
packet.handleMessage(createArray(34, (byte) 2));
|
||||||
|
assertEquals(true, packet.failed);
|
||||||
|
// passing an bigger number
|
||||||
|
packet = new MsgSetHistoryEntry_v2();
|
||||||
|
packet.handleMessage(createArray(34, (byte) 1));
|
||||||
|
assertEquals(false, packet.failed);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] createArray(int length, byte fillWith){
|
||||||
|
byte[] ret = new byte[length];
|
||||||
|
for(int i = 0; i<length; i++){
|
||||||
|
ret[i] = fillWith;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
double[] createArray(int length, double fillWith){
|
||||||
|
double[] ret = new double[length];
|
||||||
|
for(int i = 0; i<length; i++){
|
||||||
|
ret[i] = fillWith;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
package info.nightscout.androidaps.plugins.PumpdanaRv2.comm;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
|
import info.AAPSMocker;
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusAPS_v2;
|
||||||
|
import info.nightscout.utils.SP;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
/**
|
||||||
|
* Created by Rumen Georgiev on 30.10.2018
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner.class)
|
||||||
|
@PrepareForTest({MainApp.class, SP.class, L.class})
|
||||||
|
public class MsgStatusAPS_v2Test {
|
||||||
|
@Mock
|
||||||
|
Context context;
|
||||||
|
@Test
|
||||||
|
public void runTest() throws Exception{
|
||||||
|
AAPSMocker.mockMainApp();
|
||||||
|
AAPSMocker.mockApplicationContext();
|
||||||
|
AAPSMocker.mockSP();
|
||||||
|
AAPSMocker.mockL();
|
||||||
|
|
||||||
|
try {
|
||||||
|
AAPSMocker.mockTreatmentService();
|
||||||
|
} catch (Exception e){
|
||||||
|
|
||||||
|
}
|
||||||
|
MsgStatusAPS_v2 packet = new MsgStatusAPS_v2();
|
||||||
|
// test iob
|
||||||
|
//TODO Find a way to mock treatments plugin
|
||||||
|
byte[] testArray = createArray(34, (byte) 7);
|
||||||
|
double iob = MessageBase.intFromBuff(testArray, 0, 2) / 100d;
|
||||||
|
packet.handleMessage(testArray);
|
||||||
|
DanaRPump pump = DanaRPump.getInstance();
|
||||||
|
assertEquals(iob, pump.iob, 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] createArray(int length, byte fillWith){
|
||||||
|
byte[] ret = new byte[length];
|
||||||
|
for(int i = 0; i<length; i++){
|
||||||
|
ret[i] = fillWith;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
package info.nightscout.androidaps.plugins.PumpdanaRv2.comm;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
|
import info.AAPSMocker;
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusBolusExtended_v2;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MessageBase;
|
||||||
|
import info.nightscout.androidaps.plugins.Treatments.Treatment;
|
||||||
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Rumen Georgiev on 30.10.2018
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner.class)
|
||||||
|
@PrepareForTest({MainApp.class, SP.class, L.class})
|
||||||
|
public class MsgStatusBolusExtended_v2Test {
|
||||||
|
@Mock
|
||||||
|
Context context;
|
||||||
|
@Test
|
||||||
|
public void runTest() throws Exception{
|
||||||
|
AAPSMocker.mockMainApp();
|
||||||
|
AAPSMocker.mockApplicationContext();
|
||||||
|
AAPSMocker.mockSP();
|
||||||
|
AAPSMocker.mockL();
|
||||||
|
try {
|
||||||
|
AAPSMocker.mockTreatmentService();
|
||||||
|
} catch (Exception e){
|
||||||
|
|
||||||
|
}
|
||||||
|
MsgStatusBolusExtended_v2 packet = new MsgStatusBolusExtended_v2();
|
||||||
|
// test message decoding
|
||||||
|
//TODO Find a way to mock treatments plugin
|
||||||
|
packet.handleMessage(createArray(34, (byte) 7));
|
||||||
|
DanaRPump pump = DanaRPump.getInstance();
|
||||||
|
assertEquals((double) MessageBase.intFromBuff(createArray(10, (byte) 7), 2, 2)/100d, pump.extendedBolusAmount,0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] createArray(int length, byte fillWith){
|
||||||
|
byte[] ret = new byte[length];
|
||||||
|
for(int i = 0; i<length; i++){
|
||||||
|
ret[i] = fillWith;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
package info.nightscout.androidaps.plugins.PumpdanaRv2.comm;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
|
import info.AAPSMocker;
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.logging.L;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.comm.MsgStatusTempBasal_v2;
|
||||||
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
/**
|
||||||
|
* Created by Rumen Georgiev on 30.10.2018.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner.class)
|
||||||
|
@PrepareForTest({MainApp.class, SP.class, L.class, DanaRv2Plugin.class, DanaRPlugin.class})
|
||||||
|
public class MsgStatusTempBasal_v2Test {
|
||||||
|
@Test
|
||||||
|
public void runTest() {
|
||||||
|
AAPSMocker.mockMainApp();
|
||||||
|
AAPSMocker.mockApplicationContext();
|
||||||
|
AAPSMocker.mockSP();
|
||||||
|
AAPSMocker.mockL();
|
||||||
|
AAPSMocker.mockBus();
|
||||||
|
AAPSMocker.mockDanaRPlugin();
|
||||||
|
|
||||||
|
MsgStatusTempBasal_v2 packet = new MsgStatusTempBasal_v2();
|
||||||
|
DanaRPump pump = DanaRPump.getInstance();
|
||||||
|
// test message decoding
|
||||||
|
packet.handleMessage(createArray(34, (byte) 1));
|
||||||
|
assertEquals(true, pump.isTempBasalInProgress);
|
||||||
|
// passing an bigger number
|
||||||
|
packet = new MsgStatusTempBasal_v2();
|
||||||
|
|
||||||
|
packet.handleMessage(createArray(34, (byte) 2));
|
||||||
|
assertEquals(false, pump.isTempBasalInProgress);
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] createArray(int length, byte fillWith){
|
||||||
|
byte[] ret = new byte[length];
|
||||||
|
for(int i = 0; i<length; i++){
|
||||||
|
ret[i] = fillWith;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
double[] createArray(int length, double fillWith){
|
||||||
|
double[] ret = new double[length];
|
||||||
|
for(int i = 0; i<length; i++){
|
||||||
|
ret[i] = fillWith;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue