RS tests
This commit is contained in:
parent
4c4e89df98
commit
1db651055b
7 changed files with 108 additions and 109 deletions
|
@ -27,7 +27,7 @@ class DanaRS_Packet_Notify_Delivery_Complete(
|
||||||
val deliveredInsulin = byteArrayToInt(getBytes(data, DATA_START, 2)) / 100.0
|
val deliveredInsulin = byteArrayToInt(getBytes(data, DATA_START, 2)) / 100.0
|
||||||
danaRSPlugin.bolusingTreatment.insulin = deliveredInsulin
|
danaRSPlugin.bolusingTreatment.insulin = deliveredInsulin
|
||||||
val bolusingEvent = EventOverviewBolusProgress
|
val bolusingEvent = EventOverviewBolusProgress
|
||||||
bolusingEvent.status = String.format(resourceHelper.gs(R.string.bolusdelivering), deliveredInsulin)
|
bolusingEvent.status = resourceHelper.gs(R.string.bolusdelivering, deliveredInsulin)
|
||||||
bolusingEvent.t = danaRSPlugin.bolusingTreatment
|
bolusingEvent.t = danaRSPlugin.bolusingTreatment
|
||||||
bolusingEvent.percent = min((deliveredInsulin / danaRSPlugin.bolusAmountToBeDelivered * 100).toInt(), 100)
|
bolusingEvent.percent = min((deliveredInsulin / danaRSPlugin.bolusAmountToBeDelivered * 100).toInt(), 100)
|
||||||
danaRSPlugin.bolusDone = true
|
danaRSPlugin.bolusDone = true
|
||||||
|
|
24
app/src/test/java/info/TestBase.kt
Normal file
24
app/src/test/java/info/TestBase.kt
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
package info
|
||||||
|
|
||||||
|
import org.junit.Rule
|
||||||
|
import org.mockito.Mockito
|
||||||
|
import org.mockito.junit.MockitoJUnit
|
||||||
|
import org.mockito.junit.MockitoRule
|
||||||
|
|
||||||
|
open class TestBase {
|
||||||
|
// Add a JUnit rule that will setup the @Mock annotated vars and log.
|
||||||
|
// Another possibility would be to add `MockitoAnnotations.initMocks(this) to the setup method.
|
||||||
|
@get:Rule
|
||||||
|
val mockitoRule: MockitoRule = MockitoJUnit.rule()
|
||||||
|
|
||||||
|
// Workaround for Kotlin nullability.
|
||||||
|
// https://medium.com/@elye.project/befriending-kotlin-and-mockito-1c2e7b0ef791
|
||||||
|
// https://stackoverflow.com/questions/30305217/is-it-possible-to-use-mockito-in-kotlin
|
||||||
|
fun <T> anyObject(): T {
|
||||||
|
Mockito.any<T>()
|
||||||
|
return uninitialized()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("Unchecked_Cast")
|
||||||
|
fun <T> uninitialized(): T = null as T
|
||||||
|
}
|
|
@ -1,36 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
|
|
||||||
|
|
||||||
|
|
||||||
import com.cozmo.danar.util.BleCommandUtil;
|
|
||||||
|
|
||||||
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.assertEquals;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Rumen Georgiev on 8/9/2018.
|
|
||||||
*/
|
|
||||||
@RunWith(PowerMockRunner.class)
|
|
||||||
@PrepareForTest({MainApp.class, SP.class, L.class, DanaRSMessageHashTable.class})
|
|
||||||
public class DanaRSMessageHashTableTest {
|
|
||||||
@Test
|
|
||||||
public void runTest() {
|
|
||||||
AAPSMocker.mockMainApp();
|
|
||||||
AAPSMocker.mockApplicationContext();
|
|
||||||
AAPSMocker.mockSP();
|
|
||||||
AAPSMocker.mockL();
|
|
||||||
// HashMap<Integer, DanaRS_Packet> messages = new DanaRSMessageHashTable().messages;
|
|
||||||
DanaRS_Packet forTesting = new DanaRS_Packet_APS_Set_Event_History();
|
|
||||||
DanaRS_Packet testPacket = DanaRSMessageHashTable.findMessage(forTesting.getCommand());
|
|
||||||
assertEquals(BleCommandUtil.DANAR_PACKET__OPCODE__APS_SET_EVENT_HISTORY, testPacket.getOpCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.danaRS.comm
|
||||||
|
|
||||||
|
import com.cozmo.danar.util.BleCommandUtil
|
||||||
|
import info.TestBase
|
||||||
|
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||||
|
import info.nightscout.androidaps.interfaces.Constraint
|
||||||
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||||
|
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
|
||||||
|
import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
|
import org.junit.Assert
|
||||||
|
import org.junit.Before
|
||||||
|
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 DanaRSMessageHashTableTest : TestBase() {
|
||||||
|
|
||||||
|
@Mock lateinit var aapsLogger: AAPSLogger
|
||||||
|
@Mock lateinit var rxBus: RxBusWrapper
|
||||||
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
|
@Mock lateinit var danaRSPlugin: DanaRSPlugin
|
||||||
|
@Mock lateinit var activePlugin: ActivePluginProvider
|
||||||
|
@Mock lateinit var constraintChecker: ConstraintChecker
|
||||||
|
@Mock lateinit var sp: SP
|
||||||
|
lateinit var danaRPump: DanaRPump
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun runTest() {
|
||||||
|
`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0))
|
||||||
|
|
||||||
|
val danaRSMessageHashTable = DanaRSMessageHashTable(aapsLogger, rxBus, resourceHelper, danaRPump, danaRSPlugin, activePlugin, constraintChecker)
|
||||||
|
val forTesting: DanaRS_Packet = DanaRS_Packet_APS_Set_Event_History(aapsLogger, DanaRPump.CARBS, 0, 0, 0)
|
||||||
|
val testPacket: DanaRS_Packet = danaRSMessageHashTable.findMessage(forTesting.command)
|
||||||
|
Assert.assertEquals(BleCommandUtil.DANAR_PACKET__OPCODE__APS_SET_EVENT_HISTORY.toLong(), testPacket.getOpCode().toLong())
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setup() {
|
||||||
|
danaRPump = DanaRPump(aapsLogger, sp)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,46 +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.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_StartTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void runTest() {
|
|
||||||
AAPSMocker.mockMainApp();
|
|
||||||
AAPSMocker.mockApplicationContext();
|
|
||||||
AAPSMocker.mockSP();
|
|
||||||
AAPSMocker.mockL();
|
|
||||||
|
|
||||||
DanaRS_Packet_Bolus_Set_Step_Bolus_Start packet = new DanaRS_Packet_Bolus_Set_Step_Bolus_Start();
|
|
||||||
|
|
||||||
// test params
|
|
||||||
byte[] testparams = packet.getRequestParams();
|
|
||||||
assertEquals(0, testparams[0]);
|
|
||||||
assertEquals(0, testparams[2]);
|
|
||||||
|
|
||||||
// test message decoding
|
|
||||||
packet.handleMessage(new byte[]{(byte) 0, (byte) 0, (byte) 0});
|
|
||||||
assertEquals(false, packet.failed);
|
|
||||||
packet.handleMessage(new byte[]{(byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1});
|
|
||||||
assertEquals(true, packet.failed);
|
|
||||||
|
|
||||||
assertEquals("BOLUS__SET_STEP_BOLUS_START", packet.getFriendlyName());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -2,30 +2,35 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm
|
||||||
|
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.AAPSMocker
|
import info.TestBase
|
||||||
import info.nightscout.androidaps.MainApp
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.L
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
||||||
|
import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin
|
||||||
import info.nightscout.androidaps.plugins.treatments.Treatment
|
import info.nightscout.androidaps.plugins.treatments.Treatment
|
||||||
import info.nightscout.androidaps.utils.DefaultValueHelper
|
import info.nightscout.androidaps.utils.DefaultValueHelper
|
||||||
import info.nightscout.androidaps.utils.SP
|
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
|
import org.mockito.Mockito
|
||||||
|
import org.mockito.Mockito.`when`
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||||
import org.powermock.modules.junit4.PowerMockRunner
|
import org.powermock.modules.junit4.PowerMockRunner
|
||||||
|
|
||||||
@RunWith(PowerMockRunner::class)
|
@RunWith(PowerMockRunner::class)
|
||||||
@PrepareForTest(MainApp::class, SP::class, L::class)
|
@PrepareForTest(RxBusWrapper::class)
|
||||||
class DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest : DanaRS_Packet_Bolus_Set_Step_Bolus_Stop() {
|
class DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var defaultValueHelper: DefaultValueHelper
|
@Mock lateinit var defaultValueHelper: DefaultValueHelper
|
||||||
|
@Mock lateinit var rxBus: RxBusWrapper
|
||||||
|
@Mock lateinit var aapsLogger: AAPSLogger
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
@Mock lateinit var profileFunction: ProfileFunction
|
@Mock lateinit var profileFunction: ProfileFunction
|
||||||
@Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin
|
@Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin
|
||||||
|
@Mock lateinit var danaRSPlugin: DanaRSPlugin
|
||||||
|
|
||||||
private var treatmentInjector: HasAndroidInjector = HasAndroidInjector {
|
private var treatmentInjector: HasAndroidInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
|
@ -39,17 +44,15 @@ class DanaRS_Packet_Bolus_Set_Step_Bolus_StopTest : DanaRS_Packet_Bolus_Set_Step
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
@Test fun runTest() {
|
||||||
AAPSMocker.mockMainApp()
|
`when`(resourceHelper.gs(Mockito.anyInt())).thenReturn("SomeString")
|
||||||
AAPSMocker.mockApplicationContext()
|
|
||||||
AAPSMocker.mockStrings()
|
danaRSPlugin.bolusingTreatment = Treatment(treatmentInjector)
|
||||||
AAPSMocker.mockSP()
|
val testPacket = DanaRS_Packet_Bolus_Set_Step_Bolus_Stop(aapsLogger, rxBus, resourceHelper, danaRSPlugin)
|
||||||
AAPSMocker.mockL()
|
|
||||||
val testPacket = DanaRS_Packet_Bolus_Set_Step_Bolus_Stop(1.0, Treatment(treatmentInjector))
|
|
||||||
// test message decoding
|
// test message decoding
|
||||||
testPacket.handleMessage(byteArrayOf(0.toByte(), 0.toByte(), 0.toByte()))
|
testPacket.handleMessage(byteArrayOf(0.toByte(), 0.toByte(), 0.toByte()))
|
||||||
Assert.assertEquals(false, testPacket.failed)
|
Assert.assertEquals(false, testPacket.failed)
|
||||||
testPacket.handleMessage(byteArrayOf(1.toByte(), 1.toByte(), 1.toByte(), 1.toByte(), 1.toByte(), 1.toByte(), 1.toByte(), 1.toByte()))
|
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(true, testPacket.failed)
|
||||||
Assert.assertEquals("BOLUS__SET_STEP_BOLUS_STOP", friendlyName)
|
Assert.assertEquals("BOLUS__SET_STEP_BOLUS_STOP", testPacket.friendlyName)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,28 +2,34 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm
|
||||||
|
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.AAPSMocker
|
import info.TestBase
|
||||||
import info.nightscout.androidaps.MainApp
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.L
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
||||||
|
import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin
|
||||||
import info.nightscout.androidaps.plugins.treatments.Treatment
|
import info.nightscout.androidaps.plugins.treatments.Treatment
|
||||||
import info.nightscout.androidaps.utils.DefaultValueHelper
|
import info.nightscout.androidaps.utils.DefaultValueHelper
|
||||||
import info.nightscout.androidaps.utils.SP
|
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
|
import org.mockito.Mockito.`when`
|
||||||
|
import org.mockito.Mockito.anyDouble
|
||||||
|
import org.mockito.Mockito.anyInt
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest
|
import org.powermock.core.classloader.annotations.PrepareForTest
|
||||||
import org.powermock.modules.junit4.PowerMockRunner
|
import org.powermock.modules.junit4.PowerMockRunner
|
||||||
|
|
||||||
@RunWith(PowerMockRunner::class)
|
@RunWith(PowerMockRunner::class)
|
||||||
@PrepareForTest(MainApp::class, SP::class, L::class)
|
@PrepareForTest(RxBusWrapper::class)
|
||||||
class DanaRS_Packet_Notify_Delivery_CompleteTest {
|
class DanaRS_Packet_Notify_Delivery_CompleteTest : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var defaultValueHelper: DefaultValueHelper
|
@Mock lateinit var defaultValueHelper: DefaultValueHelper
|
||||||
|
@Mock lateinit var rxBus: RxBusWrapper
|
||||||
|
@Mock lateinit var aapsLogger: AAPSLogger
|
||||||
@Mock lateinit var resourceHelper: ResourceHelper
|
@Mock lateinit var resourceHelper: ResourceHelper
|
||||||
|
@Mock lateinit var danaRSPlugin: DanaRSPlugin
|
||||||
@Mock lateinit var profileFunction: ProfileFunction
|
@Mock lateinit var profileFunction: ProfileFunction
|
||||||
@Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin
|
@Mock lateinit var configBuilderPlugin: ConfigBuilderPlugin
|
||||||
|
|
||||||
|
@ -39,17 +45,15 @@ class DanaRS_Packet_Notify_Delivery_CompleteTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
@Test fun runTest() {
|
||||||
AAPSMocker.mockMainApp()
|
`when`(resourceHelper.gs(anyInt(), anyDouble())).thenReturn("SomeString")
|
||||||
AAPSMocker.mockApplicationContext()
|
|
||||||
AAPSMocker.mockSP()
|
danaRSPlugin.bolusingTreatment = Treatment(treatmentInjector)
|
||||||
AAPSMocker.mockL()
|
val packet = DanaRS_Packet_Notify_Delivery_Complete(aapsLogger, rxBus, resourceHelper, danaRSPlugin)
|
||||||
AAPSMocker.mockStrings()
|
|
||||||
val packet = DanaRS_Packet_Notify_Delivery_Complete(0.5, Treatment(treatmentInjector))
|
|
||||||
// test params
|
// test params
|
||||||
Assert.assertEquals(null, packet.requestParams)
|
Assert.assertEquals(null, packet.requestParams)
|
||||||
// test message decoding
|
// test message decoding
|
||||||
packet.handleMessage(createArray(17, 0.toByte()))
|
packet.handleMessage(createArray(17, 0.toByte()))
|
||||||
Assert.assertEquals(true, DanaRS_Packet_Notify_Delivery_Complete.done)
|
Assert.assertEquals(true, danaRSPlugin.bolusDone)
|
||||||
Assert.assertEquals("NOTIFY__DELIVERY_COMPLETE", packet.friendlyName)
|
Assert.assertEquals("NOTIFY__DELIVERY_COMPLETE", packet.friendlyName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue