RS packet tests
This commit is contained in:
parent
cb12967b17
commit
248ab8bc76
|
@ -1,42 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.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.treatments.Treatment;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Rumen on 31.07.2018.
|
||||
*/
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, SP.class, L.class})
|
||||
public class DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest extends DanaRS_Packet_Bolus_Set_Step_Bolus_Stop {
|
||||
|
||||
@Test
|
||||
public void runTest() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
AAPSMocker.mockStrings();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockL();
|
||||
|
||||
DanaRS_Packet_Bolus_Set_Step_Bolus_Stop testPacket = new DanaRS_Packet_Bolus_Set_Step_Bolus_Stop(1d , new Treatment());
|
||||
// test message decoding
|
||||
testPacket.handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 0});
|
||||
assertEquals(false, testPacket.failed);
|
||||
testPacket.handleMessage(new byte[]{(byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1});
|
||||
assertEquals(true, testPacket.failed);
|
||||
|
||||
assertEquals("BOLUS__SET_STEP_BOLUS_STOP", getFriendlyName());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm
|
||||
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
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.configBuilder.ProfileFunction
|
||||
import info.nightscout.androidaps.plugins.treatments.Treatment
|
||||
import info.nightscout.androidaps.utils.DefaultValueHelper
|
||||
import info.nightscout.androidaps.utils.SP
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import org.junit.Assert
|
||||
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
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
@PrepareForTest(MainApp::class, SP::class, L::class)
|
||||
class DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest : DanaRS_Packet_Bolus_Set_Step_Bolus_Stop() {
|
||||
|
||||
@Mock lateinit var defaultValueHelper: DefaultValueHelper
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin
|
||||
|
||||
private var treatmentInjector: HasAndroidInjector = HasAndroidInjector {
|
||||
AndroidInjector {
|
||||
if (it is Treatment) {
|
||||
it.defaultValueHelper = defaultValueHelper
|
||||
it.resourceHelper = resourceHelper
|
||||
it.profileFunction = profileFunction
|
||||
it.configBuilderPlugin = configBuilderPlugin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
AAPSMocker.mockMainApp()
|
||||
AAPSMocker.mockApplicationContext()
|
||||
AAPSMocker.mockStrings()
|
||||
AAPSMocker.mockSP()
|
||||
AAPSMocker.mockL()
|
||||
val testPacket = DanaRS_Packet_Bolus_Set_Step_Bolus_Stop(1.0, Treatment(treatmentInjector))
|
||||
// test message decoding
|
||||
testPacket.handleMessage(byteArrayOf(0.toByte(), 0.toByte(), 0.toByte()))
|
||||
Assert.assertEquals(false, testPacket.failed)
|
||||
testPacket.handleMessage(byteArrayOf(1.toByte(), 1.toByte(), 1.toByte(), 1.toByte(), 1.toByte(), 1.toByte(), 1.toByte(), 1.toByte()))
|
||||
Assert.assertEquals(true, testPacket.failed)
|
||||
Assert.assertEquals("BOLUS__SET_STEP_BOLUS_STOP", friendlyName)
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.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.treatments.Treatment;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Rumen Georgiev on 8/9/2018.
|
||||
*/
|
||||
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, SP.class, L.class})
|
||||
public class DanaRS_Packet_Notify_Delivery_CompleteTest {
|
||||
|
||||
@Test
|
||||
public void runTest() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockL();
|
||||
AAPSMocker.mockStrings();
|
||||
DanaRS_Packet_Notify_Delivery_Complete packet = new DanaRS_Packet_Notify_Delivery_Complete(0.5d,new Treatment());
|
||||
|
||||
// test params
|
||||
assertEquals(null, packet.getRequestParams());
|
||||
|
||||
// test message decoding
|
||||
packet.handleMessage(createArray(17, (byte) 0));
|
||||
assertEquals(true, packet.done);
|
||||
|
||||
assertEquals("NOTIFY__DELIVERY_COMPLETE", packet.getFriendlyName());
|
||||
}
|
||||
|
||||
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,71 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm
|
||||
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
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.configBuilder.ProfileFunction
|
||||
import info.nightscout.androidaps.plugins.treatments.Treatment
|
||||
import info.nightscout.androidaps.utils.DefaultValueHelper
|
||||
import info.nightscout.androidaps.utils.SP
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import org.junit.Assert
|
||||
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
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
@PrepareForTest(MainApp::class, SP::class, L::class)
|
||||
class DanaRS_Packet_Notify_Delivery_CompleteTest {
|
||||
|
||||
@Mock lateinit var defaultValueHelper: DefaultValueHelper
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin
|
||||
|
||||
private var treatmentInjector: HasAndroidInjector = HasAndroidInjector {
|
||||
AndroidInjector {
|
||||
if (it is Treatment) {
|
||||
it.defaultValueHelper = defaultValueHelper
|
||||
it.resourceHelper = resourceHelper
|
||||
it.profileFunction = profileFunction
|
||||
it.configBuilderPlugin = configBuilderPlugin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
AAPSMocker.mockMainApp()
|
||||
AAPSMocker.mockApplicationContext()
|
||||
AAPSMocker.mockSP()
|
||||
AAPSMocker.mockL()
|
||||
AAPSMocker.mockStrings()
|
||||
val packet = DanaRS_Packet_Notify_Delivery_Complete(0.5, Treatment(treatmentInjector))
|
||||
// test params
|
||||
Assert.assertEquals(null, packet.requestParams)
|
||||
// test message decoding
|
||||
packet.handleMessage(createArray(17, 0.toByte()))
|
||||
Assert.assertEquals(true, DanaRS_Packet_Notify_Delivery_Complete.done)
|
||||
Assert.assertEquals("NOTIFY__DELIVERY_COMPLETE", packet.friendlyName)
|
||||
}
|
||||
|
||||
fun createArray(length: Int, fillWith: Byte): ByteArray {
|
||||
val ret = ByteArray(length)
|
||||
for (i in 0 until length) {
|
||||
ret[i] = fillWith
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
fun createArray(length: Int, fillWith: Double): DoubleArray {
|
||||
val ret = DoubleArray(length)
|
||||
for (i in 0 until length) {
|
||||
ret[i] = fillWith
|
||||
}
|
||||
return ret
|
||||
}
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.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.treatments.Treatment;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Rumen Georgiev on 8/9/2018.
|
||||
*/
|
||||
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class, SP.class, L.class})
|
||||
public class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest {
|
||||
|
||||
@Test
|
||||
public void runTest() {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockApplicationContext();
|
||||
AAPSMocker.mockSP();
|
||||
AAPSMocker.mockL();
|
||||
AAPSMocker.mockStrings();
|
||||
DanaRS_Packet_Notify_Delivery_Rate_Display packet = new DanaRS_Packet_Notify_Delivery_Rate_Display(1, new Treatment());
|
||||
|
||||
// test params
|
||||
assertEquals(null, packet.getRequestParams());
|
||||
|
||||
// test message decoding
|
||||
// 0% delivered
|
||||
packet.handleMessage(createArray(17, (byte) 0));
|
||||
assertEquals(true, packet.failed);
|
||||
// 100 % delivered
|
||||
packet.handleMessage(createArray(17, (byte) 1));
|
||||
assertEquals(false, packet.failed);
|
||||
|
||||
assertEquals("NOTIFY__DELIVERY_RATE_DISPLAY", packet.getFriendlyName());
|
||||
}
|
||||
|
||||
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,75 @@
|
|||
package info.nightscout.androidaps.plugins.pump.danaRS.comm
|
||||
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
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.configBuilder.ProfileFunction
|
||||
import info.nightscout.androidaps.plugins.treatments.Treatment
|
||||
import info.nightscout.androidaps.utils.DefaultValueHelper
|
||||
import info.nightscout.androidaps.utils.SP
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import org.junit.Assert
|
||||
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
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
@PrepareForTest(MainApp::class, SP::class, L::class)
|
||||
class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest {
|
||||
|
||||
@Mock lateinit var defaultValueHelper: DefaultValueHelper
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin
|
||||
|
||||
private var treatmentInjector: HasAndroidInjector = HasAndroidInjector {
|
||||
AndroidInjector {
|
||||
if (it is Treatment) {
|
||||
it.defaultValueHelper = defaultValueHelper
|
||||
it.resourceHelper = resourceHelper
|
||||
it.profileFunction = profileFunction
|
||||
it.configBuilderPlugin = configBuilderPlugin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
AAPSMocker.mockMainApp()
|
||||
AAPSMocker.mockApplicationContext()
|
||||
AAPSMocker.mockSP()
|
||||
AAPSMocker.mockL()
|
||||
AAPSMocker.mockStrings()
|
||||
val packet = DanaRS_Packet_Notify_Delivery_Rate_Display(1.0, Treatment(treatmentInjector))
|
||||
// test params
|
||||
Assert.assertEquals(null, packet.requestParams)
|
||||
// test message decoding
|
||||
// 0% delivered
|
||||
packet.handleMessage(createArray(17, 0.toByte()))
|
||||
Assert.assertEquals(true, packet.failed)
|
||||
// 100 % delivered
|
||||
packet.handleMessage(createArray(17, 1.toByte()))
|
||||
Assert.assertEquals(false, packet.failed)
|
||||
Assert.assertEquals("NOTIFY__DELIVERY_RATE_DISPLAY", packet.friendlyName)
|
||||
}
|
||||
|
||||
fun createArray(length: Int, fillWith: Byte): ByteArray {
|
||||
val ret = ByteArray(length)
|
||||
for (i in 0 until length) {
|
||||
ret[i] = fillWith
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
fun createArray(length: Int, fillWith: Double): DoubleArray {
|
||||
val ret = DoubleArray(length)
|
||||
for (i in 0 until length) {
|
||||
ret[i] = fillWith
|
||||
}
|
||||
return ret
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue