shared-tests #1
This commit is contained in:
parent
954f6eedab
commit
00a22b8b77
39 changed files with 332 additions and 679 deletions
1
app-wear-shared/shared-tests/.gitignore
vendored
Normal file
1
app-wear-shared/shared-tests/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/build
|
34
app-wear-shared/shared-tests/build.gradle
Normal file
34
app-wear-shared/shared-tests/build.gradle
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
plugins {
|
||||||
|
id 'com.android.library'
|
||||||
|
id 'kotlin-android'
|
||||||
|
id 'kotlin-kapt'
|
||||||
|
id 'kotlinx-serialization'
|
||||||
|
id 'kotlin-allopen'
|
||||||
|
}
|
||||||
|
|
||||||
|
apply from: "${project.rootDir}/core/main/android_dependencies.gradle"
|
||||||
|
apply from: "${project.rootDir}/core/main/android_module_dependencies.gradle"
|
||||||
|
apply from: "${project.rootDir}/core/main/allopen_dependencies.gradle"
|
||||||
|
apply from: "${project.rootDir}/core/main/test_dependencies.gradle"
|
||||||
|
apply from: "${project.rootDir}/core/main/jacoco_global.gradle"
|
||||||
|
|
||||||
|
android {
|
||||||
|
namespace 'info.nightscout.sharedtests'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation project(':database:entities')
|
||||||
|
implementation project(':app-wear-shared:shared')
|
||||||
|
implementation project(':core:interfaces')
|
||||||
|
implementation project(':core:main')
|
||||||
|
implementation project(':core:utils')
|
||||||
|
implementation project(':implementation')
|
||||||
|
|
||||||
|
api "org.mockito:mockito-junit-jupiter:$mockito_version"
|
||||||
|
api "org.mockito.kotlin:mockito-kotlin:4.1.0"
|
||||||
|
api "org.junit.jupiter:junit-jupiter-api:$junit_jupiter_version"
|
||||||
|
|
||||||
|
api "com.google.dagger:dagger:$dagger_version"
|
||||||
|
api "com.google.dagger:dagger-android:$dagger_version"
|
||||||
|
api "com.google.dagger:dagger-android-support:$dagger_version"
|
||||||
|
}
|
0
app-wear-shared/shared-tests/consumer-rules.pro
Normal file
0
app-wear-shared/shared-tests/consumer-rules.pro
Normal file
21
app-wear-shared/shared-tests/proguard-rules.pro
vendored
Normal file
21
app-wear-shared/shared-tests/proguard-rules.pro
vendored
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# Add project specific ProGuard rules here.
|
||||||
|
# You can control the set of applied configuration files using the
|
||||||
|
# proguardFiles setting in build.gradle.
|
||||||
|
#
|
||||||
|
# For more details, see
|
||||||
|
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||||
|
|
||||||
|
# If your project uses WebView with JS, uncomment the following
|
||||||
|
# and specify the fully qualified class name to the JavaScript interface
|
||||||
|
# class:
|
||||||
|
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||||
|
# public *;
|
||||||
|
#}
|
||||||
|
|
||||||
|
# Uncomment this to preserve the line number information for
|
||||||
|
# debugging stack traces.
|
||||||
|
#-keepattributes SourceFile,LineNumberTable
|
||||||
|
|
||||||
|
# If you keep the line number information, uncomment this to
|
||||||
|
# hide the original source file name.
|
||||||
|
#-renamesourcefileattribute SourceFile
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest>
|
||||||
|
|
||||||
|
</manifest>
|
|
@ -1,4 +1,4 @@
|
||||||
package info.nightscout.androidaps
|
package info.nightscout.sharedtests
|
||||||
|
|
||||||
import info.nightscout.interfaces.utils.HardLimits
|
import info.nightscout.interfaces.utils.HardLimits
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
|
@ -7,7 +7,7 @@ import javax.inject.Inject
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
class HardLimitsMock @Inject constructor(
|
@Suppress("unused") class HardLimitsMock @Inject constructor(
|
||||||
private val sp: SP,
|
private val sp: SP,
|
||||||
private val rh: ResourceHelper
|
private val rh: ResourceHelper
|
||||||
) : HardLimits {
|
) : HardLimits {
|
|
@ -1,5 +1,6 @@
|
||||||
package info.nightscout.androidaps
|
package info.nightscout.sharedtests
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import info.nightscout.rx.AapsSchedulers
|
import info.nightscout.rx.AapsSchedulers
|
||||||
import info.nightscout.rx.TestAapsSchedulers
|
import info.nightscout.rx.TestAapsSchedulers
|
||||||
import info.nightscout.rx.logging.AAPSLoggerTest
|
import info.nightscout.rx.logging.AAPSLoggerTest
|
||||||
|
@ -11,6 +12,7 @@ import org.mockito.junit.jupiter.MockitoSettings
|
||||||
import org.mockito.quality.Strictness
|
import org.mockito.quality.Strictness
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
|
@Suppress("SpellCheckingInspection")
|
||||||
@ExtendWith(MockitoExtension::class)
|
@ExtendWith(MockitoExtension::class)
|
||||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
open class TestBase {
|
open class TestBase {
|
||||||
|
@ -27,11 +29,12 @@ open class TestBase {
|
||||||
// Workaround for Kotlin nullability.
|
// Workaround for Kotlin nullability.
|
||||||
// https://medium.com/@elye.project/befriending-kotlin-and-mockito-1c2e7b0ef791
|
// https://medium.com/@elye.project/befriending-kotlin-and-mockito-1c2e7b0ef791
|
||||||
// https://stackoverflow.com/questions/30305217/is-it-possible-to-use-mockito-in-kotlin
|
// https://stackoverflow.com/questions/30305217/is-it-possible-to-use-mockito-in-kotlin
|
||||||
|
@SuppressLint("CheckResult")
|
||||||
fun <T> anyObject(): T {
|
fun <T> anyObject(): T {
|
||||||
Mockito.any<T>()
|
Mockito.any<T>()
|
||||||
return uninitialized()
|
return uninitialized()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("Unchecked_Cast")
|
@Suppress("Unchecked_Cast")
|
||||||
fun <T> uninitialized(): T = null as T
|
private fun <T> uninitialized(): T = null as T
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package info.nightscout.androidaps
|
package info.nightscout.sharedtests
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
|
@ -26,13 +26,12 @@ import org.mockito.ArgumentMatchers.anyInt
|
||||||
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
|
||||||
import org.mockito.Mockito.`when`
|
|
||||||
import org.mockito.invocation.InvocationOnMock
|
import org.mockito.invocation.InvocationOnMock
|
||||||
|
|
||||||
@Suppress("SpellCheckingInspection")
|
@Suppress("SpellCheckingInspection")
|
||||||
open class TestBaseWithProfile : TestBase() {
|
open class TestBaseWithProfile : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var activePluginProvider: ActivePlugin
|
@Mock lateinit var activePlugin: ActivePlugin
|
||||||
@Mock lateinit var rh: ResourceHelper
|
@Mock lateinit var rh: ResourceHelper
|
||||||
@Mock lateinit var iobCobCalculator: IobCobCalculator
|
@Mock lateinit var iobCobCalculator: IobCobCalculator
|
||||||
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
||||||
|
@ -41,15 +40,15 @@ open class TestBaseWithProfile : TestBase() {
|
||||||
@Mock lateinit var context: Context
|
@Mock lateinit var context: Context
|
||||||
@Mock lateinit var sp: SP
|
@Mock lateinit var sp: SP
|
||||||
|
|
||||||
private lateinit var hardLimits: HardLimits
|
|
||||||
lateinit var dateUtil: DateUtil
|
lateinit var dateUtil: DateUtil
|
||||||
|
lateinit var hardLimits: HardLimits
|
||||||
val rxBus = RxBus(aapsSchedulers, aapsLogger)
|
val rxBus = RxBus(aapsSchedulers, aapsLogger)
|
||||||
|
|
||||||
val profileInjector = HasAndroidInjector {
|
val profileInjector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
if (it is ProfileStoreObject) {
|
if (it is ProfileStoreObject) {
|
||||||
it.aapsLogger = aapsLogger
|
it.aapsLogger = aapsLogger
|
||||||
it.activePlugin = activePluginProvider
|
it.activePlugin = activePlugin
|
||||||
it.config = config
|
it.config = config
|
||||||
it.rh = rh
|
it.rh = rh
|
||||||
it.rxBus = rxBus
|
it.rxBus = rxBus
|
||||||
|
@ -64,20 +63,22 @@ open class TestBaseWithProfile : TestBase() {
|
||||||
lateinit var effectiveProfileSwitch: EffectiveProfileSwitch
|
lateinit var effectiveProfileSwitch: EffectiveProfileSwitch
|
||||||
lateinit var testPumpPlugin: TestPumpPlugin
|
lateinit var testPumpPlugin: TestPumpPlugin
|
||||||
|
|
||||||
|
val now = 1656358822000L
|
||||||
|
|
||||||
@Suppress("PropertyName") val TESTPROFILENAME = "someProfile"
|
@Suppress("PropertyName") val TESTPROFILENAME = "someProfile"
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
fun prepareMock() {
|
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\"}," +
|
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\"}]," +
|
"{\"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\"}"
|
"\"target_high\":[{\"time\":\"00:00\",\"value\":\"7\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
|
||||||
testPumpPlugin = TestPumpPlugin(profileInjector)
|
invalidProfileJSON = "{\"dia\":\"1\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," +
|
||||||
`when`(activePluginProvider.activePump).thenReturn(testPumpPlugin)
|
"{\"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))
|
dateUtil = Mockito.spy(DateUtil(context))
|
||||||
`when`(dateUtil.now()).thenReturn(1656358822000)
|
testPumpPlugin = TestPumpPlugin(profileInjector)
|
||||||
|
Mockito.`when`(dateUtil.now()).thenReturn(now)
|
||||||
|
Mockito.`when`(activePlugin.activePump).thenReturn(testPumpPlugin)
|
||||||
hardLimits = HardLimitsMock(sp, rh)
|
hardLimits = HardLimitsMock(sp, rh)
|
||||||
validProfile = ProfileSealed.Pure(pureProfileFromJson(JSONObject(validProfileJSON), dateUtil)!!)
|
validProfile = ProfileSealed.Pure(pureProfileFromJson(JSONObject(validProfileJSON), dateUtil)!!)
|
||||||
effectiveProfileSwitch = EffectiveProfileSwitch(
|
effectiveProfileSwitch = EffectiveProfileSwitch(
|
|
@ -1,4 +1,4 @@
|
||||||
package info.nightscout.androidaps
|
package info.nightscout.sharedtests
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.annotations.OpenForTesting
|
import info.nightscout.androidaps.annotations.OpenForTesting
|
||||||
|
@ -19,6 +19,7 @@ class TestPumpPlugin(val injector: HasAndroidInjector) : Pump {
|
||||||
|
|
||||||
var connected = false
|
var connected = false
|
||||||
var isProfileSet = true
|
var isProfileSet = true
|
||||||
|
var pumpSuspended = false
|
||||||
|
|
||||||
override fun isConnected() = connected
|
override fun isConnected() = connected
|
||||||
override fun isConnecting() = false
|
override fun isConnecting() = false
|
||||||
|
@ -29,7 +30,7 @@ class TestPumpPlugin(val injector: HasAndroidInjector) : Pump {
|
||||||
override var pumpDescription = PumpDescription()
|
override var pumpDescription = PumpDescription()
|
||||||
|
|
||||||
override fun isInitialized(): Boolean = true
|
override fun isInitialized(): Boolean = true
|
||||||
override fun isSuspended(): Boolean = false
|
override fun isSuspended(): Boolean = pumpSuspended
|
||||||
override fun isBusy(): Boolean = false
|
override fun isBusy(): Boolean = false
|
||||||
override fun connect(reason: String) {
|
override fun connect(reason: String) {
|
||||||
connected = true
|
connected = true
|
||||||
|
@ -44,15 +45,19 @@ class TestPumpPlugin(val injector: HasAndroidInjector) : Pump {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun waitForDisconnectionInSeconds(): Int = 0
|
override fun waitForDisconnectionInSeconds(): Int = 0
|
||||||
override fun getPumpStatus(reason: String) {}
|
override fun getPumpStatus(reason: String) { /* not needed */
|
||||||
|
}
|
||||||
|
|
||||||
override fun setNewBasalProfile(profile: Profile): PumpEnactResult = PumpEnactResult(injector)
|
override fun setNewBasalProfile(profile: Profile): PumpEnactResult = PumpEnactResult(injector)
|
||||||
override fun isThisProfileSet(profile: Profile): Boolean = isProfileSet
|
override fun isThisProfileSet(profile: Profile): Boolean = isProfileSet
|
||||||
override fun lastDataTime(): Long = lastData
|
override fun lastDataTime(): Long = lastData
|
||||||
override val baseBasalRate: Double = baseBasal
|
override val baseBasalRate: Double get() = baseBasal
|
||||||
override val reservoirLevel: Double = 0.0
|
override val reservoirLevel: Double = 0.0
|
||||||
override val batteryLevel: Int = 0
|
override val batteryLevel: Int = 0
|
||||||
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult = PumpEnactResult(injector).success(true)
|
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult = PumpEnactResult(injector).success(true)
|
||||||
override fun stopBolusDelivering() {}
|
override fun stopBolusDelivering() { /* not needed */
|
||||||
|
}
|
||||||
|
|
||||||
override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult =
|
override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult =
|
||||||
PumpEnactResult(injector).success(true)
|
PumpEnactResult(injector).success(true)
|
||||||
|
|
||||||
|
@ -66,9 +71,10 @@ class TestPumpPlugin(val injector: HasAndroidInjector) : Pump {
|
||||||
override fun manufacturer(): ManufacturerType = ManufacturerType.AAPS
|
override fun manufacturer(): ManufacturerType = ManufacturerType.AAPS
|
||||||
override fun model(): PumpType = PumpType.GENERIC_AAPS
|
override fun model(): PumpType = PumpType.GENERIC_AAPS
|
||||||
override fun serialNumber(): String = "1"
|
override fun serialNumber(): String = "1"
|
||||||
override fun shortStatus(veryShort: Boolean): String = ""
|
override fun shortStatus(veryShort: Boolean): String = "Virtual Pump"
|
||||||
override val isFakingTempsByExtendedBoluses: Boolean = false
|
override val isFakingTempsByExtendedBoluses: Boolean = false
|
||||||
override fun loadTDDs(): PumpEnactResult = PumpEnactResult(injector).success(true)
|
override fun loadTDDs(): PumpEnactResult = PumpEnactResult(injector).success(true)
|
||||||
override fun canHandleDST(): Boolean = true
|
override fun canHandleDST(): Boolean = true
|
||||||
override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) {}
|
override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) { /* not needed */
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -24,7 +24,6 @@ dependencies {
|
||||||
api "androidx.preference:preference-ktx:$preferencektx_version"
|
api "androidx.preference:preference-ktx:$preferencektx_version"
|
||||||
api "net.danlew:android.joda:$joda_version"
|
api "net.danlew:android.joda:$joda_version"
|
||||||
|
|
||||||
// for old fashioned support-app version (wear)
|
|
||||||
api "com.google.dagger:dagger:$dagger_version"
|
api "com.google.dagger:dagger:$dagger_version"
|
||||||
api "com.google.dagger:dagger-android:$dagger_version"
|
api "com.google.dagger:dagger-android:$dagger_version"
|
||||||
api "com.google.dagger:dagger-android-support:$dagger_version"
|
api "com.google.dagger:dagger-android-support:$dagger_version"
|
||||||
|
|
|
@ -5,7 +5,6 @@ dependencies {
|
||||||
testImplementation "org.json:json:$json_version"
|
testImplementation "org.json:json:$json_version"
|
||||||
testImplementation "org.mockito:mockito-junit-jupiter:$mockito_version"
|
testImplementation "org.mockito:mockito-junit-jupiter:$mockito_version"
|
||||||
testImplementation "org.mockito.kotlin:mockito-kotlin:4.1.0"
|
testImplementation "org.mockito.kotlin:mockito-kotlin:4.1.0"
|
||||||
//testImplementation "org.mockito:mockito-inline:$mockito_version"
|
|
||||||
testImplementation "joda-time:joda-time:$jodatime_version"
|
testImplementation "joda-time:joda-time:$jodatime_version"
|
||||||
testImplementation 'com.google.truth:truth:1.1.5'
|
testImplementation 'com.google.truth:truth:1.1.5'
|
||||||
testImplementation "org.skyscreamer:jsonassert:1.5.0"
|
testImplementation "org.skyscreamer:jsonassert:1.5.0"
|
||||||
|
|
|
@ -25,6 +25,8 @@ dependencies {
|
||||||
implementation project(':core:ui')
|
implementation project(':core:ui')
|
||||||
implementation project(':core:utils')
|
implementation project(':core:utils')
|
||||||
|
|
||||||
|
testImplementation project(':app-wear-shared:shared-tests')
|
||||||
|
|
||||||
// Protection
|
// Protection
|
||||||
api 'androidx.biometric:biometric:1.1.0'
|
api 'androidx.biometric:biometric:1.1.0'
|
||||||
}
|
}
|
|
@ -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,6 +1,5 @@
|
||||||
package info.nightscout.implementation.iob
|
package info.nightscout.implementation.iob
|
||||||
|
|
||||||
import info.nightscout.androidaps.TestBase
|
|
||||||
import info.nightscout.core.iob.asRounded
|
import info.nightscout.core.iob.asRounded
|
||||||
import info.nightscout.core.iob.log
|
import info.nightscout.core.iob.log
|
||||||
import info.nightscout.database.entities.GlucoseValue
|
import info.nightscout.database.entities.GlucoseValue
|
||||||
|
@ -10,6 +9,7 @@ import info.nightscout.interfaces.iob.InMemoryGlucoseValue
|
||||||
import info.nightscout.interfaces.iob.IobCobCalculator
|
import info.nightscout.interfaces.iob.IobCobCalculator
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
import info.nightscout.shared.utils.T
|
import info.nightscout.shared.utils.T
|
||||||
|
import info.nightscout.sharedtests.TestBase
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package info.nightscout.implementation.overview
|
package info.nightscout.implementation.overview
|
||||||
|
|
||||||
import info.nightscout.androidaps.TestBase
|
|
||||||
import info.nightscout.database.ValueWrapper
|
import info.nightscout.database.ValueWrapper
|
||||||
import info.nightscout.database.entities.GlucoseValue
|
import info.nightscout.database.entities.GlucoseValue
|
||||||
import info.nightscout.database.impl.AppRepository
|
import info.nightscout.database.impl.AppRepository
|
||||||
|
@ -14,6 +13,7 @@ import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
import info.nightscout.shared.sharedPreferences.SP
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
import info.nightscout.shared.utils.T
|
import info.nightscout.shared.utils.T
|
||||||
|
import info.nightscout.sharedtests.TestBase
|
||||||
import io.reactivex.rxjava3.core.Single
|
import io.reactivex.rxjava3.core.Single
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
|
|
|
@ -1,47 +1,47 @@
|
||||||
package info.nightscout.implementation.profile
|
package info.nightscout.implementation.profile
|
||||||
|
|
||||||
import info.nightscout.androidaps.TestBaseWithProfile
|
|
||||||
import info.nightscout.interfaces.profile.PureProfile
|
import info.nightscout.interfaces.profile.PureProfile
|
||||||
import org.junit.Assert
|
import info.nightscout.sharedtests.TestBaseWithProfile
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
internal class ProfileStoreTest : TestBaseWithProfile() {
|
internal class ProfileStoreTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun getStartDateTest() {
|
fun getStartDateTest() {
|
||||||
Assert.assertEquals(0, getValidProfileStore().getStartDate())
|
Assertions.assertEquals(0, getValidProfileStore().getStartDate())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun getDefaultProfileTest() {
|
fun getDefaultProfileTest() {
|
||||||
Assert.assertTrue(getValidProfileStore().getDefaultProfile() is PureProfile)
|
Assertions.assertTrue(getValidProfileStore().getDefaultProfile() is PureProfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun getDefaultProfileJsonTest() {
|
fun getDefaultProfileJsonTest() {
|
||||||
Assert.assertTrue(getValidProfileStore().getDefaultProfileJson()?.has("dia") ?: false)
|
Assertions.assertTrue(getValidProfileStore().getDefaultProfileJson()?.has("dia") ?: false)
|
||||||
Assert.assertEquals(null, getInvalidProfileStore2().getDefaultProfileJson())
|
Assertions.assertEquals(null, getInvalidProfileStore2().getDefaultProfileJson())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun getDefaultProfileNameTest() {
|
fun getDefaultProfileNameTest() {
|
||||||
Assert.assertEquals(TESTPROFILENAME, getValidProfileStore().getDefaultProfileName())
|
Assertions.assertEquals(TESTPROFILENAME, getValidProfileStore().getDefaultProfileName())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun getProfileListTest() {
|
fun getProfileListTest() {
|
||||||
Assert.assertEquals(1, getValidProfileStore().getProfileList().size)
|
Assertions.assertEquals(1, getValidProfileStore().getProfileList().size)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun getSpecificProfileTest() {
|
fun getSpecificProfileTest() {
|
||||||
Assert.assertTrue(getValidProfileStore().getSpecificProfile(TESTPROFILENAME) is PureProfile)
|
Assertions.assertTrue(getValidProfileStore().getSpecificProfile(TESTPROFILENAME) is PureProfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun allProfilesValidTest() {
|
fun allProfilesValidTest() {
|
||||||
Assert.assertTrue(getValidProfileStore().allProfilesValid)
|
Assertions.assertTrue(getValidProfileStore().allProfilesValid)
|
||||||
Assert.assertFalse(getInvalidProfileStore1().allProfilesValid)
|
Assertions.assertFalse(getInvalidProfileStore1().allProfilesValid)
|
||||||
Assert.assertFalse(getInvalidProfileStore2().allProfilesValid)
|
Assertions.assertFalse(getInvalidProfileStore2().allProfilesValid)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,12 +1,11 @@
|
||||||
package info.nightscout.implementation.pump
|
package info.nightscout.implementation.pump
|
||||||
|
|
||||||
import info.nightscout.androidaps.TestBase
|
|
||||||
import info.nightscout.implementation.R
|
import info.nightscout.implementation.R
|
||||||
import info.nightscout.interfaces.pump.DetailedBolusInfo
|
import info.nightscout.interfaces.pump.DetailedBolusInfo
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
import info.nightscout.shared.sharedPreferences.SP
|
||||||
import org.junit.Assert.assertEquals
|
import info.nightscout.sharedtests.TestBase
|
||||||
import org.junit.Assert.assertNull
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
|
@ -16,7 +15,7 @@ class DetailedBolusInfoStorageTest : TestBase() {
|
||||||
|
|
||||||
@Mock lateinit var sp: SP
|
@Mock lateinit var sp: SP
|
||||||
@Mock lateinit var rh: ResourceHelper
|
@Mock lateinit var rh: ResourceHelper
|
||||||
|
|
||||||
private val info1 = DetailedBolusInfo()
|
private val info1 = DetailedBolusInfo()
|
||||||
private val info2 = DetailedBolusInfo()
|
private val info2 = DetailedBolusInfo()
|
||||||
private val info3 = DetailedBolusInfo()
|
private val info3 = DetailedBolusInfo()
|
||||||
|
@ -48,9 +47,9 @@ class DetailedBolusInfoStorageTest : TestBase() {
|
||||||
@Test
|
@Test
|
||||||
fun add() {
|
fun add() {
|
||||||
detailedBolusInfoStorage.store.clear()
|
detailedBolusInfoStorage.store.clear()
|
||||||
assertEquals(0, detailedBolusInfoStorage.store.size)
|
Assertions.assertEquals(0, detailedBolusInfoStorage.store.size)
|
||||||
detailedBolusInfoStorage.add(info1)
|
detailedBolusInfoStorage.add(info1)
|
||||||
assertEquals(1, detailedBolusInfoStorage.store.size)
|
Assertions.assertEquals(1, detailedBolusInfoStorage.store.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -59,33 +58,33 @@ class DetailedBolusInfoStorageTest : TestBase() {
|
||||||
// Look for exact bolus
|
// Look for exact bolus
|
||||||
setUp()
|
setUp()
|
||||||
var d: DetailedBolusInfo? = detailedBolusInfoStorage.findDetailedBolusInfo(1000000, 4.0)
|
var d: DetailedBolusInfo? = detailedBolusInfoStorage.findDetailedBolusInfo(1000000, 4.0)
|
||||||
assertEquals(4.0, d!!.insulin, 0.01)
|
Assertions.assertEquals(4.0, d!!.insulin, 0.01)
|
||||||
assertEquals(2, detailedBolusInfoStorage.store.size)
|
Assertions.assertEquals(2, detailedBolusInfoStorage.store.size)
|
||||||
// Look for exact bolus
|
// Look for exact bolus
|
||||||
setUp()
|
setUp()
|
||||||
d = detailedBolusInfoStorage.findDetailedBolusInfo(1000000, 3.0)
|
d = detailedBolusInfoStorage.findDetailedBolusInfo(1000000, 3.0)
|
||||||
assertEquals(3.0, d!!.insulin, 0.01)
|
Assertions.assertEquals(3.0, d!!.insulin, 0.01)
|
||||||
assertEquals(2, detailedBolusInfoStorage.store.size)
|
Assertions.assertEquals(2, detailedBolusInfoStorage.store.size)
|
||||||
// With less insulin (bolus not delivered completely). Should return first one matching date
|
// With less insulin (bolus not delivered completely). Should return first one matching date
|
||||||
setUp()
|
setUp()
|
||||||
d = detailedBolusInfoStorage.findDetailedBolusInfo(1000500, 2.0)
|
d = detailedBolusInfoStorage.findDetailedBolusInfo(1000500, 2.0)
|
||||||
assertEquals(3.0, d!!.insulin, 0.01)
|
Assertions.assertEquals(3.0, d!!.insulin, 0.01)
|
||||||
assertEquals(2, detailedBolusInfoStorage.store.size)
|
Assertions.assertEquals(2, detailedBolusInfoStorage.store.size)
|
||||||
// With less insulin (bolus not delivered completely). Should return first one matching date
|
// With less insulin (bolus not delivered completely). Should return first one matching date
|
||||||
setUp()
|
setUp()
|
||||||
d = detailedBolusInfoStorage.findDetailedBolusInfo(1000500, 3.5)
|
d = detailedBolusInfoStorage.findDetailedBolusInfo(1000500, 3.5)
|
||||||
assertEquals(4.0, d!!.insulin, 0.01)
|
Assertions.assertEquals(4.0, d!!.insulin, 0.01)
|
||||||
assertEquals(2, detailedBolusInfoStorage.store.size)
|
Assertions.assertEquals(2, detailedBolusInfoStorage.store.size)
|
||||||
// With more insulin should return null
|
// With more insulin should return null
|
||||||
setUp()
|
setUp()
|
||||||
d = detailedBolusInfoStorage.findDetailedBolusInfo(1000500, 4.5)
|
d = detailedBolusInfoStorage.findDetailedBolusInfo(1000500, 4.5)
|
||||||
assertNull(d)
|
Assertions.assertNull(d)
|
||||||
assertEquals(3, detailedBolusInfoStorage.store.size)
|
Assertions.assertEquals(3, detailedBolusInfoStorage.store.size)
|
||||||
// With more than one minute off should return null
|
// With more than one minute off should return null
|
||||||
setUp()
|
setUp()
|
||||||
d = detailedBolusInfoStorage.findDetailedBolusInfo(1070000, 4.0)
|
d = detailedBolusInfoStorage.findDetailedBolusInfo(1070000, 4.0)
|
||||||
assertNull(d)
|
Assertions.assertNull(d)
|
||||||
assertEquals(3, detailedBolusInfoStorage.store.size)
|
Assertions.assertEquals(3, detailedBolusInfoStorage.store.size)
|
||||||
// Use last, if bolus size is the same
|
// Use last, if bolus size is the same
|
||||||
// setUp()
|
// setUp()
|
||||||
// d = detailedBolusInfoStorage.findDetailedBolusInfo(1070000, 5.0)
|
// d = detailedBolusInfoStorage.findDetailedBolusInfo(1070000, 5.0)
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
package info.nightscout.implementation.pump
|
package info.nightscout.implementation.pump
|
||||||
|
|
||||||
import info.nightscout.androidaps.TestBase
|
|
||||||
import info.nightscout.interfaces.pump.PumpSync
|
import info.nightscout.interfaces.pump.PumpSync
|
||||||
import org.junit.Assert.assertEquals
|
import info.nightscout.sharedtests.TestBase
|
||||||
import org.junit.Assert.assertNull
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
@ -30,9 +29,9 @@ class TemporaryBasalStorageTest : TestBase() {
|
||||||
@Test
|
@Test
|
||||||
fun add() {
|
fun add() {
|
||||||
temporaryBasalStorage.store.clear()
|
temporaryBasalStorage.store.clear()
|
||||||
assertEquals(0, temporaryBasalStorage.store.size)
|
Assertions.assertEquals(0, temporaryBasalStorage.store.size)
|
||||||
temporaryBasalStorage.add(info1)
|
temporaryBasalStorage.add(info1)
|
||||||
assertEquals(1, temporaryBasalStorage.store.size)
|
Assertions.assertEquals(1, temporaryBasalStorage.store.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -41,38 +40,38 @@ class TemporaryBasalStorageTest : TestBase() {
|
||||||
// Look for exact bolus
|
// Look for exact bolus
|
||||||
setUp()
|
setUp()
|
||||||
var d = temporaryBasalStorage.findTemporaryBasal(1000000, 4.0)
|
var d = temporaryBasalStorage.findTemporaryBasal(1000000, 4.0)
|
||||||
assertEquals(4.0, d!!.rate, 0.01)
|
Assertions.assertEquals(4.0, d!!.rate, 0.01)
|
||||||
assertEquals(2, temporaryBasalStorage.store.size)
|
Assertions.assertEquals(2, temporaryBasalStorage.store.size)
|
||||||
// Look for exact bolus
|
// Look for exact bolus
|
||||||
setUp()
|
setUp()
|
||||||
d = temporaryBasalStorage.findTemporaryBasal(1000000, 3.0)
|
d = temporaryBasalStorage.findTemporaryBasal(1000000, 3.0)
|
||||||
assertEquals(3.0, d!!.rate, 0.01)
|
Assertions.assertEquals(3.0, d!!.rate, 0.01)
|
||||||
assertEquals(2, temporaryBasalStorage.store.size)
|
Assertions.assertEquals(2, temporaryBasalStorage.store.size)
|
||||||
// With less rate (bolus not delivered completely). Should return first one matching date
|
// With less rate (bolus not delivered completely). Should return first one matching date
|
||||||
setUp()
|
setUp()
|
||||||
d = temporaryBasalStorage.findTemporaryBasal(1000500, 2.0)
|
d = temporaryBasalStorage.findTemporaryBasal(1000500, 2.0)
|
||||||
assertEquals(3.0, d!!.rate, 0.01)
|
Assertions.assertEquals(3.0, d!!.rate, 0.01)
|
||||||
assertEquals(2, temporaryBasalStorage.store.size)
|
Assertions.assertEquals(2, temporaryBasalStorage.store.size)
|
||||||
// With less rate (bolus not delivered completely). Should return first one matching date
|
// With less rate (bolus not delivered completely). Should return first one matching date
|
||||||
setUp()
|
setUp()
|
||||||
d = temporaryBasalStorage.findTemporaryBasal(1000500, 3.5)
|
d = temporaryBasalStorage.findTemporaryBasal(1000500, 3.5)
|
||||||
assertEquals(4.0, d!!.rate, 0.01)
|
Assertions.assertEquals(4.0, d!!.rate, 0.01)
|
||||||
assertEquals(2, temporaryBasalStorage.store.size)
|
Assertions.assertEquals(2, temporaryBasalStorage.store.size)
|
||||||
// With more rate should return null
|
// With more rate should return null
|
||||||
setUp()
|
setUp()
|
||||||
d = temporaryBasalStorage.findTemporaryBasal(1000500, 4.5)
|
d = temporaryBasalStorage.findTemporaryBasal(1000500, 4.5)
|
||||||
assertNull(d)
|
Assertions.assertNull(d)
|
||||||
assertEquals(3, temporaryBasalStorage.store.size)
|
Assertions.assertEquals(3, temporaryBasalStorage.store.size)
|
||||||
// With more than one minute off should return null
|
// With more than one minute off should return null
|
||||||
setUp()
|
setUp()
|
||||||
d = temporaryBasalStorage.findTemporaryBasal(1070000, 4.0)
|
d = temporaryBasalStorage.findTemporaryBasal(1070000, 4.0)
|
||||||
assertNull(d)
|
Assertions.assertNull(d)
|
||||||
assertEquals(3, temporaryBasalStorage.store.size)
|
Assertions.assertEquals(3, temporaryBasalStorage.store.size)
|
||||||
// Use last, if bolus size is the same
|
// Use last, if bolus size is the same
|
||||||
setUp()
|
setUp()
|
||||||
d = temporaryBasalStorage.findTemporaryBasal(1070000, 5.0)
|
d = temporaryBasalStorage.findTemporaryBasal(1070000, 5.0)
|
||||||
assertEquals(5.0, d!!.rate, 0.01)
|
Assertions.assertEquals(5.0, d!!.rate, 0.01)
|
||||||
assertEquals(2, temporaryBasalStorage.store.size)
|
Assertions.assertEquals(2, temporaryBasalStorage.store.size)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,8 +5,6 @@ import android.os.Handler
|
||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.TestBaseWithProfile
|
|
||||||
import info.nightscout.androidaps.TestPumpPlugin
|
|
||||||
import info.nightscout.core.utils.fabric.FabricPrivacy
|
import info.nightscout.core.utils.fabric.FabricPrivacy
|
||||||
import info.nightscout.database.ValueWrapper
|
import info.nightscout.database.ValueWrapper
|
||||||
import info.nightscout.database.entities.Bolus
|
import info.nightscout.database.entities.Bolus
|
||||||
|
@ -36,6 +34,8 @@ import info.nightscout.rx.logging.AAPSLogger
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
import info.nightscout.shared.sharedPreferences.SP
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
|
import info.nightscout.sharedtests.TestBaseWithProfile
|
||||||
|
import info.nightscout.sharedtests.TestPumpPlugin
|
||||||
import io.reactivex.rxjava3.core.Single
|
import io.reactivex.rxjava3.core.Single
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
|
@ -50,7 +50,6 @@ import java.util.Calendar
|
||||||
class CommandQueueImplementationTest : TestBaseWithProfile() {
|
class CommandQueueImplementationTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
@Mock lateinit var constraintChecker: Constraints
|
@Mock lateinit var constraintChecker: Constraints
|
||||||
@Mock lateinit var activePlugin: ActivePlugin
|
|
||||||
@Mock lateinit var powerManager: PowerManager
|
@Mock lateinit var powerManager: PowerManager
|
||||||
@Mock lateinit var repository: AppRepository
|
@Mock lateinit var repository: AppRepository
|
||||||
@Mock lateinit var uiInteraction: UiInteraction
|
@Mock lateinit var uiInteraction: UiInteraction
|
||||||
|
@ -81,7 +80,7 @@ class CommandQueueImplementationTest : TestBaseWithProfile() {
|
||||||
androidPermission, uiInteraction, persistenceLayer
|
androidPermission, uiInteraction, persistenceLayer
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun notifyAboutNewCommand() : Boolean = true
|
override fun notifyAboutNewCommand(): Boolean = true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,7 +249,7 @@ class CommandQueueImplementationTest : TestBaseWithProfile() {
|
||||||
// add updateTime
|
// add updateTime
|
||||||
commandQueue.updateTime(null)
|
commandQueue.updateTime(null)
|
||||||
Assertions.assertEquals(7, commandQueue.size())
|
Assertions.assertEquals(7, commandQueue.size())
|
||||||
|
|
||||||
commandQueue.clear()
|
commandQueue.clear()
|
||||||
commandQueue.tempBasalAbsolute(0.0, 30, true, validProfile, PumpSync.TemporaryBasalType.NORMAL, null)
|
commandQueue.tempBasalAbsolute(0.0, 30, true, validProfile, PumpSync.TemporaryBasalType.NORMAL, null)
|
||||||
commandQueue.pickup()
|
commandQueue.pickup()
|
||||||
|
|
|
@ -4,20 +4,19 @@ import android.content.Context
|
||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.TestBaseWithProfile
|
|
||||||
import info.nightscout.androidaps.TestPumpPlugin
|
|
||||||
import info.nightscout.database.impl.AppRepository
|
import info.nightscout.database.impl.AppRepository
|
||||||
import info.nightscout.implementation.queue.commands.CommandTempBasalAbsolute
|
import info.nightscout.implementation.queue.commands.CommandTempBasalAbsolute
|
||||||
import info.nightscout.interfaces.AndroidPermission
|
import info.nightscout.interfaces.AndroidPermission
|
||||||
import info.nightscout.interfaces.constraints.Constraint
|
import info.nightscout.interfaces.constraints.Constraint
|
||||||
import info.nightscout.interfaces.constraints.Constraints
|
import info.nightscout.interfaces.constraints.Constraints
|
||||||
import info.nightscout.interfaces.db.PersistenceLayer
|
import info.nightscout.interfaces.db.PersistenceLayer
|
||||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
|
||||||
import info.nightscout.interfaces.pump.PumpSync
|
import info.nightscout.interfaces.pump.PumpSync
|
||||||
import info.nightscout.interfaces.pump.defs.PumpDescription
|
import info.nightscout.interfaces.pump.defs.PumpDescription
|
||||||
import info.nightscout.interfaces.queue.Command
|
import info.nightscout.interfaces.queue.Command
|
||||||
import info.nightscout.interfaces.ui.UiInteraction
|
import info.nightscout.interfaces.ui.UiInteraction
|
||||||
import org.junit.Assert
|
import info.nightscout.sharedtests.TestBaseWithProfile
|
||||||
|
import info.nightscout.sharedtests.TestPumpPlugin
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.mockito.ArgumentMatchers
|
import org.mockito.ArgumentMatchers
|
||||||
|
@ -27,14 +26,13 @@ import org.mockito.Mockito
|
||||||
class QueueThreadTest : TestBaseWithProfile() {
|
class QueueThreadTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
@Mock lateinit var constraintChecker: Constraints
|
@Mock lateinit var constraintChecker: Constraints
|
||||||
@Mock lateinit var activePlugin: ActivePlugin
|
|
||||||
@Mock lateinit var powerManager: PowerManager
|
@Mock lateinit var powerManager: PowerManager
|
||||||
@Mock lateinit var repository: AppRepository
|
@Mock lateinit var repository: AppRepository
|
||||||
@Mock lateinit var androidPermission: AndroidPermission
|
@Mock lateinit var androidPermission: AndroidPermission
|
||||||
@Mock lateinit var uiInteraction: UiInteraction
|
@Mock lateinit var uiInteraction: UiInteraction
|
||||||
@Mock lateinit var persistenceLayer: PersistenceLayer
|
@Mock lateinit var persistenceLayer: PersistenceLayer
|
||||||
|
|
||||||
val injector = HasAndroidInjector {
|
private val injector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
if (it is Command) {
|
if (it is Command) {
|
||||||
it.aapsLogger = aapsLogger
|
it.aapsLogger = aapsLogger
|
||||||
|
@ -64,7 +62,6 @@ class QueueThreadTest : TestBaseWithProfile() {
|
||||||
pumpDescription.basalMinimumRate = 0.1
|
pumpDescription.basalMinimumRate = 0.1
|
||||||
|
|
||||||
Mockito.`when`(context.getSystemService(Context.POWER_SERVICE)).thenReturn(powerManager)
|
Mockito.`when`(context.getSystemService(Context.POWER_SERVICE)).thenReturn(powerManager)
|
||||||
Mockito.`when`(activePlugin.activePump).thenReturn(pumpPlugin)
|
|
||||||
Mockito.`when`(profileFunction.getProfile()).thenReturn(validProfile)
|
Mockito.`when`(profileFunction.getProfile()).thenReturn(validProfile)
|
||||||
|
|
||||||
val bolusConstraint = Constraint(0.0)
|
val bolusConstraint = Constraint(0.0)
|
||||||
|
@ -85,7 +82,8 @@ class QueueThreadTest : TestBaseWithProfile() {
|
||||||
@Test
|
@Test
|
||||||
fun commandIsPickedUp() {
|
fun commandIsPickedUp() {
|
||||||
commandQueue.tempBasalAbsolute(2.0, 60, true, validProfile, PumpSync.TemporaryBasalType.NORMAL, null)
|
commandQueue.tempBasalAbsolute(2.0, 60, true, validProfile, PumpSync.TemporaryBasalType.NORMAL, null)
|
||||||
|
@Suppress("CallToThreadRun")
|
||||||
sut.run()
|
sut.run()
|
||||||
Assert.assertEquals(0, commandQueue.size())
|
Assertions.assertEquals(0, commandQueue.size())
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,8 +2,6 @@ package info.nightscout.implementation.wizard
|
||||||
|
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.TestBase
|
|
||||||
import info.nightscout.androidaps.TestPumpPlugin
|
|
||||||
import info.nightscout.core.wizard.BolusWizard
|
import info.nightscout.core.wizard.BolusWizard
|
||||||
import info.nightscout.implementation.iob.GlucoseStatusProviderImpl
|
import info.nightscout.implementation.iob.GlucoseStatusProviderImpl
|
||||||
import info.nightscout.interfaces.GlucoseUnit
|
import info.nightscout.interfaces.GlucoseUnit
|
||||||
|
@ -11,37 +9,28 @@ import info.nightscout.interfaces.aps.AutosensDataStore
|
||||||
import info.nightscout.interfaces.aps.Loop
|
import info.nightscout.interfaces.aps.Loop
|
||||||
import info.nightscout.interfaces.constraints.Constraint
|
import info.nightscout.interfaces.constraints.Constraint
|
||||||
import info.nightscout.interfaces.constraints.Constraints
|
import info.nightscout.interfaces.constraints.Constraints
|
||||||
import info.nightscout.interfaces.iob.IobCobCalculator
|
|
||||||
import info.nightscout.interfaces.iob.IobTotal
|
import info.nightscout.interfaces.iob.IobTotal
|
||||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
|
||||||
import info.nightscout.interfaces.profile.Profile
|
import info.nightscout.interfaces.profile.Profile
|
||||||
import info.nightscout.interfaces.profile.ProfileFunction
|
|
||||||
import info.nightscout.interfaces.pump.defs.PumpDescription
|
import info.nightscout.interfaces.pump.defs.PumpDescription
|
||||||
import info.nightscout.interfaces.queue.CommandQueue
|
import info.nightscout.interfaces.queue.CommandQueue
|
||||||
import info.nightscout.rx.bus.RxBus
|
import info.nightscout.rx.bus.RxBus
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
import info.nightscout.sharedtests.TestBaseWithProfile
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.Assert
|
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
import org.mockito.Mockito
|
import org.mockito.Mockito
|
||||||
import org.mockito.invocation.InvocationOnMock
|
import org.mockito.invocation.InvocationOnMock
|
||||||
|
|
||||||
class BolusWizardTest : TestBase() {
|
class BolusWizardTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
private val pumpBolusStep = 0.1
|
private val pumpBolusStep = 0.1
|
||||||
|
|
||||||
@Mock lateinit var rh: ResourceHelper
|
|
||||||
@Mock lateinit var profileFunction: ProfileFunction
|
|
||||||
@Mock lateinit var constraintChecker: Constraints
|
@Mock lateinit var constraintChecker: Constraints
|
||||||
@Mock lateinit var activePlugin: ActivePlugin
|
|
||||||
@Mock lateinit var commandQueue: CommandQueue
|
@Mock lateinit var commandQueue: CommandQueue
|
||||||
@Mock lateinit var loop: Loop
|
@Mock lateinit var loop: Loop
|
||||||
@Mock lateinit var iobCobCalculator: IobCobCalculator
|
|
||||||
@Mock lateinit var dateUtil: DateUtil
|
|
||||||
@Mock lateinit var autosensDataStore: AutosensDataStore
|
@Mock lateinit var autosensDataStore: AutosensDataStore
|
||||||
|
|
||||||
val injector = HasAndroidInjector {
|
private val injector = HasAndroidInjector {
|
||||||
AndroidInjector {
|
AndroidInjector {
|
||||||
if (it is BolusWizard) {
|
if (it is BolusWizard) {
|
||||||
it.aapsLogger = aapsLogger
|
it.aapsLogger = aapsLogger
|
||||||
|
@ -59,8 +48,6 @@ class BolusWizardTest : TestBase() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val testPumpPlugin = TestPumpPlugin(injector)
|
|
||||||
|
|
||||||
@Suppress("SameParameterValue")
|
@Suppress("SameParameterValue")
|
||||||
private fun setupProfile(targetLow: Double, targetHigh: Double, insulinSensitivityFactor: Double, insulinToCarbRatio: Double): Profile {
|
private fun setupProfile(targetLow: Double, targetHigh: Double, insulinSensitivityFactor: Double, insulinToCarbRatio: Double): Profile {
|
||||||
val profile = Mockito.mock(Profile::class.java)
|
val profile = Mockito.mock(Profile::class.java)
|
||||||
|
@ -72,7 +59,6 @@ class BolusWizardTest : TestBase() {
|
||||||
Mockito.`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
|
Mockito.`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
|
||||||
Mockito.`when`(iobCobCalculator.calculateIobFromBolus()).thenReturn(IobTotal(System.currentTimeMillis()))
|
Mockito.`when`(iobCobCalculator.calculateIobFromBolus()).thenReturn(IobTotal(System.currentTimeMillis()))
|
||||||
Mockito.`when`(iobCobCalculator.calculateIobFromTempBasalsIncludingConvertedExtended()).thenReturn(IobTotal(System.currentTimeMillis()))
|
Mockito.`when`(iobCobCalculator.calculateIobFromTempBasalsIncludingConvertedExtended()).thenReturn(IobTotal(System.currentTimeMillis()))
|
||||||
Mockito.`when`(activePlugin.activePump).thenReturn(testPumpPlugin)
|
|
||||||
testPumpPlugin.pumpDescription = PumpDescription().also {
|
testPumpPlugin.pumpDescription = PumpDescription().also {
|
||||||
it.bolusStep = pumpBolusStep
|
it.bolusStep = pumpBolusStep
|
||||||
}
|
}
|
||||||
|
@ -88,30 +74,138 @@ class BolusWizardTest : TestBase() {
|
||||||
/** Should calculate the same bolus when different blood glucose but both in target range */
|
/** Should calculate the same bolus when different blood glucose but both in target range */
|
||||||
fun shouldCalculateTheSameBolusWhenBGsInRange() {
|
fun shouldCalculateTheSameBolusWhenBGsInRange() {
|
||||||
val profile = setupProfile(4.0, 8.0, 20.0, 12.0)
|
val profile = setupProfile(4.0, 8.0, 20.0, 12.0)
|
||||||
var bw = BolusWizard(injector).doCalc(profile, "", null, 20, 0.0, 4.2, 0.0, 100, useBg = true, useCob = true, includeBolusIOB = true, includeBasalIOB = true, useSuperBolus = false, useTT = false, useTrend = false, useAlarm = false)
|
var bw =
|
||||||
|
BolusWizard(injector).doCalc(
|
||||||
|
profile,
|
||||||
|
"",
|
||||||
|
null,
|
||||||
|
20,
|
||||||
|
0.0,
|
||||||
|
4.2,
|
||||||
|
0.0,
|
||||||
|
100,
|
||||||
|
useBg = true,
|
||||||
|
useCob = true,
|
||||||
|
includeBolusIOB = true,
|
||||||
|
includeBasalIOB = true,
|
||||||
|
useSuperBolus = false,
|
||||||
|
useTT = false,
|
||||||
|
useTrend = false,
|
||||||
|
useAlarm = false
|
||||||
|
)
|
||||||
val bolusForBg42 = bw.calculatedTotalInsulin
|
val bolusForBg42 = bw.calculatedTotalInsulin
|
||||||
bw = BolusWizard(injector).doCalc(profile, "", null, 20, 0.0, 5.4, 0.0, 100, useBg = true, useCob = true, includeBolusIOB = true, includeBasalIOB = true, useSuperBolus = false, useTT = false, useTrend = false, useAlarm = false)
|
bw =
|
||||||
|
BolusWizard(injector).doCalc(
|
||||||
|
profile,
|
||||||
|
"",
|
||||||
|
null,
|
||||||
|
20,
|
||||||
|
0.0,
|
||||||
|
5.4,
|
||||||
|
0.0,
|
||||||
|
100,
|
||||||
|
useBg = true,
|
||||||
|
useCob = true,
|
||||||
|
includeBolusIOB = true,
|
||||||
|
includeBasalIOB = true,
|
||||||
|
useSuperBolus = false,
|
||||||
|
useTT = false,
|
||||||
|
useTrend = false,
|
||||||
|
useAlarm = false
|
||||||
|
)
|
||||||
val bolusForBg54 = bw.calculatedTotalInsulin
|
val bolusForBg54 = bw.calculatedTotalInsulin
|
||||||
Assert.assertEquals(bolusForBg42, bolusForBg54, 0.01)
|
Assertions.assertEquals(bolusForBg42, bolusForBg54, 0.01)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun shouldCalculateHigherBolusWhenHighBG() {
|
fun shouldCalculateHigherBolusWhenHighBG() {
|
||||||
val profile = setupProfile(4.0, 8.0, 20.0, 12.0)
|
val profile = setupProfile(4.0, 8.0, 20.0, 12.0)
|
||||||
var bw = BolusWizard(injector).doCalc(profile, "", null, 20, 0.0, 9.8, 0.0, 100, useBg = true, useCob = true, includeBolusIOB = true, includeBasalIOB = true, useSuperBolus = false, useTT = false, useTrend = false, useAlarm = false)
|
var bw =
|
||||||
|
BolusWizard(injector).doCalc(
|
||||||
|
profile,
|
||||||
|
"",
|
||||||
|
null,
|
||||||
|
20,
|
||||||
|
0.0,
|
||||||
|
9.8,
|
||||||
|
0.0,
|
||||||
|
100,
|
||||||
|
useBg = true,
|
||||||
|
useCob = true,
|
||||||
|
includeBolusIOB = true,
|
||||||
|
includeBasalIOB = true,
|
||||||
|
useSuperBolus = false,
|
||||||
|
useTT = false,
|
||||||
|
useTrend = false,
|
||||||
|
useAlarm = false
|
||||||
|
)
|
||||||
val bolusForHighBg = bw.calculatedTotalInsulin
|
val bolusForHighBg = bw.calculatedTotalInsulin
|
||||||
bw = BolusWizard(injector).doCalc(profile, "", null, 20, 0.0, 5.4, 0.0, 100, useBg = true, useCob = true, includeBolusIOB = true, includeBasalIOB = true, useSuperBolus = false, useTT = false, useTrend = false, useAlarm = false)
|
bw =
|
||||||
|
BolusWizard(injector).doCalc(
|
||||||
|
profile,
|
||||||
|
"",
|
||||||
|
null,
|
||||||
|
20,
|
||||||
|
0.0,
|
||||||
|
5.4,
|
||||||
|
0.0,
|
||||||
|
100,
|
||||||
|
useBg = true,
|
||||||
|
useCob = true,
|
||||||
|
includeBolusIOB = true,
|
||||||
|
includeBasalIOB = true,
|
||||||
|
useSuperBolus = false,
|
||||||
|
useTT = false,
|
||||||
|
useTrend = false,
|
||||||
|
useAlarm = false
|
||||||
|
)
|
||||||
val bolusForBgInRange = bw.calculatedTotalInsulin
|
val bolusForBgInRange = bw.calculatedTotalInsulin
|
||||||
Assert.assertTrue(bolusForHighBg > bolusForBgInRange)
|
Assertions.assertTrue(bolusForHighBg > bolusForBgInRange)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun shouldCalculateLowerBolusWhenLowBG() {
|
fun shouldCalculateLowerBolusWhenLowBG() {
|
||||||
val profile = setupProfile(4.0, 8.0, 20.0, 12.0)
|
val profile = setupProfile(4.0, 8.0, 20.0, 12.0)
|
||||||
var bw = BolusWizard(injector).doCalc(profile, "", null, 20, 0.0, 3.6, 0.0, 100, useBg = true, useCob = true, includeBolusIOB = true, includeBasalIOB = true, useSuperBolus = false, useTT = false, useTrend = false, useAlarm = false)
|
var bw =
|
||||||
|
BolusWizard(injector).doCalc(
|
||||||
|
profile,
|
||||||
|
"",
|
||||||
|
null,
|
||||||
|
20,
|
||||||
|
0.0,
|
||||||
|
3.6,
|
||||||
|
0.0,
|
||||||
|
100,
|
||||||
|
useBg = true,
|
||||||
|
useCob = true,
|
||||||
|
includeBolusIOB = true,
|
||||||
|
includeBasalIOB = true,
|
||||||
|
useSuperBolus = false,
|
||||||
|
useTT = false,
|
||||||
|
useTrend = false,
|
||||||
|
useAlarm = false
|
||||||
|
)
|
||||||
val bolusForLowBg = bw.calculatedTotalInsulin
|
val bolusForLowBg = bw.calculatedTotalInsulin
|
||||||
bw = BolusWizard(injector).doCalc(profile, "", null, 20, 0.0, 5.4, 0.0, 100, useBg = true, useCob = true, includeBolusIOB = true, includeBasalIOB = true, useSuperBolus = false, useTT = false, useTrend = false, useAlarm = false)
|
bw =
|
||||||
|
BolusWizard(injector).doCalc(
|
||||||
|
profile,
|
||||||
|
"",
|
||||||
|
null,
|
||||||
|
20,
|
||||||
|
0.0,
|
||||||
|
5.4,
|
||||||
|
0.0,
|
||||||
|
100,
|
||||||
|
useBg = true,
|
||||||
|
useCob = true,
|
||||||
|
includeBolusIOB = true,
|
||||||
|
includeBasalIOB = true,
|
||||||
|
useSuperBolus = false,
|
||||||
|
useTT = false,
|
||||||
|
useTrend = false,
|
||||||
|
useAlarm = false
|
||||||
|
)
|
||||||
val bolusForBgInRange = bw.calculatedTotalInsulin
|
val bolusForBgInRange = bw.calculatedTotalInsulin
|
||||||
Assert.assertTrue(bolusForLowBg < bolusForBgInRange)
|
Assertions.assertTrue(bolusForLowBg < bolusForBgInRange)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -23,6 +23,7 @@ dependencies {
|
||||||
implementation project(':core:utils')
|
implementation project(':core:utils')
|
||||||
implementation project(':core:ui')
|
implementation project(':core:ui')
|
||||||
implementation project(':core:validators')
|
implementation project(':core:validators')
|
||||||
|
implementation project(':plugins:automation')
|
||||||
|
|
||||||
api "androidx.appcompat:appcompat:$appcompat_version"
|
api "androidx.appcompat:appcompat:$appcompat_version"
|
||||||
api "androidx.swiperefreshlayout:swiperefreshlayout:$swipe_version"
|
api "androidx.swiperefreshlayout:swiperefreshlayout:$swipe_version"
|
||||||
|
@ -30,5 +31,4 @@ dependencies {
|
||||||
|
|
||||||
// APS
|
// APS
|
||||||
api 'org.mozilla:rhino:1.7.14'
|
api 'org.mozilla:rhino:1.7.14'
|
||||||
implementation project(path: ':plugins:automation')
|
|
||||||
}
|
}
|
|
@ -29,6 +29,7 @@ dependencies {
|
||||||
|
|
||||||
testImplementation project(':implementation')
|
testImplementation project(':implementation')
|
||||||
testImplementation project(':plugins:insulin')
|
testImplementation project(':plugins:insulin')
|
||||||
|
testImplementation project(':app-wear-shared:shared-tests')
|
||||||
|
|
||||||
api "androidx.appcompat:appcompat:$appcompat_version"
|
api "androidx.appcompat:appcompat:$appcompat_version"
|
||||||
api "com.google.android.material:material:$material_version"
|
api "com.google.android.material:material:$material_version"
|
||||||
|
|
|
@ -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,107 +0,0 @@
|
||||||
package info.nightscout.androidaps
|
|
||||||
|
|
||||||
import androidx.collection.ArrayMap
|
|
||||||
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.ProfileStore
|
|
||||||
import info.nightscout.interfaces.profile.PureProfile
|
|
||||||
import info.nightscout.interfaces.utils.HardLimits
|
|
||||||
import info.nightscout.interfaces.utils.JsonHelper
|
|
||||||
import info.nightscout.rx.bus.RxBus
|
|
||||||
import info.nightscout.rx.logging.AAPSLogger
|
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
|
||||||
import info.nightscout.shared.utils.DateUtil
|
|
||||||
import org.json.JSONException
|
|
||||||
import org.json.JSONObject
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
class ProfileStoreObject(val injector: HasAndroidInjector, override val data: JSONObject, val dateUtil: DateUtil) : ProfileStore {
|
|
||||||
|
|
||||||
@Inject lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Inject lateinit var activePlugin: ActivePlugin
|
|
||||||
@Inject lateinit var config: Config
|
|
||||||
@Inject lateinit var rh: ResourceHelper
|
|
||||||
@Inject lateinit var rxBus: RxBus
|
|
||||||
@Inject lateinit var hardLimits: HardLimits
|
|
||||||
|
|
||||||
init {
|
|
||||||
injector.androidInjector().inject(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val cachedObjects = ArrayMap<String, PureProfile>()
|
|
||||||
|
|
||||||
private fun storeUnits(): String? = JsonHelper.safeGetStringAllowNull(data, "units", null)
|
|
||||||
|
|
||||||
private fun getStore(): JSONObject? {
|
|
||||||
try {
|
|
||||||
if (data.has("store")) return data.getJSONObject("store")
|
|
||||||
} catch (e: JSONException) {
|
|
||||||
aapsLogger.error("Unhandled exception", e)
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getStartDate(): Long {
|
|
||||||
val iso = JsonHelper.safeGetString(data, "startDate") ?: return 0
|
|
||||||
return try {
|
|
||||||
dateUtil.fromISODateString(iso)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getDefaultProfile(): PureProfile? = getDefaultProfileName()?.let { getSpecificProfile(it) }
|
|
||||||
override fun getDefaultProfileJson(): JSONObject? = getDefaultProfileName()?.let { getSpecificProfileJson(it) }
|
|
||||||
|
|
||||||
override fun getDefaultProfileName(): String? {
|
|
||||||
val defaultProfileName = data.optString("defaultProfile")
|
|
||||||
return if (defaultProfileName.isNotEmpty()) getStore()?.has(defaultProfileName)?.let { defaultProfileName } else null
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getProfileList(): ArrayList<CharSequence> {
|
|
||||||
val ret = ArrayList<CharSequence>()
|
|
||||||
getStore()?.keys()?.let { keys ->
|
|
||||||
while (keys.hasNext()) {
|
|
||||||
val profileName = keys.next() as String
|
|
||||||
ret.add(profileName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
@Synchronized
|
|
||||||
override fun getSpecificProfile(profileName: String): PureProfile? {
|
|
||||||
var profile: PureProfile? = null
|
|
||||||
val units = JsonHelper.safeGetStringAllowNull(data, "units", storeUnits())
|
|
||||||
getStore()?.let { store ->
|
|
||||||
if (store.has(profileName)) {
|
|
||||||
profile = cachedObjects[profileName]
|
|
||||||
if (profile == null) {
|
|
||||||
JsonHelper.safeGetJSONObject(store, profileName, null)?.let { profileObject ->
|
|
||||||
profile = pureProfileFromJson(profileObject, dateUtil, units)
|
|
||||||
profile?.let { cachedObjects[profileName] = profile }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return profile
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getSpecificProfileJson(profileName: String): JSONObject? {
|
|
||||||
getStore()?.let { store ->
|
|
||||||
if (store.has(profileName))
|
|
||||||
return JsonHelper.safeGetJSONObject(store, profileName, null)
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
override val allProfilesValid: Boolean
|
|
||||||
get() = getProfileList()
|
|
||||||
.asSequence()
|
|
||||||
.map { profileName -> getSpecificProfile(profileName.toString()) }
|
|
||||||
.map { pureProfile -> pureProfile?.let { ProfileSealed.Pure(pureProfile).isValid("allProfilesValid", activePlugin.activePump, config, rh, rxBus, hardLimits, false) } }
|
|
||||||
.all { it?.isValid == true }
|
|
||||||
}
|
|
|
@ -1,182 +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.core.utils.fabric.FabricPrivacy
|
|
||||||
import info.nightscout.database.entities.EffectiveProfileSwitch
|
|
||||||
import info.nightscout.database.entities.embedments.InsulinConfiguration
|
|
||||||
import info.nightscout.interfaces.Config
|
|
||||||
import info.nightscout.interfaces.iob.IobCobCalculator
|
|
||||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
|
||||||
import info.nightscout.interfaces.profile.ProfileFunction
|
|
||||||
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 activePluginProvider: ActivePlugin
|
|
||||||
@Mock lateinit var rh: ResourceHelper
|
|
||||||
@Mock lateinit var iobCobCalculator: IobCobCalculator
|
|
||||||
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
|
||||||
@Mock lateinit var profileFunction: ProfileFunction
|
|
||||||
@Mock lateinit var config: Config
|
|
||||||
@Mock lateinit var context: Context
|
|
||||||
@Mock lateinit var sp: SP
|
|
||||||
|
|
||||||
lateinit var dateUtil: DateUtil
|
|
||||||
lateinit var hardLimits: HardLimits
|
|
||||||
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)
|
|
||||||
hardLimits = HardLimitsMock(sp, rh)
|
|
||||||
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.androidaps.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 val 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) {}
|
|
||||||
}
|
|
|
@ -1,13 +1,12 @@
|
||||||
package info.nightscout.core.extensions
|
package info.nightscout.core.extensions
|
||||||
|
|
||||||
import info.nightscout.androidaps.TestBaseWithProfile
|
|
||||||
import info.nightscout.database.entities.Bolus
|
import info.nightscout.database.entities.Bolus
|
||||||
import info.nightscout.insulin.InsulinLyumjevPlugin
|
import info.nightscout.insulin.InsulinLyumjevPlugin
|
||||||
import info.nightscout.interfaces.insulin.Insulin
|
import info.nightscout.interfaces.insulin.Insulin
|
||||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
|
||||||
import info.nightscout.interfaces.profile.ProfileFunction
|
import info.nightscout.interfaces.profile.ProfileFunction
|
||||||
import info.nightscout.interfaces.ui.UiInteraction
|
import info.nightscout.interfaces.ui.UiInteraction
|
||||||
import info.nightscout.shared.utils.T
|
import info.nightscout.shared.utils.T
|
||||||
|
import info.nightscout.sharedtests.TestBaseWithProfile
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
@ -16,13 +15,11 @@ import org.mockito.Mockito
|
||||||
|
|
||||||
class BolusExtensionKtTest : TestBaseWithProfile() {
|
class BolusExtensionKtTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
@Mock lateinit var activePlugin: ActivePlugin
|
|
||||||
@Mock lateinit var profileFunctions: ProfileFunction
|
@Mock lateinit var profileFunctions: ProfileFunction
|
||||||
@Mock lateinit var uiInteraction: UiInteraction
|
@Mock lateinit var uiInteraction: UiInteraction
|
||||||
|
|
||||||
private lateinit var insulin: Insulin
|
private lateinit var insulin: Insulin
|
||||||
|
|
||||||
private val now = 1000000L
|
|
||||||
private val dia = 7.0
|
private val dia = 7.0
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
package info.nightscout.core.extensions
|
package info.nightscout.core.extensions
|
||||||
|
|
||||||
import info.nightscout.androidaps.TestBaseWithProfile
|
|
||||||
import info.nightscout.database.entities.ExtendedBolus
|
import info.nightscout.database.entities.ExtendedBolus
|
||||||
import info.nightscout.database.entities.TemporaryBasal
|
import info.nightscout.database.entities.TemporaryBasal
|
||||||
import info.nightscout.insulin.InsulinLyumjevPlugin
|
import info.nightscout.insulin.InsulinLyumjevPlugin
|
||||||
import info.nightscout.interfaces.aps.AutosensResult
|
import info.nightscout.interfaces.aps.AutosensResult
|
||||||
import info.nightscout.interfaces.aps.SMBDefaults
|
import info.nightscout.interfaces.aps.SMBDefaults
|
||||||
import info.nightscout.interfaces.insulin.Insulin
|
import info.nightscout.interfaces.insulin.Insulin
|
||||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
|
||||||
import info.nightscout.interfaces.profile.ProfileFunction
|
import info.nightscout.interfaces.profile.ProfileFunction
|
||||||
import info.nightscout.interfaces.ui.UiInteraction
|
import info.nightscout.interfaces.ui.UiInteraction
|
||||||
import info.nightscout.shared.utils.T
|
import info.nightscout.shared.utils.T
|
||||||
|
import info.nightscout.sharedtests.TestBaseWithProfile
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
@ -19,13 +18,11 @@ import org.mockito.Mockito
|
||||||
|
|
||||||
class ExtendedBolusExtensionKtTest : TestBaseWithProfile() {
|
class ExtendedBolusExtensionKtTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
@Mock lateinit var activePlugin: ActivePlugin
|
|
||||||
@Mock lateinit var profileFunctions: ProfileFunction
|
@Mock lateinit var profileFunctions: ProfileFunction
|
||||||
@Mock lateinit var uiInteraction: UiInteraction
|
@Mock lateinit var uiInteraction: UiInteraction
|
||||||
|
|
||||||
private lateinit var insulin: Insulin
|
private lateinit var insulin: Insulin
|
||||||
|
|
||||||
private val now = 1000000L
|
|
||||||
private val dia = 7.0
|
private val dia = 7.0
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package info.nightscout.core.extensions
|
package info.nightscout.core.extensions
|
||||||
|
|
||||||
import info.nightscout.androidaps.TestBaseWithProfile
|
|
||||||
import info.nightscout.core.main.R
|
import info.nightscout.core.main.R
|
||||||
import info.nightscout.database.entities.GlucoseValue
|
import info.nightscout.database.entities.GlucoseValue
|
||||||
import info.nightscout.interfaces.GlucoseUnit
|
import info.nightscout.interfaces.GlucoseUnit
|
||||||
import info.nightscout.interfaces.iob.InMemoryGlucoseValue
|
import info.nightscout.interfaces.iob.InMemoryGlucoseValue
|
||||||
|
import info.nightscout.sharedtests.TestBaseWithProfile
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
package info.nightscout.core.extensions
|
package info.nightscout.core.extensions
|
||||||
|
|
||||||
import info.nightscout.androidaps.TestBaseWithProfile
|
|
||||||
import info.nightscout.database.entities.TemporaryBasal
|
import info.nightscout.database.entities.TemporaryBasal
|
||||||
import info.nightscout.insulin.InsulinLyumjevPlugin
|
import info.nightscout.insulin.InsulinLyumjevPlugin
|
||||||
import info.nightscout.interfaces.aps.AutosensResult
|
import info.nightscout.interfaces.aps.AutosensResult
|
||||||
import info.nightscout.interfaces.aps.SMBDefaults
|
import info.nightscout.interfaces.aps.SMBDefaults
|
||||||
import info.nightscout.interfaces.insulin.Insulin
|
import info.nightscout.interfaces.insulin.Insulin
|
||||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
|
||||||
import info.nightscout.interfaces.profile.ProfileFunction
|
import info.nightscout.interfaces.profile.ProfileFunction
|
||||||
import info.nightscout.interfaces.ui.UiInteraction
|
import info.nightscout.interfaces.ui.UiInteraction
|
||||||
import info.nightscout.shared.utils.T
|
import info.nightscout.shared.utils.T
|
||||||
|
import info.nightscout.sharedtests.TestBaseWithProfile
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
@ -18,13 +17,11 @@ import org.mockito.Mockito
|
||||||
|
|
||||||
class TemporaryBasalExtensionKtTest : TestBaseWithProfile() {
|
class TemporaryBasalExtensionKtTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
@Mock lateinit var activePlugin: ActivePlugin
|
|
||||||
@Mock lateinit var profileFunctions: ProfileFunction
|
@Mock lateinit var profileFunctions: ProfileFunction
|
||||||
@Mock lateinit var uiInteraction: UiInteraction
|
@Mock lateinit var uiInteraction: UiInteraction
|
||||||
|
|
||||||
private lateinit var insulin: Insulin
|
private lateinit var insulin: Insulin
|
||||||
|
|
||||||
private val now = 1000000L
|
|
||||||
private val dia = 7.0
|
private val dia = 7.0
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package info.nightscout.core.extensions
|
package info.nightscout.core.extensions
|
||||||
|
|
||||||
import info.nightscout.androidaps.TestBaseWithProfile
|
|
||||||
import info.nightscout.database.entities.TemporaryTarget
|
import info.nightscout.database.entities.TemporaryTarget
|
||||||
import info.nightscout.interfaces.GlucoseUnit
|
import info.nightscout.interfaces.GlucoseUnit
|
||||||
|
import info.nightscout.sharedtests.TestBaseWithProfile
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
package info.nightscout.core.extensions
|
package info.nightscout.core.extensions
|
||||||
|
|
||||||
import info.nightscout.androidaps.TestBaseWithProfile
|
|
||||||
import info.nightscout.database.entities.TherapyEvent
|
import info.nightscout.database.entities.TherapyEvent
|
||||||
import info.nightscout.database.entities.embedments.InterfaceIDs
|
import info.nightscout.database.entities.embedments.InterfaceIDs
|
||||||
import info.nightscout.shared.utils.T
|
import info.nightscout.shared.utils.T
|
||||||
|
import info.nightscout.sharedtests.TestBaseWithProfile
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.mockito.Mockito
|
import org.mockito.Mockito
|
||||||
|
|
||||||
class TherapyEventExtensionKtTest : TestBaseWithProfile() {
|
class TherapyEventExtensionKtTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
private val now = 1000000L
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun isOlderThan() {
|
fun isOlderThan() {
|
||||||
val therapyEvent = TherapyEvent(
|
val therapyEvent = TherapyEvent(
|
||||||
|
|
|
@ -2,7 +2,6 @@ package info.nightscout.plugins.general.smsCommunicator
|
||||||
|
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.TestBase
|
|
||||||
import info.nightscout.interfaces.Constants
|
import info.nightscout.interfaces.Constants
|
||||||
import info.nightscout.interfaces.smsCommunicator.Sms
|
import info.nightscout.interfaces.smsCommunicator.Sms
|
||||||
import info.nightscout.interfaces.smsCommunicator.SmsCommunicator
|
import info.nightscout.interfaces.smsCommunicator.SmsCommunicator
|
||||||
|
@ -12,7 +11,8 @@ import info.nightscout.plugins.general.smsCommunicator.otp.OneTimePasswordValida
|
||||||
import info.nightscout.shared.interfaces.ResourceHelper
|
import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
import info.nightscout.shared.utils.T
|
import info.nightscout.shared.utils.T
|
||||||
import org.junit.Assert
|
import info.nightscout.sharedtests.TestBase
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
|
@ -61,26 +61,26 @@ class AuthRequestTest : TestBase() {
|
||||||
|
|
||||||
// Check if SMS requesting code is sent
|
// Check if SMS requesting code is sent
|
||||||
var authRequest = AuthRequest(injector, requester, "Request text", "ABC", action)
|
var authRequest = AuthRequest(injector, requester, "Request text", "ABC", action)
|
||||||
Assert.assertEquals(sentSms!!.phoneNumber, "aNumber")
|
Assertions.assertEquals(sentSms!!.phoneNumber, "aNumber")
|
||||||
Assert.assertEquals(sentSms!!.text, "Request text")
|
Assertions.assertEquals(sentSms!!.text, "Request text")
|
||||||
|
|
||||||
// wrong reply
|
// wrong reply
|
||||||
actionCalled = false
|
actionCalled = false
|
||||||
authRequest.action("EFG")
|
authRequest.action("EFG")
|
||||||
Assert.assertEquals(sentSms!!.phoneNumber, "aNumber")
|
Assertions.assertEquals(sentSms!!.phoneNumber, "aNumber")
|
||||||
Assert.assertEquals(sentSms!!.text, "Wrong code. Command cancelled.")
|
Assertions.assertEquals(sentSms!!.text, "Wrong code. Command cancelled.")
|
||||||
Assert.assertFalse(actionCalled)
|
Assertions.assertFalse(actionCalled)
|
||||||
|
|
||||||
// correct reply
|
// correct reply
|
||||||
authRequest = AuthRequest(injector, requester, "Request text", "ABC", action)
|
authRequest = AuthRequest(injector, requester, "Request text", "ABC", action)
|
||||||
actionCalled = false
|
actionCalled = false
|
||||||
`when`(otp.checkOTP(anyObject())).thenReturn(OneTimePasswordValidationResult.OK)
|
`when`(otp.checkOTP(anyObject())).thenReturn(OneTimePasswordValidationResult.OK)
|
||||||
authRequest.action("ABC")
|
authRequest.action("ABC")
|
||||||
Assert.assertTrue(actionCalled)
|
Assertions.assertTrue(actionCalled)
|
||||||
// second time action should not be called
|
// second time action should not be called
|
||||||
actionCalled = false
|
actionCalled = false
|
||||||
authRequest.action("ABC")
|
authRequest.action("ABC")
|
||||||
Assert.assertFalse(actionCalled)
|
Assertions.assertFalse(actionCalled)
|
||||||
|
|
||||||
// test timed out message
|
// test timed out message
|
||||||
val now: Long = 10000
|
val now: Long = 10000
|
||||||
|
@ -89,6 +89,6 @@ class AuthRequestTest : TestBase() {
|
||||||
actionCalled = false
|
actionCalled = false
|
||||||
`when`(dateUtil.now()).thenReturn(now + T.mins(Constants.SMS_CONFIRM_TIMEOUT).msecs() + 1)
|
`when`(dateUtil.now()).thenReturn(now + T.mins(Constants.SMS_CONFIRM_TIMEOUT).msecs() + 1)
|
||||||
authRequest.action("ABC")
|
authRequest.action("ABC")
|
||||||
Assert.assertFalse(actionCalled)
|
Assertions.assertFalse(actionCalled)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
package info.nightscout.plugins.general.smsCommunicator
|
package info.nightscout.plugins.general.smsCommunicator
|
||||||
|
|
||||||
import org.junit.Assert
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
class SmsActionTest {
|
class SmsActionTest {
|
||||||
|
@ -13,49 +13,49 @@ class SmsActionTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
smsAction.run()
|
smsAction.run()
|
||||||
Assert.assertEquals(result, "A")
|
Assertions.assertEquals(result, "A")
|
||||||
smsAction = object : SmsAction(false, 1.0) {
|
smsAction = object : SmsAction(false, 1.0) {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
result = "B"
|
result = "B"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
smsAction.run()
|
smsAction.run()
|
||||||
Assert.assertEquals(result, "B")
|
Assertions.assertEquals(result, "B")
|
||||||
Assert.assertEquals(smsAction.aDouble(), 1.0, 0.000001)
|
Assertions.assertEquals(smsAction.aDouble(), 1.0, 0.000001)
|
||||||
smsAction = object : SmsAction(false, 1.0, 2) {
|
smsAction = object : SmsAction(false, 1.0, 2) {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
result = "C"
|
result = "C"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
smsAction.run()
|
smsAction.run()
|
||||||
Assert.assertEquals(result, "C")
|
Assertions.assertEquals(result, "C")
|
||||||
Assert.assertEquals(smsAction.aDouble(), 1.0, 0.000001)
|
Assertions.assertEquals(smsAction.aDouble(), 1.0, 0.000001)
|
||||||
Assert.assertEquals(smsAction.secondInteger().toLong(), 2)
|
Assertions.assertEquals(smsAction.secondInteger().toLong(), 2)
|
||||||
smsAction = object : SmsAction(false, "aString", 3) {
|
smsAction = object : SmsAction(false, "aString", 3) {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
result = "D"
|
result = "D"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
smsAction.run()
|
smsAction.run()
|
||||||
Assert.assertEquals(result, "D")
|
Assertions.assertEquals(result, "D")
|
||||||
Assert.assertEquals(smsAction.aString(), "aString")
|
Assertions.assertEquals(smsAction.aString(), "aString")
|
||||||
Assert.assertEquals(smsAction.secondInteger().toLong(), 3)
|
Assertions.assertEquals(smsAction.secondInteger().toLong(), 3)
|
||||||
smsAction = object : SmsAction(false, 4) {
|
smsAction = object : SmsAction(false, 4) {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
result = "E"
|
result = "E"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
smsAction.run()
|
smsAction.run()
|
||||||
Assert.assertEquals(result, "E")
|
Assertions.assertEquals(result, "E")
|
||||||
Assert.assertEquals(smsAction.anInteger().toLong(), 4)
|
Assertions.assertEquals(smsAction.anInteger().toLong(), 4)
|
||||||
smsAction = object : SmsAction(false, 5, 6) {
|
smsAction = object : SmsAction(false, 5, 6) {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
result = "F"
|
result = "F"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
smsAction.run()
|
smsAction.run()
|
||||||
Assert.assertEquals(result, "F")
|
Assertions.assertEquals(result, "F")
|
||||||
Assert.assertEquals(smsAction.anInteger().toLong(), 5)
|
Assertions.assertEquals(smsAction.anInteger().toLong(), 5)
|
||||||
Assert.assertEquals(smsAction.secondInteger().toLong(), 6)
|
Assertions.assertEquals(smsAction.secondInteger().toLong(), 6)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,8 +3,6 @@ package info.nightscout.plugins.general.smsCommunicator
|
||||||
import android.telephony.SmsManager
|
import android.telephony.SmsManager
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.TestBaseWithProfile
|
|
||||||
import info.nightscout.androidaps.TestPumpPlugin
|
|
||||||
import info.nightscout.database.entities.GlucoseValue
|
import info.nightscout.database.entities.GlucoseValue
|
||||||
import info.nightscout.database.impl.AppRepository
|
import info.nightscout.database.impl.AppRepository
|
||||||
import info.nightscout.database.impl.transactions.CancelCurrentOfflineEventIfAnyTransaction
|
import info.nightscout.database.impl.transactions.CancelCurrentOfflineEventIfAnyTransaction
|
||||||
|
@ -24,12 +22,9 @@ import info.nightscout.interfaces.iob.CobInfo
|
||||||
import info.nightscout.interfaces.iob.InMemoryGlucoseValue
|
import info.nightscout.interfaces.iob.InMemoryGlucoseValue
|
||||||
import info.nightscout.interfaces.iob.IobTotal
|
import info.nightscout.interfaces.iob.IobTotal
|
||||||
import info.nightscout.interfaces.logging.UserEntryLogger
|
import info.nightscout.interfaces.logging.UserEntryLogger
|
||||||
import info.nightscout.interfaces.plugin.ActivePlugin
|
|
||||||
import info.nightscout.interfaces.plugin.PluginType
|
import info.nightscout.interfaces.plugin.PluginType
|
||||||
import info.nightscout.interfaces.profile.ProfileSource
|
import info.nightscout.interfaces.profile.ProfileSource
|
||||||
import info.nightscout.interfaces.pump.PumpEnactResult
|
import info.nightscout.interfaces.pump.PumpEnactResult
|
||||||
import info.nightscout.interfaces.pump.defs.PumpDescription
|
|
||||||
import info.nightscout.interfaces.pump.defs.PumpType
|
|
||||||
import info.nightscout.interfaces.queue.Callback
|
import info.nightscout.interfaces.queue.Callback
|
||||||
import info.nightscout.interfaces.queue.CommandQueue
|
import info.nightscout.interfaces.queue.CommandQueue
|
||||||
import info.nightscout.interfaces.smsCommunicator.Sms
|
import info.nightscout.interfaces.smsCommunicator.Sms
|
||||||
|
@ -38,6 +33,7 @@ import info.nightscout.plugins.general.smsCommunicator.otp.OneTimePassword
|
||||||
import info.nightscout.plugins.general.smsCommunicator.otp.OneTimePasswordValidationResult
|
import info.nightscout.plugins.general.smsCommunicator.otp.OneTimePasswordValidationResult
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
import info.nightscout.shared.utils.T
|
import info.nightscout.shared.utils.T
|
||||||
|
import info.nightscout.sharedtests.TestBaseWithProfile
|
||||||
import io.reactivex.rxjava3.core.Single
|
import io.reactivex.rxjava3.core.Single
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
|
@ -54,10 +50,8 @@ import org.mockito.invocation.InvocationOnMock
|
||||||
class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
@Mock lateinit var constraintChecker: Constraints
|
@Mock lateinit var constraintChecker: Constraints
|
||||||
@Mock lateinit var activePlugin: ActivePlugin
|
|
||||||
@Mock lateinit var commandQueue: CommandQueue
|
@Mock lateinit var commandQueue: CommandQueue
|
||||||
@Mock lateinit var loop: Loop
|
@Mock lateinit var loop: Loop
|
||||||
@Mock lateinit var testPumpPlugin: TestPumpPlugin
|
|
||||||
@Mock lateinit var profileSource: ProfileSource
|
@Mock lateinit var profileSource: ProfileSource
|
||||||
@Mock lateinit var otp: OneTimePassword
|
@Mock lateinit var otp: OneTimePassword
|
||||||
@Mock lateinit var xDripBroadcast: XDripBroadcast
|
@Mock lateinit var xDripBroadcast: XDripBroadcast
|
||||||
|
@ -159,13 +153,6 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
null
|
null
|
||||||
}.`when`(commandQueue).extendedBolus(ArgumentMatchers.anyDouble(), ArgumentMatchers.anyInt(), ArgumentMatchers.any(Callback::class.java))
|
}.`when`(commandQueue).extendedBolus(ArgumentMatchers.anyDouble(), ArgumentMatchers.anyInt(), ArgumentMatchers.any(Callback::class.java))
|
||||||
|
|
||||||
`when`(activePlugin.activePump).thenReturn(testPumpPlugin)
|
|
||||||
|
|
||||||
`when`(testPumpPlugin.shortStatus(ArgumentMatchers.anyBoolean())).thenReturn("Virtual Pump")
|
|
||||||
`when`(testPumpPlugin.isSuspended()).thenReturn(false)
|
|
||||||
`when`(testPumpPlugin.pumpDescription).thenReturn(PumpDescription())
|
|
||||||
`when`(testPumpPlugin.model()).thenReturn(PumpType.GENERIC_AAPS)
|
|
||||||
|
|
||||||
`when`(iobCobCalculator.calculateIobFromBolus()).thenReturn(IobTotal(0))
|
`when`(iobCobCalculator.calculateIobFromBolus()).thenReturn(IobTotal(0))
|
||||||
`when`(iobCobCalculator.calculateIobFromTempBasalsIncludingConvertedExtended()).thenReturn(IobTotal(0))
|
`when`(iobCobCalculator.calculateIobFromTempBasalsIncludingConvertedExtended()).thenReturn(IobTotal(0))
|
||||||
|
|
||||||
|
@ -1011,13 +998,13 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
//BOLUS 1 (Suspended pump)
|
//BOLUS 1 (Suspended pump)
|
||||||
smsCommunicatorPlugin.lastRemoteBolusTime = 0
|
smsCommunicatorPlugin.lastRemoteBolusTime = 0
|
||||||
`when`(testPumpPlugin.isSuspended()).thenReturn(true)
|
testPumpPlugin.pumpSuspended = true
|
||||||
smsCommunicatorPlugin.messages = ArrayList()
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
sms = Sms("1234", "BOLUS 1")
|
sms = Sms("1234", "BOLUS 1")
|
||||||
smsCommunicatorPlugin.processSms(sms)
|
smsCommunicatorPlugin.processSms(sms)
|
||||||
Assertions.assertEquals("BOLUS 1", smsCommunicatorPlugin.messages[0].text)
|
Assertions.assertEquals("BOLUS 1", smsCommunicatorPlugin.messages[0].text)
|
||||||
Assertions.assertEquals("Pump suspended", smsCommunicatorPlugin.messages[1].text)
|
Assertions.assertEquals("Pump suspended", smsCommunicatorPlugin.messages[1].text)
|
||||||
`when`(testPumpPlugin.isSuspended()).thenReturn(false)
|
testPumpPlugin.pumpSuspended = false
|
||||||
|
|
||||||
//BOLUS 1 a
|
//BOLUS 1 a
|
||||||
smsCommunicatorPlugin.messages = ArrayList()
|
smsCommunicatorPlugin.messages = ArrayList()
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package info.nightscout.plugins.general.smsCommunicator
|
package info.nightscout.plugins.general.smsCommunicator
|
||||||
|
|
||||||
import android.telephony.SmsMessage
|
import android.telephony.SmsMessage
|
||||||
import info.nightscout.androidaps.TestBase
|
|
||||||
import info.nightscout.interfaces.smsCommunicator.Sms
|
import info.nightscout.interfaces.smsCommunicator.Sms
|
||||||
import org.junit.Assert
|
import info.nightscout.sharedtests.TestBase
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.mockito.Mockito
|
import org.mockito.Mockito
|
||||||
import org.mockito.Mockito.`when`
|
import org.mockito.Mockito.`when`
|
||||||
|
@ -15,32 +15,32 @@ class SmsTest : TestBase() {
|
||||||
`when`(smsMessage.originatingAddress).thenReturn("aNumber")
|
`when`(smsMessage.originatingAddress).thenReturn("aNumber")
|
||||||
`when`(smsMessage.messageBody).thenReturn("aBody")
|
`when`(smsMessage.messageBody).thenReturn("aBody")
|
||||||
var sms = Sms(smsMessage)
|
var sms = Sms(smsMessage)
|
||||||
Assert.assertEquals(sms.phoneNumber, "aNumber")
|
Assertions.assertEquals(sms.phoneNumber, "aNumber")
|
||||||
Assert.assertEquals(sms.text, "aBody")
|
Assertions.assertEquals(sms.text, "aBody")
|
||||||
Assert.assertTrue(sms.received)
|
Assertions.assertTrue(sms.received)
|
||||||
sms = Sms("aNumber", "aBody")
|
sms = Sms("aNumber", "aBody")
|
||||||
Assert.assertEquals(sms.phoneNumber, "aNumber")
|
Assertions.assertEquals(sms.phoneNumber, "aNumber")
|
||||||
Assert.assertEquals(sms.text, "aBody")
|
Assertions.assertEquals(sms.text, "aBody")
|
||||||
Assert.assertTrue(sms.sent)
|
Assertions.assertTrue(sms.sent)
|
||||||
sms = Sms("aNumber", "U")
|
sms = Sms("aNumber", "U")
|
||||||
Assert.assertEquals(sms.phoneNumber, "aNumber")
|
Assertions.assertEquals(sms.phoneNumber, "aNumber")
|
||||||
Assert.assertEquals(sms.text, "U")
|
Assertions.assertEquals(sms.text, "U")
|
||||||
Assert.assertTrue(sms.sent)
|
Assertions.assertTrue(sms.sent)
|
||||||
Assert.assertEquals(sms.toString(), "SMS from aNumber: U")
|
Assertions.assertEquals(sms.toString(), "SMS from aNumber: U")
|
||||||
|
|
||||||
// copy constructor #1
|
// copy constructor #1
|
||||||
val sms2 = Sms(sms)
|
val sms2 = Sms(sms)
|
||||||
Assert.assertEquals(sms2.phoneNumber, "aNumber")
|
Assertions.assertEquals(sms2.phoneNumber, "aNumber")
|
||||||
Assert.assertEquals(sms2.text, "U")
|
Assertions.assertEquals(sms2.text, "U")
|
||||||
Assert.assertTrue(sms2.sent)
|
Assertions.assertTrue(sms2.sent)
|
||||||
Assert.assertEquals(sms2.toString(), "SMS from aNumber: U")
|
Assertions.assertEquals(sms2.toString(), "SMS from aNumber: U")
|
||||||
|
|
||||||
// copy constructor #2
|
// copy constructor #2
|
||||||
val sms3 = Sms(sms, "different")
|
val sms3 = Sms(sms, "different")
|
||||||
Assert.assertEquals(sms3.phoneNumber, "different")
|
Assertions.assertEquals(sms3.phoneNumber, "different")
|
||||||
Assert.assertEquals(sms3.text, "U")
|
Assertions.assertEquals(sms3.text, "U")
|
||||||
Assert.assertTrue(sms3.sent)
|
Assertions.assertTrue(sms3.sent)
|
||||||
Assert.assertEquals(sms3.toString(), "SMS from different: U")
|
Assertions.assertEquals(sms3.toString(), "SMS from different: U")
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,7 +4,6 @@ import android.content.Context
|
||||||
import androidx.collection.LongSparseArray
|
import androidx.collection.LongSparseArray
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.androidaps.TestBase
|
|
||||||
import info.nightscout.database.entities.GlucoseValue
|
import info.nightscout.database.entities.GlucoseValue
|
||||||
import info.nightscout.interfaces.aps.AutosensData
|
import info.nightscout.interfaces.aps.AutosensData
|
||||||
import info.nightscout.interfaces.profile.ProfileFunction
|
import info.nightscout.interfaces.profile.ProfileFunction
|
||||||
|
@ -14,6 +13,7 @@ import info.nightscout.shared.interfaces.ResourceHelper
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
import info.nightscout.shared.sharedPreferences.SP
|
||||||
import info.nightscout.shared.utils.DateUtil
|
import info.nightscout.shared.utils.DateUtil
|
||||||
import info.nightscout.shared.utils.T
|
import info.nightscout.shared.utils.T
|
||||||
|
import info.nightscout.sharedtests.TestBase
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
|
@ -2,6 +2,7 @@ include ':app'
|
||||||
include ':wear'
|
include ':wear'
|
||||||
include ':app-wear-shared:shared'
|
include ':app-wear-shared:shared'
|
||||||
include ':app-wear-shared:shared-impl'
|
include ':app-wear-shared:shared-impl'
|
||||||
|
include ':app-wear-shared:shared-tests'
|
||||||
include ':core:main'
|
include ':core:main'
|
||||||
include ':core:graphview'
|
include ':core:graphview'
|
||||||
include ':core:graph'
|
include ':core:graph'
|
||||||
|
|
Loading…
Reference in a new issue