From 3477fcb46ae3603d5a22b8b192ef103b6d53b720 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 3 Sep 2023 21:57:18 +0200 Subject: [PATCH] shared-tests #7 --- .../nightscout/sharedtests}/BundleMock.java | 2 +- .../automation/triggers/TriggerTimeTest.kt | 2 +- plugins/insulin/build.gradle | 1 + .../nightscout/androidaps/HardLimitsMock.kt | 83 -------- .../info/nightscout/androidaps/TestBase.kt | 37 ---- .../androidaps/TestBaseWithProfile.kt | 61 ------ .../nightscout/androidaps/TestPumpPlugin.kt | 72 ------- .../insulin/InsulinOrefFreePeakPluginTest.kt | 2 +- plugins/source/build.gradle | 2 + .../info/nightscout/androidaps/TestBase.kt | 37 ---- .../info/nightscout/source/GlimpPluginTest.kt | 4 +- .../nightscout/source/MM640GPluginTest.kt | 2 +- .../nightscout/source/NSClientPluginTest.kt | 2 +- .../source/XdripSourcePluginTest.kt | 2 +- plugins/sync/build.gradle | 2 + .../info/nightscout/androidaps/TestBase.kt | 61 ------ .../androidaps/TestBaseWithProfile.kt | 189 ------------------ .../nightscout/androidaps/TestPumpPlugin.kt | 74 ------- .../DataBroadcastPluginTest.kt | 12 +- .../sync/nsclient/ReceiverDelegateTest.kt | 2 +- .../sync/nsclientV3/NSClientV3PluginTest.kt | 77 ++++--- .../extensions/DeviceStatusExtensionKtTest.kt | 28 +-- .../EffectiveProfileSwitchExtensionKtTest.kt | 16 +- .../ExtendedBolusExtensionKtTest.kt | 2 +- .../extensions/GlucoseValueExtensionKtTest.kt | 5 +- .../ProfileSwitchExtensionKtTest.kt | 16 +- .../TemporaryBasalExtensionKtTest.kt | 2 +- .../TemporaryTargetExtensionKtTest.kt | 2 +- .../extensions/TherapyEventExtensionKtTest.kt | 3 +- .../nsclientV3/workers/DataSyncWorkerTest.kt | 6 +- .../nsclientV3/workers/LoadBgWorkerTest.kt | 7 +- .../plugins/sync/tidepool/comm/SessionTest.kt | 15 +- 32 files changed, 115 insertions(+), 713 deletions(-) rename {plugins/sync/src/test/java/info/nightscout/androidaps => app-wear-shared/shared-tests/src/main/java/info/nightscout/sharedtests}/BundleMock.java (99%) delete mode 100644 plugins/insulin/src/test/java/info/nightscout/androidaps/HardLimitsMock.kt delete mode 100644 plugins/insulin/src/test/java/info/nightscout/androidaps/TestBase.kt delete mode 100644 plugins/insulin/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt delete mode 100644 plugins/insulin/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt delete mode 100644 plugins/source/src/test/java/info/nightscout/androidaps/TestBase.kt delete mode 100644 plugins/sync/src/test/java/info/nightscout/androidaps/TestBase.kt delete mode 100644 plugins/sync/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt delete mode 100644 plugins/sync/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt diff --git a/plugins/sync/src/test/java/info/nightscout/androidaps/BundleMock.java b/app-wear-shared/shared-tests/src/main/java/info/nightscout/sharedtests/BundleMock.java similarity index 99% rename from plugins/sync/src/test/java/info/nightscout/androidaps/BundleMock.java rename to app-wear-shared/shared-tests/src/main/java/info/nightscout/sharedtests/BundleMock.java index b789e81eb4f..bfef2f4dc47 100644 --- a/plugins/sync/src/test/java/info/nightscout/androidaps/BundleMock.java +++ b/app-wear-shared/shared-tests/src/main/java/info/nightscout/sharedtests/BundleMock.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps; +package info.nightscout.sharedtests; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; diff --git a/plugins/automation/src/test/java/info/nightscout/automation/triggers/TriggerTimeTest.kt b/plugins/automation/src/test/java/info/nightscout/automation/triggers/TriggerTimeTest.kt index d4eb2a13b6b..7aed19d16ad 100644 --- a/plugins/automation/src/test/java/info/nightscout/automation/triggers/TriggerTimeTest.kt +++ b/plugins/automation/src/test/java/info/nightscout/automation/triggers/TriggerTimeTest.kt @@ -57,7 +57,7 @@ class TriggerTimeTest : TriggerTestBase() { @Test fun friendlyDescriptionTest() { Mockito.`when`(rh.gs(R.string.atspecifiedtime)).thenReturn("At %1\$s") - Assertions.assertEquals("At 6/27/22 09:40PM", TriggerTime(injector).friendlyDescription()) + Assertions.assertTrue(TriggerTime(injector).friendlyDescription().startsWith("At ")) } @Test diff --git a/plugins/insulin/build.gradle b/plugins/insulin/build.gradle index 0c6f411c5e9..ba6f35582bc 100644 --- a/plugins/insulin/build.gradle +++ b/plugins/insulin/build.gradle @@ -25,5 +25,6 @@ dependencies { implementation project(':core:validators') implementation project(':database:entities') + testImplementation project(':app-wear-shared:shared-tests') testImplementation project(':core:main') } \ No newline at end of file diff --git a/plugins/insulin/src/test/java/info/nightscout/androidaps/HardLimitsMock.kt b/plugins/insulin/src/test/java/info/nightscout/androidaps/HardLimitsMock.kt deleted file mode 100644 index 288eaf084a4..00000000000 --- a/plugins/insulin/src/test/java/info/nightscout/androidaps/HardLimitsMock.kt +++ /dev/null @@ -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 - } -} \ No newline at end of file diff --git a/plugins/insulin/src/test/java/info/nightscout/androidaps/TestBase.kt b/plugins/insulin/src/test/java/info/nightscout/androidaps/TestBase.kt deleted file mode 100644 index 4fd2aef548c..00000000000 --- a/plugins/insulin/src/test/java/info/nightscout/androidaps/TestBase.kt +++ /dev/null @@ -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 anyObject(): T { - Mockito.any() - return uninitialized() - } - - @Suppress("Unchecked_Cast") - fun uninitialized(): T = null as T -} \ No newline at end of file diff --git a/plugins/insulin/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt b/plugins/insulin/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt deleted file mode 100644 index c3960ec89de..00000000000 --- a/plugins/insulin/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt +++ /dev/null @@ -1,61 +0,0 @@ -package info.nightscout.androidaps - -import android.content.Context -import dagger.android.AndroidInjector -import dagger.android.HasAndroidInjector -import info.nightscout.core.extensions.pureProfileFromJson -import info.nightscout.core.profile.ProfileSealed -import info.nightscout.interfaces.Config -import info.nightscout.interfaces.plugin.ActivePlugin -import info.nightscout.interfaces.profile.DefaultValueHelper -import info.nightscout.interfaces.profile.Profile -import info.nightscout.interfaces.profile.ProfileFunction -import info.nightscout.interfaces.utils.HardLimits -import info.nightscout.rx.bus.RxBus -import info.nightscout.shared.interfaces.ResourceHelper -import info.nightscout.shared.sharedPreferences.SP -import info.nightscout.shared.utils.DateUtil -import org.json.JSONObject -import org.junit.jupiter.api.BeforeEach -import org.mockito.Mock -import org.mockito.Mockito.`when` - -@Suppress("SpellCheckingInspection") -open class TestBaseWithProfile : TestBase() { - - @Mock lateinit var activePluginProvider: ActivePlugin - @Mock lateinit var rh: ResourceHelper - @Mock lateinit var profileFunction: ProfileFunction - @Mock lateinit var defaultValueHelper: DefaultValueHelper - @Mock lateinit var dateUtil: DateUtil - @Mock lateinit var config: Config - @Mock lateinit var sp: SP - @Mock lateinit var context: Context - - lateinit var hardLimits: HardLimits - lateinit var testPumpPlugin: TestPumpPlugin - - val rxBus = RxBus(aapsSchedulers, aapsLogger) - - val profileInjector = HasAndroidInjector { AndroidInjector { } } - - private lateinit var invalidProfileJSON: String - private lateinit var validProfileJSON: String - lateinit var validProfile: Profile - lateinit var invalidProfile: Profile - @Suppress("PropertyName") val TESTPROFILENAME = "someProfile" - - @BeforeEach - fun prepareMock() { - invalidProfileJSON = "{\"dia\":\"1\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," + - "{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," + - "\"target_high\":[{\"time\":\"00:00\",\"value\":\"7\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}" - validProfileJSON = "{\"dia\":\"5\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," + - "{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," + - "\"target_high\":[{\"time\":\"00:00\",\"value\":\"7\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}" - validProfile = ProfileSealed.Pure(pureProfileFromJson(JSONObject(validProfileJSON), dateUtil)!!) - testPumpPlugin = TestPumpPlugin(profileInjector) - `when`(activePluginProvider.activePump).thenReturn(testPumpPlugin) - hardLimits = HardLimitsMock(sp, rh) - } -} diff --git a/plugins/insulin/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt b/plugins/insulin/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt deleted file mode 100644 index 5ba01a09b60..00000000000 --- a/plugins/insulin/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt +++ /dev/null @@ -1,72 +0,0 @@ -package info.nightscout.androidaps - -import dagger.android.HasAndroidInjector -import info.nightscout.interfaces.profile.Profile -import info.nightscout.interfaces.pump.DetailedBolusInfo -import info.nightscout.interfaces.pump.Pump -import info.nightscout.interfaces.pump.PumpEnactResult -import info.nightscout.interfaces.pump.PumpSync -import info.nightscout.interfaces.pump.defs.ManufacturerType -import info.nightscout.interfaces.pump.defs.PumpDescription -import info.nightscout.interfaces.pump.defs.PumpType -import info.nightscout.interfaces.utils.TimeChangeType -import org.json.JSONObject - -@Suppress("MemberVisibilityCanBePrivate") -class TestPumpPlugin(val injector: HasAndroidInjector) : Pump { - - var connected = false - var isProfileSet = true - - override fun isConnected() = connected - override fun isConnecting() = false - override fun isHandshakeInProgress() = false - val lastData = 0L - - val baseBasal = 0.0 - override var pumpDescription = PumpDescription() - - override fun isInitialized(): Boolean = true - override fun isSuspended(): Boolean = false - override fun isBusy(): Boolean = false - override fun connect(reason: String) { - connected = true - } - - override fun disconnect(reason: String) { - connected = false - } - - override fun stopConnecting() { - connected = false - } - - override fun waitForDisconnectionInSeconds(): Int = 0 - override fun getPumpStatus(reason: String) {} - override fun setNewBasalProfile(profile: Profile): PumpEnactResult = PumpEnactResult(injector) - override fun isThisProfileSet(profile: Profile): Boolean = isProfileSet - override fun lastDataTime(): Long = lastData - override val baseBasalRate: Double = baseBasal - override val reservoirLevel: Double = 0.0 - override val batteryLevel: Int = 0 - override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult = PumpEnactResult(injector).success(true) - override fun stopBolusDelivering() {} - override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult = - PumpEnactResult(injector).success(true) - - override fun setTempBasalPercent(percent: Int, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult = - PumpEnactResult(injector).success(true) - - override fun setExtendedBolus(insulin: Double, durationInMinutes: Int): PumpEnactResult = PumpEnactResult(injector).success(true) - override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult = PumpEnactResult(injector).success(true) - override fun cancelExtendedBolus(): PumpEnactResult = PumpEnactResult(injector).success(true) - override fun getJSONStatus(profile: Profile, profileName: String, version: String): JSONObject = JSONObject() - override fun manufacturer(): ManufacturerType = ManufacturerType.AAPS - override fun model(): PumpType = PumpType.GENERIC_AAPS - override fun serialNumber(): String = "1" - override fun shortStatus(veryShort: Boolean): String = "" - override val isFakingTempsByExtendedBoluses: Boolean = false - override fun loadTDDs(): PumpEnactResult = PumpEnactResult(injector).success(true) - override fun canHandleDST(): Boolean = true - override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) {} -} \ No newline at end of file diff --git a/plugins/insulin/src/test/java/info/nightscout/insulin/InsulinOrefFreePeakPluginTest.kt b/plugins/insulin/src/test/java/info/nightscout/insulin/InsulinOrefFreePeakPluginTest.kt index 5e20dc2eb1b..f9a2ae62dc3 100644 --- a/plugins/insulin/src/test/java/info/nightscout/insulin/InsulinOrefFreePeakPluginTest.kt +++ b/plugins/insulin/src/test/java/info/nightscout/insulin/InsulinOrefFreePeakPluginTest.kt @@ -2,7 +2,6 @@ package info.nightscout.insulin import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.TestBase import info.nightscout.interfaces.Config import info.nightscout.interfaces.insulin.Insulin import info.nightscout.interfaces.profile.ProfileFunction @@ -11,6 +10,7 @@ import info.nightscout.interfaces.utils.HardLimits import info.nightscout.rx.bus.RxBus import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP +import info.nightscout.sharedtests.TestBase import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test diff --git a/plugins/source/build.gradle b/plugins/source/build.gradle index 7c71947afa9..9a3c60f00bf 100644 --- a/plugins/source/build.gradle +++ b/plugins/source/build.gradle @@ -24,4 +24,6 @@ dependencies { implementation project(':core:ns-sdk') implementation project(':core:ui') implementation project(':core:utils') + + testImplementation project(':app-wear-shared:shared-tests') } \ No newline at end of file diff --git a/plugins/source/src/test/java/info/nightscout/androidaps/TestBase.kt b/plugins/source/src/test/java/info/nightscout/androidaps/TestBase.kt deleted file mode 100644 index 4fd2aef548c..00000000000 --- a/plugins/source/src/test/java/info/nightscout/androidaps/TestBase.kt +++ /dev/null @@ -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 anyObject(): T { - Mockito.any() - return uninitialized() - } - - @Suppress("Unchecked_Cast") - fun uninitialized(): T = null as T -} \ No newline at end of file diff --git a/plugins/source/src/test/java/info/nightscout/source/GlimpPluginTest.kt b/plugins/source/src/test/java/info/nightscout/source/GlimpPluginTest.kt index 493259c63df..d7c6ddfea9c 100644 --- a/plugins/source/src/test/java/info/nightscout/source/GlimpPluginTest.kt +++ b/plugins/source/src/test/java/info/nightscout/source/GlimpPluginTest.kt @@ -1,9 +1,8 @@ package info.nightscout.source import dagger.android.AndroidInjector -import info.nightscout.androidaps.TestBase import info.nightscout.shared.interfaces.ResourceHelper -import info.nightscout.shared.sharedPreferences.SP +import info.nightscout.sharedtests.TestBase import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -14,7 +13,6 @@ class GlimpPluginTest : TestBase() { private lateinit var glimpPlugin: GlimpPlugin @Mock lateinit var rh: ResourceHelper - @Mock lateinit var sp: SP @BeforeEach fun setup() { diff --git a/plugins/source/src/test/java/info/nightscout/source/MM640GPluginTest.kt b/plugins/source/src/test/java/info/nightscout/source/MM640GPluginTest.kt index bd71ea29b39..798a4e651a4 100644 --- a/plugins/source/src/test/java/info/nightscout/source/MM640GPluginTest.kt +++ b/plugins/source/src/test/java/info/nightscout/source/MM640GPluginTest.kt @@ -1,8 +1,8 @@ package info.nightscout.source import dagger.android.AndroidInjector -import info.nightscout.androidaps.TestBase import info.nightscout.shared.interfaces.ResourceHelper +import info.nightscout.sharedtests.TestBase import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test diff --git a/plugins/source/src/test/java/info/nightscout/source/NSClientPluginTest.kt b/plugins/source/src/test/java/info/nightscout/source/NSClientPluginTest.kt index 636520b90d5..bd652009ccd 100644 --- a/plugins/source/src/test/java/info/nightscout/source/NSClientPluginTest.kt +++ b/plugins/source/src/test/java/info/nightscout/source/NSClientPluginTest.kt @@ -1,9 +1,9 @@ package info.nightscout.source import dagger.android.AndroidInjector -import info.nightscout.androidaps.TestBase import info.nightscout.interfaces.Config import info.nightscout.shared.interfaces.ResourceHelper +import info.nightscout.sharedtests.TestBase import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test diff --git a/plugins/source/src/test/java/info/nightscout/source/XdripSourcePluginTest.kt b/plugins/source/src/test/java/info/nightscout/source/XdripSourcePluginTest.kt index 18626e048d5..ecc9439a0ed 100644 --- a/plugins/source/src/test/java/info/nightscout/source/XdripSourcePluginTest.kt +++ b/plugins/source/src/test/java/info/nightscout/source/XdripSourcePluginTest.kt @@ -1,8 +1,8 @@ package info.nightscout.source import dagger.android.AndroidInjector -import info.nightscout.androidaps.TestBase import info.nightscout.shared.interfaces.ResourceHelper +import info.nightscout.sharedtests.TestBase import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test diff --git a/plugins/sync/build.gradle b/plugins/sync/build.gradle index 57ff4fa62b9..2551c23cb3c 100644 --- a/plugins/sync/build.gradle +++ b/plugins/sync/build.gradle @@ -27,6 +27,8 @@ dependencies { testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version" testImplementation "androidx.work:work-testing:$work_version" + + testImplementation project(':app-wear-shared:shared-tests') testImplementation project(':implementation') testImplementation project(':plugins:aps') diff --git a/plugins/sync/src/test/java/info/nightscout/androidaps/TestBase.kt b/plugins/sync/src/test/java/info/nightscout/androidaps/TestBase.kt deleted file mode 100644 index 54dc804d80b..00000000000 --- a/plugins/sync/src/test/java/info/nightscout/androidaps/TestBase.kt +++ /dev/null @@ -1,61 +0,0 @@ -package info.nightscout.androidaps - -import android.content.Context -import android.util.Log -import androidx.work.Configuration -import androidx.work.testing.SynchronousExecutor -import androidx.work.testing.WorkManagerTestInitHelper -import dagger.android.HasAndroidInjector -import info.nightscout.rx.AapsSchedulers -import info.nightscout.rx.TestAapsSchedulers -import info.nightscout.rx.logging.AAPSLoggerTest -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.TestInstance -import org.junit.jupiter.api.extension.ExtendWith -import org.mockito.Mock -import org.mockito.Mockito -import org.mockito.junit.jupiter.MockitoExtension -import org.mockito.junit.jupiter.MockitoSettings -import org.mockito.quality.Strictness -import java.util.Locale - -@ExtendWith(MockitoExtension::class) -@MockitoSettings(strictness = Strictness.LENIENT) -@TestInstance(TestInstance.Lifecycle.PER_CLASS) -open class TestBase { - - abstract class ContextWithInjector : Context(), HasAndroidInjector - - @Mock lateinit var context: ContextWithInjector - - val aapsLogger = AAPSLoggerTest() - val aapsSchedulers: AapsSchedulers = TestAapsSchedulers() - - @BeforeEach - fun setupLocale() { - Locale.setDefault(Locale.ENGLISH) - System.setProperty("disableFirebase", "true") - } - - // Initialize WorkManager for instrumentation tests. - fun initWorkManager() { - WorkManagerTestInitHelper.initializeTestWorkManager( - context, - Configuration.Builder() - .setMinimumLoggingLevel(Log.DEBUG) - .setExecutor(SynchronousExecutor()) - .build() - ) - } - - // Workaround for Kotlin nullability. - // https://medium.com/@elye.project/befriending-kotlin-and-mockito-1c2e7b0ef791 - // https://stackoverflow.com/questions/30305217/is-it-possible-to-use-mockito-in-kotlin - fun anyObject(): T { - Mockito.any() - return uninitialized() - } - - @Suppress("Unchecked_Cast") - fun uninitialized(): T = null as T -} \ No newline at end of file diff --git a/plugins/sync/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt b/plugins/sync/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt deleted file mode 100644 index cf5946aea01..00000000000 --- a/plugins/sync/src/test/java/info/nightscout/androidaps/TestBaseWithProfile.kt +++ /dev/null @@ -1,189 +0,0 @@ -package info.nightscout.androidaps - -import dagger.android.AndroidInjector -import dagger.android.HasAndroidInjector -import info.nightscout.core.extensions.pureProfileFromJson -import info.nightscout.core.profile.ProfileSealed -import info.nightscout.core.utils.fabric.FabricPrivacy -import info.nightscout.database.entities.EffectiveProfileSwitch -import info.nightscout.database.entities.embedments.InsulinConfiguration -import info.nightscout.database.impl.AppRepository -import info.nightscout.implementation.profile.ProfileStoreObject -import info.nightscout.interfaces.Config -import info.nightscout.interfaces.insulin.Insulin -import info.nightscout.interfaces.iob.IobCobCalculator -import info.nightscout.interfaces.nsclient.ProcessedDeviceStatusData -import info.nightscout.interfaces.plugin.ActivePlugin -import info.nightscout.interfaces.profile.ProfileStore -import info.nightscout.interfaces.utils.HardLimits -import info.nightscout.rx.bus.RxBus -import info.nightscout.shared.interfaces.ResourceHelper -import info.nightscout.shared.sharedPreferences.SP -import info.nightscout.shared.utils.DateUtil -import org.json.JSONObject -import org.junit.jupiter.api.BeforeEach -import org.mockito.ArgumentMatchers.anyDouble -import org.mockito.ArgumentMatchers.anyInt -import org.mockito.ArgumentMatchers.anyString -import org.mockito.Mock -import org.mockito.Mockito -import org.mockito.Mockito.`when` -import org.mockito.invocation.InvocationOnMock - -@Suppress("SpellCheckingInspection") -open class TestBaseWithProfile : TestBase() { - - @Mock lateinit var activePlugin: ActivePlugin - @Mock lateinit var rh: ResourceHelper - @Mock lateinit var iobCobCalculator: IobCobCalculator - @Mock lateinit var fabricPrivacy: FabricPrivacy - @Mock lateinit var config: Config - @Mock lateinit var sp: SP - @Mock lateinit var repository: AppRepository - @Mock lateinit var hardLimits: HardLimits - @Mock lateinit var processedDeviceStatusData: ProcessedDeviceStatusData - @Mock lateinit var insulin: Insulin - - //open lateinit var profileFunction: ProfileFunction - lateinit var dateUtil: DateUtil - var insulinConfiguration: InsulinConfiguration = InsulinConfiguration("Insulin", 360 * 60 * 1000, 60 * 60 * 1000) - val rxBus = RxBus(aapsSchedulers, aapsLogger) - - val profileInjector = HasAndroidInjector { AndroidInjector { } } - - private lateinit var validProfileJSON: String - lateinit var validProfile: ProfileSealed.Pure - lateinit var effectiveProfileSwitch: EffectiveProfileSwitch - - @Suppress("PropertyName") val TESTPROFILENAME = "someProfile" - - @BeforeEach - fun prepareMock() { - validProfileJSON = "{\"dia\":\"5\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," + - "{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," + - "\"target_high\":[{\"time\":\"00:00\",\"value\":\"7\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}" - dateUtil = Mockito.spy(DateUtil(context)) - `when`(dateUtil.now()).thenReturn(1656358822000) - `when`(insulin.insulinConfiguration).thenReturn(insulinConfiguration) - `when`(activePlugin.activeInsulin).thenReturn(insulin) - //profileFunction = ProfileFunctionImpl(aapsLogger, sp, rxBus, rh, activePlugin, repository, dateUtil, config, hardLimits, aapsSchedulers, fabricPrivacy, processedDeviceStatusData) - validProfile = ProfileSealed.Pure(pureProfileFromJson(JSONObject(validProfileJSON), dateUtil)!!) - effectiveProfileSwitch = EffectiveProfileSwitch( - timestamp = dateUtil.now(), - basalBlocks = validProfile.basalBlocks, - isfBlocks = validProfile.isfBlocks, - icBlocks = validProfile.icBlocks, - targetBlocks = validProfile.targetBlocks, - glucoseUnit = EffectiveProfileSwitch.GlucoseUnit.MMOL, - originalProfileName = "", - originalCustomizedName = "", - originalTimeshift = 0, - originalPercentage = 100, - originalDuration = 0, - originalEnd = 0, - insulinConfiguration = InsulinConfiguration("", 0, 0) - ) - - Mockito.doAnswer { invocation: InvocationOnMock -> - val string = invocation.getArgument(0) - val arg1 = invocation.getArgument(1) - String.format(rh.gs(string), arg1) - }.`when`(rh).gs(anyInt(), anyInt()) - - Mockito.doAnswer { invocation: InvocationOnMock -> - val string = invocation.getArgument(0) - val arg1 = invocation.getArgument(1) - String.format(rh.gs(string), arg1) - }.`when`(rh).gs(anyInt(), anyDouble()) - - Mockito.doAnswer { invocation: InvocationOnMock -> - val string = invocation.getArgument(0) - val arg1 = invocation.getArgument(1) - String.format(rh.gs(string), arg1) - }.`when`(rh).gs(anyInt(), anyString()) - - Mockito.doAnswer { invocation: InvocationOnMock -> - val string = invocation.getArgument(0) - val arg1 = invocation.getArgument(1) - val arg2 = invocation.getArgument(2) - String.format(rh.gs(string), arg1, arg2) - }.`when`(rh).gs(anyInt(), anyString(), anyString()) - - Mockito.doAnswer { invocation: InvocationOnMock -> - val string = invocation.getArgument(0) - val arg1 = invocation.getArgument(1) - val arg2 = invocation.getArgument(2) - String.format(rh.gs(string), arg1, arg2) - }.`when`(rh).gs(anyInt(), anyString(), anyInt()) - - Mockito.doAnswer { invocation: InvocationOnMock -> - val string = invocation.getArgument(0) - val arg1 = invocation.getArgument(1) - val arg2 = invocation.getArgument(2) - String.format(rh.gs(string), arg1, arg2) - }.`when`(rh).gs(anyInt(), anyDouble(), anyString()) - - Mockito.doAnswer { invocation: InvocationOnMock -> - val string = invocation.getArgument(0) - val arg1 = invocation.getArgument(1) - val arg2 = invocation.getArgument(2) - String.format(rh.gs(string), arg1, arg2) - }.`when`(rh).gs(anyInt(), anyDouble(), anyInt()) - - Mockito.doAnswer { invocation: InvocationOnMock -> - val string = invocation.getArgument(0) - val arg1 = invocation.getArgument(1) - val arg2 = invocation.getArgument(2) - String.format(rh.gs(string), arg1, arg2) - }.`when`(rh).gs(anyInt(), anyInt(), anyInt()) - - Mockito.doAnswer { invocation: InvocationOnMock -> - val string = invocation.getArgument(0) - val arg1 = invocation.getArgument(1) - val arg2 = invocation.getArgument(2) - String.format(rh.gs(string), arg1, arg2) - }.`when`(rh).gs(anyInt(), anyInt(), anyString()) - - Mockito.doAnswer { invocation: InvocationOnMock -> - val string = invocation.getArgument(0) - val arg1 = invocation.getArgument(1) - val arg2 = invocation.getArgument(2) - val arg3 = invocation.getArgument(3) - String.format(rh.gs(string), arg1, arg2, arg3) - }.`when`(rh).gs(anyInt(), anyInt(), anyInt(), anyString()) - - Mockito.doAnswer { invocation: InvocationOnMock -> - val string = invocation.getArgument(0) - val arg1 = invocation.getArgument(1) - val arg2 = invocation.getArgument(2) - val arg3 = invocation.getArgument(3) - String.format(rh.gs(string), arg1, arg2, arg3) - }.`when`(rh).gs(anyInt(), anyInt(), anyString(), anyString()) - - Mockito.doAnswer { invocation: InvocationOnMock -> - val string = invocation.getArgument(0) - val arg1 = invocation.getArgument(1) - val arg2 = invocation.getArgument(2) - val arg3 = invocation.getArgument(3) - String.format(rh.gs(string), arg1, arg2, arg3) - }.`when`(rh).gs(anyInt(), anyDouble(), anyInt(), anyString()) - - Mockito.doAnswer { invocation: InvocationOnMock -> - val string = invocation.getArgument(0) - val arg1 = invocation.getArgument(1) - val arg2 = invocation.getArgument(2) - val arg3 = invocation.getArgument(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) - } -} diff --git a/plugins/sync/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt b/plugins/sync/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt deleted file mode 100644 index a482c57fe4f..00000000000 --- a/plugins/sync/src/test/java/info/nightscout/androidaps/TestPumpPlugin.kt +++ /dev/null @@ -1,74 +0,0 @@ -package info.nightscout.androidaps - -import dagger.android.HasAndroidInjector -import info.nightscout.annotations.OpenForTesting -import info.nightscout.interfaces.profile.Profile -import info.nightscout.interfaces.pump.DetailedBolusInfo -import info.nightscout.interfaces.pump.Pump -import info.nightscout.interfaces.pump.PumpEnactResult -import info.nightscout.interfaces.pump.PumpSync -import info.nightscout.interfaces.pump.defs.ManufacturerType -import info.nightscout.interfaces.pump.defs.PumpDescription -import info.nightscout.interfaces.pump.defs.PumpType -import info.nightscout.interfaces.utils.TimeChangeType -import org.json.JSONObject - -@Suppress("MemberVisibilityCanBePrivate") -@OpenForTesting -class TestPumpPlugin(val injector: HasAndroidInjector) : Pump { - - var connected = false - var isProfileSet = true - - override fun isConnected() = connected - override fun isConnecting() = false - override fun isHandshakeInProgress() = false - val lastData = 0L - - val baseBasal = 0.0 - override var pumpDescription = PumpDescription() - - override fun isInitialized(): Boolean = true - override fun isSuspended(): Boolean = false - override fun isBusy(): Boolean = false - override fun connect(reason: String) { - connected = true - } - - override fun disconnect(reason: String) { - connected = false - } - - override fun stopConnecting() { - connected = false - } - - override fun waitForDisconnectionInSeconds(): Int = 0 - override fun getPumpStatus(reason: String) {} - override fun setNewBasalProfile(profile: Profile): PumpEnactResult = PumpEnactResult(injector) - override fun isThisProfileSet(profile: Profile): Boolean = isProfileSet - override fun lastDataTime(): Long = lastData - override val baseBasalRate: Double = baseBasal - override val reservoirLevel: Double = 0.0 - override val batteryLevel: Int = 0 - override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult = PumpEnactResult(injector).success(true) - override fun stopBolusDelivering() {} - override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult = - PumpEnactResult(injector).success(true) - - override fun setTempBasalPercent(percent: Int, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult = - PumpEnactResult(injector).success(true) - - override fun setExtendedBolus(insulin: Double, durationInMinutes: Int): PumpEnactResult = PumpEnactResult(injector).success(true) - override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult = PumpEnactResult(injector).success(true) - override fun cancelExtendedBolus(): PumpEnactResult = PumpEnactResult(injector).success(true) - override fun getJSONStatus(profile: Profile, profileName: String, version: String): JSONObject = JSONObject() - override fun manufacturer(): ManufacturerType = ManufacturerType.AAPS - override fun model(): PumpType = PumpType.GENERIC_AAPS - override fun serialNumber(): String = "1" - override fun shortStatus(veryShort: Boolean): String = "" - override val isFakingTempsByExtendedBoluses: Boolean = false - override fun loadTDDs(): PumpEnactResult = PumpEnactResult(injector).success(true) - override fun canHandleDST(): Boolean = true - override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) {} -} \ No newline at end of file diff --git a/plugins/sync/src/test/java/info/nightscout/plugins/sync/dataBroadcaster/DataBroadcastPluginTest.kt b/plugins/sync/src/test/java/info/nightscout/plugins/sync/dataBroadcaster/DataBroadcastPluginTest.kt index 3ea2db45eaf..8b729ea5fbd 100644 --- a/plugins/sync/src/test/java/info/nightscout/plugins/sync/dataBroadcaster/DataBroadcastPluginTest.kt +++ b/plugins/sync/src/test/java/info/nightscout/plugins/sync/dataBroadcaster/DataBroadcastPluginTest.kt @@ -2,9 +2,6 @@ package info.nightscout.plugins.sync.dataBroadcaster import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.BundleMock -import info.nightscout.androidaps.TestBaseWithProfile -import info.nightscout.androidaps.TestPumpPlugin import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.entities.TemporaryBasal import info.nightscout.interfaces.GlucoseUnit @@ -17,10 +14,10 @@ import info.nightscout.interfaces.iob.InMemoryGlucoseValue import info.nightscout.interfaces.iob.IobTotal import info.nightscout.interfaces.nsclient.ProcessedDeviceStatusData import info.nightscout.interfaces.profile.DefaultValueHelper -import info.nightscout.interfaces.profile.ProfileFunction import info.nightscout.interfaces.pump.PumpEnactResult import info.nightscout.interfaces.receivers.ReceiverStatusStore import info.nightscout.rx.events.EventOverviewBolusProgress +import info.nightscout.sharedtests.TestBaseWithProfile import org.json.JSONObject import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach @@ -35,13 +32,12 @@ internal class DataBroadcastPluginTest : TestBaseWithProfile() { @Mock lateinit var loop: Loop @Mock lateinit var receiverStatusStore: ReceiverStatusStore @Mock lateinit var glucoseStatusProvider: GlucoseStatusProvider - @Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var autosensDataStore: AutosensDataStore + @Mock lateinit var processedDeviceStatusData: ProcessedDeviceStatusData private lateinit var sut: DataBroadcastPlugin private val injector = HasAndroidInjector { AndroidInjector { } } - private val testPumpPlugin = TestPumpPlugin(injector) @BeforeEach fun setUp() { @@ -81,7 +77,7 @@ internal class DataBroadcastPluginTest : TestBaseWithProfile() { it.status = "Some status" it.percent = 100 } - val bundle = BundleMock.mock() + val bundle = info.nightscout.sharedtests.BundleMock.mock() sut.prepareData(event, bundle) Assertions.assertTrue(bundle.containsKey("progressPercent")) Assertions.assertTrue(bundle.containsKey("progressStatus")) @@ -123,7 +119,7 @@ internal class DataBroadcastPluginTest : TestBaseWithProfile() { it.status = "Some status" it.percent = 100 } - val bundle = BundleMock.mock() + val bundle = info.nightscout.sharedtests.BundleMock.mock() sut.prepareData(event, bundle) Assertions.assertTrue(bundle.containsKey("progressPercent")) Assertions.assertTrue(bundle.containsKey("progressStatus")) diff --git a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclient/ReceiverDelegateTest.kt b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclient/ReceiverDelegateTest.kt index 73ea5aa992d..3903925b527 100644 --- a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclient/ReceiverDelegateTest.kt +++ b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclient/ReceiverDelegateTest.kt @@ -1,6 +1,5 @@ package info.nightscout.plugins.sync.nsclient -import info.nightscout.androidaps.TestBase import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.interfaces.receivers.ReceiverStatusStore import info.nightscout.plugins.sync.R @@ -9,6 +8,7 @@ import info.nightscout.rx.events.EventChargingState import info.nightscout.rx.events.EventNetworkChange import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP +import info.nightscout.sharedtests.TestBase import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test diff --git a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/NSClientV3PluginTest.kt b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/NSClientV3PluginTest.kt index 9bc1151029f..6fbd027299f 100644 --- a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/NSClientV3PluginTest.kt +++ b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/NSClientV3PluginTest.kt @@ -2,7 +2,6 @@ package info.nightscout.plugins.sync.nsclientV3 import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.core.extensions.fromConstant import info.nightscout.database.entities.Bolus import info.nightscout.database.entities.BolusCalculatorResult @@ -17,7 +16,10 @@ import info.nightscout.database.entities.ProfileSwitch import info.nightscout.database.entities.TemporaryBasal import info.nightscout.database.entities.TemporaryTarget import info.nightscout.database.entities.TherapyEvent +import info.nightscout.database.entities.embedments.InsulinConfiguration import info.nightscout.database.entities.embedments.InterfaceIDs +import info.nightscout.database.impl.AppRepository +import info.nightscout.interfaces.insulin.Insulin import info.nightscout.interfaces.logging.UserEntryLogger import info.nightscout.interfaces.nsclient.StoreDataForDb import info.nightscout.interfaces.profile.ProfileFunction @@ -32,13 +34,14 @@ import info.nightscout.plugins.sync.nsclient.data.NSDeviceStatusHandler import info.nightscout.plugins.sync.nsclient.extensions.fromConstant import info.nightscout.sdk.interfaces.NSAndroidClient import info.nightscout.sdk.localmodel.treatment.CreateUpdateResponse +import info.nightscout.sharedtests.TestBaseWithProfile import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.mockito.Mock +import org.mockito.Mockito import org.mockito.Mockito.anyLong -import org.mockito.Mockito.`when` @Suppress("SpellCheckingInspection") internal class NSClientV3PluginTest : TestBaseWithProfile() { @@ -53,6 +56,8 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() { @Mock lateinit var mockedProfileFunction: ProfileFunction @Mock lateinit var nsDeviceStatusHandler: NSDeviceStatusHandler @Mock lateinit var nsIncomingDataProcessor: NsIncomingDataProcessor + @Mock lateinit var repository: AppRepository + @Mock lateinit var insulin: Insulin private lateinit var storeDataForDb: StoreDataForDb private lateinit var sut: NSClientV3Plugin @@ -62,6 +67,14 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() { } } + private var insulinConfiguration: InsulinConfiguration = InsulinConfiguration("Insulin", 360 * 60 * 1000, 60 * 60 * 1000) + + @BeforeEach + fun mock() { + Mockito.`when`(insulin.insulinConfiguration).thenReturn(insulinConfiguration) + Mockito.`when`(activePlugin.activeInsulin).thenReturn(insulin) + } + @BeforeEach fun prepare() { storeDataForDb = StoreDataForDbImpl(aapsLogger, rxBus, repository, sp, uel, dateUtil, config, nsClientSource, virtualPump, uiInteraction) @@ -72,7 +85,7 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() { nsDeviceStatusHandler, nsClientSource, nsIncomingDataProcessor, storeDataForDb ) sut.nsAndroidClient = nsAndroidClient - `when`(mockedProfileFunction.getProfile(anyLong())).thenReturn(validProfile) + Mockito.`when`(mockedProfileFunction.getProfile(anyLong())).thenReturn(validProfile) } @Test @@ -93,13 +106,13 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() { ) val dataPair = DataSyncSelector.PairDeviceStatus(deviceStatus, 1000) // create - `when`(nsAndroidClient.createDeviceStatus(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) + Mockito.`when`(nsAndroidClient.createDeviceStatus(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) sut.nsAdd("devicestatus", dataPair, "1/3") Assertions.assertEquals(1, storeDataForDb.nsIdDeviceStatuses.size) // update - `when`(nsAndroidClient.createDeviceStatus(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) + Mockito.`when`(nsAndroidClient.createDeviceStatus(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) sut.nsAdd("devicestatus", dataPair, "1/3") - Assertions.assertEquals(2, storeDataForDb.nsIdDeviceStatuses.size) // still only 1 + Assertions.assertEquals(2, storeDataForDb.nsIdDeviceStatuses.size) // still only 1 } @Test @@ -119,11 +132,11 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() { ) val dataPair = DataSyncSelector.PairGlucoseValue(glucoseValue, 1000) // create - `when`(nsAndroidClient.createSgv(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) + Mockito.`when`(nsAndroidClient.createSgv(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) sut.nsAdd("entries", dataPair, "1/3") Assertions.assertEquals(1, storeDataForDb.nsIdGlucoseValues.size) // update - `when`(nsAndroidClient.updateSvg(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) + Mockito.`when`(nsAndroidClient.updateSvg(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) sut.nsUpdate("entries", dataPair, "1/3") Assertions.assertEquals(2, storeDataForDb.nsIdGlucoseValues.size) } @@ -149,11 +162,11 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() { ) val dataPair = DataSyncSelector.PairFood(food, 1000) // create - `when`(nsAndroidClient.createFood(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) + Mockito.`when`(nsAndroidClient.createFood(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) sut.nsAdd("food", dataPair, "1/3") Assertions.assertEquals(1, storeDataForDb.nsIdFoods.size) // update - `when`(nsAndroidClient.updateFood(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) + Mockito.`when`(nsAndroidClient.updateFood(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) sut.nsUpdate("food", dataPair, "1/3") Assertions.assertEquals(2, storeDataForDb.nsIdFoods.size) } @@ -177,11 +190,11 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() { ) val dataPair = DataSyncSelector.PairBolus(bolus, 1000) // create - `when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) + Mockito.`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) sut.nsAdd("treatments", dataPair, "1/3") Assertions.assertEquals(1, storeDataForDb.nsIdBoluses.size) // update - `when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) + Mockito.`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) sut.nsUpdate("treatments", dataPair, "1/3") Assertions.assertEquals(2, storeDataForDb.nsIdBoluses.size) } @@ -204,11 +217,11 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() { ) val dataPair = DataSyncSelector.PairCarbs(carbs, 1000) // create - `when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) + Mockito.`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) sut.nsAdd("treatments", dataPair, "1/3") Assertions.assertEquals(1, storeDataForDb.nsIdCarbs.size) // update - `when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) + Mockito.`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) sut.nsUpdate("treatments", dataPair, "1/3") Assertions.assertEquals(2, storeDataForDb.nsIdCarbs.size) } @@ -257,11 +270,11 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() { ) val dataPair = DataSyncSelector.PairBolusCalculatorResult(bolus, 1000) // create - `when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) + Mockito.`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) sut.nsAdd("treatments", dataPair, "1/3") Assertions.assertEquals(1, storeDataForDb.nsIdBolusCalculatorResults.size) // update - `when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) + Mockito.`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) sut.nsUpdate("treatments", dataPair, "1/3") Assertions.assertEquals(2, storeDataForDb.nsIdBolusCalculatorResults.size) } @@ -295,11 +308,11 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() { ) val dataPair = DataSyncSelector.PairEffectiveProfileSwitch(profileSwitch, 1000) // create - `when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) + Mockito.`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) sut.nsAdd("treatments", dataPair, "1/3") Assertions.assertEquals(1, storeDataForDb.nsIdEffectiveProfileSwitches.size) // update - `when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) + Mockito.`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) sut.nsUpdate("treatments", dataPair, "1/3") Assertions.assertEquals(2, storeDataForDb.nsIdEffectiveProfileSwitches.size) } @@ -331,11 +344,11 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() { ) val dataPair = DataSyncSelector.PairProfileSwitch(profileSwitch, 1000) // create - `when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) + Mockito.`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) sut.nsAdd("treatments", dataPair, "1/3") Assertions.assertEquals(1, storeDataForDb.nsIdProfileSwitches.size) // update - `when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) + Mockito.`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) sut.nsUpdate("treatments", dataPair, "1/3") Assertions.assertEquals(2, storeDataForDb.nsIdProfileSwitches.size) } @@ -358,11 +371,11 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() { ) val dataPair = DataSyncSelector.PairExtendedBolus(extendedBolus, 1000) // create - `when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) + Mockito.`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) sut.nsAdd("treatments", dataPair, "1/3", validProfile) Assertions.assertEquals(1, storeDataForDb.nsIdExtendedBoluses.size) // update - `when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) + Mockito.`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) sut.nsUpdate("treatments", dataPair, "1/3", validProfile) Assertions.assertEquals(2, storeDataForDb.nsIdExtendedBoluses.size) } @@ -384,11 +397,11 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() { ) val dataPair = DataSyncSelector.PairOfflineEvent(offlineEvent, 1000) // create - `when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) + Mockito.`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) sut.nsAdd("treatments", dataPair, "1/3") Assertions.assertEquals(1, storeDataForDb.nsIdOfflineEvents.size) // update - `when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) + Mockito.`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) sut.nsUpdate("treatments", dataPair, "1/3") Assertions.assertEquals(2, storeDataForDb.nsIdOfflineEvents.size) } @@ -412,11 +425,11 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() { ) val dataPair = DataSyncSelector.PairTemporaryBasal(temporaryBasal, 1000) // create - `when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) + Mockito.`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) sut.nsAdd("treatments", dataPair, "1/3", validProfile) Assertions.assertEquals(1, storeDataForDb.nsIdTemporaryBasals.size) // update - `when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) + Mockito.`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) sut.nsUpdate("treatments", dataPair, "1/3", validProfile) Assertions.assertEquals(2, storeDataForDb.nsIdTemporaryBasals.size) } @@ -440,11 +453,11 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() { ) val dataPair = DataSyncSelector.PairTemporaryTarget(temporaryTarget, 1000) // create - `when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) + Mockito.`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) sut.nsAdd("treatments", dataPair, "1/3") Assertions.assertEquals(1, storeDataForDb.nsIdTemporaryTargets.size) // update - `when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) + Mockito.`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) sut.nsUpdate("treatments", dataPair, "1/3") Assertions.assertEquals(2, storeDataForDb.nsIdTemporaryTargets.size) } @@ -471,11 +484,11 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() { ) val dataPair = DataSyncSelector.PairTherapyEvent(therapyEvent, 1000) // create - `when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) + Mockito.`when`(nsAndroidClient.createTreatment(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) sut.nsAdd("treatments", dataPair, "1/3") Assertions.assertEquals(1, storeDataForDb.nsIdTherapyEvents.size) // update - `when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) + Mockito.`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) sut.nsUpdate("treatments", dataPair, "1/3") Assertions.assertEquals(2, storeDataForDb.nsIdTherapyEvents.size) } @@ -486,12 +499,12 @@ internal class NSClientV3PluginTest : TestBaseWithProfile() { val dataPair = DataSyncSelector.PairProfileStore(getValidProfileStore().data, 1000) // create - `when`(nsAndroidClient.createProfileStore(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) + Mockito.`when`(nsAndroidClient.createProfileStore(anyObject())).thenReturn(CreateUpdateResponse(201, "aaa")) sut.nsAdd("profile", dataPair, "1/3") // verify(dataSyncSelectorV3, Times(1)).confirmLastProfileStore(1000) // verify(dataSyncSelectorV3, Times(1)).processChangedProfileStore() // update - `when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) + Mockito.`when`(nsAndroidClient.updateTreatment(anyObject())).thenReturn(CreateUpdateResponse(200, "aaa")) sut.nsUpdate("profile", dataPair, "1/3") // verify(dataSyncSelectorV3, Times(2)).confirmLastProfileStore(1000) // verify(dataSyncSelectorV3, Times(2)).processChangedProfileStore() diff --git a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/DeviceStatusExtensionKtTest.kt b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/DeviceStatusExtensionKtTest.kt index 431796008d3..6f536526f2e 100644 --- a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/DeviceStatusExtensionKtTest.kt +++ b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/DeviceStatusExtensionKtTest.kt @@ -1,24 +1,17 @@ package info.nightscout.plugins.sync.nsclientV3.extensions -import dagger.android.AndroidInjector -import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.TestBase import info.nightscout.database.entities.DeviceStatus import info.nightscout.interfaces.Config import info.nightscout.interfaces.configBuilder.RunningConfiguration -import info.nightscout.interfaces.constraints.Constraints -import info.nightscout.interfaces.iob.IobCobCalculator import info.nightscout.interfaces.nsclient.ProcessedDeviceStatusData -import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.profile.Instantiator -import info.nightscout.interfaces.profile.ProfileFunction -import info.nightscout.plugins.aps.APSResultObject import info.nightscout.plugins.sync.nsclient.data.NSDeviceStatusHandler import info.nightscout.plugins.sync.nsclient.data.ProcessedDeviceStatusDataImpl import info.nightscout.sdk.mapper.convertToRemoteAndBack import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.utils.DateUtil +import info.nightscout.sharedtests.TestBase import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -27,11 +20,7 @@ import org.mockito.Mock @Suppress("SpellCheckingInspection") internal class DeviceStatusExtensionKtTest : TestBase() { - @Mock lateinit var constraintChecker: Constraints @Mock lateinit var sp: SP - @Mock lateinit var activePlugin: ActivePlugin - @Mock lateinit var iobCobCalculator: IobCobCalculator - @Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var rh: ResourceHelper @Mock lateinit var dateUtil: DateUtil @Mock lateinit var config: Config @@ -41,21 +30,6 @@ internal class DeviceStatusExtensionKtTest : TestBase() { private lateinit var processedDeviceStatusData: ProcessedDeviceStatusData private lateinit var nsDeviceStatusHandler: NSDeviceStatusHandler - val injector = HasAndroidInjector { - AndroidInjector { - if (it is APSResultObject) { - it.aapsLogger = aapsLogger - it.constraintChecker = constraintChecker - it.sp = sp - it.activePlugin = activePlugin - it.iobCobCalculator = iobCobCalculator - it.profileFunction = profileFunction - it.rh = rh - it.dateUtil = dateUtil - } - } - } - @BeforeEach fun setup() { processedDeviceStatusData = ProcessedDeviceStatusDataImpl(rh, dateUtil, sp, instantiator) diff --git a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/EffectiveProfileSwitchExtensionKtTest.kt b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/EffectiveProfileSwitchExtensionKtTest.kt index c8c5ec66607..1e464938fe8 100644 --- a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/EffectiveProfileSwitchExtensionKtTest.kt +++ b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/EffectiveProfileSwitchExtensionKtTest.kt @@ -1,17 +1,31 @@ package info.nightscout.plugins.sync.nsclientV3.extensions -import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.database.entities.EffectiveProfileSwitch +import info.nightscout.database.entities.embedments.InsulinConfiguration import info.nightscout.database.entities.embedments.InterfaceIDs +import info.nightscout.interfaces.insulin.Insulin import info.nightscout.plugins.sync.nsclient.extensions.fromConstant import info.nightscout.sdk.localmodel.treatment.NSEffectiveProfileSwitch import info.nightscout.sdk.mapper.convertToRemoteAndBack +import info.nightscout.sharedtests.TestBaseWithProfile import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test +import org.mockito.Mock +import org.mockito.Mockito @Suppress("SpellCheckingInspection") internal class EffectiveProfileSwitchExtensionKtTest : TestBaseWithProfile() { + @Mock lateinit var insulin: Insulin + + private var insulinConfiguration: InsulinConfiguration = InsulinConfiguration("Insulin", 360 * 60 * 1000, 60 * 60 * 1000) + + @BeforeEach + fun mock() { + Mockito.`when`(insulin.insulinConfiguration).thenReturn(insulinConfiguration) + Mockito.`when`(activePlugin.activeInsulin).thenReturn(insulin) + } @Test fun toEffectiveProfileSwitch() { val profileSwitch = EffectiveProfileSwitch( diff --git a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/ExtendedBolusExtensionKtTest.kt b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/ExtendedBolusExtensionKtTest.kt index 57e6a7df8ef..47855ffdc43 100644 --- a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/ExtendedBolusExtensionKtTest.kt +++ b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/ExtendedBolusExtensionKtTest.kt @@ -1,11 +1,11 @@ package info.nightscout.plugins.sync.nsclientV3.extensions -import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.database.entities.ExtendedBolus import info.nightscout.database.entities.embedments.InterfaceIDs import info.nightscout.sdk.localmodel.treatment.NSExtendedBolus import info.nightscout.sdk.localmodel.treatment.NSTemporaryBasal import info.nightscout.sdk.mapper.convertToRemoteAndBack +import info.nightscout.sharedtests.TestBaseWithProfile import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test diff --git a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/GlucoseValueExtensionKtTest.kt b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/GlucoseValueExtensionKtTest.kt index 2d2d8ef0964..ad44d2463a9 100644 --- a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/GlucoseValueExtensionKtTest.kt +++ b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/GlucoseValueExtensionKtTest.kt @@ -1,13 +1,12 @@ package info.nightscout.plugins.sync.nsclientV3.extensions -import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.database.entities.GlucoseValue import info.nightscout.database.entities.embedments.InterfaceIDs import info.nightscout.sdk.mapper.convertToRemoteAndBack +import info.nightscout.sharedtests.TestBaseWithProfile import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test -@Suppress("SpellCheckingInspection") internal class GlucoseValueExtensionKtTest : TestBaseWithProfile() { @Test @@ -25,7 +24,7 @@ internal class GlucoseValueExtensionKtTest : TestBaseWithProfile() { ) ) - var glucoseValue2 = glucoseValue.toNSSvgV3().convertToRemoteAndBack()?.toTransactionGlucoseValue()?.toGlucoseValue() + val glucoseValue2 = glucoseValue.toNSSvgV3().convertToRemoteAndBack()?.toTransactionGlucoseValue()?.toGlucoseValue() Assertions.assertTrue(glucoseValue.contentEqualsTo(glucoseValue2!!)) Assertions.assertTrue(glucoseValue.interfaceIdsEqualsTo(glucoseValue2)) } diff --git a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/ProfileSwitchExtensionKtTest.kt b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/ProfileSwitchExtensionKtTest.kt index 839a5123437..562a5d57e93 100644 --- a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/ProfileSwitchExtensionKtTest.kt +++ b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/ProfileSwitchExtensionKtTest.kt @@ -1,17 +1,31 @@ package info.nightscout.plugins.sync.nsclientV3.extensions -import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.core.extensions.fromConstant import info.nightscout.database.entities.ProfileSwitch +import info.nightscout.database.entities.embedments.InsulinConfiguration import info.nightscout.database.entities.embedments.InterfaceIDs +import info.nightscout.interfaces.insulin.Insulin import info.nightscout.sdk.localmodel.treatment.NSProfileSwitch import info.nightscout.sdk.mapper.convertToRemoteAndBack +import info.nightscout.sharedtests.TestBaseWithProfile import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test +import org.mockito.Mock +import org.mockito.Mockito @Suppress("SpellCheckingInspection") internal class ProfileSwitchExtensionKtTest : TestBaseWithProfile() { + @Mock lateinit var insulin: Insulin + + private var insulinConfiguration: InsulinConfiguration = InsulinConfiguration("Insulin", 360 * 60 * 1000, 60 * 60 * 1000) + + @BeforeEach + fun mock() { + Mockito.`when`(insulin.insulinConfiguration).thenReturn(insulinConfiguration) + Mockito.`when`(activePlugin.activeInsulin).thenReturn(insulin) + } @Test fun toProfileSwitch() { var profileSwitch = ProfileSwitch( diff --git a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/TemporaryBasalExtensionKtTest.kt b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/TemporaryBasalExtensionKtTest.kt index 9b4ed52fffb..758f31dbc7d 100644 --- a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/TemporaryBasalExtensionKtTest.kt +++ b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/TemporaryBasalExtensionKtTest.kt @@ -1,10 +1,10 @@ package info.nightscout.plugins.sync.nsclientV3.extensions -import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.database.entities.TemporaryBasal import info.nightscout.database.entities.embedments.InterfaceIDs import info.nightscout.sdk.localmodel.treatment.NSTemporaryBasal import info.nightscout.sdk.mapper.convertToRemoteAndBack +import info.nightscout.sharedtests.TestBaseWithProfile import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test diff --git a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/TemporaryTargetExtensionKtTest.kt b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/TemporaryTargetExtensionKtTest.kt index a9b3f7be5da..3079a0241e4 100644 --- a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/TemporaryTargetExtensionKtTest.kt +++ b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/TemporaryTargetExtensionKtTest.kt @@ -1,10 +1,10 @@ package info.nightscout.plugins.sync.nsclientV3.extensions -import info.nightscout.androidaps.TestBaseWithProfile import info.nightscout.database.entities.TemporaryTarget import info.nightscout.database.entities.embedments.InterfaceIDs import info.nightscout.sdk.localmodel.treatment.NSTemporaryTarget import info.nightscout.sdk.mapper.convertToRemoteAndBack +import info.nightscout.sharedtests.TestBaseWithProfile import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test diff --git a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/TherapyEventExtensionKtTest.kt b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/TherapyEventExtensionKtTest.kt index ae8bfa6d80d..aefa5bac9ea 100644 --- a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/TherapyEventExtensionKtTest.kt +++ b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/extensions/TherapyEventExtensionKtTest.kt @@ -1,11 +1,10 @@ package info.nightscout.plugins.sync.nsclientV3.extensions -import info.nightscout.androidaps.TestBaseWithProfile -import info.nightscout.database.entities.TemporaryTarget import info.nightscout.database.entities.TherapyEvent import info.nightscout.database.entities.embedments.InterfaceIDs import info.nightscout.sdk.localmodel.treatment.NSTherapyEvent import info.nightscout.sdk.mapper.convertToRemoteAndBack +import info.nightscout.sharedtests.TestBaseWithProfile import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test diff --git a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/workers/DataSyncWorkerTest.kt b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/workers/DataSyncWorkerTest.kt index bcb9dcd5f83..18eab903ec9 100644 --- a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/workers/DataSyncWorkerTest.kt +++ b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/workers/DataSyncWorkerTest.kt @@ -1,16 +1,17 @@ package info.nightscout.plugins.sync.nsclientV3.workers +import android.content.Context import androidx.work.ListenableWorker.Result.Success import androidx.work.testing.TestListenableWorkerBuilder import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.TestBase import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.interfaces.plugin.ActivePlugin import info.nightscout.interfaces.sync.NsClient import info.nightscout.plugins.sync.nsclientV3.DataSyncSelectorV3 import info.nightscout.plugins.sync.nsclientV3.NSClientV3Plugin import info.nightscout.rx.bus.RxBus +import info.nightscout.sharedtests.TestBase import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Assertions @@ -23,12 +24,15 @@ import org.mockito.Mockito.`when` @ExperimentalCoroutinesApi internal class DataSyncWorkerTest : TestBase() { + abstract class ContextWithInjector : Context(), HasAndroidInjector + @Mock lateinit var fabricPrivacy: FabricPrivacy @Mock lateinit var dataSyncSelectorV3: DataSyncSelectorV3 @Mock lateinit var activePlugin: ActivePlugin @Mock lateinit var nsClient: NsClient @Mock lateinit var rxBus: RxBus @Mock lateinit var nsClientV3Plugin: NSClientV3Plugin + @Mock lateinit var context: ContextWithInjector private lateinit var sut: DataSyncWorker diff --git a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadBgWorkerTest.kt b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadBgWorkerTest.kt index 67c1314bf23..3c3b2fccede 100644 --- a/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadBgWorkerTest.kt +++ b/plugins/sync/src/test/java/info/nightscout/plugins/sync/nsclientV3/workers/LoadBgWorkerTest.kt @@ -1,5 +1,6 @@ package info.nightscout.plugins.sync.nsclientV3.workers +import android.content.Context import androidx.work.ListenableWorker import androidx.work.OneTimeWorkRequest import androidx.work.WorkContinuation @@ -7,7 +8,6 @@ import androidx.work.WorkManager import androidx.work.testing.TestListenableWorkerBuilder import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.TestBase import info.nightscout.core.utils.fabric.FabricPrivacy import info.nightscout.core.utils.receivers.DataWorkerStorage import info.nightscout.database.entities.GlucoseValue @@ -30,6 +30,7 @@ import info.nightscout.sdk.remotemodel.LastModified import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP import info.nightscout.shared.utils.DateUtil +import info.nightscout.sharedtests.TestBase import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach @@ -43,6 +44,8 @@ import org.mockito.Mockito internal class LoadBgWorkerTest : TestBase() { + abstract class ContextWithInjector : Context(), HasAndroidInjector + @Mock lateinit var sp: SP @Mock lateinit var fabricPrivacy: FabricPrivacy @Mock lateinit var dateUtil: DateUtil @@ -59,6 +62,7 @@ internal class LoadBgWorkerTest : TestBase() { @Mock lateinit var nsDeviceStatusHandler: NSDeviceStatusHandler @Mock lateinit var storeDataForDb: StoreDataForDb @Mock lateinit var nsIncomingDataProcessor: NsIncomingDataProcessor + @Mock lateinit var context: ContextWithInjector private val rxBus: RxBus = RxBus(aapsSchedulers, aapsLogger) private lateinit var nsClientV3Plugin: NSClientV3Plugin @@ -162,7 +166,6 @@ internal class LoadBgWorkerTest : TestBase() { Assertions.assertTrue(result is ListenableWorker.Result.Success) } - @Test fun testNoLoadNeeded() = runTest { Mockito.`when`(workManager.beginUniqueWork(anyString(), any(), any())).thenReturn(workContinuation) diff --git a/plugins/sync/src/test/java/info/nightscout/plugins/sync/tidepool/comm/SessionTest.kt b/plugins/sync/src/test/java/info/nightscout/plugins/sync/tidepool/comm/SessionTest.kt index 95046acef19..03c6a53e5b5 100644 --- a/plugins/sync/src/test/java/info/nightscout/plugins/sync/tidepool/comm/SessionTest.kt +++ b/plugins/sync/src/test/java/info/nightscout/plugins/sync/tidepool/comm/SessionTest.kt @@ -2,8 +2,7 @@ package info.nightscout.plugins.sync.tidepool.comm import info.nightscout.plugins.sync.tidepool.messages.AuthReplyMessage import info.nightscout.plugins.sync.tidepool.messages.DatasetReplyMessage -import org.junit.Assert.assertEquals -import org.junit.Assert.assertNull +import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test class SessionTest { @@ -11,25 +10,23 @@ class SessionTest { @Test fun populateBody() { val session = Session("", "", null) - assertNull(session.authReply) + Assertions.assertNull(session.authReply) // test authReply val authReplyMessage = AuthReplyMessage() session.populateBody(authReplyMessage) - assertEquals(authReplyMessage, session.authReply) + Assertions.assertEquals(authReplyMessage, session.authReply) // test datasetReply val datasetReplyMessage = DatasetReplyMessage() - assertNull(session.datasetReply) + Assertions.assertNull(session.datasetReply) session.populateBody(datasetReplyMessage) - assertEquals(datasetReplyMessage, session.datasetReply) + Assertions.assertEquals(datasetReplyMessage, session.datasetReply) // test datasetReply as array val list: List = listOf(datasetReplyMessage) session.datasetReply = null - assertNull(session.datasetReply) session.populateBody(list) - assertEquals(datasetReplyMessage, session.datasetReply) - + Assertions.assertEquals(datasetReplyMessage, session.datasetReply) } } \ No newline at end of file