Fix tests

This commit is contained in:
Tim Gunn 2020-05-02 19:13:16 +12:00
parent 0bbdca3b4a
commit 4c2fdef71a
No known key found for this signature in database
GPG key ID: C9BC1E9D0D0AED8C
2 changed files with 8 additions and 11 deletions

View file

@ -19,6 +19,7 @@ import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.receivers.ReceiverStatusStore import info.nightscout.androidaps.receivers.ReceiverStatusStore
import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.FabricPrivacy
import info.nightscout.androidaps.utils.HardLimits
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP import info.nightscout.androidaps.utils.sharedPreferences.SP
import org.junit.Assert import org.junit.Assert
@ -49,11 +50,15 @@ class LoopPluginTest : TestBase() {
@Mock lateinit var fabricPrivacy: FabricPrivacy @Mock lateinit var fabricPrivacy: FabricPrivacy
@Mock lateinit var receiverStatusStore: ReceiverStatusStore @Mock lateinit var receiverStatusStore: ReceiverStatusStore
private lateinit var hardLimits: HardLimits
lateinit var loopPlugin: LoopPlugin lateinit var loopPlugin: LoopPlugin
val injector = HasAndroidInjector { AndroidInjector { } } val injector = HasAndroidInjector { AndroidInjector { } }
@Before fun prepareMock() { @Before fun prepareMock() {
loopPlugin = LoopPlugin(injector, aapsLogger, rxBus, sp, constraintChecker, resourceHelper, profileFunction, context, commandQueue, activePlugin, treatmentsPlugin, virtualPumpPlugin, actionStringHandler, iobCobCalculatorPlugin, receiverStatusStore, fabricPrivacy) hardLimits = HardLimits(aapsLogger, rxBus, sp, resourceHelper, context)
loopPlugin = LoopPlugin(injector, aapsLogger, rxBus, sp, constraintChecker, resourceHelper, profileFunction, context, commandQueue, activePlugin, treatmentsPlugin, virtualPumpPlugin, actionStringHandler, iobCobCalculatorPlugin, receiverStatusStore, fabricPrivacy, hardLimits)
`when`(activePlugin.getActivePump()).thenReturn(virtualPumpPlugin) `when`(activePlugin.getActivePump()).thenReturn(virtualPumpPlugin)
} }
@ -61,6 +66,7 @@ class LoopPluginTest : TestBase() {
fun testPluginInterface() { fun testPluginInterface() {
`when`(resourceHelper.gs(R.string.loop)).thenReturn("Loop") `when`(resourceHelper.gs(R.string.loop)).thenReturn("Loop")
`when`(resourceHelper.gs(R.string.loop_shortname)).thenReturn("LOOP") `when`(resourceHelper.gs(R.string.loop_shortname)).thenReturn("LOOP")
`when`(sp.getString(R.string.key_aps_mode, "open")).thenReturn("closed")
val pumpDescription = PumpDescription() val pumpDescription = PumpDescription()
`when`(virtualPumpPlugin.pumpDescription).thenReturn(pumpDescription) `when`(virtualPumpPlugin.pumpDescription).thenReturn(pumpDescription)
Assert.assertEquals(LoopFragment::class.java.name, loopPlugin.pluginDescription.fragmentClass) Assert.assertEquals(LoopFragment::class.java.name, loopPlugin.pluginDescription.fragmentClass)

View file

@ -230,6 +230,7 @@ class SafetyPluginTest : TestBaseWithProfile() {
} }
@Test fun iobShouldBeLimited() { @Test fun iobShouldBeLimited() {
`when`(sp.getString(R.string.key_aps_mode, "open")).thenReturn("closed")
`when`(sp.getDouble(R.string.key_openapsma_max_iob, 1.5)).thenReturn(1.5) `when`(sp.getDouble(R.string.key_openapsma_max_iob, 1.5)).thenReturn(1.5)
`when`(sp.getString(R.string.key_age, "")).thenReturn("teenage") `when`(sp.getString(R.string.key_age, "")).thenReturn("teenage")
@ -242,14 +243,4 @@ class SafetyPluginTest : TestBaseWithProfile() {
""".trimIndent(), d.getReasons(aapsLogger)) """.trimIndent(), d.getReasons(aapsLogger))
Assert.assertEquals("Safety: Limiting IOB to 1.5 U because of max value in preferences", d.getMostLimitedReasons(aapsLogger)) Assert.assertEquals("Safety: Limiting IOB to 1.5 U because of max value in preferences", d.getMostLimitedReasons(aapsLogger))
} }
@Test fun iobShouldBeZero() {
`when`(sp.getString(R.string.key_aps_mode, "open")).thenReturn("lgs")
// Apply IOB limits
var d = Constraint(hardLimits.MAXIOB_LGS)
d = safetyPlugin.applyMaxIOBConstraints(d)
Assert.assertEquals(0.0, d.value()!!)
Assert.assertEquals("Safety: Limiting IOB to 0.0 U because of Low Glucose Suspend", d.getMostLimitedReasons(aapsLogger))
}
} }