Dana messages tests

This commit is contained in:
Milos Kozak 2020-03-18 20:38:51 +01:00
parent 18de3f70b5
commit 50bbe1c481
46 changed files with 519 additions and 890 deletions

View file

@ -28,6 +28,7 @@ class MsgBolusStart(
failed = true failed = true
aapsLogger.debug(LTag.PUMPBTCOMM, "Messsage response: $errorCode FAILED!!") aapsLogger.debug(LTag.PUMPBTCOMM, "Messsage response: $errorCode FAILED!!")
} else { } else {
failed = false
aapsLogger.debug(LTag.PUMPBTCOMM, "Messsage response: $errorCode OK") aapsLogger.debug(LTag.PUMPBTCOMM, "Messsage response: $errorCode OK")
} }
danaRPump.messageStartErrorCode = errorCode danaRPump.messageStartErrorCode = errorCode

View file

@ -30,6 +30,7 @@ class MsgBolusStartWithSpeed(
failed = true failed = true
aapsLogger.debug(LTag.PUMPBTCOMM, "Messsage response: $errorCode FAILED!!") aapsLogger.debug(LTag.PUMPBTCOMM, "Messsage response: $errorCode FAILED!!")
} else { } else {
failed = false
aapsLogger.debug(LTag.PUMPBTCOMM, "Messsage response: $errorCode OK") aapsLogger.debug(LTag.PUMPBTCOMM, "Messsage response: $errorCode OK")
} }
danaRPump.messageStartErrorCode = errorCode danaRPump.messageStartErrorCode = errorCode

View file

@ -57,6 +57,7 @@ class MsgHistoryEvents_v2 constructor(
danaRv2Plugin.eventsLoadingDone = true danaRv2Plugin.eventsLoadingDone = true
return return
} }
danaRv2Plugin.eventsLoadingDone = false
val datetime = dateTimeSecFromBuff(bytes, 1) // 6 bytes val datetime = dateTimeSecFromBuff(bytes, 1) // 6 bytes
val param1 = intFromBuff(bytes, 7, 2) val param1 = intFromBuff(bytes, 7, 2)
val param2 = intFromBuff(bytes, 9, 2) val param2 = intFromBuff(bytes, 9, 2)

View file

@ -0,0 +1,50 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.utils.sharedPreferences.SP
import org.junit.Before
import org.mockito.Mock
open class DanaRTestBase : TestBase() {
@Mock lateinit var aapsLogger: AAPSLogger
@Mock lateinit var sp: SP
@Mock lateinit var injector: HasAndroidInjector
lateinit var danaRPump: DanaRPump
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): Array<Double> {
val ret = Array(length) { 0.0 }
for (i in 0 until length) {
ret[i] = fillWith
}
return ret
}
fun putIntToArray(array: ByteArray, position: Int, value: Int): ByteArray {
array[6 + position + 1] = (value and 0xFF).toByte()
array[6 + position] = ((value and 0xFF00) shr 8).toByte()
return array
}
fun putByteToArray(array: ByteArray, position: Int, value: Byte): ByteArray {
array[6 + position] = value
return array
}
@Before
fun setup() {
danaRPump = DanaRPump(aapsLogger, sp, injector)
}
}

View file

@ -1,57 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.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/28/2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class})
public class MsgBolusProgressTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
AAPSMocker.mockStrings();
Treatment t = new Treatment();
MsgBolusProgress packet = new MsgBolusProgress(3D, t);
// test message decoding
packet.handleMessage(createArray(34, (byte) 1));
int valueRequested = (((byte) 1 << 8) + ((byte) 1 + 0));
assertEquals(valueRequested, packet.progress,0d);
}
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;
}
}

View file

@ -0,0 +1,35 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.treatments.Treatment
import info.nightscout.androidaps.utils.resources.ResourceHelper
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers
import org.mockito.Mock
import org.mockito.Mockito.`when`
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
class MsgBolusProgressTest : DanaRTestBase() {
@Mock lateinit var resourceHelper: ResourceHelper
val rxBus = RxBusWrapper()
@Test fun runTest() {
`when`(resourceHelper.gs(ArgumentMatchers.eq(R.string.bolusdelivering), ArgumentMatchers.anyDouble())).thenReturn("Delivering %1\$.2fU")
danaRPump.bolusingTreatment = Treatment(HasAndroidInjector { AndroidInjector { } })
danaRPump.bolusAmountToBeDelivered = 3.0
val packet = MsgBolusProgress(aapsLogger, resourceHelper, rxBus, danaRPump)
// test message decoding
val array = ByteArray(100)
putIntToArray(array, 0, 2 * 100)
packet.handleMessage(array)
Assert.assertEquals(1.0, danaRPump.bolusingTreatment?.insulin!!, 0.0)
}
}

