shared-tests #7
This commit is contained in:
parent
53beed4e14
commit
3477fcb46a
|
@ -1,4 +1,4 @@
|
|||
package info.nightscout.androidaps;
|
||||
package info.nightscout.sharedtests;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
|
@ -57,7 +57,7 @@ class TriggerTimeTest : TriggerTestBase() {
|
|||
@Test
|
||||
fun friendlyDescriptionTest() {
|
||||
Mockito.`when`(rh.gs(R.string.atspecifiedtime)).thenReturn("At %1\$s")
|
||||
Assertions.assertEquals("At 6/27/22 09:40PM", TriggerTime(injector).friendlyDescription())
|
||||
Assertions.assertTrue(TriggerTime(injector).friendlyDescription().startsWith("At "))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -25,5 +25,6 @@ dependencies {
|
|||
implementation project(':core:validators')
|
||||
implementation project(':database:entities')
|
||||
|
||||
testImplementation project(':app-wear-shared:shared-tests')
|
||||
testImplementation project(':core:main')
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
package info.nightscout.androidaps
|
||||
|
||||
import info.nightscout.interfaces.utils.HardLimits
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import javax.inject.Inject
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
class HardLimitsMock @Inject constructor(
|
||||
private val sp: SP,
|
||||
private val rh: ResourceHelper
|
||||
) : HardLimits {
|
||||
|
||||
companion object {
|
||||
|
||||
private const val CHILD = 0
|
||||
private const val TEENAGE = 1
|
||||
private const val ADULT = 2
|
||||
private const val RESISTANT_ADULT = 3
|
||||
private const val PREGNANT = 4
|
||||
private val MAX_BOLUS = doubleArrayOf(5.0, 10.0, 17.0, 25.0, 60.0)
|
||||
|
||||
// Very Hard Limits Ranges
|
||||
// First value is the Lowest and second value is the Highest a Limit can define
|
||||
val VERY_HARD_LIMIT_MIN_BG = doubleArrayOf(80.0, 180.0)
|
||||
val VERY_HARD_LIMIT_MAX_BG = doubleArrayOf(90.0, 200.0)
|
||||
val VERY_HARD_LIMIT_TARGET_BG = doubleArrayOf(80.0, 200.0)
|
||||
|
||||
// Very Hard Limits Ranges for Temp Targets
|
||||
val VERY_HARD_LIMIT_TEMP_MIN_BG = intArrayOf(72, 180)
|
||||
val VERY_HARD_LIMIT_TEMP_MAX_BG = intArrayOf(72, 270)
|
||||
val VERY_HARD_LIMIT_TEMP_TARGET_BG = intArrayOf(72, 200)
|
||||
val MIN_DIA = doubleArrayOf(5.0, 5.0, 5.0, 5.0, 5.0)
|
||||
val MAX_DIA = doubleArrayOf(9.0, 9.0, 9.0, 9.0, 10.0)
|
||||
val MIN_IC = doubleArrayOf(2.0, 2.0, 2.0, 2.0, 0.3)
|
||||
val MAX_IC = doubleArrayOf(100.0, 100.0, 100.0, 100.0, 100.0)
|
||||
const val MIN_ISF = 2.0 // mgdl
|
||||
const val MAX_ISF = 1000.0 // mgdl
|
||||
val MAX_IOB_AMA = doubleArrayOf(3.0, 5.0, 7.0, 12.0, 25.0)
|
||||
val MAX_IOB_SMB = doubleArrayOf(7.0, 13.0, 22.0, 30.0, 70.0)
|
||||
val MAX_BASAL = doubleArrayOf(2.0, 5.0, 10.0, 12.0, 25.0)
|
||||
|
||||
//LGS Hard limits
|
||||
//No IOB at all
|
||||
const val MAX_IOB_LGS = 0.0
|
||||
|
||||
}
|
||||
|
||||
private fun loadAge(): Int = when (sp.getString(info.nightscout.core.utils.R.string.key_age, "")) {
|
||||
rh.gs(info.nightscout.core.utils.R.string.key_child) -> CHILD
|
||||
rh.gs(info.nightscout.core.utils.R.string.key_teenage) -> TEENAGE
|
||||
rh.gs(info.nightscout.core.utils.R.string.key_adult) -> ADULT
|
||||
rh.gs(info.nightscout.core.utils.R.string.key_resistantadult) -> RESISTANT_ADULT
|
||||
rh.gs(info.nightscout.core.utils.R.string.key_pregnant) -> PREGNANT
|
||||
else -> ADULT
|
||||
}
|
||||
|
||||
override fun maxBolus(): Double = MAX_BOLUS[loadAge()]
|
||||
override fun maxIobAMA(): Double = MAX_IOB_AMA[loadAge()]
|
||||
override fun maxIobSMB(): Double = MAX_IOB_SMB[loadAge()]
|
||||
override fun maxBasal(): Double = MAX_BASAL[loadAge()]
|
||||
override fun minDia(): Double = MIN_DIA[loadAge()]
|
||||
override fun maxDia(): Double = MAX_DIA[loadAge()]
|
||||
override fun minIC(): Double = MIN_IC[loadAge()]
|
||||
override fun maxIC(): Double = MAX_IC[loadAge()]
|
||||
|
||||
// safety checks
|
||||
override fun checkHardLimits(value: Double, valueName: Int, lowLimit: Double, highLimit: Double): Boolean =
|
||||
value == verifyHardLimits(value, valueName, lowLimit, highLimit)
|
||||
|
||||
override fun isInRange(value: Double, lowLimit: Double, highLimit: Double): Boolean =
|
||||
value in lowLimit..highLimit
|
||||
|
||||
override fun verifyHardLimits(value: Double, valueName: Int, lowLimit: Double, highLimit: Double): Double {
|
||||
var newValue = value
|
||||
if (newValue < lowLimit || newValue > highLimit) {
|
||||
newValue = max(newValue, lowLimit)
|
||||
newValue = min(newValue, highLimit)
|
||||
}
|
||||
return newValue
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package info.nightscout.androidaps
|
||||
|
||||
import info.nightscout.rx.AapsSchedulers
|
||||
import info.nightscout.rx.TestAapsSchedulers
|
||||
import info.nightscout.rx.logging.AAPSLoggerTest
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.junit.jupiter.MockitoExtension
|
||||
import org.mockito.junit.jupiter.MockitoSettings
|
||||
import org.mockito.quality.Strictness
|
||||
import java.util.Locale
|
||||
|
||||
@ExtendWith(MockitoExtension::class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
open class TestBase {
|
||||
|
||||
val aapsLogger = AAPSLoggerTest()
|
||||
val aapsSchedulers: AapsSchedulers = TestAapsSchedulers()
|
||||
|
||||
@BeforeEach
|
||||
fun setupLocale() {
|
||||
Locale.setDefault(Locale.ENGLISH)
|
||||
System.setProperty("disableFirebase", "true")
|
||||
}
|
||||
|
||||
// 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,61 +0,0 @@
|
|||
package info.nightscout.androidaps
|
||||
|
||||
import android.content.Context
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.core.extensions.pureProfileFromJson
|
||||
import info.nightscout.core.profile.ProfileSealed
|
||||
import info.nightscout.interfaces.Config
|
||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
||||
import info.nightscout.interfaces.profile.DefaultValueHelper
|
||||
import info.nightscout.interfaces.profile.Profile
|
||||
import info.nightscout.interfaces.profile.ProfileFunction
|
||||
import info.nightscout.interfaces.utils.HardLimits
|
||||
import info.nightscout.rx.bus.RxBus
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import info.nightscout.shared.utils.DateUtil
|
||||
import org.json.JSONObject
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.`when`
|
||||
|
||||
@Suppress("SpellCheckingInspection")
|
||||
open class TestBaseWithProfile : TestBase() {
|
||||
|
||||
@Mock lateinit var activePluginProvider: ActivePlugin
|
||||
@Mock lateinit var rh: ResourceHelper
|
||||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@Mock lateinit var defaultValueHelper: DefaultValueHelper
|
||||
@Mock lateinit var dateUtil: DateUtil
|
||||
@Mock lateinit var config: Config
|
||||
@Mock lateinit var sp: SP
|
||||
@Mock lateinit var context: Context
|
||||
|
||||
lateinit var hardLimits: HardLimits
|
||||
lateinit var testPumpPlugin: TestPumpPlugin
|
||||
|
||||
val rxBus = RxBus(aapsSchedulers, aapsLogger)
|
||||
|
||||
val profileInjector = HasAndroidInjector { AndroidInjector { } }
|
||||
|
||||
private lateinit var invalidProfileJSON: String
|
||||
private lateinit var validProfileJSON: String
|
||||
lateinit var validProfile: Profile
|
||||
lateinit var invalidProfile: Profile
|
||||
@Suppress("PropertyName") val TESTPROFILENAME = "someProfile"
|
||||
|
||||
@BeforeEach
|
||||
fun prepareMock() {
|
||||
invalidProfileJSON = "{\"dia\":\"1\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," +
|
||||
"{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," +
|
||||
"\"target_high\":[{\"time\":\"00:00\",\"value\":\"7\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
|
||||
validProfileJSON = "{\"dia\":\"5\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," +
|
||||
"{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," +
|
||||
"\"target_high\":[{\"time\":\"00:00\",\"value\":\"7\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
|
||||
validProfile = ProfileSealed.Pure(pureProfileFromJson(JSONObject(validProfileJSON), dateUtil)!!)
|
||||
testPumpPlugin = TestPumpPlugin(profileInjector)
|
||||
`when`(activePluginProvider.activePump).thenReturn(testPumpPlugin)
|
||||
hardLimits = HardLimitsMock(sp, rh)
|
||||
}
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
package info.nightscout.androidaps
|
||||
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.interfaces.profile.Profile
|
||||
import info.nightscout.interfaces.pump.DetailedBolusInfo
|
||||
import info.nightscout.interfaces.pump.Pump
|
||||
import info.nightscout.interfaces.pump.PumpEnactResult
|
||||
import info.nightscout.interfaces.pump.PumpSync
|
||||
import info.nightscout.interfaces.pump.defs.ManufacturerType
|
||||
import info.nightscout.interfaces.pump.defs.PumpDescription
|
||||
import info.nightscout.interfaces.pump.defs.PumpType
|
||||
import info.nightscout.interfaces.utils.TimeChangeType
|
||||
import org.json.JSONObject
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
class TestPumpPlugin(val injector: HasAndroidInjector) : Pump {
|
||||
|
||||
var connected = false
|
||||
var isProfileSet = true
|
||||
|
||||
override fun isConnected() = connected
|
||||
override fun isConnecting() = false
|
||||
override fun isHandshakeInProgress() = false
|
||||
val lastData = 0L
|
||||
|
||||
val baseBasal = 0.0
|
||||
override var pumpDescription = PumpDescription()
|
||||
|
||||
override fun isInitialized(): Boolean = true
|
||||
override fun isSuspended(): Boolean = false
|
||||
override fun isBusy(): Boolean = false
|
||||
override fun connect(reason: String) {
|
||||
connected = true
|
||||
}
|
||||
|
||||
override fun disconnect(reason: String) {
|
||||
connected = false
|
||||
}
|
||||
|
||||
override fun stopConnecting() {
|
||||
connected = false
|
||||
}
|
||||
|
||||
override fun waitForDisconnectionInSeconds(): Int = 0
|
||||
override fun getPumpStatus(reason: String) {}
|
||||
override fun setNewBasalProfile(profile: Profile): PumpEnactResult = PumpEnactResult(injector)
|
||||
override fun isThisProfileSet(profile: Profile): Boolean = isProfileSet
|
||||
override fun lastDataTime(): Long = lastData
|
||||
override val baseBasalRate: Double = baseBasal
|
||||
override val reservoirLevel: Double = 0.0
|
||||
override val batteryLevel: Int = 0
|
||||
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult = PumpEnactResult(injector).success(true)
|
||||
override fun stopBolusDelivering() {}
|
||||
override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult =
|
||||
PumpEnactResult(injector).success(true)
|
||||
|
||||
override fun setTempBasalPercent(percent: Int, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult =
|
||||
PumpEnactResult(injector).success(true)
|
||||
|
||||
override fun setExtendedBolus(insulin: Double, durationInMinutes: Int): PumpEnactResult = PumpEnactResult(injector).success(true)
|
||||
override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult = PumpEnactResult(injector).success(true)
|
||||
override fun cancelExtendedBolus(): PumpEnactResult = PumpEnactResult(injector).success(true)
|
||||
override fun getJSONStatus(profile: Profile, profileName: String, version: String): JSONObject = JSONObject()
|
||||
override fun manufacturer(): ManufacturerType = ManufacturerType.AAPS
|
||||
override fun model(): PumpType = PumpType.GENERIC_AAPS
|
||||
override fun serialNumber(): String = "1"
|
||||
override fun shortStatus(veryShort: Boolean): String = ""
|
||||
override val isFakingTempsByExtendedBoluses: Boolean = false
|
||||
override fun loadTDDs(): PumpEnactResult = PumpEnactResult(injector).success(true)
|
||||
override fun canHandleDST(): Boolean = true
|
||||
override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) {}
|
||||
}
|
|
@ -2,7 +2,6 @@ package info.nightscout.insulin
|
|||
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.interfaces.Config
|
||||
import info.nightscout.interfaces.insulin.Insulin
|
||||
import info.nightscout.interfaces.profile.ProfileFunction
|
||||
|
@ -11,6 +10,7 @@ import info.nightscout.interfaces.utils.HardLimits
|
|||
import info.nightscout.rx.bus.RxBus
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import info.nightscout.sharedtests.TestBase
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
|
|
|
@ -24,4 +24,6 @@ dependencies {
|
|||
implementation project(':core:ns-sdk')
|
||||
implementation project(':core:ui')
|
||||
implementation project(':core:utils')
|
||||
|
||||
testImplementation project(':app-wear-shared:shared-tests')
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package info.nightscout.androidaps
|
||||
|
||||
import info.nightscout.rx.AapsSchedulers
|
||||
import info.nightscout.rx.TestAapsSchedulers
|
||||
import info.nightscout.rx.logging.AAPSLoggerTest
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.junit.jupiter.MockitoExtension
|
||||
import org.mockito.junit.jupiter.MockitoSettings
|
||||
import org.mockito.quality.Strictness
|
||||
import java.util.Locale
|
||||
|
||||
@ExtendWith(MockitoExtension::class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
open class TestBase {
|
||||
|
||||
val aapsLogger = AAPSLoggerTest()
|
||||
val aapsSchedulers: AapsSchedulers = TestAapsSchedulers()
|
||||
|
||||
@BeforeEach
|
||||
fun setupLocale() {
|
||||
Locale.setDefault(Locale.ENGLISH)
|
||||
System.setProperty("disableFirebase", "true")
|
||||
}
|
||||
|
||||
// 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,9 +1,8 @@
|
|||
package info.nightscout.source
|
||||
|
||||
import dagger.android.AndroidInjector
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import info.nightscout.sharedtests.TestBase
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
|
@ -14,7 +13,6 @@ class GlimpPluginTest : TestBase() {
|
|||
private lateinit var glimpPlugin: GlimpPlugin
|
||||
|
||||
@Mock lateinit var rh: ResourceHelper
|
||||
@Mock lateinit var sp: SP
|
||||
|
||||
@BeforeEach
|
||||
fun setup() {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package info.nightscout.source
|
||||
|
||||
import dagger.android.AndroidInjector
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import info.nightscout.sharedtests.TestBase
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package info.nightscout.source
|
||||
|
||||
import dagger.android.AndroidInjector
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.interfaces.Config
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import info.nightscout.sharedtests.TestBase
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package info.nightscout.source
|
||||
|
||||
import dagger.android.AndroidInjector
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import info.nightscout.sharedtests.TestBase
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
|
|
|
@ -27,6 +27,8 @@ dependencies {
|
|||
|
||||
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version"
|
||||
testImplementation "androidx.work:work-testing:$work_version"
|
||||
|
||||
testImplementation project(':app-wear-shared:shared-tests')
|
||||
testImplementation project(':implementation')
|
||||
testImplementation project(':plugins:aps')
|
||||
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
package info.nightscout.androidaps
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import androidx.work.Configuration
|
||||
import androidx.work.testing.SynchronousExecutor
|
||||
import androidx.work.testing.WorkManagerTestInitHelper
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.rx.AapsSchedulers
|
||||
import info.nightscout.rx.TestAapsSchedulers
|
||||
import info.nightscout.rx.logging.AAPSLoggerTest
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.junit.jupiter.MockitoExtension
|
||||
import org.mockito.junit.jupiter.MockitoSettings
|
||||
import org.mockito.quality.Strictness
|
||||
import java.util.Locale
|
||||
|
||||
@ExtendWith(MockitoExtension::class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
open class TestBase {
|
||||
|
||||
abstract class ContextWithInjector : Context(), HasAndroidInjector
|
||||
|
||||
@Mock lateinit var context: ContextWithInjector
|
||||
|
||||
val aapsLogger = AAPSLoggerTest()
|
||||
val aapsSchedulers: AapsSchedulers = TestAapsSchedulers()
|
||||
|
||||
@BeforeEach
|
||||
fun setupLocale() {
|
||||
Locale.setDefault(Locale.ENGLISH)
|
||||
System.setProperty("disableFirebase", "true")
|
||||
}
|
||||
|
||||
// Initialize WorkManager for instrumentation tests.
|
||||
fun initWorkManager() {
|
||||
WorkManagerTestInitHelper.initializeTestWorkManager(
|
||||
context,
|
||||
Configuration.Builder()
|
||||
.setMinimumLoggingLevel(Log.DEBUG)
|
||||
.setExecutor(SynchronousExecutor())
|
||||
.build()
|
||||
)
|
||||
}
|
||||
|
||||
// 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,189 +0,0 @@
|
|||
package info.nightscout.androidaps
|
||||
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.core.extensions.pureProfileFromJson
|
||||
import info.nightscout.core.profile.ProfileSealed
|
||||
import info.nightscout.core.utils.fabric.FabricPrivacy
|
||||
import info.nightscout.database.entities.EffectiveProfileSwitch
|
||||
import info.nightscout.database.entities.embedments.InsulinConfiguration
|
||||
import info.nightscout.database.impl.AppRepository
|
||||
import info.nightscout.implementation.profile.ProfileStoreObject
|
||||
import info.nightscout.interfaces.Config
|
||||
import info.nightscout.interfaces.insulin.Insulin
|
||||
import info.nightscout.interfaces.iob.IobCobCalculator
|
||||
import info.nightscout.interfaces.nsclient.ProcessedDeviceStatusData
|
||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
||||
import info.nightscout.interfaces.profile.ProfileStore
|
||||
import info.nightscout.interfaces.utils.HardLimits
|
||||
import info.nightscout.rx.bus.RxBus
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import info.nightscout.shared.utils.DateUtil
|
||||
import org.json.JSONObject
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.mockito.ArgumentMatchers.anyDouble
|
||||
import org.mockito.ArgumentMatchers.anyInt
|
||||
import org.mockito.ArgumentMatchers.anyString
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.mockito.invocation.InvocationOnMock
|
||||
|
||||
@Suppress("SpellCheckingInspection")
|
||||
open class TestBaseWithProfile : TestBase() {
|
||||
|
||||
@Mock lateinit var activePlugin: ActivePlugin
|
||||
@Mock lateinit var rh: ResourceHelper
|
||||
@Mock lateinit var iobCobCalculator: IobCobCalculator
|
||||
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
||||
@Mock lateinit var config: Config
|
||||
@Mock lateinit var sp: SP
|
||||
@Mock lateinit var repository: AppRepository
|
||||
@Mock lateinit var hardLimits: HardLimits
|
||||
@Mock lateinit var processedDeviceStatusData: ProcessedDeviceStatusData
|
||||
@Mock lateinit var insulin: Insulin
|
||||
|
||||
//open lateinit var profileFunction: ProfileFunction
|
||||
lateinit var dateUtil: DateUtil
|
||||
var insulinConfiguration: InsulinConfiguration = InsulinConfiguration("Insulin", 360 * 60 * 1000, 60 * 60 * 1000)
|
||||
val rxBus = RxBus(aapsSchedulers, aapsLogger)
|
||||
|
||||
val profileInjector = HasAndroidInjector { AndroidInjector { } }
|
||||
|
||||
private lateinit var validProfileJSON: String
|
||||
lateinit var validProfile: ProfileSealed.Pure
|
||||
lateinit var effectiveProfileSwitch: EffectiveProfileSwitch
|
||||
|
||||
@Suppress("PropertyName") val TESTPROFILENAME = "someProfile"
|
||||
|
||||
@BeforeEach
|
||||
fun prepareMock() {
|
||||
validProfileJSON = "{\"dia\":\"5\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," +
|
||||
"{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," +
|
||||
"\"target_high\":[{\"time\":\"00:00\",\"value\":\"7\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
|
||||
dateUtil = Mockito.spy(DateUtil(context))
|
||||
`when`(dateUtil.now()).thenReturn(1656358822000)
|
||||
`when`(insulin.insulinConfiguration).thenReturn(insulinConfiguration)
|
||||
`when`(activePlugin.activeInsulin).thenReturn(insulin)
|
||||
//profileFunction = ProfileFunctionImpl(aapsLogger, sp, rxBus, rh, activePlugin, repository, dateUtil, config, hardLimits, aapsSchedulers, fabricPrivacy, processedDeviceStatusData)
|
||||
validProfile = ProfileSealed.Pure(pureProfileFromJson(JSONObject(validProfileJSON), dateUtil)!!)
|
||||
effectiveProfileSwitch = EffectiveProfileSwitch(
|
||||
timestamp = dateUtil.now(),
|
||||
basalBlocks = validProfile.basalBlocks,
|
||||
isfBlocks = validProfile.isfBlocks,
|
||||
icBlocks = validProfile.icBlocks,
|
||||
targetBlocks = validProfile.targetBlocks,
|
||||
glucoseUnit = EffectiveProfileSwitch.GlucoseUnit.MMOL,
|
||||
originalProfileName = "",
|
||||
originalCustomizedName = "",
|
||||
originalTimeshift = 0,
|
||||
originalPercentage = 100,
|
||||
originalDuration = 0,
|
||||
originalEnd = 0,
|
||||
insulinConfiguration = InsulinConfiguration("", 0, 0)
|
||||
)
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<Int?>(1)
|
||||
String.format(rh.gs(string), arg1)
|
||||
}.`when`(rh).gs(anyInt(), anyInt())
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<Double?>(1)
|
||||
String.format(rh.gs(string), arg1)
|
||||
}.`when`(rh).gs(anyInt(), anyDouble())
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<String?>(1)
|
||||
String.format(rh.gs(string), arg1)
|
||||
}.`when`(rh).gs(anyInt(), anyString())
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<String?>(1)
|
||||
val arg2 = invocation.getArgument<String?>(2)
|
||||
String.format(rh.gs(string), arg1, arg2)
|
||||
}.`when`(rh).gs(anyInt(), anyString(), anyString())
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<String?>(1)
|
||||
val arg2 = invocation.getArgument<Int?>(2)
|
||||
String.format(rh.gs(string), arg1, arg2)
|
||||
}.`when`(rh).gs(anyInt(), anyString(), anyInt())
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<Double?>(1)
|
||||
val arg2 = invocation.getArgument<String?>(2)
|
||||
String.format(rh.gs(string), arg1, arg2)
|
||||
}.`when`(rh).gs(anyInt(), anyDouble(), anyString())
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<Double?>(1)
|
||||
val arg2 = invocation.getArgument<Int?>(2)
|
||||
String.format(rh.gs(string), arg1, arg2)
|
||||
}.`when`(rh).gs(anyInt(), anyDouble(), anyInt())
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<Int?>(1)
|
||||
val arg2 = invocation.getArgument<Int?>(2)
|
||||
String.format(rh.gs(string), arg1, arg2)
|
||||
}.`when`(rh).gs(anyInt(), anyInt(), anyInt())
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<Int?>(1)
|
||||
val arg2 = invocation.getArgument<String?>(2)
|
||||
String.format(rh.gs(string), arg1, arg2)
|
||||
}.`when`(rh).gs(anyInt(), anyInt(), anyString())
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<Int?>(1)
|
||||
val arg2 = invocation.getArgument<Int?>(2)
|
||||
val arg3 = invocation.getArgument<String?>(3)
|
||||
String.format(rh.gs(string), arg1, arg2, arg3)
|
||||
}.`when`(rh).gs(anyInt(), anyInt(), anyInt(), anyString())
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<Int?>(1)
|
||||
val arg2 = invocation.getArgument<String?>(2)
|
||||
val arg3 = invocation.getArgument<String?>(3)
|
||||
String.format(rh.gs(string), arg1, arg2, arg3)
|
||||
}.`when`(rh).gs(anyInt(), anyInt(), anyString(), anyString())
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<Double?>(1)
|
||||
val arg2 = invocation.getArgument<Int?>(2)
|
||||
val arg3 = invocation.getArgument<String?>(3)
|
||||
String.format(rh.gs(string), arg1, arg2, arg3)
|
||||
}.`when`(rh).gs(anyInt(), anyDouble(), anyInt(), anyString())
|
||||
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val string = invocation.getArgument<Int>(0)
|
||||
val arg1 = invocation.getArgument<String?>(1)
|
||||
val arg2 = invocation.getArgument<Int?>(2)
|
||||
val arg3 = invocation.getArgument<String?>(3)
|
||||
String.format(rh.gs(string), arg1, arg2, arg3)
|
||||
}.`when`(rh).gs(anyInt(), anyString(), anyInt(), anyString())
|
||||
|
||||
}
|
||||
|
||||
fun getValidProfileStore(): ProfileStore {
|
||||
val json = JSONObject()
|
||||
val store = JSONObject()
|
||||
store.put(TESTPROFILENAME, JSONObject(validProfileJSON))
|
||||
json.put("defaultProfile", TESTPROFILENAME)
|
||||
json.put("store", store)
|
||||
return ProfileStoreObject(profileInjector, json, dateUtil)
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
package info.nightscout.androidaps
|
||||
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.annotations.OpenForTesting
|
||||
import info.nightscout.interfaces.profile.Profile
|
||||
import info.nightscout.interfaces.pump.DetailedBolusInfo
|
||||
import info.nightscout.interfaces.pump.Pump
|
||||
import info.nightscout.interfaces.pump.PumpEnactResult
|
||||
import info.nightscout.interfaces.pump.PumpSync
|
||||
import info.nightscout.interfaces.pump.defs.ManufacturerType
|
||||
import info.nightscout.interfaces.pump.defs.PumpDescription
|
||||
import info.nightscout.interfaces.pump.defs.PumpType
|
||||
import info.nightscout.interfaces.utils.TimeChangeType
|
||||
import org.json.JSONObject
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate")
|
||||
@OpenForTesting
|
||||
class TestPumpPlugin(val injector: HasAndroidInjector) : Pump {
|
||||
|
||||
var connected = false
|
||||
var isProfileSet = true
|
||||
|
||||
override fun isConnected() = connected
|
||||
override fun isConnecting() = false
|
||||
override fun isHandshakeInProgress() = false
|
||||
val lastData = 0L
|
||||
|
||||
val baseBasal = 0.0
|
||||
override var pumpDescription = PumpDescription()
|
||||
|
||||
override fun isInitialized(): Boolean = true
|
||||
override fun isSuspended(): Boolean = false
|
||||
override fun isBusy(): Boolean = false
|
||||
override fun connect(reason: String) {
|
||||
connected = true
|
||||
}
|
||||
|
||||
override fun disconnect(reason: String) {
|
||||
connected = false
|
||||
}
|
||||
|
||||
override fun stopConnecting() {
|
||||
connected = false
|
||||
}
|
||||
|
||||
override fun waitForDisconnectionInSeconds(): Int = 0
|
||||
override fun getPumpStatus(reason: String) {}
|
||||
override fun setNewBasalProfile(profile: Profile): PumpEnactResult = PumpEnactResult(injector)
|
||||
override fun isThisProfileSet(profile: Profile): Boolean = isProfileSet
|
||||
override fun lastDataTime(): Long = lastData
|
||||
override val baseBasalRate: Double = baseBasal
|
||||
override val reservoirLevel: Double = 0.0
|
||||
override val batteryLevel: Int = 0
|
||||
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult = PumpEnactResult(injector).success(true)
|
||||
override fun stopBolusDelivering() {}
|
||||
override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult =
|
||||
PumpEnactResult(injector).success(true)
|
||||
|
||||
override fun setTempBasalPercent(percent: Int, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult =
|
||||
PumpEnactResult(injector).success(true)
|
||||
|
||||
override fun setExtendedBolus(insulin: Double, durationInMinutes: Int): PumpEnactResult = PumpEnactResult(injector).success(true)
|
||||
override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult = PumpEnactResult(injector).success(true)
|
||||
override fun cancelExtendedBolus(): PumpEnactResult = PumpEnactResult(injector).success(true)
|
||||
override fun getJSONStatus(profile: Profile, profileName: String, version: String): JSONObject = JSONObject()
|
||||
override fun manufacturer(): ManufacturerType = ManufacturerType.AAPS
|
||||
override fun model(): PumpType = PumpType.GENERIC_AAPS
|
||||
override fun serialNumber(): String = "1"
|
||||
override fun shortStatus(veryShort: Boolean): String = ""
|
||||
override val isFakingTempsByExtendedBoluses: Boolean = false
|
||||
override fun loadTDDs(): PumpEnactResult = PumpEnactResult(injector).success(true)
|
||||
override fun canHandleDST(): Boolean = true
|
||||
override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) {}
|
||||
}
|
|
@ -2,9 +2,6 @@ package info.nightscout.plugins.sync.dataBroadcaster
|
|||
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.BundleMock
|
||||
import info.nightscout.androidaps.TestBaseWithProfile
|
||||
import info.nightscout.androidaps.TestPumpPlugin
|
||||
import info.nightscout.database.entities.GlucoseValue
|
||||
import info.nightscout.database.entities.TemporaryBasal
|
||||
import info.nightscout.interfaces.GlucoseUnit
|
||||
|
@ -17,10 +14,10 @@ import info.nightscout.interfaces.iob.InMemoryGlucoseValue
|
|||
import info.nightscout.interfaces.iob.IobTotal
|
||||
import info.nightscout.interfaces.nsclient.ProcessedDeviceStatusData
|
||||
import info.nightscout.interfaces.profile.DefaultValueHelper
|
||||
import info.nightscout.interfaces.profile.ProfileFunction
|
||||
import info.nightscout.interfaces.pump.PumpEnactResult
|
||||
import info.nightscout.interfaces.receivers.ReceiverStatusStore
|
||||
import info.nightscout.rx.events.EventOverviewBolusProgress
|
||||
import info.nightscout.sharedtests.TestBaseWithProfile
|
||||
import org.json.JSONObject
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
|
@ -35,13 +32,12 @@ internal class DataBroadcastPluginTest : TestBaseWithProfile() {
|
|||
@Mock lateinit var loop: Loop
|
||||
@Mock lateinit var receiverStatusStore: ReceiverStatusStore
|
||||
@Mock lateinit var glucoseStatusProvider: GlucoseStatusProvider
|
||||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@Mock lateinit var autosensDataStore: AutosensDataStore
|
||||
@Mock lateinit var processedDeviceStatusData: ProcessedDeviceStatusData
|
||||
|
||||
private lateinit var sut: DataBroadcastPlugin
|
||||
|
||||
private val injector = HasAndroidInjector { AndroidInjector { } }
|
||||
private val testPumpPlugin = TestPumpPlugin(injector)
|
||||
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
|
@ -81,7 +77,7 @@ internal class DataBroadcastPluginTest : TestBaseWithProfile() {
|
|||
it.status = "Some status"
|
||||
it.percent = 100
|
||||
}
|
||||
val bundle = BundleMock.mock()
|
||||
val bundle = info.nightscout.sharedtests.BundleMock.mock()
|
||||
sut.prepareData(event, bundle)
|
||||
Assertions.assertTrue(bundle.containsKey("progressPercent"))
|
||||
Assertions.assertTrue(bundle.containsKey("progressStatus"))
|
||||
|
@ -123,7 +119,7 @@ internal class DataBroadcastPluginTest : TestBaseWithProfile() {
|
|||
it.status = "Some status"
|
||||
it.percent = 100
|
||||
}
|
||||
val bundle = BundleMock.mock()
|
||||
val bundle = info.nightscout.sharedtests.BundleMock.mock()
|
||||
sut.prepareData(event, bundle)
|
||||
Assertions.assertTrue(bundle.containsKey("progressPercent"))
|
||||
Assertions.assertTrue(bundle.containsKey("progressStatus"))
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package info.nightscout.plugins.sync.nsclient
|
||||
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.core.utils.fabric.FabricPrivacy
|
||||
import info.nightscout.interfaces.receivers.ReceiverStatusStore
|
||||
import info.nightscout.plugins.sync.R
|
||||
|
@ -9,6 +8,7 @@ import info.nightscout.rx.events.EventChargingState
|
|||
import info.nightscout.rx.events.EventNetworkChange
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import info.nightscout.sharedtests.TestBase
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
|
|
|
@ -2,7 +2,6 @@ package info.nightscout.plugins.sync.nsclientV3
|
|||
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.TestBaseWithProfile
|
||||
import info.nightscout.core.extensions.fromConstant
|
||||
import info.nightscout.database.entities.Bolus
|
||||
import info.nightscout.database.entities.BolusCalculatorResult
|
||||
|
@ -17,7 +16,10 @@ import info.nightscout.database.entities.ProfileSwitch
|
|||
import info.nightscout.database.entities.TemporaryBasal
|
||||
import info.nightscout.database.entities.TemporaryTarget
|
||||
import info.nightscout.database.entities.TherapyEvent
|
||||
import info.nightscout.database.entities.embedments.InsulinConfiguration
|
||||
import info.nightscout.database.entities.embedments.InterfaceIDs
|
||||
import info.nightscout.database.impl.AppRepository
|
||||
import info.nightscout.interfaces.insulin.Insulin
|
||||
import info.nightscout.interfaces.logging.UserEntryLogger
|
||||
import info.nightscout.interfaces.nsclient.StoreDataForDb
|
||||
import info.nightscout.interfaces.profile.ProfileFunction
|
||||
|
@ -32,13 +34,14 @@ import info.nightscout.plugins.sync.nsclient.data.NSDeviceStatusHandler
|
|||
import info.nightscout.plugins.sync.nsclient.extensions.fromConstant
|
||||
import info.nightscout.sdk.interfaces.NSAndroidClient
|
||||
import info.nightscout.sdk.localmodel.treatment.CreateUpdateResponse
|
||||
import info.nightscout.sharedtests.TestBaseWithProfile
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.anyLong
|
||||
import org.mockito.Mockito.`when`
|
||||
|
||||
@Suppress("SpellCheckingInspection")
|
||||
internal class NSClientV3PluginTest : TestBaseWithProfile() {
|
||||
|
@ -53,6 +56,8 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() {
|
|||
@Mock lateinit var mockedProfileFunction: ProfileFunction
|
||||
@Mock lateinit var nsDeviceStatusHandler: NSDeviceStatusHandler
|
||||
@Mock lateinit var nsIncomingDataProcessor: NsIncomingDataProcessor
|
||||
@Mock lateinit var repository: AppRepository
|
||||
@Mock lateinit var insulin: Insulin
|
||||
|
||||
private lateinit var storeDataForDb: StoreDataForDb
|
||||
private lateinit var sut: NSClientV3Plugin
|
||||
|
@ -62,6 +67,14 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() {
|
|||
}
|
||||
}
|
||||
|
||||
private var insulinConfiguration: InsulinConfiguration = InsulinConfiguration("Insulin", 360 * 60 * 1000, 60 * 60 * 1000)
|
||||
|
||||
@BeforeEach
|
||||
fun mock() {
|
||||
Mockito.`when`(insulin.insulinConfiguration).thenReturn(insulinConfiguration)
|
||||
Mockito.`when`(activePlugin.activeInsulin).thenReturn(insulin)
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
fun prepare() {
|
||||
storeDataForDb = StoreDataForDbImpl(aapsLogger, rxBus, repository, sp, uel, dateUtil, config, nsClientSource, virtualPump, uiInteraction)
|
||||
|
@ -72,7 +85,7 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() {
|
|||
nsDeviceStatusHandler, nsClientSource, nsIncomingDataProcessor, storeDataForDb
|
||||
)
|
||||
sut.nsAndroidClient = nsAndroidClient
|
||||
`when`(mockedProfileFunction.getProfile(anyLong())).thenReturn(validProfile)
|
||||
Mockito.`when`(mockedProfileFunction.getProfile(anyLong())).thenReturn(validProfile)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -93,13 +106,13 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() {
|
|||
)
|
||||
val dataPair = DataSyncSelector.PairDeviceStatus(deviceStatus, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createDeviceStatus(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.createDeviceStatus(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
sut.nsAdd("devicestatus", dataPair, "1/3")
|
||||
Assertions.assertEquals(1, storeDataForDb.nsIdDeviceStatuses.size)
|
||||
// update
|
||||
`when`(nsAndroidClient.createDeviceStatus(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.createDeviceStatus(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
sut.nsAdd("devicestatus", dataPair, "1/3")
|
||||
Assertions.assertEquals(2, storeDataForDb.nsIdDeviceStatuses.size) // still only 1
|
||||
Assertions.assertEquals(2, storeDataForDb.nsIdDeviceStatuses.size) // still only 1
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -119,11 +132,11 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() {
|
|||
)
|
||||
val dataPair = DataSyncSelector.PairGlucoseValue(glucoseValue, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createSgv(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.createSgv(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
sut.nsAdd("entries", dataPair, "1/3")
|
||||
Assertions.assertEquals(1, storeDataForDb.nsIdGlucoseValues.size)
|
||||
// update
|
||||
`when`(nsAndroidClient.updateSvg(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.updateSvg(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
sut.nsUpdate("entries", dataPair, "1/3")
|
||||
Assertions.assertEquals(2, storeDataForDb.nsIdGlucoseValues.size)
|
||||
}
|
||||
|
@ -149,11 +162,11 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() {
|
|||
)
|
||||
val dataPair = DataSyncSelector.PairFood(food, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createFood(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.createFood(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
sut.nsAdd("food", dataPair, "1/3")
|
||||
Assertions.assertEquals(1, storeDataForDb.nsIdFoods.size)
|
||||
// update
|
||||
`when`(nsAndroidClient.updateFood(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.updateFood(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
sut.nsUpdate("food", dataPair, "1/3")
|
||||
Assertions.assertEquals(2, storeDataForDb.nsIdFoods.size)
|
||||
}
|
||||
|
@ -177,11 +190,11 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() {
|
|||
)
|
||||
val dataPair = DataSyncSelector.PairBolus(bolus, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
sut.nsAdd("treatments", dataPair, "1/3")
|
||||
Assertions.assertEquals(1, storeDataForDb.nsIdBoluses.size)
|
||||
// update
|
||||
`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
sut.nsUpdate("treatments", dataPair, "1/3")
|
||||
Assertions.assertEquals(2, storeDataForDb.nsIdBoluses.size)
|
||||
}
|
||||
|
@ -204,11 +217,11 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() {
|
|||
)
|
||||
val dataPair = DataSyncSelector.PairCarbs(carbs, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
sut.nsAdd("treatments", dataPair, "1/3")
|
||||
Assertions.assertEquals(1, storeDataForDb.nsIdCarbs.size)
|
||||
// update
|
||||
`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
sut.nsUpdate("treatments", dataPair, "1/3")
|
||||
Assertions.assertEquals(2, storeDataForDb.nsIdCarbs.size)
|
||||
}
|
||||
|
@ -257,11 +270,11 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() {
|
|||
)
|
||||
val dataPair = DataSyncSelector.PairBolusCalculatorResult(bolus, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
sut.nsAdd("treatments", dataPair, "1/3")
|
||||
Assertions.assertEquals(1, storeDataForDb.nsIdBolusCalculatorResults.size)
|
||||
// update
|
||||
`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
sut.nsUpdate("treatments", dataPair, "1/3")
|
||||
Assertions.assertEquals(2, storeDataForDb.nsIdBolusCalculatorResults.size)
|
||||
}
|
||||
|
@ -295,11 +308,11 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() {
|
|||
)
|
||||
val dataPair = DataSyncSelector.PairEffectiveProfileSwitch(profileSwitch, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
sut.nsAdd("treatments", dataPair, "1/3")
|
||||
Assertions.assertEquals(1, storeDataForDb.nsIdEffectiveProfileSwitches.size)
|
||||
// update
|
||||
`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
sut.nsUpdate("treatments", dataPair, "1/3")
|
||||
Assertions.assertEquals(2, storeDataForDb.nsIdEffectiveProfileSwitches.size)
|
||||
}
|
||||
|
@ -331,11 +344,11 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() {
|
|||
)
|
||||
val dataPair = DataSyncSelector.PairProfileSwitch(profileSwitch, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
sut.nsAdd("treatments", dataPair, "1/3")
|
||||
Assertions.assertEquals(1, storeDataForDb.nsIdProfileSwitches.size)
|
||||
// update
|
||||
`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
sut.nsUpdate("treatments", dataPair, "1/3")
|
||||
Assertions.assertEquals(2, storeDataForDb.nsIdProfileSwitches.size)
|
||||
}
|
||||
|
@ -358,11 +371,11 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() {
|
|||
)
|
||||
val dataPair = DataSyncSelector.PairExtendedBolus(extendedBolus, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
sut.nsAdd("treatments", dataPair, "1/3", validProfile)
|
||||
Assertions.assertEquals(1, storeDataForDb.nsIdExtendedBoluses.size)
|
||||
// update
|
||||
`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
sut.nsUpdate("treatments", dataPair, "1/3", validProfile)
|
||||
Assertions.assertEquals(2, storeDataForDb.nsIdExtendedBoluses.size)
|
||||
}
|
||||
|
@ -384,11 +397,11 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() {
|
|||
)
|
||||
val dataPair = DataSyncSelector.PairOfflineEvent(offlineEvent, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
sut.nsAdd("treatments", dataPair, "1/3")
|
||||
Assertions.assertEquals(1, storeDataForDb.nsIdOfflineEvents.size)
|
||||
// update
|
||||
`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
sut.nsUpdate("treatments", dataPair, "1/3")
|
||||
Assertions.assertEquals(2, storeDataForDb.nsIdOfflineEvents.size)
|
||||
}
|
||||
|
@ -412,11 +425,11 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() {
|
|||
)
|
||||
val dataPair = DataSyncSelector.PairTemporaryBasal(temporaryBasal, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
sut.nsAdd("treatments", dataPair, "1/3", validProfile)
|
||||
Assertions.assertEquals(1, storeDataForDb.nsIdTemporaryBasals.size)
|
||||
// update
|
||||
`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
sut.nsUpdate("treatments", dataPair, "1/3", validProfile)
|
||||
Assertions.assertEquals(2, storeDataForDb.nsIdTemporaryBasals.size)
|
||||
}
|
||||
|
@ -440,11 +453,11 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() {
|
|||
)
|
||||
val dataPair = DataSyncSelector.PairTemporaryTarget(temporaryTarget, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
sut.nsAdd("treatments", dataPair, "1/3")
|
||||
Assertions.assertEquals(1, storeDataForDb.nsIdTemporaryTargets.size)
|
||||
// update
|
||||
`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
sut.nsUpdate("treatments", dataPair, "1/3")
|
||||
Assertions.assertEquals(2, storeDataForDb.nsIdTemporaryTargets.size)
|
||||
}
|
||||
|
@ -471,11 +484,11 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() {
|
|||
)
|
||||
val dataPair = DataSyncSelector.PairTherapyEvent(therapyEvent, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
sut.nsAdd("treatments", dataPair, "1/3")
|
||||
Assertions.assertEquals(1, storeDataForDb.nsIdTherapyEvents.size)
|
||||
// update
|
||||
`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
sut.nsUpdate("treatments", dataPair, "1/3")
|
||||
Assertions.assertEquals(2, storeDataForDb.nsIdTherapyEvents.size)
|
||||
}
|
||||
|
@ -486,12 +499,12 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() {
|
|||
|
||||
val dataPair = DataSyncSelector.PairProfileStore(getValidProfileStore().data, 1000)
|
||||
// create
|
||||
`when`(nsAndroidClient.createProfileStore(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.createProfileStore(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa"))
|
||||
sut.nsAdd("profile", dataPair, "1/3")
|
||||
// verify(dataSyncSelectorV3, Times(1)).confirmLastProfileStore(1000)
|
||||
// verify(dataSyncSelectorV3, Times(1)).processChangedProfileStore()
|
||||
// update
|
||||
`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
Mockito.`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa"))
|
||||
sut.nsUpdate("profile", dataPair, "1/3")
|
||||
// verify(dataSyncSelectorV3, Times(2)).confirmLastProfileStore(1000)
|
||||
// verify(dataSyncSelectorV3, Times(2)).processChangedProfileStore()
|
||||
|
|
|
@ -1,24 +1,17 @@
|
|||
package info.nightscout.plugins.sync.nsclientV3.extensions
|
||||
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.database.entities.DeviceStatus
|
||||
import info.nightscout.interfaces.Config
|
||||
import info.nightscout.interfaces.configBuilder.RunningConfiguration
|
||||
import info.nightscout.interfaces.constraints.Constraints
|
||||
import info.nightscout.interfaces.iob.IobCobCalculator
|
||||
import info.nightscout.interfaces.nsclient.ProcessedDeviceStatusData
|
||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
||||
import info.nightscout.interfaces.profile.Instantiator
|
||||
import info.nightscout.interfaces.profile.ProfileFunction
|
||||
import info.nightscout.plugins.aps.APSResultObject
|
||||
import info.nightscout.plugins.sync.nsclient.data.NSDeviceStatusHandler
|
||||
import info.nightscout.plugins.sync.nsclient.data.ProcessedDeviceStatusDataImpl
|
||||
import info.nightscout.sdk.mapper.convertToRemoteAndBack
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import info.nightscout.shared.utils.DateUtil
|
||||
import info.nightscout.sharedtests.TestBase
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
|
@ -27,11 +20,7 @@ import org.mockito.Mock
|
|||
@Suppress("SpellCheckingInspection")
|
||||
internal class DeviceStatusExtensionKtTest : TestBase() {
|
||||
|
||||
@Mock lateinit var constraintChecker: Constraints
|
||||
@Mock lateinit var sp: SP
|
||||
@Mock lateinit var activePlugin: ActivePlugin
|
||||
@Mock lateinit var iobCobCalculator: IobCobCalculator
|
||||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@Mock lateinit var rh: ResourceHelper
|
||||
@Mock lateinit var dateUtil: DateUtil
|
||||
@Mock lateinit var config: Config
|
||||
|
@ -41,21 +30,6 @@ internal class DeviceStatusExtensionKtTest : TestBase() {
|
|||
private lateinit var processedDeviceStatusData: ProcessedDeviceStatusData
|
||||
private lateinit var nsDeviceStatusHandler: NSDeviceStatusHandler
|
||||
|
||||
val injector = HasAndroidInjector {
|
||||
AndroidInjector {
|
||||
if (it is APSResultObject) {
|
||||
it.aapsLogger = aapsLogger
|
||||
it.constraintChecker = constraintChecker
|
||||
it.sp = sp
|
||||
it.activePlugin = activePlugin
|
||||
it.iobCobCalculator = iobCobCalculator
|
||||
it.profileFunction = profileFunction
|
||||
it.rh = rh
|
||||
it.dateUtil = dateUtil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
fun setup() {
|
||||
processedDeviceStatusData = ProcessedDeviceStatusDataImpl(rh, dateUtil, sp, instantiator)
|
||||
|
|
|
@ -1,17 +1,31 @@
|
|||
package info.nightscout.plugins.sync.nsclientV3.extensions
|
||||
|
||||
import info.nightscout.androidaps.TestBaseWithProfile
|
||||
import info.nightscout.database.entities.EffectiveProfileSwitch
|
||||
import info.nightscout.database.entities.embedments.InsulinConfiguration
|
||||
import info.nightscout.database.entities.embedments.InterfaceIDs
|
||||
import info.nightscout.interfaces.insulin.Insulin
|
||||
import info.nightscout.plugins.sync.nsclient.extensions.fromConstant
|
||||
import info.nightscout.sdk.localmodel.treatment.NSEffectiveProfileSwitch
|
||||
import info.nightscout.sdk.mapper.convertToRemoteAndBack
|
||||
import info.nightscout.sharedtests.TestBaseWithProfile
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
|
||||
@Suppress("SpellCheckingInspection")
|
||||
internal class EffectiveProfileSwitchExtensionKtTest : TestBaseWithProfile() {
|
||||
|
||||
@Mock lateinit var insulin: Insulin
|
||||
|
||||
private var insulinConfiguration: InsulinConfiguration = InsulinConfiguration("Insulin", 360 * 60 * 1000, 60 * 60 * 1000)
|
||||
|
||||
@BeforeEach
|
||||
fun mock() {
|
||||
Mockito.`when`(insulin.insulinConfiguration).thenReturn(insulinConfiguration)
|
||||
Mockito.`when`(activePlugin.activeInsulin).thenReturn(insulin)
|
||||
}
|
||||
@Test
|
||||
fun toEffectiveProfileSwitch() {
|
||||
val profileSwitch = EffectiveProfileSwitch(
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package info.nightscout.plugins.sync.nsclientV3.extensions
|
||||
|
||||
import info.nightscout.androidaps.TestBaseWithProfile
|
||||
import info.nightscout.database.entities.ExtendedBolus
|
||||
import info.nightscout.database.entities.embedments.InterfaceIDs
|
||||
import info.nightscout.sdk.localmodel.treatment.NSExtendedBolus
|
||||
import info.nightscout.sdk.localmodel.treatment.NSTemporaryBasal
|
||||
import info.nightscout.sdk.mapper.convertToRemoteAndBack
|
||||
import info.nightscout.sharedtests.TestBaseWithProfile
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
package info.nightscout.plugins.sync.nsclientV3.extensions
|
||||
|
||||
import info.nightscout.androidaps.TestBaseWithProfile
|
||||
import info.nightscout.database.entities.GlucoseValue
|
||||
import info.nightscout.database.entities.embedments.InterfaceIDs
|
||||
import info.nightscout.sdk.mapper.convertToRemoteAndBack
|
||||
import info.nightscout.sharedtests.TestBaseWithProfile
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
@Suppress("SpellCheckingInspection")
|
||||
internal class GlucoseValueExtensionKtTest : TestBaseWithProfile() {
|
||||
|
||||
@Test
|
||||
|
@ -25,7 +24,7 @@ internal class GlucoseValueExtensionKtTest : TestBaseWithProfile() {
|
|||
)
|
||||
)
|
||||
|
||||
var glucoseValue2 = glucoseValue.toNSSvgV3().convertToRemoteAndBack()?.toTransactionGlucoseValue()?.toGlucoseValue()
|
||||
val glucoseValue2 = glucoseValue.toNSSvgV3().convertToRemoteAndBack()?.toTransactionGlucoseValue()?.toGlucoseValue()
|
||||
Assertions.assertTrue(glucoseValue.contentEqualsTo(glucoseValue2!!))
|
||||
Assertions.assertTrue(glucoseValue.interfaceIdsEqualsTo(glucoseValue2))
|
||||
}
|
||||
|
|
|
@ -1,17 +1,31 @@
|
|||
package info.nightscout.plugins.sync.nsclientV3.extensions
|
||||
|
||||
import info.nightscout.androidaps.TestBaseWithProfile
|
||||
import info.nightscout.core.extensions.fromConstant
|
||||
import info.nightscout.database.entities.ProfileSwitch
|
||||
import info.nightscout.database.entities.embedments.InsulinConfiguration
|
||||
import info.nightscout.database.entities.embedments.InterfaceIDs
|
||||
import info.nightscout.interfaces.insulin.Insulin
|
||||
import info.nightscout.sdk.localmodel.treatment.NSProfileSwitch
|
||||
import info.nightscout.sdk.mapper.convertToRemoteAndBack
|
||||
import info.nightscout.sharedtests.TestBaseWithProfile
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
|
||||
@Suppress("SpellCheckingInspection")
|
||||
internal class ProfileSwitchExtensionKtTest : TestBaseWithProfile() {
|
||||
|
||||
@Mock lateinit var insulin: Insulin
|
||||
|
||||
private var insulinConfiguration: InsulinConfiguration = InsulinConfiguration("Insulin", 360 * 60 * 1000, 60 * 60 * 1000)
|
||||
|
||||
@BeforeEach
|
||||
fun mock() {
|
||||
Mockito.`when`(insulin.insulinConfiguration).thenReturn(insulinConfiguration)
|
||||
Mockito.`when`(activePlugin.activeInsulin).thenReturn(insulin)
|
||||
}
|
||||
@Test
|
||||
fun toProfileSwitch() {
|
||||
var profileSwitch = ProfileSwitch(
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package info.nightscout.plugins.sync.nsclientV3.extensions
|
||||
|
||||
import info.nightscout.androidaps.TestBaseWithProfile
|
||||
import info.nightscout.database.entities.TemporaryBasal
|
||||
import info.nightscout.database.entities.embedments.InterfaceIDs
|
||||
import info.nightscout.sdk.localmodel.treatment.NSTemporaryBasal
|
||||
import info.nightscout.sdk.mapper.convertToRemoteAndBack
|
||||
import info.nightscout.sharedtests.TestBaseWithProfile
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package info.nightscout.plugins.sync.nsclientV3.extensions
|
||||
|
||||
import info.nightscout.androidaps.TestBaseWithProfile
|
||||
import info.nightscout.database.entities.TemporaryTarget
|
||||
import info.nightscout.database.entities.embedments.InterfaceIDs
|
||||
import info.nightscout.sdk.localmodel.treatment.NSTemporaryTarget
|
||||
import info.nightscout.sdk.mapper.convertToRemoteAndBack
|
||||
import info.nightscout.sharedtests.TestBaseWithProfile
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
package info.nightscout.plugins.sync.nsclientV3.extensions
|
||||
|
||||
import info.nightscout.androidaps.TestBaseWithProfile
|
||||
import info.nightscout.database.entities.TemporaryTarget
|
||||
import info.nightscout.database.entities.TherapyEvent
|
||||
import info.nightscout.database.entities.embedments.InterfaceIDs
|
||||
import info.nightscout.sdk.localmodel.treatment.NSTherapyEvent
|
||||
import info.nightscout.sdk.mapper.convertToRemoteAndBack
|
||||
import info.nightscout.sharedtests.TestBaseWithProfile
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
package info.nightscout.plugins.sync.nsclientV3.workers
|
||||
|
||||
import android.content.Context
|
||||
import androidx.work.ListenableWorker.Result.Success
|
||||
import androidx.work.testing.TestListenableWorkerBuilder
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.core.utils.fabric.FabricPrivacy
|
||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
||||
import info.nightscout.interfaces.sync.NsClient
|
||||
import info.nightscout.plugins.sync.nsclientV3.DataSyncSelectorV3
|
||||
import info.nightscout.plugins.sync.nsclientV3.NSClientV3Plugin
|
||||
import info.nightscout.rx.bus.RxBus
|
||||
import info.nightscout.sharedtests.TestBase
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Assertions
|
||||
|
@ -23,12 +24,15 @@ import org.mockito.Mockito.`when`
|
|||
@ExperimentalCoroutinesApi
|
||||
internal class DataSyncWorkerTest : TestBase() {
|
||||
|
||||
abstract class ContextWithInjector : Context(), HasAndroidInjector
|
||||
|
||||
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
||||
@Mock lateinit var dataSyncSelectorV3: DataSyncSelectorV3
|
||||
@Mock lateinit var activePlugin: ActivePlugin
|
||||
@Mock lateinit var nsClient: NsClient
|
||||
@Mock lateinit var rxBus: RxBus
|
||||
@Mock lateinit var nsClientV3Plugin: NSClientV3Plugin
|
||||
@Mock lateinit var context: ContextWithInjector
|
||||
|
||||
private lateinit var sut: DataSyncWorker
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package info.nightscout.plugins.sync.nsclientV3.workers
|
||||
|
||||
import android.content.Context
|
||||
import androidx.work.ListenableWorker
|
||||
import androidx.work.OneTimeWorkRequest
|
||||
import androidx.work.WorkContinuation
|
||||
|
@ -7,7 +8,6 @@ import androidx.work.WorkManager
|
|||
import androidx.work.testing.TestListenableWorkerBuilder
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.core.utils.fabric.FabricPrivacy
|
||||
import info.nightscout.core.utils.receivers.DataWorkerStorage
|
||||
import info.nightscout.database.entities.GlucoseValue
|
||||
|
@ -30,6 +30,7 @@ import info.nightscout.sdk.remotemodel.LastModified
|
|||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
import info.nightscout.shared.utils.DateUtil
|
||||
import info.nightscout.sharedtests.TestBase
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
|
@ -43,6 +44,8 @@ import org.mockito.Mockito
|
|||
|
||||
internal class LoadBgWorkerTest : TestBase() {
|
||||
|
||||
abstract class ContextWithInjector : Context(), HasAndroidInjector
|
||||
|
||||
@Mock lateinit var sp: SP
|
||||
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
||||
@Mock lateinit var dateUtil: DateUtil
|
||||
|
@ -59,6 +62,7 @@ internal class LoadBgWorkerTest : TestBase() {
|
|||
@Mock lateinit var nsDeviceStatusHandler: NSDeviceStatusHandler
|
||||
@Mock lateinit var storeDataForDb: StoreDataForDb
|
||||
@Mock lateinit var nsIncomingDataProcessor: NsIncomingDataProcessor
|
||||
@Mock lateinit var context: ContextWithInjector
|
||||
|
||||
private val rxBus: RxBus = RxBus(aapsSchedulers, aapsLogger)
|
||||
private lateinit var nsClientV3Plugin: NSClientV3Plugin
|
||||
|
@ -162,7 +166,6 @@ internal class LoadBgWorkerTest : TestBase() {
|
|||
Assertions.assertTrue(result is ListenableWorker.Result.Success)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun testNoLoadNeeded() = runTest {
|
||||
Mockito.`when`(workManager.beginUniqueWork(anyString(), any(), any<OneTimeWorkRequest>())).thenReturn(workContinuation)
|
||||
|
|
|
@ -2,8 +2,7 @@ package info.nightscout.plugins.sync.tidepool.comm
|
|||
|
||||
import info.nightscout.plugins.sync.tidepool.messages.AuthReplyMessage
|
||||
import info.nightscout.plugins.sync.tidepool.messages.DatasetReplyMessage
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class SessionTest {
|
||||
|
@ -11,25 +10,23 @@ class SessionTest {
|
|||
@Test
|
||||
fun populateBody() {
|
||||
val session = Session("", "", null)
|
||||
assertNull(session.authReply)
|
||||
Assertions.assertNull(session.authReply)
|
||||
|
||||
// test authReply
|
||||
val authReplyMessage = AuthReplyMessage()
|
||||
session.populateBody(authReplyMessage)
|
||||
assertEquals(authReplyMessage, session.authReply)
|
||||
Assertions.assertEquals(authReplyMessage, session.authReply)
|
||||
|
||||
// test datasetReply
|
||||
val datasetReplyMessage = DatasetReplyMessage()
|
||||
assertNull(session.datasetReply)
|
||||
Assertions.assertNull(session.datasetReply)
|
||||
session.populateBody(datasetReplyMessage)
|
||||
assertEquals(datasetReplyMessage, session.datasetReply)
|
||||
Assertions.assertEquals(datasetReplyMessage, session.datasetReply)
|
||||
|
||||
// test datasetReply as array
|
||||
val list: List<DatasetReplyMessage> = listOf(datasetReplyMessage)
|
||||
session.datasetReply = null
|
||||
assertNull(session.datasetReply)
|
||||
session.populateBody(list)
|
||||
assertEquals(datasetReplyMessage, session.datasetReply)
|
||||
|
||||
Assertions.assertEquals(datasetReplyMessage, session.datasetReply)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue