fix tests

This commit is contained in:
Milos Kozak 2020-07-02 23:04:09 +02:00
parent 6e88d127e5
commit a934677f51
6 changed files with 22 additions and 23 deletions

View file

@ -55,7 +55,7 @@ class DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest : DanaRSTestBase() {
@Before @Before
fun mock() { fun mock() {
danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, activePluginProvider, sp, commandQueue, danaPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil, Config()) danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, activePluginProvider, sp, commandQueue, danaPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil)
Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0)) Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0))
} }
} }

View file

@ -68,7 +68,7 @@ class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest : DanaRSTestBase() {
@Before @Before
fun mock() { fun mock() {
danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, activePluginProvider, sp, commandQueue, danaPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil, Config()) danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, activePluginProvider, sp, commandQueue, danaPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil)
danaPump.bolusingTreatment = Treatment(packetInjector) danaPump.bolusingTreatment = Treatment(packetInjector)
} }
} }

View file

@ -118,7 +118,7 @@ class ConstraintsCheckerTest : TestBaseWithProfile() {
objectivesPlugin = ObjectivesPlugin(injector, aapsLogger, resourceHelper, activePlugin, sp, Config()) objectivesPlugin = ObjectivesPlugin(injector, aapsLogger, resourceHelper, activePlugin, sp, Config())
comboPlugin = ComboPlugin(injector, aapsLogger, rxBus, resourceHelper, profileFunction, treatmentsPlugin, sp, commandQueue, context) comboPlugin = ComboPlugin(injector, aapsLogger, rxBus, resourceHelper, profileFunction, treatmentsPlugin, sp, commandQueue, context)
danaRPlugin = DanaRPlugin(injector, aapsLogger, rxBus, context, resourceHelper, constraintChecker, activePlugin, sp, commandQueue, danaPump, dateUtil, fabricPrivacy) danaRPlugin = DanaRPlugin(injector, aapsLogger, rxBus, context, resourceHelper, constraintChecker, activePlugin, sp, commandQueue, danaPump, dateUtil, fabricPrivacy)
danaRSPlugin = DanaRSPlugin(injector, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, activePluginProvider, sp, commandQueue, danaPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil, Config()) danaRSPlugin = DanaRSPlugin(injector, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, activePluginProvider, sp, commandQueue, danaPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil)
insightPlugin = LocalInsightPlugin(injector, aapsLogger, rxBus, resourceHelper, treatmentsPlugin, sp, commandQueue, profileFunction, nsUpload, context, uploadQueue, Config(), dateUtil) insightPlugin = LocalInsightPlugin(injector, aapsLogger, rxBus, resourceHelper, treatmentsPlugin, sp, commandQueue, profileFunction, nsUpload, context, uploadQueue, Config(), dateUtil)
openAPSSMBPlugin = OpenAPSSMBPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, treatmentsPlugin, iobCobCalculatorPlugin, hardLimits, profiler, fabricPrivacy) openAPSSMBPlugin = OpenAPSSMBPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, treatmentsPlugin, iobCobCalculatorPlugin, hardLimits, profiler, fabricPrivacy)
openAPSAMAPlugin = OpenAPSAMAPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, treatmentsPlugin, iobCobCalculatorPlugin, hardLimits, profiler, fabricPrivacy) openAPSAMAPlugin = OpenAPSAMAPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, treatmentsPlugin, iobCobCalculatorPlugin, hardLimits, profiler, fabricPrivacy)

View file

