fix tests

This commit is contained in:
Milos Kozak 2022-11-28 10:46:53 +01:00
parent 27733a2dc5
commit b2aa09890c
12 changed files with 64 additions and 45 deletions

View file

@ -6,8 +6,8 @@ import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.core.main.R
import info.nightscout.core.pump.toHtml
import info.nightscout.interfaces.pump.PumpEnactResult
import info.nightscout.plugins.aps.loop.extensions.json
import info.nightscout.plugins.extensions.toText
import info.nightscout.plugins.sync.nsShared.extensions.json
import info.nightscout.plugins.sync.nsShared.extensions.log
import org.json.JSONObject
import org.junit.Assert

View file

@ -68,9 +68,9 @@ class DetailedBolusInfoTest : TestBase() {
detailedBolusInfo.insulin = 7.0
val bolus = detailedBolusInfo.createBolus()
Assert.assertEquals(1000L, bolus?.timestamp)
Assert.assertEquals(Bolus.Type.SMB, bolus?.type)
Assert.assertEquals(7.0, bolus?.amount)
Assert.assertEquals(1000L, bolus.timestamp)
Assert.assertEquals(Bolus.Type.SMB, bolus.type)
Assert.assertEquals(7.0, bolus.amount, 0.01)
}
@Test
@ -80,8 +80,8 @@ class DetailedBolusInfoTest : TestBase() {
detailedBolusInfo.carbs = 6.0
val carbs = detailedBolusInfo.createCarbs()
Assert.assertEquals(1000L, carbs?.timestamp)
Assert.assertEquals(6.0, carbs?.amount)
Assert.assertEquals(1000L, carbs.timestamp)
Assert.assertEquals(6.0, carbs.amount, 0.01)
}
private fun createBolusCalculatorResult(): BolusCalculatorResult =

View file

@ -33,6 +33,7 @@
<string name="result">Result</string>
<string name="settings">Settings</string>
<string name="statuslights">Status lights</string>
<string name="do_ns_upload_title">Upload BG data to NS</string>
<!-- Pumps -->
<string name="battery_label">Battery</string>

View file

@ -131,5 +131,6 @@
<string name="key_snoozed_to" translatable="false">snoozedTo</string>
<string name="key_ns_receive_cgm" translatable="false">ns_receive_cgm</string>
<string name="key_ns_create_announcements_from_carbs_req" translatable="false">ns_create_announcements_from_carbs_req</string>
<string name="key_do_ns_upload" translatable="false">dexcomg5_nsupload</string>
</resources>

View file

@ -7,22 +7,29 @@ import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.androidaps.TestPumpPlugin
import info.nightscout.interfaces.logging.UserEntryLogger
import info.nightscout.automation.triggers.Trigger
import info.nightscout.database.entities.DeviceStatus
import info.nightscout.database.entities.OfflineEvent
import info.nightscout.interfaces.ConfigBuilder
import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.aps.Loop
import info.nightscout.interfaces.configBuilder.RunningConfiguration
import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.interfaces.iob.IobCobCalculator
import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.plugin.PluginBase
import info.nightscout.interfaces.plugin.PluginDescription
import info.nightscout.interfaces.profile.Profile
import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.interfaces.profile.ProfileSource
import info.nightscout.interfaces.pump.Pump
import info.nightscout.interfaces.pump.PumpEnactResult
import info.nightscout.interfaces.queue.CommandQueue
import info.nightscout.interfaces.receivers.ReceiverStatusStore
import info.nightscout.interfaces.smsCommunicator.SmsCommunicator
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.utils.DateUtil
import org.junit.Before
import org.mockito.Mock
import org.mockito.Mockito.`when`
@ -57,6 +64,16 @@ ActionsTestBase : TestBaseWithProfile() {
override fun goToZeroTemp(durationInMinutes: Int, profile: Profile, reason: OfflineEvent.Reason) {}
override fun suspendLoop(durationInMinutes: Int) {}
override fun disableCarbSuggestions(durationMinutes: Int) {}
override fun buildDeviceStatus(
dateUtil: DateUtil,
loop: Loop,
iobCobCalculatorPlugin: IobCobCalculator,
profileFunction: ProfileFunction,
pump: Pump,
receiverStatusStore: ReceiverStatusStore,
runningConfiguration: RunningConfiguration,
version: String
): DeviceStatus? = null
}
@Mock lateinit var sp: SP

View file

