shared-tests #1

This commit is contained in:
Milos Kozak 2023-09-03 15:00:24 +02:00
parent 954f6eedab
commit 00a22b8b77
39 changed files with 332 additions and 679 deletions

View file

@ -0,0 +1 @@
/build

View 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"
}

View 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

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest>
</manifest>

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps
package info.nightscout.sharedtests
import info.nightscout.interfaces.utils.HardLimits
import info.nightscout.shared.interfaces.ResourceHelper
@ -7,7 +7,7 @@ import javax.inject.Inject
import kotlin.math.max
import kotlin.math.min
class HardLimitsMock @Inject constructor(
@Suppress("unused") class HardLimitsMock @Inject constructor(
private val sp: SP,
private val rh: ResourceHelper
) : HardLimits {

View file

@ -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.TestAapsSchedulers
import info.nightscout.rx.logging.AAPSLoggerTest
@ -11,6 +12,7 @@ import org.mockito.junit.jupiter.MockitoSettings
import org.mockito.quality.Strictness
import java.util.Locale
@Suppress("SpellCheckingInspection")
@ExtendWith(MockitoExtension::class)
@MockitoSettings(strictness = Strictness.LENIENT)
open class TestBase {
@ -27,11 +29,12 @@ open class TestBase {
// 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
@SuppressLint("CheckResult")
fun <T> anyObject(): T {
Mockito.any<T>()
return uninitialized()
}
@Suppress("Unchecked_Cast")
fun <T> uninitialized(): T = null as T
private fun <T> uninitialized(): T = null as T
}

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps
package info.nightscout.sharedtests
import android.content.Context
import dagger.android.AndroidInjector
@ -26,13 +26,12 @@ 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 activePlugin: ActivePlugin
@Mock lateinit var rh: ResourceHelper
@Mock lateinit var iobCobCalculator: IobCobCalculator
@Mock lateinit var fabricPrivacy: FabricPrivacy
@ -41,15 +40,15 @@ open class TestBaseWithProfile : TestBase() {
@Mock lateinit var context: Context
@Mock lateinit var sp: SP
private lateinit var hardLimits: HardLimits
lateinit var dateUtil: DateUtil
lateinit var hardLimits: HardLimits
val rxBus = RxBus(aapsSchedulers, aapsLogger)
val profileInjector = HasAndroidInjector {
AndroidInjector {
if (it is ProfileStoreObject) {
it.aapsLogger = aapsLogger
it.activePlugin = activePluginProvider
it.activePlugin = activePlugin
it.config = config
it.rh = rh
it.rxBus = rxBus
@ -64,20 +63,22 @@ open class TestBaseWithProfile : TestBase() {
lateinit var effectiveProfileSwitch: EffectiveProfileSwitch
lateinit var testPumpPlugin: TestPumpPlugin
val now = 1656358822000L
@Suppress("PropertyName") val TESTPROFILENAME = "someProfile"
@BeforeEach
fun prepareMock() {
invalidProfileJSON = "{\"dia\":\"1\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," +
"{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," +
"\"target_high\":[{\"time\":\"00:00\",\"value\":\"7\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
validProfileJSON = "{\"dia\":\"5\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," +
"{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," +
"\"target_high\":[{\"time\":\"00:00\",\"value\":\"7\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
testPumpPlugin = TestPumpPlugin(profileInjector)
`when`(activePluginProvider.activePump).thenReturn(testPumpPlugin)
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\"}"
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)
validProfile = ProfileSealed.Pure(pureProfileFromJson(JSONObject(validProfileJSON), dateUtil)!!)
effectiveProfileSwitch = EffectiveProfileSwitch(

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps
package info.nightscout.sharedtests
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.annotations.OpenForTesting
@ -19,6 +19,7 @@ class TestPumpPlugin(val injector: HasAndroidInjector) : Pump {
var connected = false
var isProfileSet = true
var pumpSuspended = false
override fun isConnected() = connected
override fun isConnecting() = false
@ -29,7 +30,7 @@ class TestPumpPlugin(val injector: HasAndroidInjector) : Pump {
override var pumpDescription = PumpDescription()
override fun isInitialized(): Boolean = true
override fun isSuspended(): Boolean = false
override fun isSuspended(): Boolean = pumpSuspended
override fun isBusy(): Boolean = false
override fun connect(reason: String) {
connected = true
@ -44,15 +45,19 @@ class TestPumpPlugin(val injector: HasAndroidInjector) : Pump {
}
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 isThisProfileSet(profile: Profile): Boolean = isProfileSet
override fun lastDataTime(): Long = lastData
override val baseBasalRate: Double = baseBasal
override val baseBasalRate: Double get() = 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 stopBolusDelivering() { /* not needed */
}
override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult =
PumpEnactResult(injector).success(true)
@ -66,9 +71,10 @@ class TestPumpPlugin(val injector: HasAndroidInjector) : Pump {
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 fun shortStatus(veryShort: Boolean): String = "Virtual Pump"
override val isFakingTempsByExtendedBoluses: Boolean = false
override fun loadTDDs(): PumpEnactResult = PumpEnactResult(injector).success(true)
override fun canHandleDST(): Boolean = true
override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) {}
override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) { /* not needed */
}
}

View file

@ -24,7 +24,6 @@ dependencies {
api "androidx.preference:preference-ktx:$preferencektx_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-android:$dagger_version"
api "com.google.dagger:dagger-android-support:$dagger_version"

View file

@ -5,7 +5,6 @@ dependencies {
testImplementation "org.json:json:$json_version"
testImplementation "org.mockito:mockito-junit-jupiter:$mockito_version"
testImplementation "org.mockito.kotlin:mockito-kotlin:4.1.0"
//testImplementation "org.mockito:mockito-inline:$mockito_version"
testImplementation "joda-time:joda-time:$jodatime_version"
testImplementation 'com.google.truth:truth:1.1.5'
testImplementation "org.skyscreamer:jsonassert:1.5.0"

View file

@ -25,6 +25,8 @@ dependencies {
implementation project(':core:ui')
implementation project(':core:utils')
testImplementation project(':app-wear-shared:shared-tests')
// Protection
api 'androidx.biometric:biometric:1.1.0'
}

View file

@ -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
}

View file

@ -1,6 +1,5 @@
package info.nightscout.implementation.iob
import info.nightscout.androidaps.TestBase
import info.nightscout.core.iob.asRounded
import info.nightscout.core.iob.log
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.shared.utils.DateUtil
import info.nightscout.shared.utils.T
import info.nightscout.sharedtests.TestBase
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

View file

@ -1,6 +1,5 @@
package info.nightscout.implementation.overview
import info.nightscout.androidaps.TestBase
import info.nightscout.database.ValueWrapper
import info.nightscout.database.entities.GlucoseValue
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.utils.DateUtil
import info.nightscout.shared.utils.T
import info.nightscout.sharedtests.TestBase
import io.reactivex.rxjava3.core.Single
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach

View file

@ -1,47 +1,47 @@
package info.nightscout.implementation.profile
import info.nightscout.androidaps.TestBaseWithProfile
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
internal class ProfileStoreTest : TestBaseWithProfile() {
@Test
fun getStartDateTest() {
Assert.assertEquals(0, getValidProfileStore().getStartDate())
Assertions.assertEquals(0, getValidProfileStore().getStartDate())
}
@Test
fun getDefaultProfileTest() {
Assert.assertTrue(getValidProfileStore().getDefaultProfile() is PureProfile)
Assertions.assertTrue(getValidProfileStore().getDefaultProfile() is PureProfile)
}
@Test
fun getDefaultProfileJsonTest() {
Assert.assertTrue(getValidProfileStore().getDefaultProfileJson()?.has("dia") ?: false)
Assert.assertEquals(null, getInvalidProfileStore2().getDefaultProfileJson())
Assertions.assertTrue(getValidProfileStore().getDefaultProfileJson()?.has("dia") ?: false)
Assertions.assertEquals(null, getInvalidProfileStore2().getDefaultProfileJson())
}
@Test
fun getDefaultProfileNameTest() {
Assert.assertEquals(TESTPROFILENAME, getValidProfileStore().getDefaultProfileName())
Assertions.assertEquals(TESTPROFILENAME, getValidProfileStore().getDefaultProfileName())
}
@Test
fun getProfileListTest() {
Assert.assertEquals(1, getValidProfileStore().getProfileList().size)
Assertions.assertEquals(1, getValidProfileStore().getProfileList().size)
}
@Test
fun getSpecificProfileTest() {
Assert.assertTrue(getValidProfileStore().getSpecificProfile(TESTPROFILENAME) is PureProfile)
Assertions.assertTrue(getValidProfileStore().getSpecificProfile(TESTPROFILENAME) is PureProfile)
}
@Test
fun allProfilesValidTest() {
Assert.assertTrue(getValidProfileStore().allProfilesValid)
Assert.assertFalse(getInvalidProfileStore1().allProfilesValid)
Assert.assertFalse(getInvalidProfileStore2().allProfilesValid)
Assertions.assertTrue(getValidProfileStore().allProfilesValid)
Assertions.assertFalse(getInvalidProfileStore1().allProfilesValid)
Assertions.assertFalse(getInvalidProfileStore2().allProfilesValid)
}
}

View file

@ -1,12 +1,11 @@
package info.nightscout.implementation.pump
import info.nightscout.androidaps.TestBase
import info.nightscout.implementation.R
import info.nightscout.interfaces.pump.DetailedBolusInfo
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import info.nightscout.sharedtests.TestBase
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mock
@ -16,7 +15,7 @@ class DetailedBolusInfoStorageTest : TestBase() {
@Mock lateinit var sp: SP
@Mock lateinit var rh: ResourceHelper
private val info1 = DetailedBolusInfo()
private val info2 = DetailedBolusInfo()
private val info3 = DetailedBolusInfo()
@ -48,9 +47,9 @@ class DetailedBolusInfoStorageTest : TestBase() {
@Test
fun add() {
detailedBolusInfoStorage.store.clear()
assertEquals(0, detailedBolusInfoStorage.store.size)
Assertions.assertEquals(0, detailedBolusInfoStorage.store.size)
detailedBolusInfoStorage.add(info1)
assertEquals(1, detailedBolusInfoStorage.store.size)
Assertions.assertEquals(1, detailedBolusInfoStorage.store.size)
}
@Test
@ -59,33 +58,33 @@ class DetailedBolusInfoStorageTest : TestBase() {
// Look for exact bolus
setUp()
var d: DetailedBolusInfo? = detailedBolusInfoStorage.findDetailedBolusInfo(1000000, 4.0)
assertEquals(4.0, d!!.insulin, 0.01)
assertEquals(2, detailedBolusInfoStorage.store.size)
Assertions.assertEquals(4.0, d!!.insulin, 0.01)
Assertions.assertEquals(2, detailedBolusInfoStorage.store.size)
// Look for exact bolus
setUp()
d = detailedBolusInfoStorage.findDetailedBolusInfo(1000000, 3.0)
assertEquals(3.0, d!!.insulin, 0.01)
assertEquals(2, detailedBolusInfoStorage.store.size)
Assertions.assertEquals(3.0, d!!.insulin, 0.01)
Assertions.assertEquals(2, detailedBolusInfoStorage.store.size)
// With less insulin (bolus not delivered completely). Should return first one matching date
setUp()
d = detailedBolusInfoStorage.findDetailedBolusInfo(1000500, 2.0)
assertEquals(3.0, d!!.insulin, 0.01)
assertEquals(2, detailedBolusInfoStorage.store.size)
Assertions.assertEquals(3.0, d!!.insulin, 0.01)
Assertions.assertEquals(2, detailedBolusInfoStorage.store.size)
// With less insulin (bolus not delivered completely). Should return first one matching date
setUp()
d = detailedBolusInfoStorage.findDetailedBolusInfo(1000500, 3.5)
assertEquals(4.0, d!!.insulin, 0.01)
assertEquals(2, detailedBolusInfoStorage.store.size)
Assertions.assertEquals(4.0, d!!.insulin, 0.01)
Assertions.assertEquals(2, detailedBolusInfoStorage.store.size)
// With more insulin should return null
setUp()
d = detailedBolusInfoStorage.findDetailedBolusInfo(1000500, 4.5)
assertNull(d)
assertEquals(3, detailedBolusInfoStorage.store.size)
Assertions.assertNull(d)
Assertions.assertEquals(3, detailedBolusInfoStorage.store.size)
// With more than one minute off should return null
setUp()
d = detailedBolusInfoStorage.findDetailedBolusInfo(1070000, 4.0)
assertNull(d)
assertEquals(3, detailedBolusInfoStorage.store.size)
Assertions.assertNull(d)
Assertions.assertEquals(3, detailedBolusInfoStorage.store.size)
// Use last, if bolus size is the same
// setUp()
// d = detailedBolusInfoStorage.findDetailedBolusInfo(1070000, 5.0)

View file

@ -1,9 +1,8 @@
package info.nightscout.implementation.pump
import info.nightscout.androidaps.TestBase
import info.nightscout.interfaces.pump.PumpSync
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import info.nightscout.sharedtests.TestBase
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
@ -30,9 +29,9 @@ class TemporaryBasalStorageTest : TestBase() {
@Test
fun add() {
temporaryBasalStorage.store.clear()
assertEquals(0, temporaryBasalStorage.store.size)
Assertions.assertEquals(0, temporaryBasalStorage.store.size)
temporaryBasalStorage.add(info1)
assertEquals(1, temporaryBasalStorage.store.size)
Assertions.assertEquals(1, temporaryBasalStorage.store.size)
}
@Test
@ -41,38 +40,38 @@ class TemporaryBasalStorageTest : TestBase() {
// Look for exact bolus
setUp()
var d = temporaryBasalStorage.findTemporaryBasal(1000000, 4.0)
assertEquals(4.0, d!!.rate, 0.01)
assertEquals(2, temporaryBasalStorage.store.size)
Assertions.assertEquals(4.0, d!!.rate, 0.01)
Assertions.assertEquals(2, temporaryBasalStorage.store.size)
// Look for exact bolus
setUp()
d = temporaryBasalStorage.findTemporaryBasal(1000000, 3.0)
assertEquals(3.0, d!!.rate, 0.01)
assertEquals(2, temporaryBasalStorage.store.size)
Assertions.assertEquals(3.0, d!!.rate, 0.01)
Assertions.assertEquals(2, temporaryBasalStorage.store.size)
// With less rate (bolus not delivered completely). Should return first one matching date
setUp()
d = temporaryBasalStorage.findTemporaryBasal(1000500, 2.0)
assertEquals(3.0, d!!.rate, 0.01)
assertEquals(2, temporaryBasalStorage.store.size)
Assertions.assertEquals(3.0, d!!.rate, 0.01)
Assertions.assertEquals(2, temporaryBasalStorage.store.size)
// With less rate (bolus not delivered completely). Should return first one matching date
setUp()
d = temporaryBasalStorage.findTemporaryBasal(1000500, 3.5)
assertEquals(4.0, d!!.rate, 0.01)
assertEquals(2, temporaryBasalStorage.store.size)
Assertions.assertEquals(4.0, d!!.rate, 0.01)
Assertions.assertEquals(2, temporaryBasalStorage.store.size)
// With more rate should return null
setUp()
d = temporaryBasalStorage.findTemporaryBasal(1000500, 4.5)
assertNull(d)
assertEquals(3, temporaryBasalStorage.store.size)
Assertions.assertNull(d)
Assertions.assertEquals(3, temporaryBasalStorage.store.size)
// With more than one minute off should return null
setUp()
d = temporaryBasalStorage.findTemporaryBasal(1070000, 4.0)
assertNull(d)
assertEquals(3, temporaryBasalStorage.store.size)
Assertions.assertNull(d)
Assertions.assertEquals(3, temporaryBasalStorage.store.size)
// Use last, if bolus size is the same
setUp()
d = temporaryBasalStorage.findTemporaryBasal(1070000, 5.0)
assertEquals(5.0, d!!.rate, 0.01)
assertEquals(2, temporaryBasalStorage.store.size)
Assertions.assertEquals(5.0, d!!.rate, 0.01)
Assertions.assertEquals(2, temporaryBasalStorage.store.size)
}
}

View file

@ -5,8 +5,6 @@ import android.os.Handler
import android.os.PowerManager
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.androidaps.TestPumpPlugin
import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.database.ValueWrapper
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.sharedPreferences.SP
import info.nightscout.shared.utils.DateUtil
import info.nightscout.sharedtests.TestBaseWithProfile
import info.nightscout.sharedtests.TestPumpPlugin
import io.reactivex.rxjava3.core.Single
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
@ -50,7 +50,6 @@ import java.util.Calendar
class CommandQueueImplementationTest : TestBaseWithProfile() {
@Mock lateinit var constraintChecker: Constraints
@Mock lateinit var activePlugin: ActivePlugin
@Mock lateinit var powerManager: PowerManager
@Mock lateinit var repository: AppRepository
@Mock lateinit var uiInteraction: UiInteraction
@ -81,7 +80,7 @@ class CommandQueueImplementationTest : TestBaseWithProfile() {
androidPermission, uiInteraction, persistenceLayer
) {
override fun notifyAboutNewCommand() : Boolean = true
override fun notifyAboutNewCommand(): Boolean = true
}
@ -250,7 +249,7 @@ class CommandQueueImplementationTest : TestBaseWithProfile() {
// add updateTime
commandQueue.updateTime(null)
Assertions.assertEquals(7, commandQueue.size())
commandQueue.clear()
commandQueue.tempBasalAbsolute(0.0, 30, true, validProfile, PumpSync.TemporaryBasalType.NORMAL, null)
commandQueue.pickup()

View file

@ -4,20 +4,19 @@ import android.content.Context
import android.os.PowerManager
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.androidaps.TestPumpPlugin
import info.nightscout.database.impl.AppRepository
import info.nightscout.implementation.queue.commands.CommandTempBasalAbsolute
import info.nightscout.interfaces.AndroidPermission
import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.interfaces.constraints.Constraints
import info.nightscout.interfaces.db.PersistenceLayer
import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.pump.PumpSync
import info.nightscout.interfaces.pump.defs.PumpDescription
import info.nightscout.interfaces.queue.Command
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.Test
import org.mockito.ArgumentMatchers
@ -27,14 +26,13 @@ import org.mockito.Mockito
class QueueThreadTest : TestBaseWithProfile() {
@Mock lateinit var constraintChecker: Constraints
@Mock lateinit var activePlugin: ActivePlugin
@Mock lateinit var powerManager: PowerManager
@Mock lateinit var repository: AppRepository
@Mock lateinit var androidPermission: AndroidPermission
@Mock lateinit var uiInteraction: UiInteraction
@Mock lateinit var persistenceLayer: PersistenceLayer
val injector = HasAndroidInjector {
private val injector = HasAndroidInjector {
AndroidInjector {
if (it is Command) {
it.aapsLogger = aapsLogger
@ -64,7 +62,6 @@ class QueueThreadTest : TestBaseWithProfile() {
pumpDescription.basalMinimumRate = 0.1
Mockito.`when`(context.getSystemService(Context.POWER_SERVICE)).thenReturn(powerManager)
Mockito.`when`(activePlugin.activePump).thenReturn(pumpPlugin)
Mockito.`when`(profileFunction.getProfile()).thenReturn(validProfile)
val bolusConstraint = Constraint(0.0)
@ -85,7 +82,8 @@ class QueueThreadTest : TestBaseWithProfile() {
@Test
fun commandIsPickedUp() {
commandQueue.tempBasalAbsolute(2.0, 60, true, validProfile, PumpSync.TemporaryBasalType.NORMAL, null)
@Suppress("CallToThreadRun")
sut.run()
Assert.assertEquals(0, commandQueue.size())
Assertions.assertEquals(0, commandQueue.size())
}
}

View file

@ -2,8 +2,6 @@ package info.nightscout.implementation.wizard
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.TestPumpPlugin
import info.nightscout.core.wizard.BolusWizard
import info.nightscout.implementation.iob.GlucoseStatusProviderImpl
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.constraints.Constraint
import info.nightscout.interfaces.constraints.Constraints
import info.nightscout.interfaces.iob.IobCobCalculator
import info.nightscout.interfaces.iob.IobTotal
import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.profile.Profile
import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.interfaces.pump.defs.PumpDescription
import info.nightscout.interfaces.queue.CommandQueue
import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil
import org.junit.Assert
import info.nightscout.sharedtests.TestBaseWithProfile
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.invocation.InvocationOnMock
class BolusWizardTest : TestBase() {
class BolusWizardTest : TestBaseWithProfile() {
private val pumpBolusStep = 0.1
@Mock lateinit var rh: ResourceHelper
@Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var constraintChecker: Constraints
@Mock lateinit var activePlugin: ActivePlugin
@Mock lateinit var commandQueue: CommandQueue
@Mock lateinit var loop: Loop
@Mock lateinit var iobCobCalculator: IobCobCalculator
@Mock lateinit var dateUtil: DateUtil
@Mock lateinit var autosensDataStore: AutosensDataStore
val injector = HasAndroidInjector {
private val injector = HasAndroidInjector {
AndroidInjector {
if (it is BolusWizard) {
it.aapsLogger = aapsLogger
@ -59,8 +48,6 @@ class BolusWizardTest : TestBase() {
}
}
val testPumpPlugin = TestPumpPlugin(injector)
@Suppress("SameParameterValue")
private fun setupProfile(targetLow: Double, targetHigh: Double, insulinSensitivityFactor: Double, insulinToCarbRatio: Double): Profile {
val profile = Mockito.mock(Profile::class.java)
@ -72,7 +59,6 @@ class BolusWizardTest : TestBase() {
Mockito.`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
Mockito.`when`(iobCobCalculator.calculateIobFromBolus()).thenReturn(IobTotal(System.currentTimeMillis()))
Mockito.`when`(iobCobCalculator.calculateIobFromTempBasalsIncludingConvertedExtended()).thenReturn(IobTotal(System.currentTimeMillis()))
Mockito.`when`(activePlugin.activePump).thenReturn(testPumpPlugin)
testPumpPlugin.pumpDescription = PumpDescription().also {
it.bolusStep = pumpBolusStep
}
@ -88,30 +74,138 @@ class BolusWizardTest : TestBase() {
/** Should calculate the same bolus when different blood glucose but both in target range */
fun shouldCalculateTheSameBolusWhenBGsInRange() {
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
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
Assert.assertEquals(bolusForBg42, bolusForBg54, 0.01)
Assertions.assertEquals(bolusForBg42, bolusForBg54, 0.01)
}
@Test
fun shouldCalculateHigherBolusWhenHighBG() {
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
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
Assert.assertTrue(bolusForHighBg > bolusForBgInRange)
Assertions.assertTrue(bolusForHighBg > bolusForBgInRange)
}
@Test
fun shouldCalculateLowerBolusWhenLowBG() {
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
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
Assert.assertTrue(bolusForLowBg < bolusForBgInRange)
Assertions.assertTrue(bolusForLowBg < bolusForBgInRange)
}
}

View file

@ -23,6 +23,7 @@ dependencies {
implementation project(':core:utils')
implementation project(':core:ui')
implementation project(':core:validators')
implementation project(':plugins:automation')
api "androidx.appcompat:appcompat:$appcompat_version"
api "androidx.swiperefreshlayout:swiperefreshlayout:$swipe_version"
@ -30,5 +31,4 @@ dependencies {
// APS
api 'org.mozilla:rhino:1.7.14'
implementation project(path: ':plugins:automation')
}

View file

@ -29,6 +29,7 @@ dependencies {
testImplementation project(':implementation')
testImplementation project(':plugins:insulin')
testImplementation project(':app-wear-shared:shared-tests')
api "androidx.appcompat:appcompat:$appcompat_version"
api "com.google.android.material:material:$material_version"

View file

@ -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
}
}

View file

@ -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 }
}

View file

@ -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)
}
}

View file

@ -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) {}
}

View file

@ -1,13 +1,12 @@
package info.nightscout.core.extensions
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.database.entities.Bolus
import info.nightscout.insulin.InsulinLyumjevPlugin
import info.nightscout.interfaces.insulin.Insulin
import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.interfaces.ui.UiInteraction
import info.nightscout.shared.utils.T
import info.nightscout.sharedtests.TestBaseWithProfile
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
@ -16,13 +15,11 @@ import org.mockito.Mockito
class BolusExtensionKtTest : TestBaseWithProfile() {
@Mock lateinit var activePlugin: ActivePlugin
@Mock lateinit var profileFunctions: ProfileFunction
@Mock lateinit var uiInteraction: UiInteraction
private lateinit var insulin: Insulin
private val now = 1000000L
private val dia = 7.0
@BeforeEach

View file

@ -1,16 +1,15 @@
package info.nightscout.core.extensions
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.database.entities.ExtendedBolus
import info.nightscout.database.entities.TemporaryBasal
import info.nightscout.insulin.InsulinLyumjevPlugin
import info.nightscout.interfaces.aps.AutosensResult
import info.nightscout.interfaces.aps.SMBDefaults
import info.nightscout.interfaces.insulin.Insulin
import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.interfaces.ui.UiInteraction
import info.nightscout.shared.utils.T
import info.nightscout.sharedtests.TestBaseWithProfile
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
@ -19,13 +18,11 @@ import org.mockito.Mockito
class ExtendedBolusExtensionKtTest : TestBaseWithProfile() {
@Mock lateinit var activePlugin: ActivePlugin
@Mock lateinit var profileFunctions: ProfileFunction
@Mock lateinit var uiInteraction: UiInteraction
private lateinit var insulin: Insulin
private val now = 1000000L
private val dia = 7.0
@BeforeEach

View file

@ -1,10 +1,10 @@
package info.nightscout.core.extensions
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.core.main.R
import info.nightscout.database.entities.GlucoseValue
import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.iob.InMemoryGlucoseValue
import info.nightscout.sharedtests.TestBaseWithProfile
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test

View file

@ -1,15 +1,14 @@
package info.nightscout.core.extensions
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.database.entities.TemporaryBasal
import info.nightscout.insulin.InsulinLyumjevPlugin
import info.nightscout.interfaces.aps.AutosensResult
import info.nightscout.interfaces.aps.SMBDefaults
import info.nightscout.interfaces.insulin.Insulin
import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.interfaces.ui.UiInteraction
import info.nightscout.shared.utils.T
import info.nightscout.sharedtests.TestBaseWithProfile
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
@ -18,13 +17,11 @@ import org.mockito.Mockito
class TemporaryBasalExtensionKtTest : TestBaseWithProfile() {
@Mock lateinit var activePlugin: ActivePlugin
@Mock lateinit var profileFunctions: ProfileFunction
@Mock lateinit var uiInteraction: UiInteraction
private lateinit var insulin: Insulin
private val now = 1000000L
private val dia = 7.0
@BeforeEach

View file

@ -1,8 +1,8 @@
package info.nightscout.core.extensions
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.database.entities.TemporaryTarget
import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.sharedtests.TestBaseWithProfile
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test

View file

@ -1,17 +1,14 @@
package info.nightscout.core.extensions
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.database.entities.TherapyEvent
import info.nightscout.database.entities.embedments.InterfaceIDs
import info.nightscout.shared.utils.T
import info.nightscout.sharedtests.TestBaseWithProfile
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.mockito.Mockito
class TherapyEventExtensionKtTest : TestBaseWithProfile() {
private val now = 1000000L
@Test
fun isOlderThan() {
val therapyEvent = TherapyEvent(

View file

@ -2,7 +2,6 @@ package info.nightscout.plugins.general.smsCommunicator
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import info.nightscout.interfaces.Constants
import info.nightscout.interfaces.smsCommunicator.Sms
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.utils.DateUtil
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.Test
import org.mockito.Mock
@ -61,26 +61,26 @@ class AuthRequestTest : TestBase() {
// Check if SMS requesting code is sent
var authRequest = AuthRequest(injector, requester, "Request text", "ABC", action)
Assert.assertEquals(sentSms!!.phoneNumber, "aNumber")
Assert.assertEquals(sentSms!!.text, "Request text")
Assertions.assertEquals(sentSms!!.phoneNumber, "aNumber")
Assertions.assertEquals(sentSms!!.text, "Request text")
// wrong reply
actionCalled = false
authRequest.action("EFG")
Assert.assertEquals(sentSms!!.phoneNumber, "aNumber")
Assert.assertEquals(sentSms!!.text, "Wrong code. Command cancelled.")
Assert.assertFalse(actionCalled)
Assertions.assertEquals(sentSms!!.phoneNumber, "aNumber")
Assertions.assertEquals(sentSms!!.text, "Wrong code. Command cancelled.")
Assertions.assertFalse(actionCalled)
// correct reply
authRequest = AuthRequest(injector, requester, "Request text", "ABC", action)
actionCalled = false
`when`(otp.checkOTP(anyObject())).thenReturn(OneTimePasswordValidationResult.OK)
authRequest.action("ABC")
Assert.assertTrue(actionCalled)
Assertions.assertTrue(actionCalled)
// second time action should not be called
actionCalled = false
authRequest.action("ABC")
Assert.assertFalse(actionCalled)
Assertions.assertFalse(actionCalled)
// test timed out message
val now: Long = 10000
@ -89,6 +89,6 @@ class AuthRequestTest : TestBase() {
actionCalled = false
`when`(dateUtil.now()).thenReturn(now + T.mins(Constants.SMS_CONFIRM_TIMEOUT).msecs() + 1)
authRequest.action("ABC")
Assert.assertFalse(actionCalled)
Assertions.assertFalse(actionCalled)
}
}

View file

@ -1,6 +1,6 @@
package info.nightscout.plugins.general.smsCommunicator
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class SmsActionTest {
@ -13,49 +13,49 @@ class SmsActionTest {
}
}
smsAction.run()
Assert.assertEquals(result, "A")
Assertions.assertEquals(result, "A")
smsAction = object : SmsAction(false, 1.0) {
override fun run() {
result = "B"
}
}
smsAction.run()
Assert.assertEquals(result, "B")
Assert.assertEquals(smsAction.aDouble(), 1.0, 0.000001)
Assertions.assertEquals(result, "B")
Assertions.assertEquals(smsAction.aDouble(), 1.0, 0.000001)
smsAction = object : SmsAction(false, 1.0, 2) {
override fun run() {
result = "C"
}
}
smsAction.run()
Assert.assertEquals(result, "C")
Assert.assertEquals(smsAction.aDouble(), 1.0, 0.000001)
Assert.assertEquals(smsAction.secondInteger().toLong(), 2)
Assertions.assertEquals(result, "C")
Assertions.assertEquals(smsAction.aDouble(), 1.0, 0.000001)
Assertions.assertEquals(smsAction.secondInteger().toLong(), 2)
smsAction = object : SmsAction(false, "aString", 3) {
override fun run() {
result = "D"
}
}
smsAction.run()
Assert.assertEquals(result, "D")
Assert.assertEquals(smsAction.aString(), "aString")
Assert.assertEquals(smsAction.secondInteger().toLong(), 3)
Assertions.assertEquals(result, "D")
Assertions.assertEquals(smsAction.aString(), "aString")
Assertions.assertEquals(smsAction.secondInteger().toLong(), 3)
smsAction = object : SmsAction(false, 4) {
override fun run() {
result = "E"
}
}
smsAction.run()
Assert.assertEquals(result, "E")
Assert.assertEquals(smsAction.anInteger().toLong(), 4)
Assertions.assertEquals(result, "E")
Assertions.assertEquals(smsAction.anInteger().toLong(), 4)
smsAction = object : SmsAction(false, 5, 6) {
override fun run() {
result = "F"
}
}
smsAction.run()
Assert.assertEquals(result, "F")
Assert.assertEquals(smsAction.anInteger().toLong(), 5)
Assert.assertEquals(smsAction.secondInteger().toLong(), 6)
Assertions.assertEquals(result, "F")
Assertions.assertEquals(smsAction.anInteger().toLong(), 5)
Assertions.assertEquals(smsAction.secondInteger().toLong(), 6)
}
}

View file

@ -3,8 +3,6 @@ package info.nightscout.plugins.general.smsCommunicator
import android.telephony.SmsManager
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.androidaps.TestPumpPlugin
import info.nightscout.database.entities.GlucoseValue
import info.nightscout.database.impl.AppRepository
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.IobTotal
import info.nightscout.interfaces.logging.UserEntryLogger
import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.plugin.PluginType
import info.nightscout.interfaces.profile.ProfileSource
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.CommandQueue
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.shared.utils.DateUtil
import info.nightscout.shared.utils.T
import info.nightscout.sharedtests.TestBaseWithProfile
import io.reactivex.rxjava3.core.Single
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
@ -54,10 +50,8 @@ import org.mockito.invocation.InvocationOnMock
class SmsCommunicatorPluginTest : TestBaseWithProfile() {
@Mock lateinit var constraintChecker: Constraints
@Mock lateinit var activePlugin: ActivePlugin
@Mock lateinit var commandQueue: CommandQueue
@Mock lateinit var loop: Loop
@Mock lateinit var testPumpPlugin: TestPumpPlugin
@Mock lateinit var profileSource: ProfileSource
@Mock lateinit var otp: OneTimePassword
@Mock lateinit var xDripBroadcast: XDripBroadcast
@ -159,13 +153,6 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
null
}.`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.calculateIobFromTempBasalsIncludingConvertedExtended()).thenReturn(IobTotal(0))
@ -1011,13 +998,13 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
//BOLUS 1 (Suspended pump)
smsCommunicatorPlugin.lastRemoteBolusTime = 0
`when`(testPumpPlugin.isSuspended()).thenReturn(true)
testPumpPlugin.pumpSuspended = true
smsCommunicatorPlugin.messages = ArrayList()
sms = Sms("1234", "BOLUS 1")
smsCommunicatorPlugin.processSms(sms)
Assertions.assertEquals("BOLUS 1", smsCommunicatorPlugin.messages[0].text)
Assertions.assertEquals("Pump suspended", smsCommunicatorPlugin.messages[1].text)
`when`(testPumpPlugin.isSuspended()).thenReturn(false)
testPumpPlugin.pumpSuspended = false
//BOLUS 1 a
smsCommunicatorPlugin.messages = ArrayList()

View file

@ -1,9 +1,9 @@
package info.nightscout.plugins.general.smsCommunicator
import android.telephony.SmsMessage
import info.nightscout.androidaps.TestBase
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.mockito.Mockito
import org.mockito.Mockito.`when`
@ -15,32 +15,32 @@ class SmsTest : TestBase() {
`when`(smsMessage.originatingAddress).thenReturn("aNumber")
`when`(smsMessage.messageBody).thenReturn("aBody")
var sms = Sms(smsMessage)
Assert.assertEquals(sms.phoneNumber, "aNumber")
Assert.assertEquals(sms.text, "aBody")
Assert.assertTrue(sms.received)
Assertions.assertEquals(sms.phoneNumber, "aNumber")
Assertions.assertEquals(sms.text, "aBody")
Assertions.assertTrue(sms.received)
sms = Sms("aNumber", "aBody")
Assert.assertEquals(sms.phoneNumber, "aNumber")
Assert.assertEquals(sms.text, "aBody")
Assert.assertTrue(sms.sent)
Assertions.assertEquals(sms.phoneNumber, "aNumber")
Assertions.assertEquals(sms.text, "aBody")
Assertions.assertTrue(sms.sent)
sms = Sms("aNumber", "U")
Assert.assertEquals(sms.phoneNumber, "aNumber")
Assert.assertEquals(sms.text, "U")
Assert.assertTrue(sms.sent)
Assert.assertEquals(sms.toString(), "SMS from aNumber: U")
Assertions.assertEquals(sms.phoneNumber, "aNumber")
Assertions.assertEquals(sms.text, "U")
Assertions.assertTrue(sms.sent)
Assertions.assertEquals(sms.toString(), "SMS from aNumber: U")
// copy constructor #1
val sms2 = Sms(sms)
Assert.assertEquals(sms2.phoneNumber, "aNumber")
Assert.assertEquals(sms2.text, "U")
Assert.assertTrue(sms2.sent)
Assert.assertEquals(sms2.toString(), "SMS from aNumber: U")
Assertions.assertEquals(sms2.phoneNumber, "aNumber")
Assertions.assertEquals(sms2.text, "U")
Assertions.assertTrue(sms2.sent)
Assertions.assertEquals(sms2.toString(), "SMS from aNumber: U")
// copy constructor #2
val sms3 = Sms(sms, "different")
Assert.assertEquals(sms3.phoneNumber, "different")
Assert.assertEquals(sms3.text, "U")
Assert.assertTrue(sms3.sent)
Assert.assertEquals(sms3.toString(), "SMS from different: U")
Assertions.assertEquals(sms3.phoneNumber, "different")
Assertions.assertEquals(sms3.text, "U")
Assertions.assertTrue(sms3.sent)
Assertions.assertEquals(sms3.toString(), "SMS from different: U")
}
}

View file

@ -4,7 +4,6 @@ import android.content.Context
import androidx.collection.LongSparseArray
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import info.nightscout.database.entities.GlucoseValue
import info.nightscout.interfaces.aps.AutosensData
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.utils.DateUtil
import info.nightscout.shared.utils.T
import info.nightscout.sharedtests.TestBase
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

View file

@ -2,6 +2,7 @@ include ':app'
include ':wear'
include ':app-wear-shared:shared'
include ':app-wear-shared:shared-impl'
include ':app-wear-shared:shared-tests'
include ':core:main'
include ':core:graphview'
include ':core:graph'