@ -14,13 +14,11 @@ import org.junit.Assert
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers
import org.mockito.ArgumentMatchers.anyBoolean import org.mockito.ArgumentMatchers.anyBoolean
import org.mockito.ArgumentMatchers.anyInt import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.anyLong import org.mockito.ArgumentMatchers.anyLong
import org.mockito.ArgumentMatchers.anyString import org.mockito.ArgumentMatchers.anyString
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.Mockito.`when` import org.mockito.Mockito.`when`
import org.powermock.api.mockito.PowerMockito import org.powermock.api.mockito.PowerMockito
import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.core.classloader.annotations.PrepareForTest
@ -51,12 +49,12 @@ class NsClientReceiverDelegateTest : TestBase() {
@Test fun testCalculateStatusChargingState() { @Test fun testCalculateStatusChargingState() {
PowerMockito.mockStatic(SP::class.java) PowerMockito.mockStatic(SP::class.java)
Mockito.`when`(sp.getBoolean(ArgumentMatchers.anyInt(), ArgumentMatchers.anyBoolean())).thenReturn(false) `when`(sp.getBoolean(anyInt(), anyBoolean())).thenReturn(false)
var ev = EventChargingState(true, 0) var ev = EventChargingState(true, 0)
Assert.assertTrue(sut!!.calculateStatus(ev)) Assert.assertTrue(sut!!.calculateStatus(ev))
ev = EventChargingState(false, 0) ev = EventChargingState(false, 0)
Assert.assertTrue(sut!!.calculateStatus(ev)) Assert.assertTrue(sut!!.calculateStatus(ev))
Mockito.`when`(sp.getBoolean(ArgumentMatchers.anyInt(), ArgumentMatchers.anyBoolean())).thenReturn(true) `when`(sp.getBoolean(anyInt(), anyBoolean())).thenReturn(true)
ev = EventChargingState(true, 0) ev = EventChargingState(true, 0)
Assert.assertTrue(sut!!.calculateStatus(ev)) Assert.assertTrue(sut!!.calculateStatus(ev))
ev = EventChargingState(false, 0) ev = EventChargingState(false, 0)
@ -67,24 +65,24 @@ class NsClientReceiverDelegateTest : TestBase() {
PowerMockito.mockStatic(SP::class.java) PowerMockito.mockStatic(SP::class.java)
// wifiOnly = false // wifiOnly = false
// allowRoaming = false as well // allowRoaming = false as well
Mockito.`when`(sp.getBoolean(ArgumentMatchers.anyInt(), ArgumentMatchers.anyBoolean())).thenReturn(false) `when`(sp.getBoolean(anyInt(), anyBoolean())).thenReturn(false)
Mockito.`when`(sp.getString(ArgumentMatchers.anyInt(), ArgumentMatchers.anyString())).thenReturn("") `when`(sp.getString(anyInt(), anyString())).thenReturn("")
val ev = EventNetworkChange() val ev = EventNetworkChange()
ev.ssid = "<unknown ssid>" ev.ssid = "<unknown ssid>"
ev.mobileConnected = true ev.mobileConnected = true
ev.wifiConnected = true ev.wifiConnected = true
Assert.assertTrue(sut!!.calculateStatus(ev)) Assert.assertTrue(sut!!.calculateStatus(ev))
ev.ssid = "test" ev.ssid = "test"
Mockito.`when`(sp.getString(ArgumentMatchers.anyInt(), ArgumentMatchers.anyString())).thenReturn("\"test\"") `when`(sp.getString(anyInt(), anyString())).thenReturn("test")
Assert.assertTrue(sut!!.calculateStatus(ev)) Assert.assertTrue(sut!!.calculateStatus(ev))
ev.ssid = "\"test\"" ev.ssid = "test"
Assert.assertTrue(sut!!.calculateStatus(ev)) Assert.assertTrue(sut!!.calculateStatus(ev))
ev.wifiConnected = false ev.wifiConnected = false
Assert.assertTrue(sut!!.calculateStatus(ev)) Assert.assertTrue(sut!!.calculateStatus(ev))
// wifiOnly = true // wifiOnly = true
// allowRoaming = true as well // allowRoaming = true as well
Mockito.`when`(sp.getBoolean(ArgumentMatchers.anyInt(), ArgumentMatchers.anyBoolean())).thenReturn(true) `when`(sp.getBoolean(anyInt(), anyBoolean())).thenReturn(true)
ev.wifiConnected = true ev.wifiConnected = true
Assert.assertTrue(sut!!.calculateStatus(ev)) Assert.assertTrue(sut!!.calculateStatus(ev))
ev.wifiConnected = false ev.wifiConnected = false
@ -92,39 +90,39 @@ class NsClientReceiverDelegateTest : TestBase() {
// wifiOnly = false // wifiOnly = false
// allowRoaming = false as well // allowRoaming = false as well
Mockito.`when`(sp.getBoolean(ArgumentMatchers.anyInt(), ArgumentMatchers.anyBoolean())).thenReturn(false) `when`(sp.getBoolean(anyInt(), anyBoolean())).thenReturn(false)
ev.wifiConnected = false ev.wifiConnected = false
ev.roaming = true ev.roaming = true
Assert.assertTrue(!sut!!.calculateStatus(ev)) Assert.assertTrue(!sut!!.calculateStatus(ev))
// wifiOnly = false // wifiOnly = false
// allowRoaming = true // allowRoaming = true
Mockito.`when`(sp.getBoolean(R.string.key_ns_wifionly, false)).thenReturn(false) `when`(sp.getBoolean(R.string.key_ns_wifionly, false)).thenReturn(false)
Mockito.`when`(sp.getBoolean(R.string.key_ns_allowroaming, true)).thenReturn(true) `when`(sp.getBoolean(R.string.key_ns_allowroaming, true)).thenReturn(true)
ev.wifiConnected = false ev.wifiConnected = false
ev.roaming = true ev.roaming = true
Assert.assertTrue(sut!!.calculateStatus(ev)) Assert.assertTrue(sut!!.calculateStatus(ev))
// wifiOnly = true // wifiOnly = true
// allowRoaming = true // allowRoaming = true
Mockito.`when`(sp.getBoolean(R.string.key_ns_wifionly, false)).thenReturn(true) `when`(sp.getBoolean(R.string.key_ns_wifionly, false)).thenReturn(true)
Mockito.`when`(sp.getBoolean(R.string.key_ns_allowroaming, true)).thenReturn(true) `when`(sp.getBoolean(R.string.key_ns_allowroaming, true)).thenReturn(true)
ev.wifiConnected = false ev.wifiConnected = false
ev.roaming = true ev.roaming = true
Assert.assertTrue(!sut!!.calculateStatus(ev)) Assert.assertTrue(!sut!!.calculateStatus(ev))
// wifiOnly = true // wifiOnly = true
// allowRoaming = true // allowRoaming = true
Mockito.`when`(sp.getBoolean(R.string.key_ns_wifionly, false)).thenReturn(true) `when`(sp.getBoolean(R.string.key_ns_wifionly, false)).thenReturn(true)
Mockito.`when`(sp.getBoolean(R.string.key_ns_allowroaming, true)).thenReturn(true) `when`(sp.getBoolean(R.string.key_ns_allowroaming, true)).thenReturn(true)
ev.wifiConnected = true ev.wifiConnected = true
ev.roaming = true ev.roaming = true
Assert.assertTrue(sut!!.calculateStatus(ev)) Assert.assertTrue(sut!!.calculateStatus(ev))
// wifiOnly = false // wifiOnly = false
// allowRoaming = false // allowRoaming = false
Mockito.`when`(sp.getBoolean(R.string.key_ns_wifionly, false)).thenReturn(false) `when`(sp.getBoolean(R.string.key_ns_wifionly, false)).thenReturn(false)
Mockito.`when`(sp.getBoolean(R.string.key_ns_allowroaming, true)).thenReturn(false) `when`(sp.getBoolean(R.string.key_ns_allowroaming, true)).thenReturn(false)
ev.wifiConnected = true ev.wifiConnected = true
ev.roaming = true ev.roaming = true
Assert.assertTrue(sut!!.calculateStatus(ev)) Assert.assertTrue(sut!!.calculateStatus(ev))

View file

@ -65,6 +65,6 @@ class DanaRSPluginTest : DanaRSTestBase() {
Mockito.`when`(resourceHelper.gs(eq(R.string.limitingbasalratio), anyObject(), anyObject())).thenReturn("limitingbasalratio") Mockito.`when`(resourceHelper.gs(eq(R.string.limitingbasalratio), anyObject(), anyObject())).thenReturn("limitingbasalratio")
Mockito.`when`(resourceHelper.gs(eq(R.string.limitingpercentrate), anyObject(), anyObject())).thenReturn("limitingpercentrate") Mockito.`when`(resourceHelper.gs(eq(R.string.limitingpercentrate), anyObject(), anyObject())).thenReturn("limitingpercentrate")
danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, activePluginProvider, sp, commandQueue, danaPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil, Config()) danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, activePluginProvider, sp, commandQueue, danaPump, detailedBolusInfoStorage, fabricPrivacy, dateUtil)
} }
} }

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.source
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.Config
import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
@ -23,7 +24,7 @@ class NSClientPluginTest : TestBase() {
@Before @Before
fun setup() { fun setup() {
nsClientSourcePlugin = NSClientSourcePlugin(HasAndroidInjector { AndroidInjector { } }, resourceHelper, aapsLogger, sp) nsClientSourcePlugin = NSClientSourcePlugin(HasAndroidInjector { AndroidInjector { } }, resourceHelper, aapsLogger, sp, Config())
} }
@Test fun advancedFilteringSupported() { @Test fun advancedFilteringSupported() {