View file

@ -1,54 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.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.utils.SP;
import static org.junit.Assert.*;
/**
* Created by Rumen Georgiev on 8/28/2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class})
public class MsgBolusStartTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
MsgBolusStart packet = new MsgBolusStart();
// test message decoding
packet.handleMessage(createArray(34, (byte) 1));
assertEquals(true, packet.failed);
packet = new MsgBolusStart();
packet.handleMessage(createArray(34, (byte) 2));
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;
}
}

View file

@ -0,0 +1,34 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.Mockito.`when`
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
@PrepareForTest(ConstraintChecker::class)
class MsgBolusStartTest : DanaRTestBase() {
@Mock lateinit var constraintChecker: ConstraintChecker
@Test fun runTest() {
`when`(constraintChecker.applyBolusConstraints(Constraint(anyObject()))).thenReturn(Constraint(0.0))
val packet = MsgBolusStart(aapsLogger, constraintChecker, danaRPump, 1.0)
// test message decoding
val array = ByteArray(100)
putByteToArray(array, 0, 1)
packet.handleMessage(array)
Assert.assertEquals(true, packet.failed)
putByteToArray(array, 0, 2)
packet.handleMessage(array)
Assert.assertEquals(false, packet.failed)
}
}

View file

@ -1,54 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.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.utils.SP;
import static org.junit.Assert.*;
/**
* Created by Rumen Georgiev on 8/28/2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class})
public class MsgBolusStartWithSpeedTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
MsgBolusStartWithSpeed packet = new MsgBolusStartWithSpeed();
// test message decoding
packet.handleMessage(createArray(34, (byte) 1));
assertEquals(true, packet.failed);
packet = new MsgBolusStartWithSpeed();
packet.handleMessage(createArray(34, (byte) 2));
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;
}
}

View file

@ -0,0 +1,34 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.Mockito
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
@PrepareForTest(ConstraintChecker::class)
class MsgBolusStartWithSpeedTest : DanaRTestBase() {
@Mock lateinit var constraintChecker: ConstraintChecker
@Test fun runTest() {
Mockito.`when`(constraintChecker.applyBolusConstraints(Constraint(anyObject()))).thenReturn(Constraint(0.0))
val packet = MsgBolusStartWithSpeed(aapsLogger, constraintChecker, danaRPump, 0.0, 0)
// test message decoding
val array = ByteArray(100)
putByteToArray(array, 0, 1)
packet.handleMessage(array)
Assert.assertEquals(true, packet.failed)
putByteToArray(array, 0, 2)
packet.handleMessage(array)
Assert.assertEquals(false, packet.failed)
}
}

View file

@ -1,54 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.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/28/2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class})
public class MsgBolusStopTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
AAPSMocker.mockStrings();
Treatment t = new Treatment();
MsgBolusStop packet = new MsgBolusStop(1d,t);
// test message decoding
packet.handleMessage(createArray(34, (byte) 1));
assertEquals(true, packet.stopped);
}
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;
}
}

View file

@ -0,0 +1,31 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.treatments.Treatment
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.mockito.Mockito.`when`
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
class MsgBolusStopTest : DanaRTestBase() {
@Mock lateinit var resourceHelper: ResourceHelper
val rxBus = RxBusWrapper()
@Test fun runTest() {
`when`(resourceHelper.gs(R.string.overview_bolusprogress_delivered)).thenReturn("Delivered")
danaRPump.bolusingTreatment = Treatment(HasAndroidInjector { AndroidInjector { } })
val packet = MsgBolusStop(aapsLogger, rxBus, resourceHelper, danaRPump)
// test message decoding
packet.handleMessage(ByteArray(100))
Assert.assertEquals(true, danaRPump.bolusStopped)
}
}

View file

@ -1,56 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.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.pump.danaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
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/28/2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class, DanaRPlugin.class})
public class MsgCheckValueTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
Treatment t = new Treatment();
MsgCheckValue packet = new MsgCheckValue();
// 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;
}
}

View file

@ -0,0 +1,25 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
class MsgCheckValueTest : DanaRTestBase() {
@Mock lateinit var danaRPlugin: DanaRPlugin
@Test fun runTest() {
val packet = MsgCheckValue(aapsLogger, danaRPump, danaRPlugin)
// test message decoding
val array = ByteArray(100)
putByteToArray(array, 0, DanaRPump.EXPORT_MODEL.toByte())
packet.handleMessage(array)
Assert.assertEquals(DanaRPump.EXPORT_MODEL, danaRPump.model)
}
}

View file

@ -1,58 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.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.general.nsclient.NSUpload;
import info.nightscout.androidaps.utils.SP;
import static org.junit.Assert.assertEquals;
/**
* Created by Rumen Georgiev on 8/28/2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class, NSUpload.class})
public class MsgErrorTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
AAPSMocker.mockNSUpload();
MsgError packet = new MsgError();
// test message decoding
packet.handleMessage(createArray(34, (byte) 1));
assertEquals(true, packet.failed);
// bigger than 8 - no error
packet = new MsgError();
packet.handleMessage(createArray(34, (byte) 10));
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;
}
}

View file

@ -0,0 +1,36 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
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.api.mockito.PowerMockito
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
@PrepareForTest(NSUpload::class)
class MsgErrorTest : DanaRTestBase() {
@Mock lateinit var resourceHelper: ResourceHelper
val rxBus = RxBusWrapper()
@Test fun runTest() {
PowerMockito.mockStatic(NSUpload::class.java)
val packet = MsgError(aapsLogger, rxBus, resourceHelper, danaRPump)
// test message decoding
val array = ByteArray(100)
putByteToArray(array, 0, 1)
packet.handleMessage(array)
Assert.assertEquals(true, packet.failed)
// bigger than 8 - no error
putByteToArray(array, 0, 10)
packet.handleMessage(array)
Assert.assertEquals(false, packet.failed)
}
}

View file

@ -1,32 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.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.general.nsclient.NSUpload;
import info.nightscout.androidaps.utils.SP;
/**
* Created by Rumen Georgiev on 8/30/2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class, NSUpload.class})
public class MsgHistoryAlarmTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
MsgHistoryAlarm packet = new MsgHistoryAlarm();
// nothing left to test
}
}

View file

@ -0,0 +1,17 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
class MsgHistoryAlarmTest : DanaRTestBase() {
val rxBus = RxBusWrapper()
@Test fun runTest() {
val packet = MsgHistoryAlarm(aapsLogger, rxBus)
// nothing left to test
}
}

View file

@ -1,53 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.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.general.nsclient.NSUpload;
import info.nightscout.androidaps.utils.SP;
import static org.junit.Assert.*;
/**
* Created by Rumen Georgiev on 8/30/2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class, NSUpload.class})
public class MsgHistoryAllDoneTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
MsgHistoryAllDone packet = new MsgHistoryAllDone();
// test message decoding
packet.handleMessage(createArray(34, (byte) 1));
assertEquals(true, packet.received);
}
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;
}
}

View file

@ -0,0 +1,18 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
class MsgHistoryAllDoneTest : DanaRTestBase() {
@Test fun runTest() {
val packet = MsgHistoryAllDone(aapsLogger, danaRPump)
// test message decoding
packet.handleMessage(ByteArray(0))
Assert.assertEquals(true, danaRPump.historyDoneReceived)
}
}

View file

@ -1,57 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.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.general.nsclient.NSUpload;
import info.nightscout.androidaps.utils.SP;
import static org.junit.Assert.assertEquals;
/**
* Created by Rumen Georgiev on 8/30/2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class, NSUpload.class})
public class MsgHistoryAllTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
AAPSMocker.mockDatabaseHelper();
MsgHistoryAll packet = new MsgHistoryAll();
// test message decoding
packet.handleMessage(createArray(34, (byte) 1));
assertEquals(false, packet.failed);
// passing an bigger number
packet.handleMessage(createArray(34, (byte) 17));
assertEquals(true, 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;
}
}

View file

@ -0,0 +1,34 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.db.DatabaseHelper
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.`when`
import org.powermock.api.mockito.PowerMockito
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
@PrepareForTest(MainApp::class)
class MsgHistoryAllTest : DanaRTestBase() {
@Test fun runTest() {
PowerMockito.mockStatic(MainApp::class.java)
`when`(MainApp.getDbHelper()).thenReturn(PowerMockito.mock(DatabaseHelper::class.java))
val packet = MsgHistoryAll(aapsLogger, RxBusWrapper())
// test message decoding
val array = ByteArray(100)
putByteToArray(array, 0, 1)
packet.handleMessage(array)
Assert.assertEquals(false, packet.failed)
// passing an bigger number
putByteToArray(array, 0, 17)
packet.handleMessage(array)
Assert.assertEquals(true, packet.failed)
}
}

View file

@ -1,32 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.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.general.nsclient.NSUpload;
import info.nightscout.androidaps.utils.SP;
/**
* Created by Rumen Georgiev on 8/30/2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class, NSUpload.class})
public class MsgHistoryBasalHourTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
MsgHistoryBasalHour packet = new MsgHistoryBasalHour();
// nothing left to test
}
}

View file

@ -0,0 +1,15 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
class MsgHistoryBasalHourTest : DanaRTestBase() {
@Test fun runTest() {
val packet = MsgHistoryBasalHour(aapsLogger, RxBusWrapper())
// nothing left to test
}
}

View file

@ -1,32 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.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.general.nsclient.NSUpload;
import info.nightscout.androidaps.utils.SP;
/**
* Created by Rumen Georgiev on 8/30/2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class, NSUpload.class})
public class MsgHistoryBolusTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
MsgHistoryBolus packet = new MsgHistoryBolus();
// nothing left to test
}
}

View file

@ -0,0 +1,15 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
class MsgHistoryBolusTest : DanaRTestBase() {
@Test fun runTest() {
val packet = MsgHistoryBolus(aapsLogger, RxBusWrapper())
// nothing left to test
}
}

View file

@ -1,32 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.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.general.nsclient.NSUpload;
import info.nightscout.androidaps.utils.SP;
/**
* Created by Rumen Georgiev on 8/30/2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class, NSUpload.class})
public class MsgHistoryCarboTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
MsgHistoryCarbo packet = new MsgHistoryCarbo();
// nothing left to test
}
}

View file

@ -0,0 +1,15 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
class MsgHistoryCarboTest : DanaRTestBase() {
@Test fun runTest() {
val packet = MsgHistoryCarbo(aapsLogger, RxBusWrapper())
// nothing left to test
}
}

View file

@ -1,32 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.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.general.nsclient.NSUpload;
import info.nightscout.androidaps.utils.SP;
/**
* Created by Rumen Georgiev on 8/30/2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class, NSUpload.class})
public class MsgHistoryDailyInsulinTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
MsgHistoryDailyInsulin packet = new MsgHistoryDailyInsulin();
// nothing left to test
}
}

View file

@ -0,0 +1,15 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
class MsgHistoryDailyInsulinTest : DanaRTestBase() {
@Test fun runTest() {
val packet = MsgHistoryDailyInsulin(aapsLogger, RxBusWrapper())
// nothing left to test
}
}

View file

@ -1,32 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.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.general.nsclient.NSUpload;
import info.nightscout.androidaps.utils.SP;
/**
* Created by Rumen Georgiev on 8/30/2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class, NSUpload.class})
public class MsgHistoryDoneTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
MsgHistoryDone packet = new MsgHistoryDone();
// nothing left to test
}
}

View file

@ -0,0 +1,14 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
class MsgHistoryDoneTest : DanaRTestBase() {
@Test fun runTest() {
val packet = MsgHistoryDone(aapsLogger, danaRPump)
// nothing left to test
}
}

View file

@ -1,32 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.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.general.nsclient.NSUpload;
import info.nightscout.androidaps.utils.SP;
/**
* Created by Rumen Georgiev on 8/30/2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class, NSUpload.class})
public class MsgHistoryErrorTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
MsgHistoryError packet = new MsgHistoryError();
// nothing left to test
}
}

View file

@ -0,0 +1,15 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
class MsgHistoryErrorTest : DanaRTestBase() {
@Test fun runTest() {
val packet = MsgHistoryError(aapsLogger, RxBusWrapper())
// nothing left to test
}
}

View file

@ -1,32 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.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.general.nsclient.NSUpload;
import info.nightscout.androidaps.utils.SP;
/**
* Created by Rumen Georgiev on 8/30/2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class, NSUpload.class})
public class MsgHistoryGlucoseTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
MsgHistoryGlucose packet = new MsgHistoryGlucose();
// nothing left to test
}
}

View file

@ -0,0 +1,15 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
class MsgHistoryGlucoseTest : DanaRTestBase() {
@Test fun runTest() {
val packet = MsgHistoryGlucose(aapsLogger, RxBusWrapper())
// nothing left to test
}
}

View file

@ -1,32 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.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.general.nsclient.NSUpload;
import info.nightscout.androidaps.utils.SP;
/**
* Created by Rumen Georgiev on 8/30/2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class, NSUpload.class})
public class MsgHistoryNewDoneTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
MsgHistoryNewDone packet = new MsgHistoryNewDone();
// nothing left to test
}
}

View file

@ -0,0 +1,14 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
class MsgHistoryNewDoneTest : DanaRTestBase() {
@Test fun runTest() {
val packet = MsgHistoryNewDone(aapsLogger, danaRPump)
// nothing left to test
}
}

View file

@ -1,32 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.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.general.nsclient.NSUpload;
import info.nightscout.androidaps.utils.SP;
/**
* Created by Rumen Georgiev on 8/30/2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class, NSUpload.class})
public class MsgHistoryNewTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
MsgHistoryNew packet = new MsgHistoryNew();
// nothing left to test
}
}

View file

@ -0,0 +1,15 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
class MsgHistoryNewTest : DanaRTestBase() {
@Test fun runTest() {
val packet = MsgHistoryNew(aapsLogger, RxBusWrapper())
// nothing left to test
}
}

View file

@ -1,32 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.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.general.nsclient.NSUpload;
import info.nightscout.androidaps.utils.SP;
/**
* Created by Rumen Georgiev on 8/30/2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class, NSUpload.class})
public class MsgHistoryRefillTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
MsgHistoryRefill packet = new MsgHistoryRefill();
// nothing left to test
}
}

View file

@ -0,0 +1,15 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
class MsgHistoryRefillTest : DanaRTestBase() {
@Test fun runTest() {
val packet = MsgHistoryRefill(aapsLogger, RxBusWrapper())
// nothing left to test
}
}

View file

@ -1,32 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.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.general.nsclient.NSUpload;
import info.nightscout.androidaps.utils.SP;
/**
* Created by Rumen Georgiev on 8/30/2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class, NSUpload.class})
public class MsgHistorySuspendTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
MsgHistorySuspend packet = new MsgHistorySuspend();
// nothing left to test
}
}

View file

@ -0,0 +1,15 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
class MsgHistorySuspendTest : DanaRTestBase() {
@Test fun runTest() {
val packet = MsgHistorySuspend(aapsLogger, RxBusWrapper())
// nothing left to test
}
}

View file

@ -1,63 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaRv2.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.TreatmentService;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.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.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;
}
}

View file

@ -0,0 +1,39 @@
package info.nightscout.androidaps.plugins.pump.danaRv2.comm
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage
import info.nightscout.androidaps.plugins.pump.danaR.comm.DanaRTestBase
import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
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(DetailedBolusInfoStorage::class)
class MsgHistoryEvents_v2Test : DanaRTestBase() {
@Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage
@Mock lateinit var danaRv2Plugin: DanaRv2Plugin
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin
@Test @Throws(Exception::class) fun runTest() {
var packet = MsgHistoryEvents_v2(aapsLogger, resourceHelper, detailedBolusInfoStorage, danaRv2Plugin, RxBusWrapper(), treatmentsPlugin, 0)
// test message decoding
val array = ByteArray(100)
putByteToArray(array, 0, 0xFF.toByte())
packet.handleMessage(array)
Assert.assertEquals(true, danaRv2Plugin.eventsLoadingDone)
// passing an bigger number
putByteToArray(array, 0, 0x01.toByte())
packet.handleMessage(array)
Assert.assertEquals(false, danaRv2Plugin.eventsLoadingDone)
}
}