diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.kt index cfabe73346..32fa6abf91 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPlugin.kt @@ -186,10 +186,10 @@ class SafetyPlugin @Inject constructor( override fun applyMaxIOBConstraints(maxIob: Constraint): Constraint { val apsMode = sp.getString(R.string.key_aps_mode, "open") - val maxIobPref: Double = if (openAPSSMBPlugin.isEnabled(PluginType.APS)) sp.getDouble(R.string.key_openapssmb_max_iob, 3.0) else sp.getDouble(R.string.key_openapsma_max_iob, 1.5) + val maxIobPref: Double = if (openAPSSMBPlugin.isEnabled()) sp.getDouble(R.string.key_openapssmb_max_iob, 3.0) else sp.getDouble(R.string.key_openapsma_max_iob, 1.5) maxIob.setIfSmaller(aapsLogger, maxIobPref, String.format(resourceHelper.gs(R.string.limitingiob), maxIobPref, resourceHelper.gs(R.string.maxvalueinpreferences)), this) - if (openAPSAMAPlugin.isEnabled(PluginType.APS)) maxIob.setIfSmaller(aapsLogger, hardLimits.maxIobAMA(), String.format(resourceHelper.gs(R.string.limitingiob), hardLimits.maxIobAMA(), resourceHelper.gs(R.string.hardlimit)), this) - if (openAPSSMBPlugin.isEnabled(PluginType.APS)) maxIob.setIfSmaller(aapsLogger, hardLimits.maxIobSMB(), String.format(resourceHelper.gs(R.string.limitingiob), hardLimits.maxIobSMB(), resourceHelper.gs(R.string.hardlimit)), this) + if (openAPSAMAPlugin.isEnabled()) maxIob.setIfSmaller(aapsLogger, hardLimits.maxIobAMA(), String.format(resourceHelper.gs(R.string.limitingiob), hardLimits.maxIobAMA(), resourceHelper.gs(R.string.hardlimit)), this) + if (openAPSSMBPlugin.isEnabled()) maxIob.setIfSmaller(aapsLogger, hardLimits.maxIobSMB(), String.format(resourceHelper.gs(R.string.limitingiob), hardLimits.maxIobSMB(), resourceHelper.gs(R.string.hardlimit)), this) if (apsMode == "lgs") maxIob.setIfSmaller(aapsLogger, HardLimits.MAX_IOB_LGS, String.format(resourceHelper.gs(R.string.limitingiob), HardLimits.MAX_IOB_LGS, resourceHelper.gs(R.string.lowglucosesuspend)), this) return maxIob } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/LoggerUtils.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/LoggerUtils.kt index e6ce7fb821..63bf4a5724 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/LoggerUtils.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/LoggerUtils.kt @@ -1,6 +1,7 @@ package info.nightscout.androidaps.plugins.general.maintenance import ch.qos.logback.classic.LoggerContext +import info.nightscout.androidaps.annotations.OpenForTesting import org.slf4j.LoggerFactory import javax.inject.Inject import javax.inject.Singleton @@ -8,6 +9,7 @@ import javax.inject.Singleton /** * This class provides several methods for log-handling (eg. sending logs as emails). */ +@OpenForTesting @Singleton class LoggerUtils @Inject constructor() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSSettingsStatus.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSSettingsStatus.kt index 7efeb7c466..43e68ec743 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSSettingsStatus.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSSettingsStatus.kt @@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.general.nsclient.data import android.content.Context import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.R +import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.database.entities.UserEntry import info.nightscout.androidaps.database.entities.UserEntry.Action import info.nightscout.androidaps.logging.AAPSLogger @@ -113,6 +114,7 @@ import javax.inject.Singleton } */ @Suppress("SpellCheckingInspection") +@OpenForTesting @Singleton class NSSettingsStatus @Inject constructor( private val aapsLogger: AAPSLogger, diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt index f78d83b4e2..6615448602 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt @@ -13,6 +13,7 @@ import androidx.work.workDataOf import dagger.android.HasAndroidInjector import info.nightscout.androidaps.Constants import info.nightscout.androidaps.R +import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.entities.OfflineEvent @@ -59,6 +60,7 @@ import javax.inject.Singleton import kotlin.math.max import kotlin.math.min +@OpenForTesting @Singleton class SmsCommunicatorPlugin @Inject constructor( injector: HasAndroidInjector, diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/otp/OneTimePassword.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/otp/OneTimePassword.kt index 77470340a1..75235ca487 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/otp/OneTimePassword.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/otp/OneTimePassword.kt @@ -5,6 +5,7 @@ import com.eatthepath.otp.HmacOneTimePasswordGenerator import com.google.common.io.BaseEncoding import info.nightscout.androidaps.Constants import info.nightscout.androidaps.R +import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP @@ -15,6 +16,7 @@ import javax.crypto.spec.SecretKeySpec import javax.inject.Inject import javax.inject.Singleton +@OpenForTesting @Singleton class OneTimePassword @Inject constructor( private val sp: SP, diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt index 5929d53b77..94d907973a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfilePlugin.kt @@ -8,6 +8,7 @@ import androidx.work.workDataOf import dagger.android.HasAndroidInjector import info.nightscout.androidaps.Constants import info.nightscout.androidaps.R +import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.data.ProfileSealed import info.nightscout.androidaps.data.PureProfile import info.nightscout.androidaps.events.EventProfileStoreChanged @@ -35,6 +36,7 @@ import javax.inject.Inject import javax.inject.Singleton import kotlin.collections.ArrayList +@OpenForTesting @Singleton class LocalProfilePlugin @Inject constructor( injector: HasAndroidInjector, diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/source/GlimpPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/source/GlimpPlugin.kt index d2b167a43d..a6e0f24821 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/source/GlimpPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/source/GlimpPlugin.kt @@ -6,6 +6,7 @@ import androidx.work.WorkerParameters import androidx.work.workDataOf import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R +import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.entities.GlucoseValue import info.nightscout.androidaps.database.transactions.CgmSourceTransaction @@ -21,6 +22,7 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP import javax.inject.Inject import javax.inject.Singleton +@OpenForTesting @Singleton class GlimpPlugin @Inject constructor( injector: HasAndroidInjector, diff --git a/app/src/main/java/info/nightscout/androidaps/utils/Profiler.kt b/app/src/main/java/info/nightscout/androidaps/utils/Profiler.kt index b3ac2bbe94..b5a5ba1697 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/Profiler.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/Profiler.kt @@ -1,10 +1,12 @@ package info.nightscout.androidaps.utils +import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag import javax.inject.Inject import javax.inject.Singleton +@OpenForTesting @Singleton class Profiler @Inject constructor(val aapsLogger: AAPSLogger) { diff --git a/app/src/main/java/info/nightscout/androidaps/utils/XdripCalibrations.kt b/app/src/main/java/info/nightscout/androidaps/utils/XdripCalibrations.kt index bc7d5ff479..133a03187a 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/XdripCalibrations.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/XdripCalibrations.kt @@ -4,6 +4,7 @@ import android.content.Context import android.content.Intent import android.os.Bundle import info.nightscout.androidaps.R +import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.interfaces.GlucoseUnit import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.logging.AAPSLogger @@ -12,6 +13,7 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper import javax.inject.Inject import javax.inject.Singleton +@OpenForTesting @Singleton class XdripCalibrations @Inject constructor( private val aapsLogger: AAPSLogger, diff --git a/app/src/main/java/info/nightscout/androidaps/utils/buildHelper/BuildHelper.kt b/app/src/main/java/info/nightscout/androidaps/utils/buildHelper/BuildHelper.kt index 04dbd0d789..a2963c4b77 100644 --- a/app/src/main/java/info/nightscout/androidaps/utils/buildHelper/BuildHelper.kt +++ b/app/src/main/java/info/nightscout/androidaps/utils/buildHelper/BuildHelper.kt @@ -1,12 +1,14 @@ package info.nightscout.androidaps.utils.buildHelper import info.nightscout.androidaps.BuildConfig +import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.plugins.general.maintenance.PrefFileListProvider import java.io.File import javax.inject.Inject import javax.inject.Singleton +@OpenForTesting @Singleton class BuildHelper @Inject constructor( private val config: Config, diff --git a/app/src/test/java/info/nightscout/androidaps/data/QuickWizardTest.kt b/app/src/test/java/info/nightscout/androidaps/data/QuickWizardTest.kt index 8bd8c49739..61f30ea92e 100644 --- a/app/src/test/java/info/nightscout/androidaps/data/QuickWizardTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/data/QuickWizardTest.kt @@ -15,7 +15,6 @@ import org.junit.Before import org.junit.Test import org.mockito.Mock import org.mockito.Mockito.`when` -import org.powermock.api.mockito.PowerMockito class QuickWizardTest : TestBase() { @@ -44,7 +43,7 @@ class QuickWizardTest : TestBase() { @Before fun mock() { - PowerMockito.`when`(profileFunction.secondsFromMidnight()).thenReturn(0) + `when`(profileFunction.secondsFromMidnight()).thenReturn(0) `when`(sp.getString(R.string.key_quickwizard, "[]")).thenReturn("[]") quickWizard = QuickWizard(sp, injector) } diff --git a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt index 874175a2be..19f7b55364 100644 --- a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt @@ -1,6 +1,5 @@ package info.nightscout.androidaps.interfaces -import android.content.Context import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.R @@ -36,22 +35,13 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.Mockito.`when` -import org.powermock.core.classloader.annotations.PrepareForTest -import org.powermock.modules.junit4.PowerMockRunner import java.util.* /** * Created by mike on 18.03.2018. */ -@RunWith(PowerMockRunner::class) -@PrepareForTest( - ConstraintChecker::class, SP::class, Context::class, - OpenAPSAMAPlugin::class, OpenAPSSMBPlugin::class, - VirtualPumpPlugin::class, DetailedBolusInfoStorage::class, TemporaryBasalStorage::class, GlimpPlugin::class, Profiler::class, - UserEntryLogger::class, PrefFileListProvider::class, AppRepository::class, InsightDatabaseDao::class) class ConstraintsCheckerTest : TestBaseWithProfile() { @Mock lateinit var activePlugin: ActivePlugin @@ -98,7 +88,6 @@ class ConstraintsCheckerTest : TestBaseWithProfile() { fun prepare() { `when`(resourceHelper.gs(R.string.closed_loop_disabled_on_dev_branch)).thenReturn("Running dev version. Closed loop is disabled.") `when`(resourceHelper.gs(R.string.closedmodedisabledinpreferences)).thenReturn("Closed loop mode disabled in preferences") - `when`(resourceHelper.gs(R.string.objectivenotstarted)).thenReturn("Objective %d not started") `when`(resourceHelper.gs(R.string.novalidbasalrate)).thenReturn("No valid basal rate read from pump") `when`(resourceHelper.gs(R.string.autosensdisabledinpreferences)).thenReturn("Autosens disabled in preferences") `when`(resourceHelper.gs(R.string.smbdisabledinpreferences)).thenReturn("SMB disabled in preferences") @@ -125,6 +114,10 @@ class ConstraintsCheckerTest : TestBaseWithProfile() { `when`(resourceHelper.gs(R.string.limitingbasalratio, 0.8, "pump limit")).thenReturn("") `when`(resourceHelper.gs(R.string.limitingpercentrate, 200, "pump limit")).thenReturn("") `when`(resourceHelper.gs(R.string.combo_pump_unsupported_operation)).thenReturn("Requested operation not supported by pump") + `when`(resourceHelper.gs(R.string.objectivenotstarted, 9)).thenReturn("Objective 9 not started") + `when`(resourceHelper.gs(R.string.objectivenotstarted, 8)).thenReturn("Objective 8 not started") + `when`(resourceHelper.gs(R.string.objectivenotstarted, 6)).thenReturn("Objective 6 not started") + `when`(resourceHelper.gs(R.string.objectivenotstarted, 1)).thenReturn("Objective 1 not started") // RS constructor `when`(sp.getString(R.string.key_danars_address, "")).thenReturn("") diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/dstHelper/DstHelperPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/dstHelper/DstHelperPluginTest.kt index da4192d33d..74cb492f49 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/dstHelper/DstHelperPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/dstHelper/DstHelperPluginTest.kt @@ -11,14 +11,11 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mock -import org.powermock.modules.junit4.PowerMockRunner import java.text.DateFormat import java.text.SimpleDateFormat import java.util.* -@RunWith(PowerMockRunner::class) class DstHelperPluginTest : TestBase() { @Mock lateinit var resourceHelper: ResourceHelper diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.kt index c08f4c9033..795a677695 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.kt @@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.constraints.objectives import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.utils.buildHelper.ConfigImpl import info.nightscout.androidaps.R import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.interfaces.ActivePlugin @@ -10,19 +9,15 @@ import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.logging.UserEntryLogger import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.androidaps.utils.buildHelper.ConfigImpl import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.Mockito.`when` -import org.powermock.core.classloader.annotations.PrepareForTest -import org.powermock.modules.junit4.PowerMockRunner -@RunWith(PowerMockRunner::class) -@PrepareForTest(UserEntryLogger::class, DateUtil::class) class ObjectivesPluginTest : TestBase() { @Mock lateinit var resourceHelper: ResourceHelper @@ -46,7 +41,10 @@ class ObjectivesPluginTest : TestBase() { @Before fun prepareMock() { objectivesPlugin = ObjectivesPlugin(injector, aapsLogger, resourceHelper, activePlugin, sp, ConfigImpl(), dateUtil, uel) objectivesPlugin.onStart() - `when`(resourceHelper.gs(R.string.objectivenotstarted)).thenReturn("Objective %1\$d not started") + `when`(resourceHelper.gs(R.string.objectivenotstarted, 9)).thenReturn("Objective 9 not started") + `when`(resourceHelper.gs(R.string.objectivenotstarted, 8)).thenReturn("Objective 8 not started") + `when`(resourceHelper.gs(R.string.objectivenotstarted, 6)).thenReturn("Objective 6 not started") + `when`(resourceHelper.gs(R.string.objectivenotstarted, 1)).thenReturn("Objective 1 not started") } @Test fun notStartedObjectivesShouldLimitLoopInvocation() { @@ -78,7 +76,7 @@ class ObjectivesPluginTest : TestBase() { objectivesPlugin.objectives[ObjectivesPlugin.SMB_OBJECTIVE].startedOn = 0 var c = Constraint(true) c = objectivesPlugin.isSMBModeEnabled(c) - Assert.assertEquals(true, c.getReasons(aapsLogger).contains("Objective 10 not started")) + Assert.assertEquals(true, c.getReasons(aapsLogger).contains("Objective 9 not started")) Assert.assertEquals(false, c.value()) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPluginTest.kt index 209e7d2da6..bc54c57e09 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/safety/SafetyPluginTest.kt @@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.constraints.safety import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.utils.buildHelper.ConfigImpl import info.nightscout.androidaps.Constants import info.nightscout.androidaps.R import info.nightscout.androidaps.TestBaseWithProfile @@ -18,18 +17,14 @@ import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin import info.nightscout.androidaps.plugins.source.GlimpPlugin import info.nightscout.androidaps.utils.HardLimits import info.nightscout.androidaps.utils.buildHelper.BuildHelper +import info.nightscout.androidaps.utils.buildHelper.ConfigImpl import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.Mockito.`when` -import org.powermock.core.classloader.annotations.PrepareForTest -import org.powermock.modules.junit4.PowerMockRunner -@RunWith(PowerMockRunner::class) -@PrepareForTest(ConstraintChecker::class, BuildHelper::class, VirtualPumpPlugin::class, GlimpPlugin::class) class SafetyPluginTest : TestBaseWithProfile() { @Mock lateinit var sp: SP @@ -231,17 +226,18 @@ class SafetyPluginTest : TestBaseWithProfile() { } @Test fun iobShouldBeLimited() { + `when`(openAPSSMBPlugin.isEnabled()).thenReturn(true) + `when`(openAPSAMAPlugin.isEnabled()).thenReturn(false) `when`(sp.getString(R.string.key_aps_mode, "open")).thenReturn("closed") `when`(sp.getDouble(R.string.key_openapsma_max_iob, 1.5)).thenReturn(1.5) + `when`(sp.getDouble(R.string.key_openapssmb_max_iob, 3.0)).thenReturn(3.0) `when`(sp.getString(R.string.key_age, "")).thenReturn("teenage") // Apply all limits var d = Constraint(Constants.REALLYHIGHIOB) d = safetyPlugin.applyMaxIOBConstraints(d) - Assert.assertEquals(1.5, d.value(), 0.01) - Assert.assertEquals(""" - Safety: Limiting IOB to 1.5 U because of max value in preferences - """.trimIndent(), d.getReasons(aapsLogger)) - Assert.assertEquals("Safety: Limiting IOB to 1.5 U because of max value in preferences", d.getMostLimitedReasons(aapsLogger)) + Assert.assertEquals(3.0, d.value(), 0.01) + Assert.assertEquals("Safety: Limiting IOB to 3.0 U because of max value in preferences\nSafety: Limiting IOB to 12.0 U because of hard limit", d.getReasons(aapsLogger)) + Assert.assertEquals("Safety: Limiting IOB to 3.0 U because of max value in preferences", d.getMostLimitedReasons(aapsLogger)) } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/storage/StorageConstraintPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/storage/StorageConstraintPluginTest.kt index 6be468634c..780fc29a0a 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/storage/StorageConstraintPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/storage/StorageConstraintPluginTest.kt @@ -10,14 +10,11 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.Mockito.`when` import org.mockito.Mockito.anyInt import org.mockito.Mockito.anyLong -import org.powermock.modules.junit4.PowerMockRunner -@RunWith(PowerMockRunner::class) class StorageConstraintPluginTest : TestBase() { @Mock lateinit var resourceHelper: ResourceHelper diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePluginTest.kt index 0a8dd8db50..14ab61d104 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/maintenance/MaintenancePluginTest.kt @@ -2,24 +2,19 @@ package info.nightscout.androidaps.plugins.general.maintenance import android.content.Context import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.utils.buildHelper.ConfigImpl import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.plugins.general.nsclient.data.NSSettingsStatus import info.nightscout.androidaps.utils.buildHelper.BuildHelper +import info.nightscout.androidaps.utils.buildHelper.ConfigImpl import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.Mockito.`when` -import org.powermock.core.classloader.annotations.PrepareForTest -import org.powermock.modules.junit4.PowerMockRunner import java.io.File -@RunWith(PowerMockRunner::class) -@PrepareForTest(NSSettingsStatus::class, BuildHelper::class, LoggerUtils::class, PrefFileListProvider::class) class MaintenancePluginTest : TestBase() { @Mock lateinit var injector: HasAndroidInjector diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/nsclient/NsClientReceiverDelegateTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/nsclient/NsClientReceiverDelegateTest.kt index 74751fe5f5..c4ae16c2d7 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/nsclient/NsClientReceiverDelegateTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/nsclient/NsClientReceiverDelegateTest.kt @@ -12,19 +12,13 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith import org.mockito.ArgumentMatchers.anyBoolean import org.mockito.ArgumentMatchers.anyInt import org.mockito.ArgumentMatchers.anyLong import org.mockito.ArgumentMatchers.anyString import org.mockito.Mock import org.mockito.Mockito.`when` -import org.powermock.api.mockito.PowerMockito -import org.powermock.core.classloader.annotations.PrepareForTest -import org.powermock.modules.junit4.PowerMockRunner -@RunWith(PowerMockRunner::class) -@PrepareForTest(SP::class, Context::class) class NsClientReceiverDelegateTest : TestBase() { @Mock lateinit var context: Context @@ -47,7 +41,6 @@ class NsClientReceiverDelegateTest : TestBase() { } @Test fun testCalculateStatusChargingState() { - PowerMockito.mockStatic(SP::class.java) `when`(sp.getBoolean(anyInt(), anyBoolean())).thenReturn(false) var ev = EventChargingState(true, 0) Assert.assertTrue(sut!!.calculateStatus(ev)) @@ -61,7 +54,6 @@ class NsClientReceiverDelegateTest : TestBase() { } @Test fun testCalculateStatusNetworkState() { - PowerMockito.mockStatic(SP::class.java) // wifiOnly = false // allowRoaming = false as well `when`(sp.getBoolean(anyInt(), anyBoolean())).thenReturn(false) diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequestTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequestTest.kt index cf4e9d1b87..228c4aa802 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequestTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequestTest.kt @@ -13,17 +13,12 @@ import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.Mockito.`when` +import org.mockito.Mockito.doAnswer import org.mockito.invocation.InvocationOnMock import org.mockito.stubbing.Answer -import org.powermock.api.mockito.PowerMockito -import org.powermock.core.classloader.annotations.PrepareForTest -import org.powermock.modules.junit4.PowerMockRunner -@RunWith(PowerMockRunner::class) -@PrepareForTest(SmsCommunicatorPlugin::class, DateUtil::class, OneTimePassword::class) class AuthRequestTest : TestBase() { @Mock lateinit var smsCommunicatorPlugin: SmsCommunicatorPlugin @@ -48,7 +43,7 @@ class AuthRequestTest : TestBase() { @Before fun prepareTests() { `when`(resourceHelper.gs(R.string.sms_wrongcode)).thenReturn("Wrong code. Command cancelled.") - PowerMockito.doAnswer(Answer { invocation: InvocationOnMock -> + doAnswer(Answer { invocation: InvocationOnMock -> sentSms = invocation.getArgument(0) null } as Answer<*>).`when`(smsCommunicatorPlugin).sendSMS(anyObject()) @@ -87,11 +82,10 @@ class AuthRequestTest : TestBase() { // test timed out message val now: Long = 10000 - PowerMockito.mockStatic(DateUtil::class.java) - PowerMockito.`when`(dateUtil.now()).thenReturn(now) + `when`(dateUtil.now()).thenReturn(now) authRequest = AuthRequest(injector, requester, "Request text", "ABC", action) actionCalled = false - PowerMockito.`when`(dateUtil.now()).thenReturn(now + T.mins(Constants.SMS_CONFIRM_TIMEOUT).msecs() + 1) + `when`(dateUtil.now()).thenReturn(now + T.mins(Constants.SMS_CONFIRM_TIMEOUT).msecs() + 1) authRequest.action("ABC") Assert.assertFalse(actionCalled) } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsActionTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsActionTest.kt index ba47efe6c9..e0563c27c9 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsActionTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsActionTest.kt @@ -2,10 +2,7 @@ package info.nightscout.androidaps.plugins.general.smsCommunicator import org.junit.Assert import org.junit.Test -import org.junit.runner.RunWith -import org.powermock.modules.junit4.PowerMockRunner -@RunWith(PowerMockRunner::class) class SmsActionTest { var result = "" diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt index a2c6d32a08..b3512e29ce 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.kt @@ -52,6 +52,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner import java.util.* +// Powermock needed to mock SmsManager @RunWith(PowerMockRunner::class) @PrepareForTest( ConstraintChecker::class, FabricPrivacy::class, VirtualPumpPlugin::class, XdripCalibrations::class, @@ -310,7 +311,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { `when`(sp.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true) //LOOP STATUS : disabled - PowerMockito.`when`(loopPlugin.enabled).thenReturn(false) + `when`(loopPlugin.enabled).thenReturn(false) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "LOOP STATUS") smsCommunicatorPlugin.processSms(sms) @@ -318,9 +319,9 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { Assert.assertEquals("Loop is disabled", smsCommunicatorPlugin.messages[1].text) //LOOP STATUS : suspended - PowerMockito.`when`(loopPlugin.minutesToEndOfSuspend()).thenReturn(10) - PowerMockito.`when`(loopPlugin.enabled).thenReturn(true) - PowerMockito.`when`(loopPlugin.isSuspended).thenReturn(true) + `when`(loopPlugin.minutesToEndOfSuspend()).thenReturn(10) + `when`(loopPlugin.enabled).thenReturn(true) + `when`(loopPlugin.isSuspended).thenReturn(true) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "LOOP STATUS") smsCommunicatorPlugin.processSms(sms) @@ -328,8 +329,8 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { Assert.assertEquals("Suspended (10 m)", smsCommunicatorPlugin.messages[1].text) //LOOP STATUS : enabled - PowerMockito.`when`(loopPlugin.enabled).thenReturn(true) - PowerMockito.`when`(loopPlugin.isSuspended).thenReturn(false) + `when`(loopPlugin.enabled).thenReturn(true) + `when`(loopPlugin.isSuspended).thenReturn(false) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "LOOP STATUS") smsCommunicatorPlugin.processSms(sms) @@ -338,7 +339,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { Assert.assertEquals("Loop is enabled", smsCommunicatorPlugin.messages[1].text) //LOOP : wrong format - PowerMockito.`when`(loopPlugin.enabled).thenReturn(true) + `when`(loopPlugin.enabled).thenReturn(true) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "LOOP") smsCommunicatorPlugin.processSms(sms) @@ -347,7 +348,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages[1].text) //LOOP DISABLE : already disabled - PowerMockito.`when`(loopPlugin.enabled).thenReturn(false) + `when`(loopPlugin.enabled).thenReturn(false) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "LOOP DISABLE") smsCommunicatorPlugin.processSms(sms) @@ -357,7 +358,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { //LOOP DISABLE : from enabled hasBeenRun = false - PowerMockito.`when`(loopPlugin.enabled).thenReturn(true) + `when`(loopPlugin.enabled).thenReturn(true) // PowerMockito.doAnswer(Answer { // hasBeenRun = true // null @@ -375,7 +376,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { //Assert.assertTrue(hasBeenRun) //LOOP ENABLE : already enabled - PowerMockito.`when`(loopPlugin.enabled).thenReturn(true) + `when`(loopPlugin.enabled).thenReturn(true) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "LOOP ENABLE") smsCommunicatorPlugin.processSms(sms) @@ -385,7 +386,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { //LOOP ENABLE : from disabled hasBeenRun = false - PowerMockito.`when`(loopPlugin.enabled).thenReturn(false) + `when`(loopPlugin.enabled).thenReturn(false) // PowerMockito.doAnswer(Answer { // hasBeenRun = true // null @@ -479,8 +480,8 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages[1].text) //NSCLIENT RESTART - PowerMockito.`when`(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true) - PowerMockito.`when`(loopPlugin.isSuspended).thenReturn(false) + `when`(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true) + `when`(loopPlugin.isSuspended).thenReturn(false) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "NSCLIENT RESTART") smsCommunicatorPlugin.processSms(sms) @@ -489,8 +490,8 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { Assert.assertTrue(smsCommunicatorPlugin.messages[1].text.contains("NSCLIENT RESTART")) //NSCLIENT BLA BLA - PowerMockito.`when`(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true) - PowerMockito.`when`(loopPlugin.isSuspended).thenReturn(false) + `when`(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true) + `when`(loopPlugin.isSuspended).thenReturn(false) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "NSCLIENT BLA BLA") smsCommunicatorPlugin.processSms(sms) @@ -499,8 +500,8 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages[1].text) //NSCLIENT BLABLA - PowerMockito.`when`(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true) - PowerMockito.`when`(loopPlugin.isSuspended).thenReturn(false) + `when`(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true) + `when`(loopPlugin.isSuspended).thenReturn(false) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "NSCLIENT BLABLA") smsCommunicatorPlugin.processSms(sms) @@ -536,7 +537,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { repository.runTransactionForResult(anyObject>()) ).thenReturn(Single.just(CancelCurrentOfflineEventIfAnyTransaction.TransactionResult().apply { })) - PowerMockito.`when`(loopPlugin.enabled).thenReturn(true) + `when`(loopPlugin.enabled).thenReturn(true) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "PUMP CONNECT") smsCommunicatorPlugin.processSms(sms) @@ -902,7 +903,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { Assert.assertEquals("BOLUS", smsCommunicatorPlugin.messages[0].text) Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages[1].text) `when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(1.0)) - PowerMockito.`when`(dateUtilMocked.now()).thenReturn(1000L) + `when`(dateUtilMocked.now()).thenReturn(1000L) `when`(sp.getLong(R.string.key_smscommunicator_remotebolusmindistance, T.msecs(Constants.remoteBolusMinDistance).mins())).thenReturn(15L) //BOLUS 1 smsCommunicatorPlugin.messages = ArrayList() @@ -911,7 +912,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.messages[0].text) Assert.assertEquals("Remote bolus not available. Try again later.", smsCommunicatorPlugin.messages[1].text) `when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0)) - PowerMockito.`when`(dateUtilMocked.now()).thenReturn(Constants.remoteBolusMinDistance + 1002L) + `when`(dateUtilMocked.now()).thenReturn(Constants.remoteBolusMinDistance + 1002L) //BOLUS 0 smsCommunicatorPlugin.messages = ArrayList() @@ -942,13 +943,13 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { //BOLUS 1 (Suspended pump) smsCommunicatorPlugin.lastRemoteBolusTime = 0 - PowerMockito.`when`(virtualPumpPlugin.isSuspended()).thenReturn(true) + `when`(virtualPumpPlugin.isSuspended()).thenReturn(true) smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "BOLUS 1") smsCommunicatorPlugin.processSms(sms) Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.messages[0].text) Assert.assertEquals("Pump suspended", smsCommunicatorPlugin.messages[1].text) - PowerMockito.`when`(virtualPumpPlugin.isSuspended()).thenReturn(false) + `when`(virtualPumpPlugin.isSuspended()).thenReturn(false) //BOLUS 1 a smsCommunicatorPlugin.messages = ArrayList() @@ -993,7 +994,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { smsCommunicatorPlugin.processSms(sms) Assert.assertEquals("CAL 0", smsCommunicatorPlugin.messages[0].text) Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages[1].text) - PowerMockito.`when`(xdripCalibrations.sendIntent(ArgumentMatchers.anyDouble())).thenReturn(true) + `when`(xdripCalibrations.sendIntent(ArgumentMatchers.anyDouble())).thenReturn(true) //CAL 1 smsCommunicatorPlugin.messages = ArrayList() sms = Sms("1234", "CAL 1") @@ -1007,7 +1008,7 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() { } @Test fun processCarbsTest() { - PowerMockito.`when`(dateUtilMocked.now()).thenReturn(1000000L) + `when`(dateUtilMocked.now()).thenReturn(1000000L) `when`(sp.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(false) //CAL smsCommunicatorPlugin.messages = ArrayList() diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsTest.kt index 8224865402..608314af3d 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsTest.kt @@ -4,13 +4,8 @@ import android.telephony.SmsMessage import info.nightscout.androidaps.TestBase import org.junit.Assert import org.junit.Test -import org.junit.runner.RunWith import org.powermock.api.mockito.PowerMockito -import org.powermock.core.classloader.annotations.PrepareForTest -import org.powermock.modules.junit4.PowerMockRunner -@RunWith(PowerMockRunner::class) -@PrepareForTest(SmsMessage::class) class SmsTest : TestBase() { @Test fun doTests() { diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPluginUTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPluginUTest.kt index 53b4bc6086..3cae396031 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPluginUTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/virtual/VirtualPumpPluginUTest.kt @@ -1,7 +1,6 @@ package info.nightscout.androidaps.plugins.pump.virtual import dagger.android.AndroidInjector -import info.nightscout.androidaps.utils.buildHelper.ConfigImpl import info.nightscout.androidaps.R import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.interfaces.CommandQueueProvider @@ -12,19 +11,15 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.pump.common.defs.PumpType import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.FabricPrivacy +import info.nightscout.androidaps.utils.buildHelper.ConfigImpl import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mock -import org.powermock.api.mockito.PowerMockito -import org.powermock.core.classloader.annotations.PrepareForTest -import org.powermock.modules.junit4.PowerMockRunner +import org.mockito.Mockito.`when` -@RunWith(PowerMockRunner::class) -@PrepareForTest(FabricPrivacy::class, DateUtil::class) class VirtualPumpPluginUTest : TestBase() { private val rxBus = RxBusWrapper(aapsSchedulers) @@ -46,16 +41,16 @@ class VirtualPumpPluginUTest : TestBase() { @Test fun refreshConfiguration() { - PowerMockito.`when`(sp.getString(R.string.key_virtualpump_type, "Generic AAPS")).thenReturn("Accu-Chek Combo") + `when`(sp.getString(R.string.key_virtualpump_type, "Generic AAPS")).thenReturn("Accu-Chek Combo") virtualPumpPlugin.refreshConfiguration() Assert.assertEquals(PumpType.ACCU_CHEK_COMBO, virtualPumpPlugin.pumpType) } @Test fun refreshConfigurationTwice() { - PowerMockito.`when`(sp.getString(R.string.key_virtualpump_type, "Generic AAPS")).thenReturn("Accu-Chek Combo") + `when`(sp.getString(R.string.key_virtualpump_type, "Generic AAPS")).thenReturn("Accu-Chek Combo") virtualPumpPlugin.refreshConfiguration() - PowerMockito.`when`(sp.getString(R.string.key_virtualpump_type, "Generic AAPS")).thenReturn("Accu-Chek Combo") + `when`(sp.getString(R.string.key_virtualpump_type, "Generic AAPS")).thenReturn("Accu-Chek Combo") virtualPumpPlugin.refreshConfiguration() Assert.assertEquals(PumpType.ACCU_CHEK_COMBO, virtualPumpPlugin.pumpType) } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/source/XdripPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/source/XdripPluginTest.kt index ed1dc9c91d..8b49149b3d 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/source/XdripPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/source/XdripPluginTest.kt @@ -3,16 +3,12 @@ package info.nightscout.androidaps.plugins.source import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector import info.nightscout.androidaps.TestBase -import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.utils.resources.ResourceHelper import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mock -import org.powermock.modules.junit4.PowerMockRunner -@RunWith(PowerMockRunner::class) class XdripPluginTest : TestBase() { private lateinit var xdripPlugin: XdripPlugin diff --git a/automation/build.gradle b/automation/build.gradle index e3b5a31fa9..5e06a3e587 100644 --- a/automation/build.gradle +++ b/automation/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' +apply plugin: 'kotlin-allopen' apply plugin: 'com.hiya.jacoco-android' apply from: "${project.rootDir}/gradle/android_dependencies.gradle" diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt index e730cd61a7..6fa4f2c439 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationPlugin.kt @@ -5,6 +5,7 @@ import android.os.Handler import android.os.HandlerThread import android.os.SystemClock import dagger.android.HasAndroidInjector +import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.events.* import info.nightscout.androidaps.interfaces.Config @@ -38,6 +39,7 @@ import javax.inject.Inject import javax.inject.Singleton import kotlin.collections.ArrayList +@OpenForTesting @Singleton class AutomationPlugin @Inject constructor( injector: HasAndroidInjector, diff --git a/automation/src/main/java/info/nightscout/androidaps/services/LastLocationDataContainer.kt b/automation/src/main/java/info/nightscout/androidaps/services/LastLocationDataContainer.kt index f546abb8cf..aa184ade9c 100644 --- a/automation/src/main/java/info/nightscout/androidaps/services/LastLocationDataContainer.kt +++ b/automation/src/main/java/info/nightscout/androidaps/services/LastLocationDataContainer.kt @@ -1,13 +1,11 @@ package info.nightscout.androidaps.services import android.location.Location +import info.nightscout.androidaps.annotations.OpenForTesting import javax.inject.Inject import javax.inject.Singleton -/** - * Created by adrian on 2020-01-06. - */ - +@OpenForTesting @Singleton class LastLocationDataContainer @Inject constructor() { var lastLocation: Location? = null diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResumeTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResumeTest.kt index 598fc9628c..e630a0df01 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResumeTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionLoopResumeTest.kt @@ -9,11 +9,8 @@ import io.reactivex.Single import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.`when` -import org.powermock.modules.junit4.PowerMockRunner -@RunWith(PowerMockRunner::class) class ActionLoopResumeTest : ActionsTestBase() { lateinit var sut: ActionLoopResume diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotificationTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotificationTest.kt index 72a50156b8..d48c9683a1 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotificationTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/actions/ActionNotificationTest.kt @@ -6,23 +6,26 @@ import info.nightscout.androidaps.TestBase import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.data.PumpEnactResult import info.nightscout.androidaps.database.AppRepository +import info.nightscout.androidaps.database.transactions.CancelCurrentTemporaryTargetIfAnyTransaction +import info.nightscout.androidaps.database.transactions.InsertAndCancelCurrentTemporaryTargetTransaction +import info.nightscout.androidaps.database.transactions.InsertTherapyEventAnnouncementTransaction +import info.nightscout.androidaps.database.transactions.Transaction import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.automation.elements.InputString import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.utils.resources.ResourceHelper +import io.reactivex.Completable +import io.reactivex.Single import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith import org.mockito.ArgumentMatchers import org.mockito.Mock import org.mockito.Mockito import org.mockito.Mockito.`when` -import org.powermock.core.classloader.annotations.PrepareForTest -import org.powermock.modules.junit4.PowerMockRunner +import org.mockito.Mockito.any +import org.mockito.Mockito.doNothing -@RunWith(PowerMockRunner::class) -@PrepareForTest(RxBusWrapper::class) class ActionNotificationTest : TestBase() { @Mock lateinit var resourceHelper: ResourceHelper @@ -47,7 +50,14 @@ class ActionNotificationTest : TestBase() { fun setup() { `when`(resourceHelper.gs(R.string.ok)).thenReturn("OK") `when`(resourceHelper.gs(R.string.notification)).thenReturn("Notification") - `when`(resourceHelper.gs(ArgumentMatchers.eq(R.string.notification_message), ArgumentMatchers.anyString())).thenReturn("Notification: %s") + `when`( + resourceHelper.gs( + ArgumentMatchers.eq(R.string.notification_message), + ArgumentMatchers.anyString() + ) + ).thenReturn("Notification: %s") + `when`(repository.runTransaction(anyObject>())) + .thenReturn(Completable.fromAction {}) sut = ActionNotification(injector) } @@ -81,7 +91,10 @@ class ActionNotificationTest : TestBase() { @Test fun toJSONTest() { sut.text = InputString("Asd") - Assert.assertEquals("{\"data\":{\"text\":\"Asd\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionNotification\"}", sut.toJSON()) + Assert.assertEquals( + "{\"data\":{\"text\":\"Asd\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionNotification\"}", + sut.toJSON() + ) } @Test fun fromJSONTest() { diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorConnectTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorConnectTest.kt index 16db4a10c7..0842c232d8 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorConnectTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorConnectTest.kt @@ -3,10 +3,7 @@ package info.nightscout.androidaps.plugins.general.automation.elements import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase import org.junit.Assert import org.junit.Test -import org.junit.runner.RunWith -import org.powermock.modules.junit4.PowerMockRunner -@RunWith(PowerMockRunner::class) class ComparatorConnectTest : TriggerTestBase() { @Test fun labelsTest() { diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorExistsTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorExistsTest.kt index 94a00c6833..1011db6565 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorExistsTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorExistsTest.kt @@ -3,10 +3,7 @@ package info.nightscout.androidaps.plugins.general.automation.elements import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase import org.junit.Assert import org.junit.Test -import org.junit.runner.RunWith -import org.powermock.modules.junit4.PowerMockRunner -@RunWith(PowerMockRunner::class) class ComparatorExistsTest : TriggerTestBase() { @Test fun labelsTest() { diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorTest.kt index e33ade173f..71b8fc4233 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/ComparatorTest.kt @@ -3,10 +3,7 @@ package info.nightscout.androidaps.plugins.general.automation.elements import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase import org.junit.Assert import org.junit.Test -import org.junit.runner.RunWith -import org.powermock.modules.junit4.PowerMockRunner -@RunWith(PowerMockRunner::class) class ComparatorTest : TriggerTestBase() { @Test diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBgTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBgTest.kt index b84e1e5ff5..ee20a8e851 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBgTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputBgTest.kt @@ -1,16 +1,12 @@ package info.nightscout.androidaps.plugins.general.automation.elements -import info.nightscout.androidaps.Constants import info.nightscout.androidaps.interfaces.GlucoseUnit import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.`when` -import org.powermock.modules.junit4.PowerMockRunner -@RunWith(PowerMockRunner::class) class InputBgTest : TriggerTestBase() { @Test diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDurationTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDurationTest.kt index f1becea887..424efd6d36 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDurationTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputDurationTest.kt @@ -3,10 +3,7 @@ package info.nightscout.androidaps.plugins.general.automation.elements import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase import org.junit.Assert import org.junit.Test -import org.junit.runner.RunWith -import org.powermock.modules.junit4.PowerMockRunner -@RunWith(PowerMockRunner::class) class InputDurationTest : TriggerTestBase() { @Test fun setValueTest() { diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulinTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulinTest.kt index f4f8c8b770..c2b2c53ceb 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulinTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputInsulinTest.kt @@ -3,10 +3,7 @@ package info.nightscout.androidaps.plugins.general.automation.elements import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase import org.junit.Assert import org.junit.Test -import org.junit.runner.RunWith -import org.powermock.modules.junit4.PowerMockRunner -@RunWith(PowerMockRunner::class) class InputInsulinTest : TriggerTestBase() { @Test fun setValueTest() { diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercentTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercentTest.kt index 1cf2e8e0df..a75c044cf7 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercentTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputPercentTest.kt @@ -3,10 +3,7 @@ package info.nightscout.androidaps.plugins.general.automation.elements import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase import org.junit.Assert import org.junit.Test -import org.junit.runner.RunWith -import org.powermock.modules.junit4.PowerMockRunner -@RunWith(PowerMockRunner::class) class InputPercentTest : TriggerTestBase() { @Test fun setValueTest() { diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputStringTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputStringTest.kt index 6a8ce2d94b..7bce11b606 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputStringTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputStringTest.kt @@ -3,10 +3,7 @@ package info.nightscout.androidaps.plugins.general.automation.elements import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase import org.junit.Assert import org.junit.Test -import org.junit.runner.RunWith -import org.powermock.modules.junit4.PowerMockRunner -@RunWith(PowerMockRunner::class) class InputStringTest : TriggerTestBase() { @Test fun setValueTest() { diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTargetTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTargetTest.kt index d5a8b89e93..6690a7a017 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTargetTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/elements/InputTempTargetTest.kt @@ -1,16 +1,10 @@ package info.nightscout.androidaps.plugins.general.automation.elements -import info.nightscout.androidaps.Constants import info.nightscout.androidaps.interfaces.GlucoseUnit -import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTestBase import org.junit.Assert import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.Mock -import org.powermock.modules.junit4.PowerMockRunner -@RunWith(PowerMockRunner::class) class InputTempTargetTest : TriggerTestBase() { @Test fun setValueTest() { diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAutosensValueTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAutosensValueTest.kt index 39ddf09fde..29c5e1994e 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAutosensValueTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerAutosensValueTest.kt @@ -13,7 +13,6 @@ import org.junit.runner.RunWith import org.mockito.ArgumentMatchers import org.mockito.Mockito import org.mockito.Mockito.`when` -import org.powermock.api.mockito.PowerMockito import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @@ -65,14 +64,14 @@ class TriggerAutosensValueTest : TriggerTestBase() { t.autosens.value = 390.0 t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER Assert.assertTrue(t.shouldRun()) - PowerMockito.`when`(autosensDataStore.getLastAutosensData(anyObject(), anyObject(), anyObject())).thenReturn(AutosensData(injector)) + `when`(autosensDataStore.getLastAutosensData(anyObject(), anyObject(), anyObject())).thenReturn(AutosensData(injector)) t = TriggerAutosensValue(injector) t.autosens.value = 80.0 t.comparator.value = Comparator.Compare.IS_EQUAL_OR_LESSER Assert.assertFalse(t.shouldRun()) // Test autosensData == null and Comparator == IS_NOT_AVAILABLE - PowerMockito.`when`(autosensDataStore.getLastAutosensData(anyObject(), anyObject(), anyObject())).thenReturn(null) + `when`(autosensDataStore.getLastAutosensData(anyObject(), anyObject(), anyObject())).thenReturn(null) t = TriggerAutosensValue(injector) t.comparator.value = Comparator.Compare.IS_NOT_AVAILABLE Assert.assertTrue(t.shouldRun()) @@ -114,7 +113,7 @@ class TriggerAutosensValueTest : TriggerTestBase() { @Before fun mock() { - PowerMockito.`when`(dateUtil.now()).thenReturn(now) + `when`(dateUtil.now()).thenReturn(now) } private fun generateAutosensData(): AutosensData { diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBgTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBgTest.kt index 76d1980ac0..e9ee52718f 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBgTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBgTest.kt @@ -1,25 +1,17 @@ package info.nightscout.androidaps.plugins.general.automation.triggers import com.google.common.base.Optional -import info.nightscout.androidaps.Constants import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.database.entities.GlucoseValue import info.nightscout.androidaps.interfaces.GlucoseUnit -import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.plugins.general.automation.elements.Comparator -import info.nightscout.androidaps.utils.DateUtil import org.json.JSONObject import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.`when` -import org.powermock.core.classloader.annotations.PrepareForTest -import org.powermock.modules.junit4.PowerMockRunner import java.util.* -@RunWith(PowerMockRunner::class) -@PrepareForTest(DateUtil::class, ProfileFunction::class) class TriggerBgTest : TriggerTestBase() { var now = 1514766900000L diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgoTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgoTest.kt index 29beab1464..11d2b392c6 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgoTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerBolusAgoTest.kt @@ -4,27 +4,20 @@ import com.google.common.base.Optional import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.database.entities.Bolus import info.nightscout.androidaps.plugins.general.automation.elements.Comparator -import info.nightscout.androidaps.utils.DateUtil import org.json.JSONException import org.json.JSONObject import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.`when` -import org.powermock.api.mockito.PowerMockito -import org.powermock.core.classloader.annotations.PrepareForTest -import org.powermock.modules.junit4.PowerMockRunner -@RunWith(PowerMockRunner::class) -@PrepareForTest(DateUtil::class) class TriggerBolusAgoTest : TriggerTestBase() { var now = 1514766900000L @Before fun mock() { - PowerMockito.`when`(dateUtil.now()).thenReturn(now) + `when`(dateUtil.now()).thenReturn(now) } @Test diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerCOBTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerCOBTest.kt index d125ee5655..1176417304 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerCOBTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerCOBTest.kt @@ -4,31 +4,25 @@ import com.google.common.base.Optional import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.plugins.general.automation.elements.Comparator import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo -import info.nightscout.androidaps.utils.DateUtil import org.json.JSONObject import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith import org.mockito.ArgumentMatchers -import org.powermock.api.mockito.PowerMockito -import org.powermock.core.classloader.annotations.PrepareForTest -import org.powermock.modules.junit4.PowerMockRunner +import org.mockito.Mockito.`when` -@RunWith(PowerMockRunner::class) -@PrepareForTest(DateUtil::class) class TriggerCOBTest : TriggerTestBase() { var now = 1514766900000L @Before fun mock() { - PowerMockito.`when`(dateUtil.now()).thenReturn(now) - PowerMockito.`when`(sp.getInt(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())).thenReturn(48) + `when`(dateUtil.now()).thenReturn(now) + `when`(sp.getInt(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())).thenReturn(48) } @Test fun shouldRunTest() { // COB value is 6 - PowerMockito.`when`(iobCobCalculator.getCobInfo(false, "AutomationTriggerCOB")).thenReturn(CobInfo(0, 6.0, 2.0)) + `when`(iobCobCalculator.getCobInfo(false, "AutomationTriggerCOB")).thenReturn(CobInfo(0, 6.0, 2.0)) var t: TriggerCOB = TriggerCOB(injector).setValue(1.0).comparator(Comparator.Compare.IS_EQUAL) Assert.assertFalse(t.shouldRun()) t = TriggerCOB(injector).setValue(6.0).comparator(Comparator.Compare.IS_EQUAL) diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDeltaTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDeltaTest.kt index 964cbb5e0f..9f23dffbfc 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDeltaTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerDeltaTest.kt @@ -1,34 +1,25 @@ package info.nightscout.androidaps.plugins.general.automation.triggers import com.google.common.base.Optional -import info.nightscout.androidaps.Constants import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.database.entities.GlucoseValue import info.nightscout.androidaps.interfaces.GlucoseUnit -import info.nightscout.androidaps.interfaces.ProfileFunction import info.nightscout.androidaps.plugins.general.automation.elements.Comparator import info.nightscout.androidaps.plugins.general.automation.elements.InputDelta.DeltaType -import info.nightscout.androidaps.utils.DateUtil import org.json.JSONObject import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.`when` -import org.powermock.api.mockito.PowerMockito -import org.powermock.core.classloader.annotations.PrepareForTest -import org.powermock.modules.junit4.PowerMockRunner import java.util.* -@RunWith(PowerMockRunner::class) -@PrepareForTest(DateUtil::class, ProfileFunction::class) class TriggerDeltaTest : TriggerTestBase() { var now = 1514766900000L @Before fun mock() { - PowerMockito.`when`(dateUtil.now()).thenReturn(now) + `when`(dateUtil.now()).thenReturn(now) `when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL) } diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocationTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocationTest.kt index c533c8f257..8f80672065 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocationTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocationTest.kt @@ -4,29 +4,19 @@ import android.location.Location import com.google.common.base.Optional import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.plugins.general.automation.elements.InputLocationMode -import info.nightscout.androidaps.services.LocationService -import info.nightscout.androidaps.utils.DateUtil import org.json.JSONException import org.json.JSONObject import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.`when` -import org.powermock.api.mockito.PowerMockito -import org.powermock.core.classloader.annotations.PrepareForTest -import org.powermock.modules.junit4.PowerMockRunner -@RunWith(PowerMockRunner::class) -@PrepareForTest(DateUtil::class, LocationService::class) class TriggerLocationTest : TriggerTestBase() { var now = 1514766900000L @Before fun mock() { - PowerMockito.mockStatic(LocationService::class.java) `when`(dateUtil.now()).thenReturn(now) - PowerMockito.spy(LocationService::class.java) `when`(locationDataContainer.lastLocation).thenReturn(mockedLocation()) } diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerProfilePercentTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerProfilePercentTest.kt index 27c910ca78..d1343adf6c 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerProfilePercentTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerProfilePercentTest.kt @@ -3,27 +3,20 @@ package info.nightscout.androidaps.plugins.general.automation.triggers import com.google.common.base.Optional import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.plugins.general.automation.elements.Comparator -import info.nightscout.androidaps.utils.DateUtil import org.json.JSONException import org.json.JSONObject import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mockito.`when` -import org.powermock.api.mockito.PowerMockito -import org.powermock.core.classloader.annotations.PrepareForTest -import org.powermock.modules.junit4.PowerMockRunner -@RunWith(PowerMockRunner::class) -@PrepareForTest(DateUtil::class) class TriggerProfilePercentTest : TriggerTestBase() { private val now = 1514766900000L @Before fun mock() { `when`(profileFunction.getProfile()).thenReturn(validProfile) - PowerMockito.`when`(dateUtil.now()).thenReturn(now) + `when`(dateUtil.now()).thenReturn(now) } @Test fun shouldRunTest() { diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerPumpLastConnectionTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerPumpLastConnectionTest.kt index bddce94217..1bd94e4e25 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerPumpLastConnectionTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerPumpLastConnectionTest.kt @@ -3,25 +3,19 @@ package info.nightscout.androidaps.plugins.general.automation.triggers import com.google.common.base.Optional import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.plugins.general.automation.elements.Comparator -import info.nightscout.androidaps.utils.DateUtil import org.json.JSONObject import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith -import org.powermock.api.mockito.PowerMockito -import org.powermock.core.classloader.annotations.PrepareForTest -import org.powermock.modules.junit4.PowerMockRunner +import org.mockito.Mockito.`when` -@RunWith(PowerMockRunner::class) -@PrepareForTest(DateUtil::class) class TriggerPumpLastConnectionTest : TriggerTestBase() { var now = 1514766900000L @Before fun mock() { - PowerMockito.`when`(dateUtil.now()).thenReturn(now) + `when`(dateUtil.now()).thenReturn(now) } @Test @@ -29,7 +23,7 @@ class TriggerPumpLastConnectionTest : TriggerTestBase() { // System.currentTimeMillis() is always 0 // and so is every last connection time Assert.assertEquals(0L, testPumpPlugin.lastDataTime()) - PowerMockito.`when`(dateUtil.now()).thenReturn(now + 10 * 60 * 1000) // set current time to now + 10 min + `when`(dateUtil.now()).thenReturn(now + 10 * 60 * 1000) // set current time to now + 10 min var t = TriggerPumpLastConnection(injector).setValue(110).comparator(Comparator.Compare.IS_EQUAL) Assert.assertEquals(110, t.minutesAgo.value) Assert.assertEquals(Comparator.Compare.IS_EQUAL, t.comparator.value) diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerRecurringTimeTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerRecurringTimeTest.kt index e764e22747..e63ec3118b 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerRecurringTimeTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerRecurringTimeTest.kt @@ -1,26 +1,20 @@ package info.nightscout.androidaps.plugins.general.automation.triggers -import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.MidnightTime import info.nightscout.androidaps.utils.T import org.json.JSONObject import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith -import org.powermock.api.mockito.PowerMockito -import org.powermock.core.classloader.annotations.PrepareForTest -import org.powermock.modules.junit4.PowerMockRunner +import org.mockito.Mockito.`when` -@RunWith(PowerMockRunner::class) -@PrepareForTest(DateUtil::class) class TriggerRecurringTimeTest : TriggerTestBase() { var now : Long = 0L @Before fun mock() { now = MidnightTime.calc() + T.mins(95).msecs() // 95 min from midnight - PowerMockito.`when`(dateUtil.now()).thenReturn(now) + `when`(dateUtil.now()).thenReturn(now) } @Test fun shouldRunTest() { diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTargetTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTargetTest.kt index 64ba71fd14..7960208905 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTargetTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTempTargetTest.kt @@ -3,24 +3,18 @@ package info.nightscout.androidaps.plugins.general.automation.triggers import com.google.common.base.Optional import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.plugins.general.automation.elements.ComparatorExists -import info.nightscout.androidaps.utils.DateUtil import org.json.JSONObject import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith -import org.powermock.api.mockito.PowerMockito -import org.powermock.core.classloader.annotations.PrepareForTest -import org.powermock.modules.junit4.PowerMockRunner +import org.mockito.Mockito.`when` -@RunWith(PowerMockRunner::class) -@PrepareForTest(DateUtil::class) class TriggerTempTargetTest : TriggerTestBase() { var now = 1514766900000L @Before fun mock() { - PowerMockito.`when`(dateUtil.now()).thenReturn(now) + `when`(dateUtil.now()).thenReturn(now) } /* @Test fun shouldRunTest() { @@ -29,7 +23,7 @@ class TriggerTempTargetTest : TriggerTestBase() { Assert.assertFalse(t.shouldRun()) t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS) Assert.assertTrue(t.shouldRun()) - PowerMockito.`when`(repository.getTemporaryTargetActiveAt(anyObject())).thenReturn(TemporaryTarget(duration = 0, highTarget = 0.0, lowTarget = 0.0, reason = TemporaryTarget.Reason.CUSTOM, timestamp = 0)) + `when`(repository.getTemporaryTargetActiveAt(anyObject())).thenReturn(TemporaryTarget(duration = 0, highTarget = 0.0, lowTarget = 0.0, reason = TemporaryTarget.Reason.CUSTOM, timestamp = 0)) t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS) Assert.assertFalse(t.shouldRun()) t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS) diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt index 350b987dbd..dcd98a45e9 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTestBase.kt @@ -3,13 +3,13 @@ package info.nightscout.androidaps.plugins.general.automation.triggers import android.content.Context import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector -import info.nightscout.androidaps.plugins.general.automation.TestBaseWithProfile import info.nightscout.androidaps.TestPumpPlugin import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.IobCobCalculator import info.nightscout.androidaps.interfaces.PluginDescription import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.general.automation.AutomationPlugin +import info.nightscout.androidaps.plugins.general.automation.TestBaseWithProfile import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensDataStore import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProvider import info.nightscout.androidaps.receivers.ReceiverStatusStore @@ -18,9 +18,7 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP import org.junit.Before import org.mockito.Mock import org.mockito.Mockito.`when` -import org.powermock.core.classloader.annotations.PrepareForTest -@PrepareForTest(LastLocationDataContainer::class, AutomationPlugin::class, AutosensDataStore::class) open class TriggerTestBase : TestBaseWithProfile() { @Mock lateinit var sp: SP diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeRangeTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeRangeTest.kt index 3e01059aa6..55e31d328f 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeRangeTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeRangeTest.kt @@ -2,19 +2,13 @@ package info.nightscout.androidaps.plugins.general.automation.triggers import com.google.common.base.Optional import info.nightscout.androidaps.automation.R -import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.MidnightTime import org.json.JSONObject import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith -import org.powermock.api.mockito.PowerMockito -import org.powermock.core.classloader.annotations.PrepareForTest -import org.powermock.modules.junit4.PowerMockRunner +import org.mockito.Mockito.`when` -@RunWith(PowerMockRunner::class) -@PrepareForTest(DateUtil::class) class TriggerTimeRangeTest : TriggerTestBase() { var now = 754 // in minutes from midnight @@ -23,7 +17,7 @@ class TriggerTimeRangeTest : TriggerTestBase() { @Before fun mock() { val nowMills = MidnightTime.calcPlusMinutes(now) - PowerMockito.`when`(dateUtil.now()).thenReturn(nowMills) + `when`(dateUtil.now()).thenReturn(nowMills) } @Test diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeTest.kt index 8c38c37761..a1de73c1fd 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerTimeTest.kt @@ -10,7 +10,7 @@ import org.junit.Assert import org.junit.Before import org.junit.Test import org.junit.runner.RunWith -import org.powermock.api.mockito.PowerMockito +import org.mockito.Mockito.`when` import org.powermock.core.classloader.annotations.PrepareForTest import org.powermock.modules.junit4.PowerMockRunner @@ -21,7 +21,7 @@ class TriggerTimeTest : TriggerTestBase() { var now = 1514766900000L @Before fun mock() { - PowerMockito.`when`(dateUtil.now()).thenReturn(now) + `when`(dateUtil.now()).thenReturn(now) } @Test fun shouldRunTest() { diff --git a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerWifiSsidTest.kt b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerWifiSsidTest.kt index 4b38476f98..3e7fe4549e 100644 --- a/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerWifiSsidTest.kt +++ b/automation/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerWifiSsidTest.kt @@ -4,27 +4,19 @@ import com.google.common.base.Optional import info.nightscout.androidaps.automation.R import info.nightscout.androidaps.events.EventNetworkChange import info.nightscout.androidaps.plugins.general.automation.elements.Comparator -import info.nightscout.androidaps.receivers.NetworkChangeReceiver -import info.nightscout.androidaps.utils.DateUtil import org.json.JSONException import org.json.JSONObject import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith -import org.powermock.api.mockito.PowerMockito -import org.powermock.core.classloader.annotations.PrepareForTest -import org.powermock.modules.junit4.PowerMockRunner +import org.mockito.Mockito.`when` -@RunWith(PowerMockRunner::class) -@PrepareForTest(NetworkChangeReceiver::class, DateUtil::class) class TriggerWifiSsidTest : TriggerTestBase() { var now = 1514766900000L @Before fun mock() { - PowerMockito.mockStatic(NetworkChangeReceiver::class.java) - PowerMockito.`when`(dateUtil.now()).thenReturn(now) + `when`(dateUtil.now()).thenReturn(now) } @Test fun shouldRunTest() { diff --git a/combo/build.gradle b/combo/build.gradle index 6e8a0ec0c6..c81f96b15c 100644 --- a/combo/build.gradle +++ b/combo/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' +apply plugin: 'kotlin-allopen' apply plugin: 'com.hiya.jacoco-android' apply from: "${project.rootDir}/gradle/android_dependencies.gradle" diff --git a/core/build.gradle b/core/build.gradle index c56fb46cb5..8f3db0440e 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -14,8 +14,3 @@ apply from: "${project.rootDir}/gradle/jacoco_global.gradle" dependencies { implementation project(':database') } - -allOpen { - // allows mocking for classes w/o directly opening them for release builds - annotation 'info.nightscout.androidaps.annotations.OpenForTesting' -} \ No newline at end of file diff --git a/core/src/main/java/info/nightscout/androidaps/logging/UserEntryLogger.kt b/core/src/main/java/info/nightscout/androidaps/logging/UserEntryLogger.kt index 9bed01b2f0..3e0e70efcb 100644 --- a/core/src/main/java/info/nightscout/androidaps/logging/UserEntryLogger.kt +++ b/core/src/main/java/info/nightscout/androidaps/logging/UserEntryLogger.kt @@ -1,5 +1,6 @@ package info.nightscout.androidaps.logging +import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.entities.ValueWithUnit import info.nightscout.androidaps.database.entities.UserEntry.Action @@ -14,6 +15,7 @@ import io.reactivex.rxkotlin.subscribeBy import javax.inject.Inject import javax.inject.Singleton +@OpenForTesting @Singleton class UserEntryLogger @Inject constructor( private val aapsLogger: AAPSLogger, diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConstraintChecker.kt b/core/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConstraintChecker.kt index 718956c90b..3b47c4670a 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConstraintChecker.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConstraintChecker.kt @@ -1,6 +1,7 @@ package info.nightscout.androidaps.plugins.configBuilder import info.nightscout.androidaps.Constants +import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.interfaces.Profile import info.nightscout.androidaps.interfaces.ActivePlugin import info.nightscout.androidaps.interfaces.Constraint @@ -9,6 +10,7 @@ import info.nightscout.androidaps.interfaces.PluginType import javax.inject.Inject import javax.inject.Singleton +@OpenForTesting @Singleton class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlugin) : Constraints { diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/PrefFileListProvider.kt b/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/PrefFileListProvider.kt index 189251db92..d4355cbb53 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/PrefFileListProvider.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/PrefFileListProvider.kt @@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.general.maintenance import android.content.Context import android.os.Environment +import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.core.R import info.nightscout.androidaps.interfaces.Config import info.nightscout.androidaps.plugins.constraints.versionChecker.VersionCheckerUtils @@ -19,6 +20,7 @@ import javax.inject.Singleton import kotlin.math.abs @Suppress("SpellCheckingInspection") +@OpenForTesting @Singleton class PrefFileListProvider @Inject constructor( private val resourceHelper: ResourceHelper, diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/AutosensDataStore.kt b/core/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/AutosensDataStore.kt index 5cbfe021a3..4a2a20edbd 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/AutosensDataStore.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/AutosensDataStore.kt @@ -1,6 +1,7 @@ package info.nightscout.androidaps.plugins.iob.iobCobCalculator import androidx.collection.LongSparseArray +import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.data.InMemoryGlucoseValue import info.nightscout.androidaps.database.AppRepository import info.nightscout.androidaps.database.entities.GlucoseValue @@ -14,6 +15,7 @@ import info.nightscout.androidaps.utils.T import kotlin.math.abs import kotlin.math.roundToLong +@OpenForTesting class AutosensDataStore { private val dataLock = Any() diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorage.kt b/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorage.kt index 57a732cbc3..41e55e4844 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorage.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/DetailedBolusInfoStorage.kt @@ -1,5 +1,6 @@ package info.nightscout.androidaps.plugins.pump.common.bolusInfo +import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -9,6 +10,7 @@ import javax.inject.Inject import javax.inject.Singleton import kotlin.math.abs +@OpenForTesting @Singleton class DetailedBolusInfoStorage @Inject constructor( val aapsLogger: AAPSLogger diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/TemporaryBasalStorage.kt b/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/TemporaryBasalStorage.kt index 0a5ac50f67..78c074e41a 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/TemporaryBasalStorage.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/pump/common/bolusInfo/TemporaryBasalStorage.kt @@ -1,5 +1,6 @@ package info.nightscout.androidaps.plugins.pump.common.bolusInfo +import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.interfaces.PumpSync import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.LTag @@ -9,6 +10,7 @@ import javax.inject.Inject import javax.inject.Singleton import kotlin.math.abs +@OpenForTesting @Singleton class TemporaryBasalStorage @Inject constructor( val aapsLogger: AAPSLogger diff --git a/core/src/test/java/info/nightscout/androidaps/plugins/iob/iobCalculator/GlucoseStatusTest.kt b/core/src/test/java/info/nightscout/androidaps/plugins/iob/iobCalculator/GlucoseStatusTest.kt index 31319712a1..20975c9654 100644 --- a/core/src/test/java/info/nightscout/androidaps/plugins/iob/iobCalculator/GlucoseStatusTest.kt +++ b/core/src/test/java/info/nightscout/androidaps/plugins/iob/iobCalculator/GlucoseStatusTest.kt @@ -12,20 +12,14 @@ import info.nightscout.androidaps.utils.T import org.junit.Assert import org.junit.Before import org.junit.Test -import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.Mockito.`when` -import org.powermock.api.mockito.PowerMockito -import org.powermock.core.classloader.annotations.PrepareForTest -import org.powermock.modules.junit4.PowerMockRunner import java.util.* /** * Created by mike on 26.03.2018. */ @Suppress("SpellCheckingInspection") -@RunWith(PowerMockRunner::class) -@PrepareForTest(DateUtil::class, AutosensDataStore::class) class GlucoseStatusTest : TestBase() { @Mock lateinit var dateUtil: DateUtil @@ -48,7 +42,7 @@ class GlucoseStatusTest : TestBase() { } @Test fun calculateValidGlucoseStatus() { - PowerMockito.`when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(generateValidBgData()) + `when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(generateValidBgData()) val glucoseStatus = GlucoseStatusProvider(aapsLogger, iobCobCalculatorPlugin, dateUtil).glucoseStatusData!! Assert.assertEquals(214.0, glucoseStatus.glucose, 0.001) Assert.assertEquals(-2.0, glucoseStatus.delta, 0.001) @@ -58,7 +52,7 @@ class GlucoseStatusTest : TestBase() { } @Test fun calculateMostRecentGlucoseStatus() { - PowerMockito.`when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(generateMostRecentBgData()) + `when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(generateMostRecentBgData()) val glucoseStatus: GlucoseStatus = GlucoseStatusProvider(aapsLogger, iobCobCalculatorPlugin, dateUtil).glucoseStatusData!! Assert.assertEquals(215.0, glucoseStatus.glucose, 0.001) // (214+216) / 2 Assert.assertEquals(-1.0, glucoseStatus.delta, 0.001) @@ -68,7 +62,7 @@ class GlucoseStatusTest : TestBase() { } @Test fun oneRecordShouldProduceZeroDeltas() { - PowerMockito.`when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(generateOneCurrentRecordBgData()) + `when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(generateOneCurrentRecordBgData()) val glucoseStatus: GlucoseStatus = GlucoseStatusProvider(aapsLogger, iobCobCalculatorPlugin, dateUtil).glucoseStatusData!! Assert.assertEquals(214.0, glucoseStatus.glucose, 0.001) Assert.assertEquals(0.0, glucoseStatus.delta, 0.001) @@ -78,19 +72,19 @@ class GlucoseStatusTest : TestBase() { } @Test fun insufficientDataShouldReturnNull() { - PowerMockito.`when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(generateInsufficientBgData()) + `when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(generateInsufficientBgData()) val glucoseStatus: GlucoseStatus? = GlucoseStatusProvider(aapsLogger, iobCobCalculatorPlugin, dateUtil).glucoseStatusData Assert.assertEquals(null, glucoseStatus) } @Test fun oldDataShouldReturnNull() { - PowerMockito.`when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(generateOldBgData()) + `when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(generateOldBgData()) val glucoseStatus: GlucoseStatus? = GlucoseStatusProvider(aapsLogger, iobCobCalculatorPlugin, dateUtil).glucoseStatusData Assert.assertEquals(null, glucoseStatus) } @Test fun returnOldDataIfAllowed() { - PowerMockito.`when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(generateOldBgData()) + `when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(generateOldBgData()) val glucoseStatus: GlucoseStatus? = GlucoseStatusProvider(aapsLogger, iobCobCalculatorPlugin, dateUtil).getGlucoseStatusData(true) Assert.assertNotEquals(null, glucoseStatus) } @@ -100,7 +94,7 @@ class GlucoseStatusTest : TestBase() { } @Test fun calculateGlucoseStatusForLibreTestBgData() { - PowerMockito.`when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(generateLibreTestData()) + `when`(autosensDataStore.getBgReadingsDataTableCopy()).thenReturn(generateLibreTestData()) val glucoseStatus: GlucoseStatus = GlucoseStatusProvider(aapsLogger, iobCobCalculatorPlugin, dateUtil).glucoseStatusData!! Assert.assertEquals(100.0, glucoseStatus.glucose, 0.001) // Assert.assertEquals(-10.0, glucoseStatus.delta, 0.001) diff --git a/dana/build.gradle b/dana/build.gradle index 46e26b9616..2f86ece0a2 100644 --- a/dana/build.gradle +++ b/dana/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' +apply plugin: 'kotlin-allopen' apply plugin: 'com.hiya.jacoco-android' apply from: "${project.rootDir}/gradle/android_dependencies.gradle" diff --git a/danar/build.gradle b/danar/build.gradle index 230038a50c..1e7087736e 100644 --- a/danar/build.gradle +++ b/danar/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' +apply plugin: 'kotlin-allopen' apply plugin: 'com.hiya.jacoco-android' apply from: "${project.rootDir}/gradle/android_dependencies.gradle" diff --git a/danars/build.gradle b/danars/build.gradle index a013ae98af..a754c4b87e 100644 --- a/danars/build.gradle +++ b/danars/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' +apply plugin: 'kotlin-allopen' apply plugin: 'com.hiya.jacoco-android' apply from: "${project.rootDir}/gradle/android_dependencies.gradle" diff --git a/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistorySuspendTest.kt b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistorySuspendTest.kt index af5b2adcbd..bcdfc7e85c 100644 --- a/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistorySuspendTest.kt +++ b/danars/src/test/java/info/nightscout/androidaps/danars/comm/DanaRsPacketHistorySuspendTest.kt @@ -5,10 +5,7 @@ import dagger.android.HasAndroidInjector import info.nightscout.androidaps.danars.DanaRSTestBase import org.junit.Assert import org.junit.Test -import org.junit.runner.RunWith -import org.powermock.modules.junit4.PowerMockRunner -@RunWith(PowerMockRunner::class) class DanaRsPacketHistorySuspendTest : DanaRSTestBase() { private val packetInjector = HasAndroidInjector { diff --git a/database/build.gradle b/database/build.gradle index f570a3d484..af81fc73ac 100644 --- a/database/build.gradle +++ b/database/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' +apply plugin: 'kotlin-allopen' apply from: "${project.rootDir}/gradle/android_dependencies.gradle" apply from: "${project.rootDir}/gradle/android_module_dependencies.gradle" @@ -39,3 +40,8 @@ dependencies { implementation "com.google.dagger:dagger-android-support:$dagger_version" api "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" } + +allOpen { + // allows mocking for classes w/o directly opening them for release builds + annotation 'info.nightscout.androidaps.annotations.OpenForTesting' +} \ No newline at end of file diff --git a/core/src/debug/java/info/nightscout/androidaps/annotations/OpenForTesting.kt b/database/src/debug/java/info/nightscout/androidaps/annotations/OpenForTesting.kt similarity index 100% rename from core/src/debug/java/info/nightscout/androidaps/annotations/OpenForTesting.kt rename to database/src/debug/java/info/nightscout/androidaps/annotations/OpenForTesting.kt diff --git a/database/src/main/java/info/nightscout/androidaps/database/AppRepository.kt b/database/src/main/java/info/nightscout/androidaps/database/AppRepository.kt index 458eff722e..eaab40563d 100644 --- a/database/src/main/java/info/nightscout/androidaps/database/AppRepository.kt +++ b/database/src/main/java/info/nightscout/androidaps/database/AppRepository.kt @@ -1,5 +1,6 @@ package info.nightscout.androidaps.database +import info.nightscout.androidaps.annotations.OpenForTesting import info.nightscout.androidaps.database.data.NewEntries import info.nightscout.androidaps.database.entities.* import info.nightscout.androidaps.database.interfaces.DBEntry @@ -15,6 +16,7 @@ import javax.inject.Inject import javax.inject.Singleton import kotlin.math.roundToInt +@OpenForTesting @Singleton open class AppRepository @Inject internal constructor( internal val database: AppDatabase diff --git a/core/src/release/java/info/nightscout/androidaps/annotations/OpenForTesting.kt b/database/src/release/java/info/nightscout/androidaps/annotations/OpenForTesting.kt similarity index 100% rename from core/src/release/java/info/nightscout/androidaps/annotations/OpenForTesting.kt rename to database/src/release/java/info/nightscout/androidaps/annotations/OpenForTesting.kt diff --git a/diaconn/build.gradle b/diaconn/build.gradle index 46e26b9616..2f86ece0a2 100644 --- a/diaconn/build.gradle +++ b/diaconn/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' +apply plugin: 'kotlin-allopen' apply plugin: 'com.hiya.jacoco-android' apply from: "${project.rootDir}/gradle/android_dependencies.gradle" diff --git a/gradle/android_module_dependencies.gradle b/gradle/android_module_dependencies.gradle index 7125e612f7..d163350b9b 100644 --- a/gradle/android_module_dependencies.gradle +++ b/gradle/android_module_dependencies.gradle @@ -22,4 +22,9 @@ dependencies { annotationProcessor "com.google.dagger:dagger-android-processor:$dagger_version" kapt "com.google.dagger:dagger-android-processor:$dagger_version" kapt "com.google.dagger:dagger-compiler:$dagger_version" -} \ No newline at end of file +} + +allOpen { + // allows mocking for classes w/o directly opening them for release builds + annotation 'info.nightscout.androidaps.annotations.OpenForTesting' +} diff --git a/insight/build.gradle b/insight/build.gradle index 46e26b9616..2f86ece0a2 100644 --- a/insight/build.gradle +++ b/insight/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' +apply plugin: 'kotlin-allopen' apply plugin: 'com.hiya.jacoco-android' apply from: "${project.rootDir}/gradle/android_dependencies.gradle" diff --git a/medtronic/build.gradle b/medtronic/build.gradle index f7106a59bd..136b5a3b05 100644 --- a/medtronic/build.gradle +++ b/medtronic/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' +apply plugin: 'kotlin-allopen' apply plugin: 'com.hiya.jacoco-android' apply from: "${project.rootDir}/gradle/android_dependencies.gradle" diff --git a/omnipod-common/build.gradle b/omnipod-common/build.gradle index aba1f22144..6c5d9d7776 100644 --- a/omnipod-common/build.gradle +++ b/omnipod-common/build.gradle @@ -2,6 +2,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' +apply plugin: 'kotlin-allopen' apply plugin: 'com.hiya.jacoco-android' apply from: "${project.rootDir}/gradle/android_dependencies.gradle" diff --git a/omnipod-dash/build.gradle b/omnipod-dash/build.gradle index fa2e0aa670..ed4ab0304f 100644 --- a/omnipod-dash/build.gradle +++ b/omnipod-dash/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' +apply plugin: 'kotlin-allopen' apply plugin: 'com.hiya.jacoco-android' apply from: "${project.rootDir}/gradle/android_dependencies.gradle" diff --git a/omnipod-eros/build.gradle b/omnipod-eros/build.gradle index db27c83b0e..4cf2467f9f 100644 --- a/omnipod-eros/build.gradle +++ b/omnipod-eros/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' +apply plugin: 'kotlin-allopen' apply plugin: 'com.hiya.jacoco-android' apply from: "${project.rootDir}/gradle/android_dependencies.gradle" diff --git a/openhumans/build.gradle b/openhumans/build.gradle index e3b5a31fa9..5e06a3e587 100644 --- a/openhumans/build.gradle +++ b/openhumans/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' +apply plugin: 'kotlin-allopen' apply plugin: 'com.hiya.jacoco-android' apply from: "${project.rootDir}/gradle/android_dependencies.gradle" diff --git a/pump-common/build.gradle b/pump-common/build.gradle index 10a6c55b08..5457b18d34 100644 --- a/pump-common/build.gradle +++ b/pump-common/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' +apply plugin: 'kotlin-allopen' apply plugin: 'com.hiya.jacoco-android' apply from: "${project.rootDir}/gradle/android_dependencies.gradle" diff --git a/rileylink/build.gradle b/rileylink/build.gradle index edbb3c241d..3ea01781f9 100644 --- a/rileylink/build.gradle +++ b/rileylink/build.gradle @@ -1,6 +1,7 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' +apply plugin: 'kotlin-allopen' apply plugin: 'com.hiya.jacoco-android' apply from: "${project.rootDir}/gradle/android_dependencies.gradle" diff --git a/wear/build.gradle b/wear/build.gradle index b7152ebe07..4ef90de165 100644 --- a/wear/build.gradle +++ b/wear/build.gradle @@ -12,6 +12,7 @@ buildscript { } apply plugin: 'com.android.application' apply plugin: 'kotlin-android' +apply plugin: 'kotlin-allopen' apply plugin: 'com.hiya.jacoco-android' jacoco { diff --git a/wear/src/test/java/info/nightscout/androidaps/testing/mockers/LogMocker.java b/wear/src/test/java/info/nightscout/androidaps/testing/mockers/LogMocker.java index 5c374665bc..0dccaafced 100644 --- a/wear/src/test/java/info/nightscout/androidaps/testing/mockers/LogMocker.java +++ b/wear/src/test/java/info/nightscout/androidaps/testing/mockers/LogMocker.java @@ -1,9 +1,9 @@ package info.nightscout.androidaps.testing.mockers; -import android.util.Log; - import static org.powermock.api.mockito.PowerMockito.mockStatic; +import android.util.Log; + public class LogMocker { public static void prepareMock() { mockStatic(Log.class); diff --git a/wear/src/test/java/info/nightscout/androidaps/testing/mockers/WearUtilMocker.java b/wear/src/test/java/info/nightscout/androidaps/testing/mockers/WearUtilMocker.java index 11a89f0699..e3f24e878e 100644 --- a/wear/src/test/java/info/nightscout/androidaps/testing/mockers/WearUtilMocker.java +++ b/wear/src/test/java/info/nightscout/androidaps/testing/mockers/WearUtilMocker.java @@ -1,11 +1,15 @@ package info.nightscout.androidaps.testing.mockers; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyString; +import static org.powermock.api.mockito.PowerMockito.mockStatic; + import android.os.Bundle; import com.google.android.gms.wearable.Asset; import com.google.android.gms.wearable.DataMap; -import org.junit.Assert; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.powermock.api.mockito.PowerMockito; @@ -15,11 +19,6 @@ import java.util.ArrayList; import info.nightscout.androidaps.interaction.utils.Constants; import info.nightscout.androidaps.interaction.utils.WearUtil; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.anyString; -import static org.powermock.api.mockito.PowerMockito.mockStatic; - public class WearUtilMocker { public static final long REF_NOW = 1572610530000L;