@ -28,14 +28,12 @@ open class TriggerTestBase : TestBaseWithProfile() {
@Mock lateinit var autosensDataStore: AutosensDataStore
@Mock lateinit var context: Context
@Mock lateinit var automationPlugin: AutomationPlugin
lateinit var receiverStatusStore: ReceiverStatusStore
@Mock lateinit var receiverStatusStore: ReceiverStatusStore
private val pluginDescription = PluginDescription()
lateinit var testPumpPlugin: TestPumpPlugin
@Before
fun prepareMock1() {
receiverStatusStore = ReceiverStatusStore(context, rxBus)
testPumpPlugin = TestPumpPlugin(pluginDescription, aapsLogger, rh, injector)
`when`(activePlugin.activePump).thenReturn(testPumpPlugin)
`when`(iobCobCalculator.ads).thenReturn(autosensDataStore)

View file

@ -14,14 +14,13 @@ import org.mockito.Mockito.`when`
class TriggerWifiSsidTest : TriggerTestBase() {
var now = 1514766900000L
@Before fun mock() {
`when`(dateUtil.now()).thenReturn(now)
}
@Test fun shouldRunTest() {
val e = EventNetworkChange()
receiverStatusStore.lastNetworkEvent = e
`when`(receiverStatusStore.lastNetworkEvent).thenReturn(e)
var t: TriggerWifiSsid = TriggerWifiSsid(injector).setValue("aSSID").comparator(Comparator.Compare.IS_EQUAL)
e.wifiConnected = false
Assert.assertFalse(t.shouldRun())
@ -36,7 +35,7 @@ class TriggerWifiSsidTest : TriggerTestBase() {
Assert.assertTrue(t.shouldRun())
// no network data
receiverStatusStore.lastNetworkEvent = null
`when`(receiverStatusStore.lastNetworkEvent).thenReturn(null)
Assert.assertFalse(t.shouldRun())
}

View file

@ -56,11 +56,11 @@ import info.nightscout.interfaces.queue.CommandQueue
import info.nightscout.interfaces.receivers.ReceiverStatusStore
import info.nightscout.interfaces.ui.ActivityNames
import info.nightscout.interfaces.utils.HardLimits
import info.nightscout.interfaces.utils.Round
import info.nightscout.plugins.R
import info.nightscout.plugins.aps.loop.events.EventLoopSetLastRunGui
import info.nightscout.plugins.aps.loop.events.EventLoopUpdateGui
import info.nightscout.plugins.aps.loop.events.EventNewOpenLoopNotification
import info.nightscout.plugins.aps.loop.extensions.json
import info.nightscout.plugins.pump.virtual.VirtualPumpPlugin
import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.bus.RxBus
@ -782,33 +782,6 @@ class LoopPlugin @Inject constructor(
configuration = runningConfiguration.configuration().toString()
)
}
fun PumpEnactResult.json(baseBasal: Double): JSONObject {
val result = JSONObject()
when {
bolusDelivered > 0 -> {
result.put("smb", bolusDelivered)
}
isTempCancel -> {
result.put("rate", 0)
result.put("duration", 0)
}
isPercent -> {
// Nightscout is expecting absolute value
val abs = Round.roundTo(baseBasal * percent / 100, 0.01)
result.put("rate", abs)
result.put("duration", duration)
}
else -> {
result.put("rate", absolute)
result.put("duration", duration)
}
}
return result
}
companion object {
private const val CHANNEL_ID = "AAPS-OpenLoop"

View file

@ -0,0 +1,32 @@
package info.nightscout.plugins.aps.loop.extensions
import info.nightscout.interfaces.pump.PumpEnactResult
import info.nightscout.interfaces.utils.Round
import org.json.JSONObject
fun PumpEnactResult.json(baseBasal: Double): JSONObject {
val result = JSONObject()
when {
bolusDelivered > 0 -> {
result.put("smb", bolusDelivered)
}
isTempCancel -> {
result.put("rate", 0)
result.put("duration", 0)
}
isPercent -> {
// Nightscout is expecting absolute value
val abs = Round.roundTo(baseBasal * percent / 100, 0.01)
result.put("rate", abs)
result.put("duration", duration)
}
else -> {
result.put("rate", absolute)
result.put("duration", duration)
}
}
return result
}

View file

@ -411,7 +411,6 @@
<string name="virtualpump_uploadstatus_title">Upload status to NS</string>
<!-- Source -->
<string name="key_do_ns_upload" translatable="false">dexcomg5_nsupload</string>
<string name="key_dexcom_log_ns_sensor_change" translatable="false">dexcom_lognssensorchange</string>
<string name="key_last_processed_glunovo_timestamp" translatable="false">last_processed_glunovo_timestamp</string>
<string name="key_last_processed_intelligo_timestamp" translatable="false">last_processed_intelligo_timestamp</string>
@ -449,7 +448,6 @@
<string name="do_xdrip_upload_title">Send BG data to xDrip+</string>
<string name="do_xdrip_upload_summary">In xDrip+ select 640g/Eversense data source</string>
<string name="do_ns_upload_title">Upload BG data to NS</string>
<string name="bgsource_upload">BG upload settings</string>
<string name="dexcom_log_ns_sensor_change_title">Log sensor change to NS</string>
<string name="dexcom_log_ns_sensor_change_summary">Create event \"Sensor Change\" in NS automatically on sensor start</string>

View file

@ -3,7 +3,7 @@ package info.nightscout.plugins.sync.nsclient
import android.content.Context
import info.nightscout.androidaps.TestBase
import info.nightscout.interfaces.receivers.ReceiverStatusStore
import info.nightscout.plugins.R
import info.nightscout.plugins.sync.R
import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.events.EventChargingState
import info.nightscout.rx.events.EventNetworkChange
@ -22,13 +22,13 @@ class NsClientReceiverDelegateTest : TestBase() {
@Mock lateinit var rh: ResourceHelper
val rxBus = RxBus(aapsSchedulers, aapsLogger)
private lateinit var receiverStatusStore: ReceiverStatusStore
@Mock private lateinit var receiverStatusStore: ReceiverStatusStore
private lateinit var sut: NsClientReceiverDelegate
@Before
fun prepare() {
receiverStatusStore = ReceiverStatusStore(context, rxBus)
//receiverStatusStore = ReceiverStatusStore(context, rxBus)
sut = NsClientReceiverDelegate(rxBus, rh, sp, receiverStatusStore)
}