remove PowerMockRunner where possible
This commit is contained in:
parent
d43393e2af
commit
d33f62b23d
|
@ -186,10 +186,10 @@ class SafetyPlugin @Inject constructor(
|
|||
|
||||
override fun applyMaxIOBConstraints(maxIob: Constraint<Double>): Constraint<Double> {
|
||||
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
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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("")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
}
|
|
@ -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))
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 = ""
|
||||
|
|
|
@ -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<Transaction<CancelCurrentOfflineEventIfAnyTransaction.TransactionResult>>())
|
||||
).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()
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<Transaction<InsertTherapyEventAnnouncementTransaction.TransactionResult>>()))
|
||||
.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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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'
|
||||
}
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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'
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -23,3 +23,8 @@ dependencies {
|
|||
kapt "com.google.dagger:dagger-android-processor:$dagger_version"
|
||||
kapt "com.google.dagger:dagger-compiler:$dagger_version"
|
||||
}
|
||||
|
||||
allOpen {
|
||||
// allows mocking for classes w/o directly opening them for release builds
|
||||
annotation 'info.nightscout.androidaps.annotations.OpenForTesting'
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue