shared-tests #5

This commit is contained in:
Milos Kozak 2023-09-03 21:10:34 +02:00
parent d950c7986c
commit d1694e9763
70 changed files with 520 additions and 1392 deletions

View file

@ -6,6 +6,7 @@ import info.nightscout.rx.TestAapsSchedulers
import info.nightscout.rx.logging.AAPSLoggerTest
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.ArgumentMatcher
import org.mockito.Mockito
import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.junit.jupiter.MockitoSettings
@ -26,6 +27,18 @@ open class TestBase {
System.setProperty("disableFirebase", "true")
}
@SuppressLint("CheckResult")
fun <T> argThatKotlin(matcher: ArgumentMatcher<T>): T {
Mockito.argThat(matcher)
return uninitialized()
}
@SuppressLint("CheckResult")
fun <T> eqObject(expected: T): T {
Mockito.eq<T>(expected)
return uninitialized()
}
// Workaround for Kotlin nullability.
// https://medium.com/@elye.project/befriending-kotlin-and-mockito-1c2e7b0ef791
// https://stackoverflow.com/questions/30305217/is-it-possible-to-use-mockito-in-kotlin

View file

@ -63,7 +63,7 @@ open class TestBaseWithProfile : TestBase() {
lateinit var effectiveProfileSwitch: EffectiveProfileSwitch
lateinit var testPumpPlugin: TestPumpPlugin
val now = 1656358822000L
var now = 1656358822000L
@Suppress("PropertyName") val TESTPROFILENAME = "someProfile"

View file

@ -25,6 +25,8 @@ dependencies {
implementation project(':core:validators')
implementation project(':plugins:automation')
testImplementation project(':app-wear-shared:shared-tests')
api "androidx.appcompat:appcompat:$appcompat_version"
api "androidx.swiperefreshlayout:swiperefreshlayout:$swipe_version"
api "androidx.gridlayout:gridlayout:$gridlayout_version"

View file

@ -1,83 +0,0 @@
package info.nightscout.androidaps
import info.nightscout.interfaces.utils.HardLimits
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP
import javax.inject.Inject
import kotlin.math.max
import kotlin.math.min
class HardLimitsMock @Inject constructor(
private val sp: SP,
private val rh: ResourceHelper
) : HardLimits {
companion object {
private const val CHILD = 0
private const val TEENAGE = 1
private const val ADULT = 2
private const val RESISTANT_ADULT = 3
private const val PREGNANT = 4
private val MAX_BOLUS = doubleArrayOf(5.0, 10.0, 17.0, 25.0, 60.0)
// Very Hard Limits Ranges
// First value is the Lowest and second value is the Highest a Limit can define
val VERY_HARD_LIMIT_MIN_BG = doubleArrayOf(80.0, 180.0)
val VERY_HARD_LIMIT_MAX_BG = doubleArrayOf(90.0, 200.0)
val VERY_HARD_LIMIT_TARGET_BG = doubleArrayOf(80.0, 200.0)
// Very Hard Limits Ranges for Temp Targets
val VERY_HARD_LIMIT_TEMP_MIN_BG = intArrayOf(72, 180)
val VERY_HARD_LIMIT_TEMP_MAX_BG = intArrayOf(72, 270)
val VERY_HARD_LIMIT_TEMP_TARGET_BG = intArrayOf(72, 200)
val MIN_DIA = doubleArrayOf(5.0, 5.0, 5.0, 5.0, 5.0)
val MAX_DIA = doubleArrayOf(9.0, 9.0, 9.0, 9.0, 10.0)
val MIN_IC = doubleArrayOf(2.0, 2.0, 2.0, 2.0, 0.3)
val MAX_IC = doubleArrayOf(100.0, 100.0, 100.0, 100.0, 100.0)
const val MIN_ISF = 2.0 // mgdl
const val MAX_ISF = 1000.0 // mgdl
val MAX_IOB_AMA = doubleArrayOf(3.0, 5.0, 7.0, 12.0, 25.0)
val MAX_IOB_SMB = doubleArrayOf(7.0, 13.0, 22.0, 30.0, 70.0)
val MAX_BASAL = doubleArrayOf(2.0, 5.0, 10.0, 12.0, 25.0)
//LGS Hard limits
//No IOB at all
const val MAX_IOB_LGS = 0.0
}
private fun loadAge(): Int = when (sp.getString(info.nightscout.core.utils.R.string.key_age, "")) {
rh.gs(info.nightscout.core.utils.R.string.key_child) -> CHILD
rh.gs(info.nightscout.core.utils.R.string.key_teenage) -> TEENAGE
rh.gs(info.nightscout.core.utils.R.string.key_adult) -> ADULT
rh.gs(info.nightscout.core.utils.R.string.key_resistantadult) -> RESISTANT_ADULT
rh.gs(info.nightscout.core.utils.R.string.key_pregnant) -> PREGNANT
else -> ADULT
}
override fun maxBolus(): Double = MAX_BOLUS[loadAge()]
override fun maxIobAMA(): Double = MAX_IOB_AMA[loadAge()]
override fun maxIobSMB(): Double = MAX_IOB_SMB[loadAge()]
override fun maxBasal(): Double = MAX_BASAL[loadAge()]
override fun minDia(): Double = MIN_DIA[loadAge()]
override fun maxDia(): Double = MAX_DIA[loadAge()]
override fun minIC(): Double = MIN_IC[loadAge()]
override fun maxIC(): Double = MAX_IC[loadAge()]
// safety checks
override fun checkHardLimits(value: Double, valueName: Int, lowLimit: Double, highLimit: Double): Boolean =
value == verifyHardLimits(value, valueName, lowLimit, highLimit)
override fun isInRange(value: Double, lowLimit: Double, highLimit: Double): Boolean =
value in lowLimit..highLimit
override fun verifyHardLimits(value: Double, valueName: Int, lowLimit: Double, highLimit: Double): Double {
var newValue = value
if (newValue < lowLimit || newValue > highLimit) {
newValue = max(newValue, lowLimit)
newValue = min(newValue, highLimit)
}
return newValue
}
}

View file

@ -1,107 +0,0 @@
package info.nightscout.androidaps
import androidx.collection.ArrayMap
import dagger.android.HasAndroidInjector
import info.nightscout.core.extensions.pureProfileFromJson
import info.nightscout.core.profile.ProfileSealed
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.profile.ProfileStore
import info.nightscout.interfaces.profile.PureProfile
import info.nightscout.interfaces.utils.HardLimits
import info.nightscout.interfaces.utils.JsonHelper
import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil
import org.json.JSONException
import org.json.JSONObject
import javax.inject.Inject
class ProfileStoreObject(val injector: HasAndroidInjector, override val data: JSONObject, val dateUtil: DateUtil) : ProfileStore {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var activePlugin: ActivePlugin
@Inject lateinit var config: Config
@Inject lateinit var rh: ResourceHelper
@Inject lateinit var rxBus: RxBus
@Inject lateinit var hardLimits: HardLimits
init {
injector.androidInjector().inject(this)
}
private val cachedObjects = ArrayMap<String, PureProfile>()
private fun storeUnits(): String? = JsonHelper.safeGetStringAllowNull(data, "units", null)
private fun getStore(): JSONObject? {
try {
if (data.has("store")) return data.getJSONObject("store")
} catch (e: JSONException) {
aapsLogger.error("Unhandled exception", e)
}
return null
}
override fun getStartDate(): Long {
val iso = JsonHelper.safeGetString(data, "created_at") ?: JsonHelper.safeGetString(data,"startDate") ?: return 0
return try {
dateUtil.fromISODateString(iso)
} catch (e: Exception) {
0
}
}
override fun getDefaultProfile(): PureProfile? = getDefaultProfileName()?.let { getSpecificProfile(it) }
override fun getDefaultProfileJson(): JSONObject? = getDefaultProfileName()?.let { getSpecificProfileJson(it) }
override fun getDefaultProfileName(): String? {
val defaultProfileName = data.optString("defaultProfile")
return if (defaultProfileName.isNotEmpty()) getStore()?.has(defaultProfileName)?.let { defaultProfileName } else null
}
override fun getProfileList(): ArrayList<CharSequence> {
val ret = ArrayList<CharSequence>()
getStore()?.keys()?.let { keys ->
while (keys.hasNext()) {
val profileName = keys.next() as String
ret.add(profileName)
}
}
return ret
}
@Synchronized
override fun getSpecificProfile(profileName: String): PureProfile? {
var profile: PureProfile? = null
val units = JsonHelper.safeGetStringAllowNull(data, "units", storeUnits())
getStore()?.let { store ->
if (store.has(profileName)) {
profile = cachedObjects[profileName]
if (profile == null) {
JsonHelper.safeGetJSONObject(store, profileName, null)?.let { profileObject ->
profile = pureProfileFromJson(profileObject, dateUtil, units)
profile?.let { cachedObjects[profileName] = profile }
}
}
}
}
return profile
}
private fun getSpecificProfileJson(profileName: String): JSONObject? {
getStore()?.let { store ->
if (store.has(profileName))
return JsonHelper.safeGetJSONObject(store, profileName, null)
}
return null
}
override val allProfilesValid: Boolean
get() = getProfileList()
.asSequence()
.map { profileName -> getSpecificProfile(profileName.toString()) }
.map { pureProfile -> pureProfile?.let { ProfileSealed.Pure(pureProfile).isValid("allProfilesValid", activePlugin.activePump, config, rh, rxBus, hardLimits, false) } }
.all { it?.isValid == true }
}

View file

@ -1,37 +0,0 @@
package info.nightscout.androidaps
import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.TestAapsSchedulers
import info.nightscout.rx.logging.AAPSLoggerTest
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.Mockito
import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.junit.jupiter.MockitoSettings
import org.mockito.quality.Strictness
import java.util.Locale
@ExtendWith(MockitoExtension::class)
@MockitoSettings(strictness = Strictness.LENIENT)
open class TestBase {
val aapsLogger = AAPSLoggerTest()
val aapsSchedulers: AapsSchedulers = TestAapsSchedulers()
@BeforeEach
fun setupLocale() {
Locale.setDefault(Locale.ENGLISH)
System.setProperty("disableFirebase", "true")
}
// Workaround for Kotlin nullability.
// https://medium.com/@elye.project/befriending-kotlin-and-mockito-1c2e7b0ef791
// https://stackoverflow.com/questions/30305217/is-it-possible-to-use-mockito-in-kotlin
fun <T> anyObject(): T {
Mockito.any<T>()
return uninitialized()
}
@Suppress("Unchecked_Cast")
fun <T> uninitialized(): T = null as T
}

View file

@ -1,180 +0,0 @@
package info.nightscout.androidaps
import android.content.Context
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.core.extensions.pureProfileFromJson
import info.nightscout.core.profile.ProfileSealed
import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.database.entities.EffectiveProfileSwitch
import info.nightscout.database.entities.embedments.InsulinConfiguration
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.iob.IobCobCalculator
import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.interfaces.profile.ProfileStore
import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil
import org.json.JSONObject
import org.junit.jupiter.api.BeforeEach
import org.mockito.ArgumentMatchers.anyDouble
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.anyString
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.Mockito.`when`
import org.mockito.invocation.InvocationOnMock
@Suppress("SpellCheckingInspection")
open class TestBaseWithProfile : TestBase() {
@Mock lateinit var activePluginProvider: ActivePlugin
@Mock lateinit var rh: ResourceHelper
@Mock lateinit var iobCobCalculator: IobCobCalculator
@Mock lateinit var fabricPrivacy: FabricPrivacy
@Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var config: Config
@Mock lateinit var context: Context
lateinit var dateUtil: DateUtil
lateinit var testPumpPlugin: TestPumpPlugin
val rxBus = RxBus(aapsSchedulers, aapsLogger)
val profileInjector = HasAndroidInjector { AndroidInjector { } }
private lateinit var validProfileJSON: String
lateinit var validProfile: ProfileSealed.Pure
lateinit var effectiveProfileSwitch: EffectiveProfileSwitch
@Suppress("PropertyName") val TESTPROFILENAME = "someProfile"
@BeforeEach
fun prepareMock() {
validProfileJSON = "{\"dia\":\"5\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," +
"{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," +
"\"target_high\":[{\"time\":\"00:00\",\"value\":\"7\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
dateUtil = Mockito.spy(DateUtil(context))
`when`(dateUtil.now()).thenReturn(1656358822000)
validProfile = ProfileSealed.Pure(pureProfileFromJson(JSONObject(validProfileJSON), dateUtil)!!)
testPumpPlugin = TestPumpPlugin(profileInjector)
`when`(activePluginProvider.activePump).thenReturn(testPumpPlugin)
effectiveProfileSwitch = EffectiveProfileSwitch(
timestamp = dateUtil.now(),
basalBlocks = validProfile.basalBlocks,
isfBlocks = validProfile.isfBlocks,
icBlocks = validProfile.icBlocks,
targetBlocks = validProfile.targetBlocks,
glucoseUnit = EffectiveProfileSwitch.GlucoseUnit.MMOL,
originalProfileName = "",
originalCustomizedName = "",
originalTimeshift = 0,
originalPercentage = 100,
originalDuration = 0,
originalEnd = 0,
insulinConfiguration = InsulinConfiguration("", 0, 0)
)
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<Int?>(1)
String.format(rh.gs(string), arg1)
}.`when`(rh).gs(anyInt(), anyInt())
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<Double?>(1)
String.format(rh.gs(string), arg1)
}.`when`(rh).gs(anyInt(), anyDouble())
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<String?>(1)
String.format(rh.gs(string), arg1)
}.`when`(rh).gs(anyInt(), anyString())
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<String?>(1)
val arg2 = invocation.getArgument<String?>(2)
String.format(rh.gs(string), arg1, arg2)
}.`when`(rh).gs(anyInt(), anyString(), anyString())
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<String?>(1)
val arg2 = invocation.getArgument<Int?>(2)
String.format(rh.gs(string), arg1, arg2)
}.`when`(rh).gs(anyInt(), anyString(), anyInt())
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<Double?>(1)
val arg2 = invocation.getArgument<String?>(2)
String.format(rh.gs(string), arg1, arg2)
}.`when`(rh).gs(anyInt(), anyDouble(), anyString())
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<Double?>(1)
val arg2 = invocation.getArgument<Int?>(2)
String.format(rh.gs(string), arg1, arg2)
}.`when`(rh).gs(anyInt(), anyDouble(), anyInt())
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<Int?>(1)
val arg2 = invocation.getArgument<Int?>(2)
String.format(rh.gs(string), arg1, arg2)
}.`when`(rh).gs(anyInt(), anyInt(), anyInt())
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<Int?>(1)
val arg2 = invocation.getArgument<String?>(2)
String.format(rh.gs(string), arg1, arg2)
}.`when`(rh).gs(anyInt(), anyInt(), anyString())
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<Int?>(1)
val arg2 = invocation.getArgument<Int?>(2)
val arg3 = invocation.getArgument<String?>(3)
String.format(rh.gs(string), arg1, arg2, arg3)
}.`when`(rh).gs(anyInt(), anyInt(), anyInt(), anyString())
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<Int?>(1)
val arg2 = invocation.getArgument<String?>(2)
val arg3 = invocation.getArgument<String?>(3)
String.format(rh.gs(string), arg1, arg2, arg3)
}.`when`(rh).gs(anyInt(), anyInt(), anyString(), anyString())
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<Double?>(1)
val arg2 = invocation.getArgument<Int?>(2)
val arg3 = invocation.getArgument<String?>(3)
String.format(rh.gs(string), arg1, arg2, arg3)
}.`when`(rh).gs(anyInt(), anyDouble(), anyInt(), anyString())
Mockito.doAnswer { invocation: InvocationOnMock ->
val string = invocation.getArgument<Int>(0)
val arg1 = invocation.getArgument<String?>(1)
val arg2 = invocation.getArgument<Int?>(2)
val arg3 = invocation.getArgument<String?>(3)
String.format(rh.gs(string), arg1, arg2, arg3)
}.`when`(rh).gs(anyInt(), anyString(), anyInt(), anyString())
}
fun getValidProfileStore(): ProfileStore {
val json = JSONObject()
val store = JSONObject()
store.put(TESTPROFILENAME, JSONObject(validProfileJSON))
json.put("defaultProfile", TESTPROFILENAME)
json.put("store", store)
return ProfileStoreObject(profileInjector, json, dateUtil)
}
}

View file

@ -1,72 +0,0 @@
package info.nightscout.androidaps
import dagger.android.HasAndroidInjector
import info.nightscout.interfaces.profile.Profile
import info.nightscout.interfaces.pump.DetailedBolusInfo
import info.nightscout.interfaces.pump.Pump
import info.nightscout.interfaces.pump.PumpEnactResult
import info.nightscout.interfaces.pump.PumpSync
import info.nightscout.interfaces.pump.defs.ManufacturerType
import info.nightscout.interfaces.pump.defs.PumpDescription
import info.nightscout.interfaces.pump.defs.PumpType
import info.nightscout.interfaces.utils.TimeChangeType
import org.json.JSONObject
@Suppress("MemberVisibilityCanBePrivate")
class TestPumpPlugin(val injector: HasAndroidInjector) : Pump {
var connected = false
var isProfileSet = true
override fun isConnected() = connected
override fun isConnecting() = false
override fun isHandshakeInProgress() = false
val lastData = 0L
val baseBasal = 0.0
override val pumpDescription = PumpDescription()
override fun isInitialized(): Boolean = true
override fun isSuspended(): Boolean = false
override fun isBusy(): Boolean = false
override fun connect(reason: String) {
connected = true
}
override fun disconnect(reason: String) {
connected = false
}
override fun stopConnecting() {
connected = false
}
override fun waitForDisconnectionInSeconds(): Int = 0
override fun getPumpStatus(reason: String) {}
override fun setNewBasalProfile(profile: Profile): PumpEnactResult = PumpEnactResult(injector)
override fun isThisProfileSet(profile: Profile): Boolean = isProfileSet
override fun lastDataTime(): Long = lastData
override val baseBasalRate: Double = baseBasal
override val reservoirLevel: Double = 0.0
override val batteryLevel: Int = 0
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult = PumpEnactResult(injector).success(true)
override fun stopBolusDelivering() {}
override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult =
PumpEnactResult(injector).success(true)
override fun setTempBasalPercent(percent: Int, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult =
PumpEnactResult(injector).success(true)
override fun setExtendedBolus(insulin: Double, durationInMinutes: Int): PumpEnactResult = PumpEnactResult(injector).success(true)
override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult = PumpEnactResult(injector).success(true)
override fun cancelExtendedBolus(): PumpEnactResult = PumpEnactResult(injector).success(true)
override fun getJSONStatus(profile: Profile, profileName: String, version: String): JSONObject = JSONObject()
override fun manufacturer(): ManufacturerType = ManufacturerType.AAPS
override fun model(): PumpType = PumpType.GENERIC_AAPS
override fun serialNumber(): String = "1"
override fun shortStatus(veryShort: Boolean): String = ""
override val isFakingTempsByExtendedBoluses: Boolean = false
override fun loadTDDs(): PumpEnactResult = PumpEnactResult(injector).success(true)
override fun canHandleDST(): Boolean = true
override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) {}
}

View file

@ -2,14 +2,13 @@ package info.nightscout.plugins.aps.loop
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.database.entities.TemporaryBasal
import info.nightscout.interfaces.aps.APSResult
import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.interfaces.constraints.Constraints
import info.nightscout.interfaces.pump.defs.PumpType
import info.nightscout.interfaces.utils.JsonHelper.safeGetDouble
import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.sharedtests.TestBaseWithProfile
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
@ -20,7 +19,6 @@ import org.mockito.Mockito.`when`
class APSResultTest : TestBaseWithProfile() {
@Mock lateinit var constraints: Constraints
@Mock lateinit var sp: SP
private val injector = HasAndroidInjector { AndroidInjector { } }
@ -59,7 +57,7 @@ class APSResultTest : TestBaseWithProfile() {
it.aapsLogger = aapsLogger
it.constraintChecker = constraints
it.sp = sp
it.activePlugin = activePluginProvider
it.activePlugin = activePlugin
it.iobCobCalculator = iobCobCalculator
it.profileFunction = profileFunction
it.rh = rh
@ -300,7 +298,7 @@ class APSResultTest : TestBaseWithProfile() {
it.aapsLogger = aapsLogger
it.constraintChecker = constraints
it.sp = sp
it.activePlugin = activePluginProvider
it.activePlugin = activePlugin
it.iobCobCalculator = iobCobCalculator
it.profileFunction = profileFunction
it.rh = rh
@ -317,7 +315,7 @@ class APSResultTest : TestBaseWithProfile() {
it.aapsLogger = aapsLogger
it.constraintChecker = constraints
it.sp = sp
it.activePlugin = activePluginProvider
it.activePlugin = activePlugin
it.iobCobCalculator = iobCobCalculator
it.profileFunction = profileFunction
it.rh = rh
@ -331,7 +329,6 @@ class APSResultTest : TestBaseWithProfile() {
@BeforeEach
fun prepare() {
`when`(constraints.isClosedLoopAllowed(anyObject())).thenReturn(closedLoopEnabled)
`when`(activePluginProvider.activePump).thenReturn(testPumpPlugin)
`when`(sp.getDouble(ArgumentMatchers.anyInt(), ArgumentMatchers.anyDouble())).thenReturn(30.0)
`when`(profileFunction.getProfile()).thenReturn(validProfile)
}

View file

@ -1,7 +1,5 @@
package info.nightscout.plugins.general.autotune
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.core.profile.ProfileSealed
import info.nightscout.database.entities.data.Block
import info.nightscout.database.entities.data.TargetBlock
@ -9,12 +7,12 @@ import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.profile.PureProfile
import info.nightscout.interfaces.utils.JsonHelper
import info.nightscout.plugins.general.autotune.data.PreppedGlucose
import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.utils.DateUtil
import info.nightscout.shared.utils.T
import info.nightscout.sharedtests.TestBaseWithProfile
import org.json.JSONArray
import org.json.JSONObject
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mock
@ -24,9 +22,7 @@ import java.util.TimeZone
class AutotuneCoreTest : TestBaseWithProfile() {
@Mock lateinit var sp: SP
@Mock lateinit var autotuneFS: AutotuneFS
@Mock lateinit var injector: HasAndroidInjector
private lateinit var autotuneCore: AutotuneCore
private var min5mCarbImpact = 0.0
private var autotuneMin = 0.0
@ -53,12 +49,12 @@ class AutotuneCoreTest : TestBaseWithProfile() {
val oapsOutputProfile = atProfileFromOapsJson(JSONObject(oapsOutputProfileJson), dateUtil)
val outProfile = autotuneCore.tuneAllTheThings(prep, inputProfile, inputProfile)
oapsOutputProfile?.let {
Assert.assertEquals(oapsOutputProfile.isf, outProfile.isf, 0.0)
Assert.assertEquals(oapsOutputProfile.ic, outProfile.ic, 0.0)
Assertions.assertEquals(oapsOutputProfile.isf, outProfile.isf, 0.0)
Assertions.assertEquals(oapsOutputProfile.ic, outProfile.ic, 0.0)
for (i in 0..23)
Assert.assertEquals(oapsOutputProfile.basal[i], outProfile.basal[i], 0.0)
Assertions.assertEquals(oapsOutputProfile.basal[i], outProfile.basal[i], 0.0)
}
?: Assert.fail()
?: Assertions.fail()
}
@Suppress("SpellCheckingInspection")
@ -77,12 +73,12 @@ class AutotuneCoreTest : TestBaseWithProfile() {
val oapsOutputProfile = atProfileFromOapsJson(JSONObject(oapsOutputProfileJson), dateUtil)
val outProfile = autotuneCore.tuneAllTheThings(prep, inputProfile, pumpProfile)
oapsOutputProfile?.let {
Assert.assertEquals(oapsOutputProfile.isf, outProfile.isf, 0.0)
Assert.assertEquals(oapsOutputProfile.ic, outProfile.ic, 0.0)
Assertions.assertEquals(oapsOutputProfile.isf, outProfile.isf, 0.0)
Assertions.assertEquals(oapsOutputProfile.ic, outProfile.ic, 0.0)
for (i in 0..23)
Assert.assertEquals(oapsOutputProfile.basal[i], outProfile.basal[i], 0.0)
Assertions.assertEquals(oapsOutputProfile.basal[i], outProfile.basal[i], 0.0)
}
?: Assert.fail()
?: Assertions.fail()
}
/**

View file

@ -1,7 +1,5 @@
package info.nightscout.plugins.general.autotune
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.core.extensions.shiftBlock
import info.nightscout.core.profile.ProfileSealed
import info.nightscout.database.entities.Bolus
@ -20,9 +18,10 @@ import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.utils.DateUtil
import info.nightscout.shared.utils.T
import info.nightscout.sharedtests.TestBaseWithProfile
import org.json.JSONArray
import org.json.JSONObject
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mock
@ -32,9 +31,7 @@ import java.util.TimeZone
class AutotunePrepTest : TestBaseWithProfile() {
@Mock lateinit var sp: SP
@Mock lateinit var autotuneFS: AutotuneFS
@Mock lateinit var injector: HasAndroidInjector
@Mock lateinit var repository: AppRepository
private lateinit var autotunePrep: AutotunePrep
private lateinit var autotuneIob: TestAutotuneIob
@ -70,21 +67,21 @@ class AutotunePrepTest : TestBaseWithProfile() {
try {
aapsPreppedGlucose?.let { // compare all categorization calculated by aaps plugin (aapsPreppedGlucose) with categorization calculated by OpenAPS (oapsPreppedGlucose)
for (i in aapsPreppedGlucose.crData.indices)
Assert.assertTrue(oapsPreppedGlucose.crData[i].equals(aapsPreppedGlucose.crData[i]))
Assertions.assertTrue(oapsPreppedGlucose.crData[i].equals(aapsPreppedGlucose.crData[i]))
for (i in aapsPreppedGlucose.csfGlucoseData.indices)
Assert.assertTrue(oapsPreppedGlucose.csfGlucoseData[i].equals(aapsPreppedGlucose.csfGlucoseData[i]))
Assertions.assertTrue(oapsPreppedGlucose.csfGlucoseData[i].equals(aapsPreppedGlucose.csfGlucoseData[i]))
oapsPreppedGlucose.isfGlucoseData = oapsPreppedGlucose.isfGlucoseData.sortedBy { it.date }
aapsPreppedGlucose.isfGlucoseData = aapsPreppedGlucose.isfGlucoseData.sortedBy { it.date }
for (i in aapsPreppedGlucose.isfGlucoseData.indices)
Assert.assertTrue(oapsPreppedGlucose.isfGlucoseData[i].equals(aapsPreppedGlucose.isfGlucoseData[i]))
Assertions.assertTrue(oapsPreppedGlucose.isfGlucoseData[i].equals(aapsPreppedGlucose.isfGlucoseData[i]))
oapsPreppedGlucose.basalGlucoseData = oapsPreppedGlucose.basalGlucoseData.sortedBy { it.date }
aapsPreppedGlucose.basalGlucoseData = aapsPreppedGlucose.basalGlucoseData.sortedBy { it.date }
for (i in aapsPreppedGlucose.basalGlucoseData.indices)
Assert.assertTrue(oapsPreppedGlucose.basalGlucoseData[i].equals(aapsPreppedGlucose.basalGlucoseData[i]))
Assertions.assertTrue(oapsPreppedGlucose.basalGlucoseData[i].equals(aapsPreppedGlucose.basalGlucoseData[i]))
}
?: Assert.fail()
?: Assertions.fail()
} catch (e: Exception) {
Assert.fail()
Assertions.fail()
}
}
@ -109,21 +106,21 @@ class AutotunePrepTest : TestBaseWithProfile() {
try {
aapsPreppedGlucose?.let { // compare all categorization calculated by aaps plugin (aapsPreppedGlucose) with categorization calculated by OpenAPS (oapsPreppedGlucose)
for (i in aapsPreppedGlucose.crData.indices)
Assert.assertTrue(oapsPreppedGlucose.crData[i].equals(aapsPreppedGlucose.crData[i]))
Assertions.assertTrue(oapsPreppedGlucose.crData[i].equals(aapsPreppedGlucose.crData[i]))
for (i in aapsPreppedGlucose.csfGlucoseData.indices)
Assert.assertTrue(oapsPreppedGlucose.csfGlucoseData[i].equals(aapsPreppedGlucose.csfGlucoseData[i]))
Assertions.assertTrue(oapsPreppedGlucose.csfGlucoseData[i].equals(aapsPreppedGlucose.csfGlucoseData[i]))
oapsPreppedGlucose.isfGlucoseData = oapsPreppedGlucose.isfGlucoseData.sortedBy { it.date }
aapsPreppedGlucose.isfGlucoseData = aapsPreppedGlucose.isfGlucoseData.sortedBy { it.date }
for (i in aapsPreppedGlucose.isfGlucoseData.indices)
Assert.assertTrue(oapsPreppedGlucose.isfGlucoseData[i].equals(aapsPreppedGlucose.isfGlucoseData[i]))
Assertions.assertTrue(oapsPreppedGlucose.isfGlucoseData[i].equals(aapsPreppedGlucose.isfGlucoseData[i]))
oapsPreppedGlucose.basalGlucoseData = oapsPreppedGlucose.basalGlucoseData.sortedBy { it.date }
aapsPreppedGlucose.basalGlucoseData = aapsPreppedGlucose.basalGlucoseData.sortedBy { it.date }
for (i in aapsPreppedGlucose.basalGlucoseData.indices)
Assert.assertTrue(oapsPreppedGlucose.basalGlucoseData[i].equals(aapsPreppedGlucose.basalGlucoseData[i]))
Assertions.assertTrue(oapsPreppedGlucose.basalGlucoseData[i].equals(aapsPreppedGlucose.basalGlucoseData[i]))
}
?: Assert.fail()
?: Assertions.fail()
} catch (e: Exception) {
Assert.fail()
Assertions.fail()
}
}
@ -148,21 +145,21 @@ class AutotunePrepTest : TestBaseWithProfile() {
try {
aapsPreppedGlucose?.let { // compare all categorization calculated by aaps plugin (aapsPreppedGlucose) with categorization calculated by OpenAPS (oapsPreppedGlucose)
for (i in aapsPreppedGlucose.crData.indices)
Assert.assertTrue(oapsPreppedGlucose.crData[i].equals(aapsPreppedGlucose.crData[i]))
Assertions.assertTrue(oapsPreppedGlucose.crData[i].equals(aapsPreppedGlucose.crData[i]))
for (i in aapsPreppedGlucose.csfGlucoseData.indices)
Assert.assertTrue(oapsPreppedGlucose.csfGlucoseData[i].equals(aapsPreppedGlucose.csfGlucoseData[i]))
Assertions.assertTrue(oapsPreppedGlucose.csfGlucoseData[i].equals(aapsPreppedGlucose.csfGlucoseData[i]))
oapsPreppedGlucose.isfGlucoseData = oapsPreppedGlucose.isfGlucoseData.sortedBy { it.date }
aapsPreppedGlucose.isfGlucoseData = aapsPreppedGlucose.isfGlucoseData.sortedBy { it.date }
for (i in aapsPreppedGlucose.isfGlucoseData.indices)
Assert.assertTrue(oapsPreppedGlucose.isfGlucoseData[i].equals(aapsPreppedGlucose.isfGlucoseData[i]))
Assertions.assertTrue(oapsPreppedGlucose.isfGlucoseData[i].equals(aapsPreppedGlucose.isfGlucoseData[i]))
oapsPreppedGlucose.basalGlucoseData = oapsPreppedGlucose.basalGlucoseData.sortedBy { it.date }
aapsPreppedGlucose.basalGlucoseData = aapsPreppedGlucose.basalGlucoseData.sortedBy { it.date }
for (i in aapsPreppedGlucose.basalGlucoseData.indices)
Assert.assertTrue(oapsPreppedGlucose.basalGlucoseData[i].equals(aapsPreppedGlucose.basalGlucoseData[i]))
Assertions.assertTrue(oapsPreppedGlucose.basalGlucoseData[i].equals(aapsPreppedGlucose.basalGlucoseData[i]))
}
?: Assert.fail()
?: Assertions.fail()
} catch (e: Exception) {
Assert.fail()
Assertions.fail()
}
}

View file

@ -1,11 +1,11 @@
package info.nightscout.plugins.general.autotune
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.plugins.general.autotune.data.BGDatum
import info.nightscout.plugins.general.autotune.data.CRDatum
import info.nightscout.plugins.general.autotune.data.PreppedGlucose
import info.nightscout.sharedtests.TestBaseWithProfile
import org.json.JSONObject
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.io.File
@ -43,10 +43,10 @@ class PreppedGlucoseTest : TestBaseWithProfile() {
JSONObject("{\"device\":\"AndroidAPS-DexcomG6\",\"date\":1653180549000,\"dateString\":\"2022-05-22T00:49:09.000Z\",\"isValid\":true,\"sgv\":121,\"direction\":\"FortyFiveDown\",\"type\":\"sgv\",\"_id\":\"628988a3da46aa0004d1e0f5\",\"glucose\":121,\"avgDelta\":\"-5.25\",\"BGI\":-3.32,\"deviation\":\"-1.93\"}"),
dateUtil
)
Assert.assertEquals(3, prep1.crData.size)
Assert.assertTrue(crData0.equals(prep1.crData[0]))
Assert.assertTrue(csfDataEnd.equals(prep1.csfGlucoseData[prep1.csfGlucoseData.size - 1]))
Assert.assertTrue(isfData0.equals(prep1.isfGlucoseData[0]))
Assert.assertTrue(basalDataEnd.equals(prep1.basalGlucoseData[prep1.basalGlucoseData.size - 1]))
Assertions.assertEquals(3, prep1.crData.size)
Assertions.assertTrue(crData0.equals(prep1.crData[0]))
Assertions.assertTrue(csfDataEnd.equals(prep1.csfGlucoseData[prep1.csfGlucoseData.size - 1]))
Assertions.assertTrue(isfData0.equals(prep1.isfGlucoseData[0]))
Assertions.assertTrue(basalDataEnd.equals(prep1.basalGlucoseData[prep1.basalGlucoseData.size - 1]))
}
}

View file

@ -26,6 +26,7 @@ dependencies {
implementation project(':app-wear-shared:shared')
implementation project(':core:interfaces')
testImplementation project(':app-wear-shared:shared-tests')
testImplementation project(':implementation')
testImplementation project(':plugins:main')

View file

@ -1,107 +0,0 @@
package info.nightscout.androidaps
import androidx.collection.ArrayMap
import dagger.android.HasAndroidInjector
import info.nightscout.core.extensions.pureProfileFromJson
import info.nightscout.core.profile.ProfileSealed
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.profile.ProfileStore
import info.nightscout.interfaces.profile.PureProfile
import info.nightscout.interfaces.utils.HardLimits
import info.nightscout.interfaces.utils.JsonHelper
import info.nightscout.rx.bus.RxBus
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil
import org.json.JSONException
import org.json.JSONObject
import javax.inject.Inject
class ProfileStoreObject(val injector: HasAndroidInjector, override val data: JSONObject, val dateUtil: DateUtil) : ProfileStore {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var activePlugin: ActivePlugin
@Inject lateinit var config: Config
@Inject lateinit var rh: ResourceHelper
@Inject lateinit var rxBus: RxBus
@Inject lateinit var hardLimits: HardLimits
init {
injector.androidInjector().inject(this)
}
private val cachedObjects = ArrayMap<String, PureProfile>()
private fun storeUnits(): String? = JsonHelper.safeGetStringAllowNull(data, "units", null)
private fun getStore(): JSONObject? {
try {
if (data.has("store")) return data.getJSONObject("store")
} catch (e: JSONException) {
aapsLogger.error("Unhandled exception", e)
}
return null
}
override fun getStartDate(): Long {
val iso = JsonHelper.safeGetString(data, "created_at") ?: JsonHelper.safeGetString(data,"startDate") ?: return 0
return try {
dateUtil.fromISODateString(iso)
} catch (e: Exception) {
0
}
}
override fun getDefaultProfile(): PureProfile? = getDefaultProfileName()?.let { getSpecificProfile(it) }
override fun getDefaultProfileJson(): JSONObject? = getDefaultProfileName()?.let { getSpecificProfileJson(it) }
override fun getDefaultProfileName(): String? {
val defaultProfileName = data.optString("defaultProfile")
return if (defaultProfileName.isNotEmpty()) getStore()?.has(defaultProfileName)?.let { defaultProfileName } else null
}
override fun getProfileList(): ArrayList<CharSequence> {
val ret = ArrayList<CharSequence>()
getStore()?.keys()?.let { keys ->
while (keys.hasNext()) {
val profileName = keys.next() as String
ret.add(profileName)
}
}
return ret
}
@Synchronized
override fun getSpecificProfile(profileName: String): PureProfile? {
var profile: PureProfile? = null
val units = JsonHelper.safeGetStringAllowNull(data, "units", storeUnits())
getStore()?.let { store ->
if (store.has(profileName)) {
profile = cachedObjects[profileName]
if (profile == null) {
JsonHelper.safeGetJSONObject(store, profileName, null)?.let { profileObject ->
profile = pureProfileFromJson(profileObject, dateUtil, units)
profile?.let { cachedObjects[profileName] = profile }
}
}
}
}
return profile
}
private fun getSpecificProfileJson(profileName: String): JSONObject? {
getStore()?.let { store ->
if (store.has(profileName))
return JsonHelper.safeGetJSONObject(store, profileName, null)
}
return null
}
override val allProfilesValid: Boolean
get() = getProfileList()
.asSequence()
.map { profileName -> getSpecificProfile(profileName.toString()) }
.map { pureProfile -> pureProfile?.let { ProfileSealed.Pure(pureProfile).isValid("allProfilesValid", activePlugin.activePump, config, rh, rxBus, hardLimits, false) } }
.all { it?.isValid == true }
}

View file

@ -1,49 +0,0 @@
package info.nightscout.androidaps
import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.TestAapsSchedulers
import info.nightscout.rx.logging.AAPSLoggerTest
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.ArgumentMatcher
import org.mockito.Mockito
import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.junit.jupiter.MockitoSettings
import org.mockito.quality.Strictness
import java.util.Locale
@Suppress("SpellCheckingInspection")
@ExtendWith(MockitoExtension::class)
@MockitoSettings(strictness = Strictness.LENIENT)
open class TestBase {
val aapsLogger = AAPSLoggerTest()
val aapsSchedulers: AapsSchedulers = TestAapsSchedulers()
@BeforeEach
fun setupLocale() {
Locale.setDefault(Locale.ENGLISH)
System.setProperty("disableFirebase", "true")
}
// Workaround for Kotlin nullability.
// https://medium.com/@elye.project/befriending-kotlin-and-mockito-1c2e7b0ef791
// https://stackoverflow.com/questions/30305217/is-it-possible-to-use-mockito-in-kotlin
fun <T> anyObject(): T {
Mockito.any<T>()
return uninitialized()
}
fun <T> argThatKotlin(matcher: ArgumentMatcher<T>): T {
Mockito.argThat(matcher)
return uninitialized()
}
fun <T> eqObject(expected: T): T {
Mockito.eq<T>(expected)
return uninitialized()
}
@Suppress("Unchecked_Cast")
fun <T> uninitialized(): T = null as T
}

View file

@ -1,61 +0,0 @@
package info.nightscout.androidaps
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.core.extensions.pureProfileFromJson
import info.nightscout.core.profile.ProfileSealed
import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.database.impl.AppRepository
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.profile.DefaultValueHelper
import info.nightscout.interfaces.profile.Profile
import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.interfaces.profile.ProfileStore
import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil
import org.json.JSONObject
import org.junit.jupiter.api.BeforeEach
import org.mockito.Mock
@Suppress("SpellCheckingInspection")
open class TestBaseWithProfile : TestBase() {
@Mock lateinit var activePluginProvider: ActivePlugin
@Mock lateinit var rh: ResourceHelper
@Mock lateinit var fabricPrivacy: FabricPrivacy
@Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var defaultValueHelper: DefaultValueHelper
@Mock lateinit var dateUtil: DateUtil
@Mock lateinit var config: Config
@Mock lateinit var repository: AppRepository
val rxBus = RxBus(aapsSchedulers, aapsLogger)
private val profileInjector = HasAndroidInjector {
AndroidInjector {
}
}
private lateinit var validProfileJSON: String
lateinit var validProfile: Profile
@Suppress("PropertyName") val TESTPROFILENAME = "someProfile"
@BeforeEach
fun prepareMock() {
validProfileJSON = "{\"dia\":\"5\",\"carbratio\":[{\"time\":\"00:00\",\"value\":\"30\"}],\"carbs_hr\":\"20\",\"delay\":\"20\",\"sens\":[{\"time\":\"00:00\",\"value\":\"3\"}," +
"{\"time\":\"2:00\",\"value\":\"3.4\"}],\"timezone\":\"UTC\",\"basal\":[{\"time\":\"00:00\",\"value\":\"1\"}],\"target_low\":[{\"time\":\"00:00\",\"value\":\"4.5\"}]," +
"\"target_high\":[{\"time\":\"00:00\",\"value\":\"7\"}],\"startDate\":\"1970-01-01T00:00:00.000Z\",\"units\":\"mmol\"}"
validProfile = ProfileSealed.Pure(pureProfileFromJson(JSONObject(validProfileJSON), dateUtil)!!)
}
fun getValidProfileStore(): ProfileStore {
val json = JSONObject()
val store = JSONObject()
store.put(TESTPROFILENAME, JSONObject(validProfileJSON))
json.put("defaultProfile", TESTPROFILENAME)
json.put("store", store)
return ProfileStoreObject(profileInjector, json, dateUtil)
}
}

View file

@ -1,86 +0,0 @@
package info.nightscout.androidaps
import dagger.android.HasAndroidInjector
import info.nightscout.interfaces.plugin.PluginBase
import info.nightscout.interfaces.plugin.PluginDescription
import info.nightscout.interfaces.profile.Profile
import info.nightscout.interfaces.pump.DetailedBolusInfo
import info.nightscout.interfaces.pump.Pump
import info.nightscout.interfaces.pump.PumpEnactResult
import info.nightscout.interfaces.pump.PumpSync
import info.nightscout.interfaces.pump.defs.ManufacturerType
import info.nightscout.interfaces.pump.defs.PumpDescription
import info.nightscout.interfaces.pump.defs.PumpType
import info.nightscout.interfaces.utils.TimeChangeType
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.shared.interfaces.ResourceHelper
import org.json.JSONObject
@Suppress("MemberVisibilityCanBePrivate")
class TestPumpPlugin(
pluginDescription: PluginDescription,
aapsLogger: AAPSLogger,
rh: ResourceHelper,
injector: HasAndroidInjector
) : PluginBase(
pluginDescription, aapsLogger, rh, injector
), Pump {
var connected = false
var isProfileSet = true
var specialEnable = true
override fun isConnected() = connected
override fun isConnecting() = false
override fun isHandshakeInProgress() = false
val lastData = 0L
val baseBasal = 0.0
override val pumpDescription = PumpDescription()
override fun isInitialized(): Boolean = true
override fun isSuspended(): Boolean = false
override fun isBusy(): Boolean = false
override fun connect(reason: String) {
connected = true
}
override fun disconnect(reason: String) {
connected = false
}
override fun stopConnecting() {
connected = false
}
override fun waitForDisconnectionInSeconds(): Int = 0
override fun getPumpStatus(reason: String) {}
override fun setNewBasalProfile(profile: Profile): PumpEnactResult = PumpEnactResult(injector)
override fun isThisProfileSet(profile: Profile): Boolean = isProfileSet
override fun lastDataTime(): Long = lastData
override val baseBasalRate: Double = baseBasal
override val reservoirLevel: Double = 0.0
override val batteryLevel: Int = 0
override fun deliverTreatment(detailedBolusInfo: DetailedBolusInfo): PumpEnactResult = PumpEnactResult(injector).success(true)
override fun stopBolusDelivering() {}
override fun setTempBasalAbsolute(absoluteRate: Double, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult = PumpEnactResult(
injector
).success(true)
override fun setTempBasalPercent(percent: Int, durationInMinutes: Int, profile: Profile, enforceNew: Boolean, tbrType: PumpSync.TemporaryBasalType): PumpEnactResult =
PumpEnactResult(injector).success(true)
override fun setExtendedBolus(insulin: Double, durationInMinutes: Int): PumpEnactResult = PumpEnactResult(injector).success(true)
override fun cancelTempBasal(enforceNew: Boolean): PumpEnactResult = PumpEnactResult(injector).success(true)
override fun cancelExtendedBolus(): PumpEnactResult = PumpEnactResult(injector).success(true)
override fun getJSONStatus(profile: Profile, profileName: String, version: String): JSONObject = JSONObject()
override fun manufacturer(): ManufacturerType = ManufacturerType.AAPS
override fun model(): PumpType = PumpType.GENERIC_AAPS
override fun serialNumber(): String = "1"
override fun shortStatus(veryShort: Boolean): String = ""
override val isFakingTempsByExtendedBoluses: Boolean = false
override fun loadTDDs(): PumpEnactResult = PumpEnactResult(injector).success(true)
override fun canHandleDST(): Boolean = true
override fun timezoneOrDSTChanged(timeChangeType: TimeChangeType) {}
override fun specialEnableCondition(): Boolean = specialEnable
}

View file

@ -2,7 +2,6 @@ package info.nightscout.automation
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import info.nightscout.automation.actions.Action
import info.nightscout.automation.actions.ActionLoopEnable
import info.nightscout.automation.actions.ActionStopProcessing
@ -13,8 +12,9 @@ import info.nightscout.interfaces.ConfigBuilder
import info.nightscout.interfaces.aps.Loop
import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.sharedtests.TestBase
import org.json.JSONObject
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.mockito.Mock
@ -46,39 +46,39 @@ class AutomationEventTest : TestBase() {
// create test object
val event = AutomationEventObject(injector)
event.title = "Test"
event.trigger = TriggerDummy(injector).instantiate(JSONObject(TriggerConnectorTest.oneItem)) as TriggerConnector
event.trigger = TriggerDummy(injector).instantiate(JSONObject(TriggerConnectorTest().oneItem)) as TriggerConnector
event.addAction(ActionLoopEnable(injector))
// export to json
val eventJsonExpected =
"{\"userAction\":false,\"autoRemove\":false,\"readOnly\":false,\"trigger\":\"{\\\"data\\\":{\\\"connectorType\\\":\\\"AND\\\",\\\"triggerList\\\":[\\\"{\\\\\\\"data\\\\\\\":{\\\\\\\"connectorType\\\\\\\":\\\\\\\"AND\\\\\\\",\\\\\\\"triggerList\\\\\\\":[]},\\\\\\\"type\\\\\\\":\\\\\\\"TriggerConnector\\\\\\\"}\\\"]},\\\"type\\\":\\\"TriggerConnector\\\"}\",\"title\":\"Test\",\"systemAction\":false,\"actions\":[\"{\\\"type\\\":\\\"ActionLoopEnable\\\"}\"],\"enabled\":true}"
Assert.assertEquals(eventJsonExpected, event.toJSON())
Assertions.assertEquals(eventJsonExpected, event.toJSON())
// clone
val clone = AutomationEventObject(injector).fromJSON(eventJsonExpected, 1)
// check title
Assert.assertEquals(event.title, clone.title)
Assertions.assertEquals(event.title, clone.title)
// check trigger
Assert.assertNotNull(clone.trigger)
Assert.assertFalse(event.trigger === clone.trigger) // not the same object reference
Assert.assertEquals(event.trigger.javaClass, clone.trigger.javaClass)
Assert.assertEquals(event.trigger.toJSON(), clone.trigger.toJSON())
Assertions.assertNotNull(clone.trigger)
Assertions.assertFalse(event.trigger === clone.trigger) // not the same object reference
Assertions.assertEquals(event.trigger.javaClass, clone.trigger.javaClass)
Assertions.assertEquals(event.trigger.toJSON(), clone.trigger.toJSON())
// check action
Assert.assertEquals(1, clone.actions.size)
Assert.assertFalse(event.actions === clone.actions) // not the same object reference
Assert.assertEquals(clone.toJSON(), clone.toJSON())
Assertions.assertEquals(1, clone.actions.size)
Assertions.assertFalse(event.actions === clone.actions) // not the same object reference
Assertions.assertEquals(clone.toJSON(), clone.toJSON())
}
@Test
fun hasStopProcessing() {
val event = AutomationEventObject(injector)
event.title = "Test"
event.trigger = TriggerDummy(injector).instantiate(JSONObject(TriggerConnectorTest.oneItem)) as TriggerConnector
Assert.assertFalse(event.hasStopProcessing())
event.trigger = TriggerDummy(injector).instantiate(JSONObject(TriggerConnectorTest().oneItem)) as TriggerConnector
Assertions.assertFalse(event.hasStopProcessing())
event.addAction(ActionStopProcessing(injector))
Assert.assertTrue(event.hasStopProcessing())
Assertions.assertTrue(event.hasStopProcessing())
}
}

View file

@ -3,9 +3,9 @@ package info.nightscout.automation
import android.content.Context
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import info.nightscout.automation.services.LocationServiceHelper
import info.nightscout.automation.triggers.Trigger
import info.nightscout.automation.ui.TimerUtil
import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.GlucoseUnit
@ -13,11 +13,11 @@ import info.nightscout.interfaces.aps.Loop
import info.nightscout.interfaces.constraints.Constraints
import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.automation.ui.TimerUtil
import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.utils.DateUtil
import info.nightscout.sharedtests.TestBase
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test

View file

@ -3,9 +3,9 @@ package info.nightscout.automation
import android.content.Context
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import info.nightscout.automation.services.LocationServiceHelper
import info.nightscout.automation.triggers.Trigger
import info.nightscout.automation.ui.TimerUtil
import info.nightscout.core.utils.fabric.FabricPrivacy
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.GlucoseUnit
@ -13,11 +13,11 @@ import info.nightscout.interfaces.aps.Loop
import info.nightscout.interfaces.constraints.Constraints
import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.profile.ProfileFunction
import info.nightscout.automation.ui.TimerUtil
import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.utils.DateUtil
import info.nightscout.sharedtests.TestBase
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
@ -59,8 +59,10 @@ class CarbTimerImplTest : TestBase() {
Mockito.`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
dateUtil = DateUtil(context)
timerUtil = TimerUtil(context)
automationPlugin = AutomationPlugin(injector, rh, context, sp, fabricPrivacy, loop, rxBus, constraintChecker, aapsLogger, aapsSchedulers, config, locationServiceHelper, dateUtil,
activePlugin, timerUtil)
automationPlugin = AutomationPlugin(
injector, rh, context, sp, fabricPrivacy, loop, rxBus, constraintChecker, aapsLogger, aapsSchedulers, config, locationServiceHelper, dateUtil,
activePlugin, timerUtil
)
}
@Test

View file

@ -2,11 +2,11 @@ package info.nightscout.automation
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import info.nightscout.automation.triggers.Trigger
import info.nightscout.automation.triggers.TriggerConnector
import info.nightscout.automation.triggers.TriggerDummy
import org.junit.Assert
import info.nightscout.sharedtests.TestBase
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class ComposeTriggerTest : TestBase() {
@ -23,16 +23,16 @@ class ComposeTriggerTest : TestBase() {
root.list.add(t1)
val t2: Trigger = TriggerDummy(injector)
root.list.add(t2)
Assert.assertEquals(3, root.size())
Assert.assertEquals(t0, root.list[0])
Assert.assertEquals(t1, root.list[1])
Assert.assertEquals(t2, root.list[2])
Assertions.assertEquals(3, root.size())
Assertions.assertEquals(t0, root.list[0])
Assertions.assertEquals(t1, root.list[1])
Assertions.assertEquals(t2, root.list[2])
// remove a trigger
root.list.remove(t1)
Assert.assertEquals(2, root.size())
Assert.assertEquals(t0, root.list[0])
Assert.assertEquals(t2, root.list[1])
Assertions.assertEquals(2, root.size())
Assertions.assertEquals(t0, root.list[0])
Assertions.assertEquals(t2, root.list[1])
}
@Test
@ -44,6 +44,6 @@ class ComposeTriggerTest : TestBase() {
t[i] = TriggerDummy(injector)
root.list.add(t[i]!!)
}
Assert.assertEquals(4, root.size())
Assertions.assertEquals(4, root.size())
}
}

View file

@ -3,17 +3,17 @@ package info.nightscout.automation.actions
import android.content.Context
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import info.nightscout.automation.R
import info.nightscout.automation.elements.InputString
import info.nightscout.automation.ui.TimerUtil
import info.nightscout.interfaces.Config
import info.nightscout.interfaces.pump.PumpEnactResult
import info.nightscout.interfaces.queue.Callback
import info.nightscout.automation.ui.TimerUtil
import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.utils.DateUtil
import org.junit.Assert
import info.nightscout.sharedtests.TestBase
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers
@ -56,39 +56,39 @@ class ActionAlarmTest : TestBase() {
}
@Test fun friendlyNameTest() {
Assert.assertEquals(info.nightscout.core.ui.R.string.alarm, sut.friendlyName())
Assertions.assertEquals(info.nightscout.core.ui.R.string.alarm, sut.friendlyName())
}
@Test fun shortDescriptionTest() {
sut.text = InputString("Asd")
Assert.assertEquals("Alarm: %s", sut.shortDescription())
Assertions.assertEquals("Alarm: %s", sut.shortDescription())
}
@Test fun iconTest() {
Assert.assertEquals(info.nightscout.core.main.R.drawable.ic_access_alarm_24dp, sut.icon())
Assertions.assertEquals(info.nightscout.core.main.R.drawable.ic_access_alarm_24dp, sut.icon())
}
@Test fun doActionTest() {
sut.text = InputString("Asd")
sut.doAction(object : Callback() {
override fun run() {
Assert.assertTrue(result.success)
Assertions.assertTrue(result.success)
}
})
}
@Test fun hasDialogTest() {
Assert.assertTrue(sut.hasDialog())
Assertions.assertTrue(sut.hasDialog())
}
@Test fun toJSONTest() {
sut.text = InputString("Asd")
Assert.assertEquals("{\"data\":{\"text\":\"Asd\"},\"type\":\"ActionAlarm\"}", sut.toJSON())
Assertions.assertEquals("{\"data\":{\"text\":\"Asd\"},\"type\":\"ActionAlarm\"}", sut.toJSON())
}
@Test fun fromJSONTest() {
sut.text = InputString("Asd")
sut.fromJSON("{\"text\":\"Asd\"}")
Assert.assertEquals("Asd", sut.text.value)
Assertions.assertEquals("Asd", sut.text.value)
}
}

View file

@ -8,7 +8,7 @@ import info.nightscout.database.impl.transactions.Transaction
import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.queue.Callback
import io.reactivex.rxjava3.core.Single
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers
@ -21,12 +21,7 @@ class ActionCarePortalEventTest : ActionsTestBase() {
@BeforeEach
fun setup() {
`when`(sp.getString(ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn("AAPS")
`when`(
rh.gs(
ArgumentMatchers.eq(info.nightscout.core.ui.R.string.careportal_note_message),
ArgumentMatchers.anyString()
)
).thenReturn("Note : %s")
`when`(rh.gs(info.nightscout.core.ui.R.string.careportal_note_message)).thenReturn("Note : %s")
`when`(dateUtil.now()).thenReturn(0)
`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
`when`(repository.runTransactionForResult(anyObject<Transaction<InsertIfNewByTimestampTherapyEventTransaction.TransactionResult>>()))
@ -40,31 +35,31 @@ class ActionCarePortalEventTest : ActionsTestBase() {
}
@Test fun friendlyNameTest() {
Assert.assertEquals(info.nightscout.core.ui.R.string.careportal, sut.friendlyName())
Assertions.assertEquals(info.nightscout.core.ui.R.string.careportal, sut.friendlyName())
}
@Test fun shortDescriptionTest() {
Assert.assertEquals("Note : %s", sut.shortDescription())
Assertions.assertEquals("Note : Asd", sut.shortDescription())
}
@Test fun iconTest() {
Assert.assertEquals(info.nightscout.core.main.R.drawable.ic_cp_note, sut.icon())
Assertions.assertEquals(info.nightscout.core.main.R.drawable.ic_cp_note, sut.icon())
}
@Test fun doActionTest() {
sut.doAction(object : Callback() {
override fun run() {
Assert.assertTrue(result.success)
Assertions.assertTrue(result.success)
}
})
}
@Test fun hasDialogTest() {
Assert.assertTrue(sut.hasDialog())
Assertions.assertTrue(sut.hasDialog())
}
@Test fun toJSONTest() {
Assert.assertEquals(
Assertions.assertEquals(
"{\"data\":{\"note\":\"Asd\",\"cpEvent\":\"NOTE\",\"durationInMinutes\":5},\"type\":\"ActionCarePortalEvent\"}",
sut.toJSON()
)
@ -73,8 +68,8 @@ class ActionCarePortalEventTest : ActionsTestBase() {
@Test fun fromJSONTest() {
sut.note = InputString("Asd")
sut.fromJSON("{\"note\":\"Asd\",\"cpEvent\":\"NOTE\",\"durationInMinutes\":5}")
Assert.assertEquals("Asd", sut.note.value)
Assert.assertEquals(5, sut.duration.value)
Assert.assertEquals(InputCarePortalMenu.EventType.NOTE, sut.cpEvent.value)
Assertions.assertEquals("Asd", sut.note.value)
Assertions.assertEquals(5, sut.duration.value)
Assertions.assertEquals(InputCarePortalMenu.EventType.NOTE, sut.cpEvent.value)
}
}

View file

@ -1,7 +1,7 @@
package info.nightscout.automation.actions
import org.json.JSONObject
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class ActionDummyTest : ActionsTestBase() {
@ -9,12 +9,12 @@ class ActionDummyTest : ActionsTestBase() {
@Test
fun instantiateTest() {
var action: Action? = ActionDummy(injector).instantiate(JSONObject("{\"type\":\"info.nightscout.androidaps.plugins.general.automation.actions.ActionDummy\"}"))
Assert.assertTrue(action is ActionDummy)
Assertions.assertTrue(action is ActionDummy)
action = ActionDummy(injector).instantiate(JSONObject("{\"type\":\"info.nightscout.automation.actions.ActionDummy\"}"))
Assert.assertTrue(action is ActionDummy)
Assertions.assertTrue(action is ActionDummy)
action = ActionDummy(injector).instantiate(JSONObject("{\"type\":\"ActionDummy\"}"))
Assert.assertTrue(action is ActionDummy)
Assertions.assertTrue(action is ActionDummy)
}
}

View file

@ -3,7 +3,7 @@ package info.nightscout.automation.actions
import info.nightscout.automation.R
import info.nightscout.interfaces.plugin.PluginType
import info.nightscout.interfaces.queue.Callback
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers.eq
@ -27,17 +27,17 @@ class ActionLoopDisableTest : ActionsTestBase() {
@Test
fun friendlyNameTest() {
Assert.assertEquals(info.nightscout.core.ui.R.string.disableloop, sut.friendlyName())
Assertions.assertEquals(info.nightscout.core.ui.R.string.disableloop, sut.friendlyName())
}
@Test
fun shortDescriptionTest() {
Assert.assertEquals("Disable loop", sut.shortDescription())
Assertions.assertEquals("Disable loop", sut.shortDescription())
}
@Test
fun iconTest() {
Assert.assertEquals(R.drawable.ic_stop_24dp, sut.icon())
Assertions.assertEquals(R.drawable.ic_stop_24dp, sut.icon())
}
@Test

View file

@ -3,7 +3,7 @@ package info.nightscout.automation.actions
import info.nightscout.automation.R
import info.nightscout.interfaces.plugin.PluginType
import info.nightscout.interfaces.queue.Callback
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mockito
@ -24,15 +24,15 @@ class ActionLoopEnableTest : ActionsTestBase() {
}
@Test fun friendlyNameTest() {
Assert.assertEquals(info.nightscout.core.ui.R.string.enableloop, sut.friendlyName())
Assertions.assertEquals(info.nightscout.core.ui.R.string.enableloop, sut.friendlyName())
}
@Test fun shortDescriptionTest() {
Assert.assertEquals("Enable loop", sut.shortDescription())
Assertions.assertEquals("Enable loop", sut.shortDescription())
}
@Test fun iconTest() {
Assert.assertEquals(R.drawable.ic_play_circle_outline_24dp, sut.icon())
Assertions.assertEquals(R.drawable.ic_play_circle_outline_24dp, sut.icon())
}
@Test fun doActionTest() {

View file

@ -6,7 +6,7 @@ import info.nightscout.database.impl.transactions.CancelCurrentOfflineEventIfAny
import info.nightscout.database.impl.transactions.Transaction
import info.nightscout.interfaces.queue.Callback
import io.reactivex.rxjava3.core.Single
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when`
@ -25,15 +25,15 @@ class ActionLoopResumeTest : ActionsTestBase() {
}
@Test fun friendlyNameTest() {
Assert.assertEquals(info.nightscout.core.ui.R.string.resumeloop, sut.friendlyName())
Assertions.assertEquals(info.nightscout.core.ui.R.string.resumeloop, sut.friendlyName())
}
@Test fun shortDescriptionTest() {
Assert.assertEquals("Resume loop", sut.shortDescription())
Assertions.assertEquals("Resume loop", sut.shortDescription())
}
@Test fun iconTest() {
Assert.assertEquals(R.drawable.ic_replay_24dp, sut.icon())
Assertions.assertEquals(R.drawable.ic_replay_24dp, sut.icon())
}
@Test fun doActionTest() {

View file

@ -3,10 +3,9 @@ package info.nightscout.automation.actions
import info.nightscout.automation.R
import info.nightscout.automation.elements.InputDuration
import info.nightscout.interfaces.queue.Callback
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers
import org.mockito.Mockito
import org.mockito.Mockito.`when`
@ -18,23 +17,23 @@ class ActionLoopSuspendTest : ActionsTestBase() {
fun setup() {
`when`(context.getString(info.nightscout.core.ui.R.string.suspendloop)).thenReturn("Suspend loop")
`when`(rh.gs(ArgumentMatchers.eq(R.string.suspendloopforXmin), ArgumentMatchers.anyInt())).thenReturn("Suspend loop for %d min")
`when`(rh.gs(R.string.suspendloopforXmin)).thenReturn("Suspend loop for %d min")
`when`(context.getString(R.string.alreadysuspended)).thenReturn("Already suspended")
sut = ActionLoopSuspend(injector)
}
@Test fun friendlyNameTest() {
Assert.assertEquals(info.nightscout.core.ui.R.string.suspendloop, sut.friendlyName())
Assertions.assertEquals(info.nightscout.core.ui.R.string.suspendloop, sut.friendlyName())
}
@Test fun shortDescriptionTest() {
sut.minutes = InputDuration(30, InputDuration.TimeUnit.MINUTES)
Assert.assertEquals("Suspend loop for %d min", sut.shortDescription())
Assertions.assertEquals("Suspend loop for 30 min", sut.shortDescription())
}
@Test fun iconTest() {
Assert.assertEquals(R.drawable.ic_pause_circle_outline_24dp, sut.icon())
Assertions.assertEquals(R.drawable.ic_pause_circle_outline_24dp, sut.icon())
}
@Test fun doActionTest() {
@ -58,11 +57,11 @@ class ActionLoopSuspendTest : ActionsTestBase() {
a.minutes = InputDuration(20, InputDuration.TimeUnit.MINUTES)
val b = ActionLoopSuspend(injector)
b.apply(a)
Assert.assertEquals(20, b.minutes.getMinutes().toLong())
Assertions.assertEquals(20, b.minutes.getMinutes().toLong())
}
@Test fun hasDialogTest() {
val a = ActionLoopSuspend(injector)
Assert.assertTrue(a.hasDialog())
Assertions.assertTrue(a.hasDialog())
}
}

View file

@ -3,7 +3,6 @@ package info.nightscout.automation.actions
import android.content.Context
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import info.nightscout.automation.R
import info.nightscout.automation.elements.InputString
import info.nightscout.database.impl.AppRepository
@ -13,8 +12,9 @@ import info.nightscout.interfaces.pump.PumpEnactResult
import info.nightscout.interfaces.queue.Callback
import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.sharedtests.TestBase
import io.reactivex.rxjava3.core.Completable
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers
@ -60,22 +60,22 @@ class ActionNotificationTest : TestBase() {
}
@Test fun friendlyNameTest() {
Assert.assertEquals(info.nightscout.core.ui.R.string.notification, sut.friendlyName())
Assertions.assertEquals(info.nightscout.core.ui.R.string.notification, sut.friendlyName())
}
@Test fun shortDescriptionTest() {
sut.text = InputString("Asd")
Assert.assertEquals("Notification: %s", sut.shortDescription())
Assertions.assertEquals("Notification: %s", sut.shortDescription())
}
@Test fun iconTest() {
Assert.assertEquals(R.drawable.ic_notifications, sut.icon())
Assertions.assertEquals(R.drawable.ic_notifications, sut.icon())
}
@Test fun doActionTest() {
sut.doAction(object : Callback() {
override fun run() {
Assert.assertTrue(result.success)
Assertions.assertTrue(result.success)
}
})
Mockito.verify(rxBus, Mockito.times(2)).send(anyObject())
@ -83,12 +83,12 @@ class ActionNotificationTest : TestBase() {
}
@Test fun hasDialogTest() {
Assert.assertTrue(sut.hasDialog())
Assertions.assertTrue(sut.hasDialog())
}
@Test fun toJSONTest() {
sut.text = InputString("Asd")
Assert.assertEquals(
Assertions.assertEquals(
"{\"data\":{\"text\":\"Asd\"},\"type\":\"ActionNotification\"}",
sut.toJSON()
)
@ -97,6 +97,6 @@ class ActionNotificationTest : TestBase() {
@Test fun fromJSONTest() {
sut.text = InputString("Asd")
sut.fromJSON("{\"text\":\"Asd\"}")
Assert.assertEquals("Asd", sut.text.value)
Assertions.assertEquals("Asd", sut.text.value)
}
}

View file

@ -4,7 +4,7 @@ import info.nightscout.automation.R
import info.nightscout.automation.elements.InputDuration
import info.nightscout.automation.elements.InputPercent
import info.nightscout.interfaces.queue.Callback
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mockito
@ -24,17 +24,17 @@ class ActionProfileSwitchPercentTest : ActionsTestBase() {
}
@Test fun friendlyNameTest() {
Assert.assertEquals(R.string.profilepercentage, sut.friendlyName())
Assertions.assertEquals(R.string.profilepercentage, sut.friendlyName())
}
@Test fun shortDescriptionTest() {
sut.pct = InputPercent(100.0)
sut.duration = InputDuration(30, InputDuration.TimeUnit.MINUTES)
Assert.assertNull(sut.shortDescription()) // not mocked
Assertions.assertEquals("Start profile 100% for 30 min", sut.shortDescription())
}
@Test fun iconTest() {
Assert.assertEquals(info.nightscout.interfaces.R.drawable.ic_actions_profileswitch, sut.icon())
Assertions.assertEquals(info.nightscout.interfaces.R.drawable.ic_actions_profileswitch, sut.icon())
}
@Test fun doActionTest() {
@ -43,25 +43,25 @@ class ActionProfileSwitchPercentTest : ActionsTestBase() {
sut.duration = InputDuration(30, InputDuration.TimeUnit.MINUTES)
sut.doAction(object : Callback() {
override fun run() {
Assert.assertTrue(result.success)
Assertions.assertTrue(result.success)
}
})
Mockito.verify(profileFunction, Mockito.times(1)).createProfileSwitch(30, 110, 0)
}
@Test fun hasDialogTest() {
Assert.assertTrue(sut.hasDialog())
Assertions.assertTrue(sut.hasDialog())
}
@Test fun toJSONTest() {
sut.pct = InputPercent(100.0)
sut.duration = InputDuration(30, InputDuration.TimeUnit.MINUTES)
Assert.assertEquals("{\"data\":{\"percentage\":100,\"durationInMinutes\":30},\"type\":\"ActionProfileSwitchPercent\"}", sut.toJSON())
Assertions.assertEquals("{\"data\":{\"percentage\":100,\"durationInMinutes\":30},\"type\":\"ActionProfileSwitchPercent\"}", sut.toJSON())
}
@Test fun fromJSONTest() {
sut.fromJSON("{\"percentage\":100,\"durationInMinutes\":30}")
Assert.assertEquals(100.0, sut.pct.value, 0.001)
Assert.assertEquals(30.0, sut.duration.getMinutes().toDouble(), 0.001)
Assertions.assertEquals(100.0, sut.pct.value, 0.001)
Assertions.assertEquals(30.0, sut.duration.getMinutes().toDouble(), 0.001)
}
}

View file

@ -3,10 +3,9 @@ package info.nightscout.automation.actions
import info.nightscout.automation.R
import info.nightscout.automation.elements.InputProfileName
import info.nightscout.interfaces.queue.Callback
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers
import org.mockito.ArgumentMatchers.anyLong
import org.mockito.Mockito
import org.mockito.Mockito.anyInt
@ -21,7 +20,7 @@ class ActionProfileSwitchTest : ActionsTestBase() {
@BeforeEach fun setUp() {
`when`(rh.gs(R.string.profilename)).thenReturn("Change profile to")
`when`(rh.gs(ArgumentMatchers.eq(R.string.changengetoprofilename), ArgumentMatchers.anyString())).thenReturn("Change profile to %s")
`when`(rh.gs(R.string.changengetoprofilename)).thenReturn("Change profile to %s")
`when`(context.getString(R.string.alreadyset)).thenReturn("Already set")
`when`(context.getString(info.nightscout.core.ui.R.string.notexists)).thenReturn("not exists")
`when`(context.getString(info.nightscout.core.validators.R.string.error_field_must_not_be_empty)).thenReturn("The field must not be empty")
@ -31,11 +30,11 @@ class ActionProfileSwitchTest : ActionsTestBase() {
}
@Test fun friendlyName() {
Assert.assertEquals(R.string.profilename, sut.friendlyName())
Assertions.assertEquals(R.string.profilename, sut.friendlyName())
}
@Test fun shortDescriptionTest() {
Assert.assertEquals("Change profile to %s", sut.shortDescription())
Assertions.assertEquals("Change profile to ", sut.shortDescription())
}
@Test fun doAction() {
@ -44,7 +43,7 @@ class ActionProfileSwitchTest : ActionsTestBase() {
sut.inputProfileName = InputProfileName(rh, activePlugin, "")
sut.doAction(object : Callback() {
override fun run() {
Assert.assertFalse(result.success)
Assertions.assertFalse(result.success)
}
})
@ -53,7 +52,7 @@ class ActionProfileSwitchTest : ActionsTestBase() {
sut.inputProfileName = InputProfileName(rh, activePlugin, "someProfile")
sut.doAction(object : Callback() {
override fun run() {
Assert.assertFalse(result.success)
Assertions.assertFalse(result.success)
}
})
@ -63,8 +62,8 @@ class ActionProfileSwitchTest : ActionsTestBase() {
sut.inputProfileName = InputProfileName(rh, activePlugin, "Test")
sut.doAction(object : Callback() {
override fun run() {
Assert.assertTrue(result.success)
Assert.assertEquals("Already set", result.comment)
Assertions.assertTrue(result.success)
Assertions.assertEquals("Already set", result.comment)
}
})
@ -73,8 +72,8 @@ class ActionProfileSwitchTest : ActionsTestBase() {
sut.inputProfileName = InputProfileName(rh, activePlugin, "Test")
sut.doAction(object : Callback() {
override fun run() {
Assert.assertFalse(result.success)
Assert.assertEquals("not exists", result.comment)
Assertions.assertFalse(result.success)
Assertions.assertEquals("not exists", result.comment)
}
})
@ -84,29 +83,29 @@ class ActionProfileSwitchTest : ActionsTestBase() {
sut.inputProfileName = InputProfileName(rh, activePlugin, TESTPROFILENAME)
sut.doAction(object : Callback() {
override fun run() {
Assert.assertTrue(result.success)
Assert.assertEquals("OK", result.comment)
Assertions.assertTrue(result.success)
Assertions.assertEquals("OK", result.comment)
}
})
Mockito.verify(profileFunction, Mockito.times(1)).createProfileSwitch(anyObject(), anyString(), anyInt(), anyInt(), anyInt(), anyLong())
}
@Test fun hasDialogTest() {
Assert.assertTrue(sut.hasDialog())
Assertions.assertTrue(sut.hasDialog())
}
@Test fun toJSONTest() {
sut.inputProfileName = InputProfileName(rh, activePlugin, "Test")
Assert.assertEquals(stringJson, sut.toJSON())
Assertions.assertEquals(stringJson, sut.toJSON())
}
@Test fun fromJSONTest() {
val data = "{\"profileToSwitchTo\":\"Test\"}"
sut.fromJSON(data)
Assert.assertEquals("Test", sut.inputProfileName.value)
Assertions.assertEquals("Test", sut.inputProfileName.value)
}
@Test fun iconTest() {
Assert.assertEquals(info.nightscout.interfaces.R.drawable.ic_actions_profileswitch, sut.icon())
Assertions.assertEquals(info.nightscout.interfaces.R.drawable.ic_actions_profileswitch, sut.icon())
}
}

View file

@ -3,11 +3,10 @@ package info.nightscout.automation.actions
import info.nightscout.automation.R
import info.nightscout.automation.elements.InputString
import info.nightscout.interfaces.queue.Callback
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers.anyString
import org.mockito.ArgumentMatchers.eq
import org.mockito.Mockito.`when`
class ActionSendSMSTest : ActionsTestBase() {
@ -17,22 +16,22 @@ class ActionSendSMSTest : ActionsTestBase() {
@BeforeEach
fun setup() {
`when`(rh.gs(eq(R.string.sendsmsactionlabel), anyString())).thenReturn("Send SMS: %s")
`when`(rh.gs(R.string.sendsmsactionlabel)).thenReturn("Send SMS: %s")
`when`(rh.gs(R.string.sendsmsactiondescription)).thenReturn("Send SMS to all numbers")
sut = ActionSendSMS(injector)
}
@Test fun friendlyNameTest() {
Assert.assertEquals(R.string.sendsmsactiondescription, sut.friendlyName())
Assertions.assertEquals(R.string.sendsmsactiondescription, sut.friendlyName())
}
@Test fun shortDescriptionTest() {
Assert.assertEquals("Send SMS: %s", sut.shortDescription())
Assertions.assertEquals("Send SMS: ", sut.shortDescription())
}
@Test fun iconTest() {
Assert.assertEquals(R.drawable.ic_notifications, sut.icon())
Assertions.assertEquals(R.drawable.ic_notifications, sut.icon())
}
@Test fun doActionTest() {
@ -40,22 +39,22 @@ class ActionSendSMSTest : ActionsTestBase() {
sut.text = InputString("Asd")
sut.doAction(object : Callback() {
override fun run() {
Assert.assertTrue(result.success)
Assertions.assertTrue(result.success)
}
})
}
@Test fun hasDialogTest() {
Assert.assertTrue(sut.hasDialog())
Assertions.assertTrue(sut.hasDialog())
}
@Test fun toJSONTest() {
sut.text = InputString("Asd")
Assert.assertEquals("{\"data\":{\"text\":\"Asd\"},\"type\":\"ActionSendSMS\"}", sut.toJSON())
Assertions.assertEquals("{\"data\":{\"text\":\"Asd\"},\"type\":\"ActionSendSMS\"}", sut.toJSON())
}
@Test fun fromJSONTest() {
sut.fromJSON("{\"text\":\"Asd\"}")
Assert.assertEquals("Asd", sut.text.value)
Assertions.assertEquals("Asd", sut.text.value)
}
}

View file

@ -9,7 +9,7 @@ import info.nightscout.database.impl.transactions.Transaction
import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.queue.Callback
import io.reactivex.rxjava3.core.Single
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mockito
@ -27,18 +27,18 @@ class ActionStartTempTargetTest : ActionsTestBase() {
}
@Test fun friendlyNameTest() {
Assert.assertEquals(R.string.starttemptarget, sut.friendlyName())
Assertions.assertEquals(R.string.starttemptarget, sut.friendlyName())
}
@Test fun shortDescriptionTest() {
sut.value = InputTempTarget(profileFunction)
sut.value.value = 100.0
sut.duration = InputDuration(30, InputDuration.TimeUnit.MINUTES)
Assert.assertEquals("Start temp target: 100mg/dl@null(Automation)", sut.shortDescription())
Assertions.assertEquals("Start temp target: 100mg/dl@null(Automation)", sut.shortDescription())
}
@Test fun iconTest() {
Assert.assertEquals(info.nightscout.core.main.R.drawable.ic_temptarget_high, sut.icon())
Assertions.assertEquals(info.nightscout.core.main.R.drawable.ic_temptarget_high, sut.icon())
}
@Test fun doActionTest() {
@ -78,27 +78,27 @@ class ActionStartTempTargetTest : ActionsTestBase() {
sut.doAction(object : Callback() {
override fun run() {
Assert.assertTrue(result.success)
Assertions.assertTrue(result.success)
}
})
Mockito.verify(repository, Mockito.times(1)).runTransactionForResult(anyObject<Transaction<InsertAndCancelCurrentTemporaryTargetTransaction.TransactionResult>>())
}
@Test fun hasDialogTest() {
Assert.assertTrue(sut.hasDialog())
Assertions.assertTrue(sut.hasDialog())
}
@Test fun toJSONTest() {
sut.value = InputTempTarget(profileFunction)
sut.value.value = 100.0
sut.duration = InputDuration(30, InputDuration.TimeUnit.MINUTES)
Assert.assertEquals("{\"data\":{\"durationInMinutes\":30,\"units\":\"mg/dl\",\"value\":100},\"type\":\"ActionStartTempTarget\"}", sut.toJSON())
Assertions.assertEquals("{\"data\":{\"durationInMinutes\":30,\"units\":\"mg/dl\",\"value\":100},\"type\":\"ActionStartTempTarget\"}", sut.toJSON())
}
@Test fun fromJSONTest() {
sut.fromJSON("{\"value\":100,\"durationInMinutes\":30,\"units\":\"mg/dl\"}")
Assert.assertEquals(GlucoseUnit.MGDL, sut.value.units)
Assert.assertEquals(100.0, sut.value.value, 0.001)
Assert.assertEquals(30.0, sut.duration.getMinutes().toDouble(), 0.001)
Assertions.assertEquals(GlucoseUnit.MGDL, sut.value.units)
Assertions.assertEquals(100.0, sut.value.value, 0.001)
Assertions.assertEquals(30.0, sut.duration.getMinutes().toDouble(), 0.001)
}
}

View file

@ -2,7 +2,7 @@ package info.nightscout.automation.actions
import info.nightscout.automation.R
import info.nightscout.interfaces.queue.Callback
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when`
@ -20,24 +20,24 @@ class ActionStopProcessingTest : ActionsTestBase() {
@Test
fun friendlyNameTest() {
Assert.assertEquals(R.string.stop_processing, sut.friendlyName())
Assertions.assertEquals(R.string.stop_processing, sut.friendlyName())
}
@Test
fun shortDescriptionTest() {
Assert.assertEquals("Stop processing", sut.shortDescription())
Assertions.assertEquals("Stop processing", sut.shortDescription())
}
@Test
fun iconTest() {
Assert.assertEquals(R.drawable.ic_stop_24dp, sut.icon())
Assertions.assertEquals(R.drawable.ic_stop_24dp, sut.icon())
}
@Test
fun doActionTest() {
sut.doAction(object : Callback() {
override fun run() {
Assert.assertTrue(result.success)
Assertions.assertTrue(result.success)
}
})
}

View file

@ -6,7 +6,7 @@ import info.nightscout.database.impl.transactions.CancelCurrentTemporaryTargetIf
import info.nightscout.database.impl.transactions.Transaction
import info.nightscout.interfaces.queue.Callback
import io.reactivex.rxjava3.core.Single
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mockito
@ -24,15 +24,15 @@ class ActionStopTempTargetTest : ActionsTestBase() {
}
@Test fun friendlyNameTest() {
Assert.assertEquals(info.nightscout.core.ui.R.string.stoptemptarget, sut.friendlyName())
Assertions.assertEquals(info.nightscout.core.ui.R.string.stoptemptarget, sut.friendlyName())
}
@Test fun shortDescriptionTest() {
Assert.assertEquals("Stop temp target", sut.shortDescription())
Assertions.assertEquals("Stop temp target", sut.shortDescription())
}
@Test fun iconTest() {
Assert.assertEquals(R.drawable.ic_stop_24dp, sut.icon())
Assertions.assertEquals(R.drawable.ic_stop_24dp, sut.icon())
}
@Test fun doActionTest() {
@ -52,22 +52,22 @@ class ActionStopTempTargetTest : ActionsTestBase() {
sut.doAction(object : Callback() {
override fun run() {
Assert.assertTrue(result.success)
Assertions.assertTrue(result.success)
}
})
Mockito.verify(repository, Mockito.times(1)).runTransactionForResult((anyObject<Transaction<CancelCurrentTemporaryTargetIfAnyTransaction.TransactionResult>>()))
}
@Test fun hasDialogTest() {
Assert.assertFalse(sut.hasDialog())
Assertions.assertFalse(sut.hasDialog())
}
@Test fun toJSONTest() {
Assert.assertEquals("{\"type\":\"ActionStopTempTarget\"}", sut.toJSON())
Assertions.assertEquals("{\"type\":\"ActionStopTempTarget\"}", sut.toJSON())
}
@Test fun fromJSONTest() {
sut.fromJSON("{\"reason\":\"Test\"}")
Assert.assertNotNull(sut)
Assertions.assertNotNull(sut)
}
}

View file

@ -1,13 +1,11 @@
package info.nightscout.automation.actions
import android.content.Context
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.androidaps.TestPumpPlugin
import info.nightscout.automation.triggers.Trigger
import info.nightscout.database.entities.DeviceStatus
import info.nightscout.database.entities.OfflineEvent
import info.nightscout.database.impl.AppRepository
import info.nightscout.interfaces.ConfigBuilder
import info.nightscout.interfaces.GlucoseUnit
import info.nightscout.interfaces.aps.Loop
@ -15,7 +13,6 @@ import info.nightscout.interfaces.configBuilder.RunningConfiguration
import info.nightscout.interfaces.constraints.Constraint
import info.nightscout.interfaces.iob.IobCobCalculator
import info.nightscout.interfaces.logging.UserEntryLogger
import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.plugin.PluginBase
import info.nightscout.interfaces.plugin.PluginDescription
import info.nightscout.interfaces.plugin.PluginType
@ -29,8 +26,8 @@ import info.nightscout.interfaces.receivers.ReceiverStatusStore
import info.nightscout.interfaces.smsCommunicator.SmsCommunicator
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.shared.interfaces.ResourceHelper
import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.utils.DateUtil
import info.nightscout.sharedtests.TestBaseWithProfile
import org.junit.jupiter.api.BeforeEach
import org.mockito.Mock
import org.mockito.Mockito.`when`
@ -79,18 +76,13 @@ ActionsTestBase : TestBaseWithProfile() {
override fun setPluginEnabled(type: PluginType, newState: Boolean) {}
}
@Mock lateinit var sp: SP
@Mock lateinit var commandQueue: CommandQueue
@Mock lateinit var configBuilder: ConfigBuilder
@Mock lateinit var activePlugin: ActivePlugin
@Mock lateinit var profilePlugin: ProfileSource
@Mock lateinit var smsCommunicator: SmsCommunicator
@Mock lateinit var loopPlugin: TestLoopPlugin
@Mock lateinit var uel: UserEntryLogger
@Mock lateinit var context: Context
private val pluginDescription = PluginDescription()
lateinit var testPumpPlugin: TestPumpPlugin
@Mock lateinit var repository: AppRepository
var injector: HasAndroidInjector = HasAndroidInjector {
AndroidInjector {
@ -196,8 +188,6 @@ ActionsTestBase : TestBaseWithProfile() {
@BeforeEach
fun mock() {
testPumpPlugin = TestPumpPlugin(pluginDescription, aapsLogger, rh, injector)
`when`(activePlugin.activePump).thenReturn(testPumpPlugin)
`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
`when`(activePlugin.activeProfileSource).thenReturn(profilePlugin)
`when`(profilePlugin.profile).thenReturn(getValidProfileStore())

View file

@ -1,18 +1,18 @@
package info.nightscout.automation.elements
import info.nightscout.automation.triggers.TriggerTestBase
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class ComparatorConnectTest : TriggerTestBase() {
@Test fun labelsTest() {
Assert.assertEquals(2, ComparatorConnect.Compare.labels(rh).size)
Assertions.assertEquals(2, ComparatorConnect.Compare.labels(rh).size)
}
@Test fun setValueTest() {
val c = ComparatorConnect(rh)
c.value = ComparatorConnect.Compare.ON_DISCONNECT
Assert.assertEquals(ComparatorConnect.Compare.ON_DISCONNECT, c.value)
Assertions.assertEquals(ComparatorConnect.Compare.ON_DISCONNECT, c.value)
}
}

View file

@ -1,18 +1,18 @@
package info.nightscout.automation.elements
import info.nightscout.automation.triggers.TriggerTestBase
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class ComparatorExistsTest : TriggerTestBase() {
@Test fun labelsTest() {
Assert.assertEquals(2, ComparatorExists.Compare.labels(rh).size)
Assertions.assertEquals(2, ComparatorExists.Compare.labels(rh).size)
}
@Test fun setValueTest() {
val c = ComparatorExists(rh)
c.value = ComparatorExists.Compare.NOT_EXISTS
Assert.assertEquals(ComparatorExists.Compare.NOT_EXISTS, c.value)
Assertions.assertEquals(ComparatorExists.Compare.NOT_EXISTS, c.value)
}
}

View file

@ -1,35 +1,35 @@
package info.nightscout.automation.elements
import info.nightscout.automation.triggers.TriggerTestBase
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class ComparatorTest : TriggerTestBase() {
@Test
fun checkTest() {
Assert.assertTrue(Comparator.Compare.IS_EQUAL.check(1, 1))
Assert.assertTrue(Comparator.Compare.IS_LESSER.check(1, 2))
Assert.assertTrue(Comparator.Compare.IS_EQUAL_OR_LESSER.check(1, 2))
Assert.assertTrue(Comparator.Compare.IS_EQUAL_OR_LESSER.check(2, 2))
Assert.assertTrue(Comparator.Compare.IS_GREATER.check(2, 1))
Assert.assertTrue(Comparator.Compare.IS_EQUAL_OR_GREATER.check(2, 1))
Assert.assertTrue(Comparator.Compare.IS_EQUAL_OR_GREATER.check(2, 2))
Assert.assertFalse(Comparator.Compare.IS_LESSER.check(2, 1))
Assert.assertFalse(Comparator.Compare.IS_EQUAL_OR_LESSER.check(2, 1))
Assert.assertFalse(Comparator.Compare.IS_GREATER.check(1, 2))
Assert.assertFalse(Comparator.Compare.IS_EQUAL_OR_GREATER.check(1, 2))
// Assert.assertTrue(Comparator.Compare.IS_NOT_AVAILABLE.check<Int?>(1, null))
Assertions.assertTrue(Comparator.Compare.IS_EQUAL.check(1, 1))
Assertions.assertTrue(Comparator.Compare.IS_LESSER.check(1, 2))
Assertions.assertTrue(Comparator.Compare.IS_EQUAL_OR_LESSER.check(1, 2))
Assertions.assertTrue(Comparator.Compare.IS_EQUAL_OR_LESSER.check(2, 2))
Assertions.assertTrue(Comparator.Compare.IS_GREATER.check(2, 1))
Assertions.assertTrue(Comparator.Compare.IS_EQUAL_OR_GREATER.check(2, 1))
Assertions.assertTrue(Comparator.Compare.IS_EQUAL_OR_GREATER.check(2, 2))
Assertions.assertFalse(Comparator.Compare.IS_LESSER.check(2, 1))
Assertions.assertFalse(Comparator.Compare.IS_EQUAL_OR_LESSER.check(2, 1))
Assertions.assertFalse(Comparator.Compare.IS_GREATER.check(1, 2))
Assertions.assertFalse(Comparator.Compare.IS_EQUAL_OR_GREATER.check(1, 2))
// Assertions.assertTrue(Comparator.Compare.IS_NOT_AVAILABLE.check<Int?>(1, null))
}
@Test
fun labelsTest() {
Assert.assertEquals(6, Comparator.Compare.labels(rh).size)
Assertions.assertEquals(6, Comparator.Compare.labels(rh).size)
}
@Test
fun setValueTest() {
val c: Comparator = Comparator(rh).setValue(Comparator.Compare.IS_EQUAL_OR_GREATER)
Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_GREATER, c.value)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_GREATER, c.value)
}
}

View file

@ -2,7 +2,7 @@ package info.nightscout.automation.elements
import info.nightscout.automation.triggers.TriggerTestBase
import info.nightscout.interfaces.GlucoseUnit
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when`
@ -12,12 +12,12 @@ class InputBgTest : TriggerTestBase() {
@Test
fun setValueTest() {
var i: InputBg = InputBg(profileFunction).setUnits(GlucoseUnit.MMOL).setValue(5.0)
Assert.assertEquals(5.0, i.value, 0.01)
Assert.assertEquals(InputBg.MMOL_MIN, i.minValue, 0.01)
Assertions.assertEquals(5.0, i.value, 0.01)
Assertions.assertEquals(InputBg.MMOL_MIN, i.minValue, 0.01)
i = InputBg(profileFunction).setValue(100.0).setUnits(GlucoseUnit.MGDL)
Assert.assertEquals(100.0, i.value, 0.01)
Assert.assertEquals(InputBg.MGDL_MIN, i.minValue, 0.01)
Assert.assertEquals(GlucoseUnit.MGDL, i.units)
Assertions.assertEquals(100.0, i.value, 0.01)
Assertions.assertEquals(InputBg.MGDL_MIN, i.minValue, 0.01)
Assertions.assertEquals(GlucoseUnit.MGDL, i.units)
}
@BeforeEach

View file

@ -1,19 +1,19 @@
package info.nightscout.automation.elements
import info.nightscout.automation.triggers.TriggerTestBase
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class InputCarePortalEventTest : TriggerTestBase() {
@Test
fun labelsTest() {
Assert.assertEquals(4, InputCarePortalMenu.EventType.labels(rh).size)
Assertions.assertEquals(4, InputCarePortalMenu.EventType.labels(rh).size)
}
@Test
fun setValueTest() {
val cp = InputCarePortalMenu(rh, InputCarePortalMenu.EventType.EXERCISE)
Assert.assertEquals(InputCarePortalMenu.EventType.EXERCISE, cp.value)
Assertions.assertEquals(InputCarePortalMenu.EventType.EXERCISE, cp.value)
}
}

View file

@ -1,20 +1,20 @@
package info.nightscout.automation.elements
import info.nightscout.automation.triggers.TriggerTestBase
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class InputDurationTest : TriggerTestBase() {
@Test fun setValueTest() {
var i = InputDuration(5, InputDuration.TimeUnit.MINUTES)
Assert.assertEquals(5, i.value)
Assert.assertEquals(InputDuration.TimeUnit.MINUTES, i.unit)
Assertions.assertEquals(5, i.value)
Assertions.assertEquals(InputDuration.TimeUnit.MINUTES, i.unit)
i = InputDuration(5, InputDuration.TimeUnit.HOURS)
Assert.assertEquals(5, i.value)
Assert.assertEquals(InputDuration.TimeUnit.HOURS, i.unit)
Assert.assertEquals(5 * 60, i.getMinutes())
Assertions.assertEquals(5, i.value)
Assertions.assertEquals(InputDuration.TimeUnit.HOURS, i.unit)
Assertions.assertEquals(5 * 60, i.getMinutes())
i.setMinutes(60)
Assert.assertEquals(1, i.value)
Assertions.assertEquals(1, i.value)
}
}

View file

@ -1,7 +1,7 @@
package info.nightscout.automation.elements
import info.nightscout.automation.triggers.TriggerTestBase
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class InputInsulinTest : TriggerTestBase() {
@ -9,6 +9,6 @@ class InputInsulinTest : TriggerTestBase() {
@Test fun setValueTest() {
val i = InputInsulin()
i.value = 5.0
Assert.assertEquals(5.0, i.value, 0.01)
Assertions.assertEquals(5.0, i.value, 0.01)
}
}

View file

@ -1,7 +1,7 @@
package info.nightscout.automation.elements
import info.nightscout.automation.triggers.TriggerTestBase
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class InputPercentTest : TriggerTestBase() {
@ -9,6 +9,6 @@ class InputPercentTest : TriggerTestBase() {
@Test fun setValueTest() {
val i = InputPercent()
i.value = 10.0
Assert.assertEquals(10.0, i.value, 0.01)
Assertions.assertEquals(10.0, i.value, 0.01)
}
}

View file

@ -1,15 +1,15 @@
package info.nightscout.automation.elements
import info.nightscout.automation.triggers.TriggerTestBase
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class InputProfileNameTest : TriggerTestBase() {
@Test fun setValue() {
val inputProfileName = InputProfileName(rh, activePlugin, "Test")
Assert.assertEquals("Test", inputProfileName.value)
Assertions.assertEquals("Test", inputProfileName.value)
inputProfileName.value = "Test2"
Assert.assertEquals("Test2", inputProfileName.value)
Assertions.assertEquals("Test2", inputProfileName.value)
}
}

View file

@ -1,7 +1,7 @@
package info.nightscout.automation.elements
import info.nightscout.automation.triggers.TriggerTestBase
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class InputStringTest : TriggerTestBase() {
@ -9,6 +9,6 @@ class InputStringTest : TriggerTestBase() {
@Test fun setValueTest() {
val i = InputString()
i.value = "asd"
Assert.assertEquals("asd", i.value)
Assertions.assertEquals("asd", i.value)
}
}

View file

@ -2,7 +2,7 @@ package info.nightscout.automation.elements
import info.nightscout.automation.triggers.TriggerTestBase
import info.nightscout.interfaces.GlucoseUnit
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class InputTempTargetTest : TriggerTestBase() {
@ -11,10 +11,10 @@ class InputTempTargetTest : TriggerTestBase() {
val i = InputTempTarget(profileFunction)
i.units = GlucoseUnit.MMOL
i.value = 5.0
Assert.assertEquals(5.0, i.value, 0.01)
Assertions.assertEquals(5.0, i.value, 0.01)
i.units = GlucoseUnit.MGDL
i.value = 100.0
Assert.assertEquals(100.0, i.value, 0.01)
Assert.assertEquals(GlucoseUnit.MGDL, i.units)
Assertions.assertEquals(100.0, i.value, 0.01)
Assertions.assertEquals(GlucoseUnit.MGDL, i.units)
}
}

View file

@ -1,7 +1,7 @@
package info.nightscout.automation.elements
import info.nightscout.automation.triggers.TriggerTestBase
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class LabelWithElementTest : TriggerTestBase() {
@ -9,8 +9,8 @@ class LabelWithElementTest : TriggerTestBase() {
@Test
fun constructorTest() {
val l = LabelWithElement(rh, "A", "B", InputInsulin())
Assert.assertEquals("A", l.textPre)
Assert.assertEquals("B", l.textPost)
Assert.assertEquals(InputInsulin::class.java, l.element!!.javaClass)
Assertions.assertEquals("A", l.textPre)
Assertions.assertEquals("B", l.textPost)
Assertions.assertEquals(InputInsulin::class.java, l.element!!.javaClass)
}
}

View file

@ -2,8 +2,8 @@ package info.nightscout.automation.elements
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBase
import org.junit.Assert
import info.nightscout.sharedtests.TestBase
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class LayoutBuilderTest : TestBase() {
@ -14,15 +14,15 @@ class LayoutBuilderTest : TestBase() {
val layoutBuilder = LayoutBuilder()
val inputInsulin = InputInsulin()
layoutBuilder.add(inputInsulin)
Assert.assertEquals(1, layoutBuilder.mElements.size)
Assertions.assertEquals(1, layoutBuilder.mElements.size)
}
@Test fun addConditionalTest() {
val layoutBuilder = LayoutBuilder()
val inputInsulin = InputInsulin()
layoutBuilder.maybeAdd(inputInsulin, true)
Assert.assertEquals(1, layoutBuilder.mElements.size)
Assertions.assertEquals(1, layoutBuilder.mElements.size)
layoutBuilder.maybeAdd(inputInsulin, false)
Assert.assertEquals(1, layoutBuilder.mElements.size)
Assertions.assertEquals(1, layoutBuilder.mElements.size)
}
}

View file

@ -2,7 +2,7 @@ package info.nightscout.automation.elements
import info.nightscout.automation.triggers.TriggerDummy
import info.nightscout.automation.triggers.TriggerTestBase
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when`
@ -10,9 +10,9 @@ class StaticLabelTest : TriggerTestBase() {
@Test fun constructor() {
var sl = StaticLabel(rh, "any", TriggerDummy(injector))
Assert.assertEquals("any", sl.label)
Assertions.assertEquals("any", sl.label)
`when`(rh.gs(info.nightscout.core.ui.R.string.pumplimit)).thenReturn("pump limit")
sl = StaticLabel(rh, info.nightscout.core.ui.R.string.pumplimit, TriggerDummy(injector))
Assert.assertEquals("pump limit", sl.label)
Assertions.assertEquals("pump limit", sl.label)
}
}

View file

@ -6,7 +6,6 @@ import info.nightscout.automation.elements.Comparator
import info.nightscout.plugins.iob.iobCobCalculator.data.AutosensDataObject
import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers
import org.mockito.Mockito
@ -14,7 +13,6 @@ import org.mockito.Mockito.`when`
class TriggerAutosensValueTest : TriggerTestBase() {
var now = 1514766900000L
@Test fun shouldRunTest() {
`when`(sp.getDouble(Mockito.eq(info.nightscout.core.utils.R.string.key_openapsama_autosens_max), ArgumentMatchers.anyDouble())).thenReturn(1.2)
`when`(sp.getDouble(Mockito.eq(info.nightscout.core.utils.R.string.key_openapsama_autosens_min), ArgumentMatchers.anyDouble())).thenReturn(0.7)
@ -105,11 +103,6 @@ class TriggerAutosensValueTest : TriggerTestBase() {
Assertions.assertEquals(Optional.of(R.drawable.ic_as), TriggerAutosensValue(injector).icon())
}
@BeforeEach
fun mock() {
`when`(dateUtil.now()).thenReturn(now)
}
private fun generateAutosensData(): AutosensDataObject {
return AutosensDataObject(injector)
}

View file

@ -3,13 +3,11 @@ package info.nightscout.automation.triggers
import com.google.common.base.Optional
import info.nightscout.automation.elements.ComparatorConnect
import org.json.JSONObject
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
@Suppress("SpellCheckingInspection")
class TriggerBTDeviceTest : TriggerTestBase() {
var now = 1514766900000L
private var someName = "Headset"
private var btJson = "{\"data\":{\"comparator\":\"ON_CONNECT\",\"name\":\"Headset\"},\"type\":\"TriggerBTDevice\"}"
@ -21,19 +19,19 @@ class TriggerBTDeviceTest : TriggerTestBase() {
@Test fun toJSON() {
val t = TriggerBTDevice(injector)
t.btDevice.value = someName
Assert.assertEquals(btJson, t.toJSON())
Assertions.assertEquals(btJson, t.toJSON())
}
@Test
fun fromJSON() {
val t2 = TriggerDummy(injector).instantiate(JSONObject(btJson)) as TriggerBTDevice
Assert.assertEquals(ComparatorConnect.Compare.ON_CONNECT, t2.comparator.value)
Assert.assertEquals("Headset", t2.btDevice.value)
Assertions.assertEquals(ComparatorConnect.Compare.ON_CONNECT, t2.comparator.value)
Assertions.assertEquals("Headset", t2.btDevice.value)
}
@Test
fun icon() {
Assert.assertEquals(Optional.of(info.nightscout.core.ui.R.drawable.ic_bluetooth_white_48dp), TriggerBTDevice(injector).icon())
Assertions.assertEquals(Optional.of(info.nightscout.core.ui.R.drawable.ic_bluetooth_white_48dp), TriggerBTDevice(injector).icon())
}
@Test fun duplicate() {
@ -42,7 +40,7 @@ class TriggerBTDeviceTest : TriggerTestBase() {
it.btDevice.value = someName
}
val t1 = t.duplicate() as TriggerBTDevice
Assert.assertEquals("Headset", t1.btDevice.value)
Assert.assertEquals(ComparatorConnect.Compare.ON_DISCONNECT, t.comparator.value)
Assertions.assertEquals("Headset", t1.btDevice.value)
Assertions.assertEquals(ComparatorConnect.Compare.ON_DISCONNECT, t.comparator.value)
}
}

View file

@ -13,12 +13,9 @@ import org.mockito.Mockito.`when`
class TriggerBgTest : TriggerTestBase() {
var now = 1514766900000L
@BeforeEach
fun prepare() {
`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
`when`(dateUtil.now()).thenReturn(now)
}
@Test

View file

@ -7,20 +7,12 @@ import info.nightscout.database.entities.Bolus
import io.reactivex.rxjava3.core.Single
import org.json.JSONException
import org.json.JSONObject
import org.junit.Assert
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when`
class TriggerBolusAgoTest : TriggerTestBase() {
var now = 1514766900000L
@BeforeEach
fun mock() {
`when`(dateUtil.now()).thenReturn(now)
}
@Test
fun shouldRunTest() {
// Set last bolus time to now
@ -37,26 +29,26 @@ class TriggerBolusAgoTest : TriggerTestBase() {
)
`when`(dateUtil.now()).thenReturn(now + 10 * 60 * 1000) // set current time to now + 10 min
var t = TriggerBolusAgo(injector).setValue(110).comparator(Comparator.Compare.IS_EQUAL)
Assert.assertEquals(110, t.minutesAgo.value)
Assert.assertEquals(Comparator.Compare.IS_EQUAL, t.comparator.value)
Assert.assertFalse(t.shouldRun())
Assertions.assertEquals(110, t.minutesAgo.value)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t.comparator.value)
Assertions.assertFalse(t.shouldRun())
t = TriggerBolusAgo(injector).setValue(10).comparator(Comparator.Compare.IS_EQUAL)
Assert.assertEquals(10, t.minutesAgo.value)
Assert.assertTrue(t.shouldRun())
Assertions.assertEquals(10, t.minutesAgo.value)
Assertions.assertTrue(t.shouldRun())
t = TriggerBolusAgo(injector).setValue(5).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerBolusAgo(injector).setValue(310).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerBolusAgo(injector).setValue(420).comparator(Comparator.Compare.IS_EQUAL)
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
t = TriggerBolusAgo(injector).setValue(390).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerBolusAgo(injector).setValue(390).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
t = TriggerBolusAgo(injector).setValue(2).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerBolusAgo(injector).setValue(390).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
// Set last bolus time to 0
`when`(repository.getLastBolusRecordOfTypeWrapped(Bolus.Type.NORMAL)).thenReturn(
Single.just(
@ -70,30 +62,30 @@ class TriggerBolusAgoTest : TriggerTestBase() {
)
)
t = TriggerBolusAgo(injector).comparator(Comparator.Compare.IS_NOT_AVAILABLE)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
}
@Test fun copyConstructorTest() {
val t: TriggerBolusAgo = TriggerBolusAgo(injector).setValue(213).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
val t1 = t.duplicate() as TriggerBolusAgo
Assert.assertEquals(213, t1.minutesAgo.value)
Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
Assertions.assertEquals(213, t1.minutesAgo.value)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
}
private var lbJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"minutesAgo\":410},\"type\":\"TriggerBolusAgo\"}"
@Test fun toJSONTest() {
val t: TriggerBolusAgo = TriggerBolusAgo(injector).setValue(410).comparator(Comparator.Compare.IS_EQUAL)
Assert.assertEquals(lbJson, t.toJSON())
Assertions.assertEquals(lbJson, t.toJSON())
}
@Test @Throws(JSONException::class) fun fromJSONTest() {
val t: TriggerBolusAgo = TriggerBolusAgo(injector).setValue(410).comparator(Comparator.Compare.IS_EQUAL)
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerBolusAgo
Assert.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
Assert.assertEquals(410, t2.minutesAgo.value)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
Assertions.assertEquals(410, t2.minutesAgo.value)
}
@Test fun iconTest() {
Assert.assertEquals(Optional.of(info.nightscout.core.main.R.drawable.ic_bolus), TriggerBolusAgo(injector).icon())
Assertions.assertEquals(Optional.of(info.nightscout.core.main.R.drawable.ic_bolus), TriggerBolusAgo(injector).icon())
}
}

View file

@ -4,7 +4,7 @@ import com.google.common.base.Optional
import info.nightscout.automation.elements.Comparator
import info.nightscout.interfaces.iob.CobInfo
import org.json.JSONObject
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers
@ -12,10 +12,7 @@ import org.mockito.Mockito.`when`
class TriggerCOBTest : TriggerTestBase() {
var now = 1514766900000L
@BeforeEach fun mock() {
`when`(dateUtil.now()).thenReturn(now)
`when`(sp.getInt(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt())).thenReturn(48)
}
@ -23,48 +20,44 @@ class TriggerCOBTest : TriggerTestBase() {
// COB value is 6
`when`(iobCobCalculator.getCobInfo("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())
Assertions.assertFalse(t.shouldRun())
t = TriggerCOB(injector).setValue(6.0).comparator(Comparator.Compare.IS_EQUAL)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerCOB(injector).setValue(5.0).comparator(Comparator.Compare.IS_GREATER)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerCOB(injector).setValue(5.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerCOB(injector).setValue(6.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerCOB(injector).setValue(1.0).comparator(Comparator.Compare.IS_EQUAL)
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
t = TriggerCOB(injector).setValue(10.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerCOB(injector).setValue(5.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
}
@Test fun copyConstructorTest() {
val t: TriggerCOB = TriggerCOB(injector).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
Assert.assertEquals(213.0, t.cob.value, 0.01)
Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
Assertions.assertEquals(213.0, t.cob.value, 0.01)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
}
private var bgJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"carbs\":4},\"type\":\"TriggerCOB\"}"
@Test fun toJSONTest() {
val t: TriggerCOB = TriggerCOB(injector).setValue(4.0).comparator(Comparator.Compare.IS_EQUAL)
Assert.assertEquals(bgJson, t.toJSON())
Assertions.assertEquals(bgJson, t.toJSON())
}
@Test
fun fromJSONTest() {
val t: TriggerCOB = TriggerCOB(injector).setValue(4.0).comparator(Comparator.Compare.IS_EQUAL)
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerCOB
Assert.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
Assert.assertEquals(4.0, t2.cob.value, 0.01)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
Assertions.assertEquals(4.0, t2.cob.value, 0.01)
}
@Test fun iconTest() {
Assert.assertEquals(Optional.of(info.nightscout.core.main.R.drawable.ic_cp_bolus_carbs), TriggerCOB(injector).icon())
}
fun generateCobInfo(): CobInfo {
return CobInfo(0, 6.0, 0.0)
Assertions.assertEquals(Optional.of(info.nightscout.core.main.R.drawable.ic_cp_bolus_carbs), TriggerCOB(injector).icon())
}
}

View file

@ -2,81 +2,79 @@ package info.nightscout.automation.triggers
import org.json.JSONException
import org.json.JSONObject
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class TriggerConnectorTest : TriggerTestBase() {
private val empty = "{\"data\":{\"connectorType\":\"AND\",\"triggerList\":[]},\"type\":\"TriggerConnector\"}"
val oneItem =
"{\"data\":{\"connectorType\":\"AND\",\"triggerList\":[\"{\\\"data\\\":{\\\"connectorType\\\":\\\"AND\\\",\\\"triggerList\\\":[]},\\\"type\\\":\\\"TriggerConnector\\\"}\"]},\"type\":\"TriggerConnector\"}"
@Test fun testTriggerList() {
val t = TriggerConnector(injector)
val t2 = TriggerConnector(injector)
val t3 = TriggerConnector(injector)
Assert.assertTrue(t.size() == 0)
Assertions.assertTrue(t.size() == 0)
t.list.add(t2)
Assert.assertTrue(t.size() == 1)
Assert.assertEquals(t2, t.list[0])
Assertions.assertTrue(t.size() == 1)
Assertions.assertEquals(t2, t.list[0])
t.list.add(t3)
Assert.assertTrue(t.size() == 2)
Assert.assertEquals(t2, t.list[0])
Assert.assertEquals(t3, t.list[1])
Assert.assertTrue(t.list.remove(t2))
Assert.assertTrue(t.size() == 1)
Assert.assertEquals(t3, t.list[0])
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.size() == 2)
Assertions.assertEquals(t2, t.list[0])
Assertions.assertEquals(t3, t.list[1])
Assertions.assertTrue(t.list.remove(t2))
Assertions.assertTrue(t.size() == 1)
Assertions.assertEquals(t3, t.list[0])
Assertions.assertTrue(t.shouldRun())
}
@Test fun testListTriggerOR() {
val t = TriggerConnector(injector, TriggerConnector.Type.OR)
t.list.add(TriggerDummy(injector))
t.list.add(TriggerDummy(injector))
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
t.list.add(TriggerDummy(injector, true))
t.list.add(TriggerDummy(injector))
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
}
@Test fun testListTriggerXOR() {
val t = TriggerConnector(injector, TriggerConnector.Type.XOR)
t.list.add(TriggerDummy(injector))
t.list.add(TriggerDummy(injector))
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
t.list.add(TriggerDummy(injector, true))
t.list.add(TriggerDummy(injector))
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t.list.add(TriggerDummy(injector, true))
t.list.add(TriggerDummy(injector))
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
}
@Test fun testListTriggerAND() {
val t = TriggerConnector(injector, TriggerConnector.Type.AND)
t.list.add(TriggerDummy(injector, true))
t.list.add(TriggerDummy(injector, true))
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t.list.add(TriggerDummy(injector, true))
t.list.add(TriggerDummy(injector))
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
}
@Test fun toJSONTest() {
val t = TriggerConnector(injector)
Assert.assertEquals(empty, t.toJSON())
Assertions.assertEquals(empty, t.toJSON())
t.list.add(TriggerConnector(injector))
Assert.assertEquals(oneItem, t.toJSON())
Assertions.assertEquals(oneItem, t.toJSON())
}
@Test @Throws(JSONException::class) fun fromJSONTest() {
val t = TriggerConnector(injector)
t.list.add(TriggerConnector(injector))
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerConnector
Assert.assertEquals(1, t2.size().toLong())
Assert.assertTrue(t2.list[0] is TriggerConnector)
Assertions.assertEquals(1, t2.size().toLong())
Assertions.assertTrue(t2.list[0] is TriggerConnector)
}
companion object {
const val empty = "{\"data\":{\"connectorType\":\"AND\",\"triggerList\":[]},\"type\":\"TriggerConnector\"}"
const val oneItem =
"{\"data\":{\"connectorType\":\"AND\",\"triggerList\":[\"{\\\"data\\\":{\\\"connectorType\\\":\\\"AND\\\",\\\"triggerList\\\":[]},\\\"type\\\":\\\"TriggerConnector\\\"}\"]},\"type\":\"TriggerConnector\"}"
}
}

View file

@ -15,10 +15,9 @@ import org.mockito.Mockito.`when`
class TriggerDeltaTest : TriggerTestBase() {
var now = 1514766900000L
@BeforeEach
fun mock() {
now = 1514766900000L
`when`(dateUtil.now()).thenReturn(now)
`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
}

View file

@ -1,7 +1,7 @@
package info.nightscout.automation.triggers
import org.json.JSONObject
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class TriggerDummyTest : TriggerTestBase() {
@ -9,13 +9,13 @@ class TriggerDummyTest : TriggerTestBase() {
@Test
fun instantiateTest() {
var trigger: Trigger? = TriggerDummy(injector).instantiate(JSONObject("{\"data\":{},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerDummy\"}"))
Assert.assertTrue(trigger is TriggerDummy)
Assertions.assertTrue(trigger is TriggerDummy)
trigger = TriggerDummy(injector).instantiate(JSONObject("{\"data\":{},\"type\":\"info.nightscout.automation.triggers.TriggerDummy\"}"))
Assert.assertTrue(trigger is TriggerDummy)
Assertions.assertTrue(trigger is TriggerDummy)
trigger = TriggerDummy(injector).instantiate(JSONObject("{\"data\":{},\"type\":\"TriggerDummy\"}"))
Assert.assertTrue(trigger is TriggerDummy)
Assertions.assertTrue(trigger is TriggerDummy)
}
}

View file

@ -6,7 +6,6 @@ import info.nightscout.database.entities.HeartRate
import io.reactivex.rxjava3.core.Single
import org.json.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mockito.verify
import org.mockito.Mockito.verifyNoMoreInteractions
@ -14,13 +13,6 @@ import org.mockito.Mockito.`when`
class TriggerHeartRateTest : TriggerTestBase() {
private var now = 1000L
@BeforeEach
fun mock() {
`when`(dateUtil.now()).thenReturn(now)
}
@Test
fun friendlyName() {
Assertions.assertEquals(R.string.triggerHeartRate, TriggerHeartRate(injector).friendlyName())

View file

@ -5,7 +5,7 @@ import info.nightscout.automation.R
import info.nightscout.automation.elements.Comparator
import info.nightscout.interfaces.iob.IobTotal
import org.json.JSONObject
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers
@ -13,57 +13,54 @@ import org.mockito.Mockito.`when`
class TriggerIobTest : TriggerTestBase() {
var now = 1514766900000L
@BeforeEach fun mock() {
`when`(dateUtil.now()).thenReturn(now)
`when`(profileFunction.getProfile()).thenReturn(validProfile)
}
@Test fun shouldRunTest() {
`when`(iobCobCalculator.calculateFromTreatmentsAndTemps(ArgumentMatchers.anyLong(), anyObject())).thenReturn(generateIobRecordData())
var t: TriggerIob = TriggerIob(injector).setValue(1.1).comparator(Comparator.Compare.IS_EQUAL)
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
t = TriggerIob(injector).setValue(1.0).comparator(Comparator.Compare.IS_EQUAL)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerIob(injector).setValue(0.8).comparator(Comparator.Compare.IS_GREATER)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerIob(injector).setValue(0.8).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerIob(injector).setValue(0.9).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerIob(injector).setValue(1.2).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerIob(injector).setValue(1.1).comparator(Comparator.Compare.IS_EQUAL)
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
t = TriggerIob(injector).setValue(1.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerIob(injector).setValue(0.9).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
}
@Test fun copyConstructorTest() {
val t: TriggerIob = TriggerIob(injector).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
Assert.assertEquals(213.0, t.insulin.value, 0.01)
Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
Assertions.assertEquals(213.0, t.insulin.value, 0.01)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
}
private var bgJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"insulin\":4.1},\"type\":\"TriggerIob\"}"
@Test fun toJSONTest() {
val t: TriggerIob = TriggerIob(injector).setValue(4.1).comparator(Comparator.Compare.IS_EQUAL)
Assert.assertEquals(bgJson, t.toJSON())
Assertions.assertEquals(bgJson, t.toJSON())
}
@Test
fun fromJSONTest() {
val t: TriggerIob = TriggerIob(injector).setValue(4.1).comparator(Comparator.Compare.IS_EQUAL)
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerIob
Assert.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
Assert.assertEquals(4.1, t2.insulin.value, 0.01)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
Assertions.assertEquals(4.1, t2.insulin.value, 0.01)
}
@Test fun iconTest() {
Assert.assertEquals(Optional.of(R.drawable.ic_keyboard_capslock), TriggerIob(injector).icon())
Assertions.assertEquals(Optional.of(R.drawable.ic_keyboard_capslock), TriggerIob(injector).icon())
}
private fun generateIobRecordData(): IobTotal {

View file

@ -6,17 +6,14 @@ import info.nightscout.automation.R
import info.nightscout.automation.elements.InputLocationMode
import org.json.JSONException
import org.json.JSONObject
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when`
class TriggerLocationTest : TriggerTestBase() {
var now = 1514766900000L
@BeforeEach fun mock() {
`when`(dateUtil.now()).thenReturn(now)
`when`(locationDataContainer.lastLocation).thenReturn(mockedLocation())
}
@ -27,10 +24,10 @@ class TriggerLocationTest : TriggerTestBase() {
t.distance.setValue(2.0)
t.modeSelected.value = InputLocationMode.Mode.INSIDE
val t1 = t.duplicate() as TriggerLocation
Assert.assertEquals(213.0, t1.latitude.value, 0.01)
Assert.assertEquals(212.0, t1.longitude.value, 0.01)
Assert.assertEquals(2.0, t1.distance.value, 0.01)
Assert.assertEquals(InputLocationMode.Mode.INSIDE, t1.modeSelected.value)
Assertions.assertEquals(213.0, t1.latitude.value, 0.01)
Assertions.assertEquals(212.0, t1.longitude.value, 0.01)
Assertions.assertEquals(2.0, t1.distance.value, 0.01)
Assertions.assertEquals(InputLocationMode.Mode.INSIDE, t1.modeSelected.value)
}
@Test fun shouldRunTest() {
@ -40,12 +37,12 @@ class TriggerLocationTest : TriggerTestBase() {
t.distance.setValue(2.0)
// t.modeSelected.setValue(InputLocationMode.Mode.OUTSIDE);
`when`(locationDataContainer.lastLocation).thenReturn(null)
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
`when`(locationDataContainer.lastLocation).thenReturn(mockedLocation())
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerLocation(injector)
t.distance.setValue(-500.0)
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
//Test of GOING_IN - last mode should be OUTSIDE, and current mode should be INSIDE
t = TriggerLocation(injector)
@ -54,9 +51,9 @@ class TriggerLocationTest : TriggerTestBase() {
`when`(locationDataContainer.lastLocation).thenReturn(null)
`when`(locationDataContainer.lastLocation).thenReturn(mockedLocationOut())
t.modeSelected.value = InputLocationMode.Mode.GOING_IN
Assert.assertEquals(t.lastMode, InputLocationMode.Mode.OUTSIDE)
Assert.assertEquals(t.currentMode(5.0), InputLocationMode.Mode.INSIDE)
Assert.assertTrue(t.shouldRun())
Assertions.assertEquals(t.lastMode, InputLocationMode.Mode.OUTSIDE)
Assertions.assertEquals(t.currentMode(5.0), InputLocationMode.Mode.INSIDE)
Assertions.assertTrue(t.shouldRun())
//Test of GOING_OUT - last mode should be INSIDE, and current mode should be OUTSIDE
// Currently unavailable due to problems with Location mocking
@ -70,7 +67,7 @@ class TriggerLocationTest : TriggerTestBase() {
t.distance.setValue(2.0)
t.modeSelected.value = InputLocationMode.Mode.OUTSIDE
// t.modeSelected = t.modeSelected.value
Assert.assertEquals(locationJson, t.toJSON())
Assertions.assertEquals(locationJson, t.toJSON())
}
@Test @Throws(JSONException::class) fun fromJSONTest() {
@ -80,22 +77,22 @@ class TriggerLocationTest : TriggerTestBase() {
t.distance.setValue(2.0)
t.modeSelected.value = InputLocationMode.Mode.INSIDE
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerLocation
Assert.assertEquals(t.latitude.value, t2.latitude.value, 0.01)
Assert.assertEquals(t.longitude.value, t2.longitude.value, 0.01)
Assert.assertEquals(t.distance.value, t2.distance.value, 0.01)
Assert.assertEquals(t.modeSelected.value, t2.modeSelected.value)
Assertions.assertEquals(t.latitude.value, t2.latitude.value, 0.01)
Assertions.assertEquals(t.longitude.value, t2.longitude.value, 0.01)
Assertions.assertEquals(t.distance.value, t2.distance.value, 0.01)
Assertions.assertEquals(t.modeSelected.value, t2.modeSelected.value)
}
@Test fun friendlyNameTest() {
Assert.assertEquals(R.string.location, TriggerLocation(injector).friendlyName())
Assertions.assertEquals(R.string.location, TriggerLocation(injector).friendlyName())
}
@Test fun friendlyDescriptionTest() {
Assert.assertEquals(null, TriggerLocation(injector).friendlyDescription()) //not mocked }
Assertions.assertEquals(null, TriggerLocation(injector).friendlyDescription()) //not mocked }
}
@Test fun iconTest() {
Assert.assertEquals(Optional.of(R.drawable.ic_location_on), TriggerLocation(injector).icon())
Assertions.assertEquals(Optional.of(R.drawable.ic_location_on), TriggerLocation(injector).icon())
}
private fun mockedLocation(): Location {

View file

@ -4,66 +4,63 @@ import com.google.common.base.Optional
import info.nightscout.automation.R
import info.nightscout.automation.elements.Comparator
import org.json.JSONObject
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when`
class TriggerProfilePercentTest : TriggerTestBase() {
private val now = 1514766900000L
@BeforeEach fun mock() {
`when`(profileFunction.getProfile()).thenReturn(validProfile)
`when`(dateUtil.now()).thenReturn(now)
}
@Test fun shouldRunTest() {
var t: TriggerProfilePercent = TriggerProfilePercent(injector).setValue(101.0).comparator(Comparator.Compare.IS_EQUAL)
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
t = TriggerProfilePercent(injector).setValue(100.0).comparator(Comparator.Compare.IS_EQUAL)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerProfilePercent(injector).setValue(100.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerProfilePercent(injector).setValue(90.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerProfilePercent(injector).setValue(100.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerProfilePercent(injector).setValue(101.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerProfilePercent(injector).setValue(215.0).comparator(Comparator.Compare.IS_EQUAL)
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
t = TriggerProfilePercent(injector).setValue(110.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
t = TriggerProfilePercent(injector).setValue(90.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
}
@Test fun copyConstructorTest() {
val t: TriggerProfilePercent = TriggerProfilePercent(injector).setValue(213.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
val t1 = t.duplicate() as TriggerProfilePercent
Assert.assertEquals(213.0, t1.pct.value, 0.01)
Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
Assertions.assertEquals(213.0, t1.pct.value, 0.01)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
}
private val bgJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"percentage\":110},\"type\":\"TriggerProfilePercent\"}"
@Test fun toJSONTest() {
val t: TriggerProfilePercent = TriggerProfilePercent(injector).setValue(110.0).comparator(Comparator.Compare.IS_EQUAL)
Assert.assertEquals(bgJson, t.toJSON())
Assertions.assertEquals(bgJson, t.toJSON())
}
@Test fun fromJSONTest() {
val t: TriggerProfilePercent = TriggerProfilePercent(injector).setValue(120.0).comparator(Comparator.Compare.IS_EQUAL)
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerProfilePercent
Assert.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
Assert.assertEquals(120.0, t2.pct.value, 0.01)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
Assertions.assertEquals(120.0, t2.pct.value, 0.01)
}
@Test fun iconTest() {
Assert.assertEquals(Optional.of(info.nightscout.interfaces.R.drawable.ic_actions_profileswitch), TriggerProfilePercent(injector).icon())
Assertions.assertEquals(Optional.of(info.nightscout.interfaces.R.drawable.ic_actions_profileswitch), TriggerProfilePercent(injector).icon())
}
@Test fun friendlyNameTest() {
Assert.assertEquals(R.string.profilepercentage, TriggerProfilePercent(injector).friendlyName()) // not mocked
Assertions.assertEquals(R.string.profilepercentage, TriggerProfilePercent(injector).friendlyName()) // not mocked
}
}

View file

@ -4,67 +4,59 @@ import com.google.common.base.Optional
import info.nightscout.automation.R
import info.nightscout.automation.elements.Comparator
import org.json.JSONObject
import org.junit.Assert
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when`
class TriggerPumpLastConnectionTest : TriggerTestBase() {
var now = 1514766900000L
@BeforeEach
fun mock() {
`when`(dateUtil.now()).thenReturn(now)
}
@Test
fun shouldRunTest() {
// System.currentTimeMillis() is always 0
// and so is every last connection time
Assert.assertEquals(0L, testPumpPlugin.lastDataTime())
Assertions.assertEquals(0L, testPumpPlugin.lastDataTime())
`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)
Assert.assertFalse(t.shouldRun())
Assertions.assertEquals(110, t.minutesAgo.value)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t.comparator.value)
Assertions.assertFalse(t.shouldRun())
t = TriggerPumpLastConnection(injector).setValue(10).comparator(Comparator.Compare.IS_EQUAL)
Assert.assertEquals(10, t.minutesAgo.value)
Assert.assertFalse(t.shouldRun()) // 0 == 10 -> FALSE
Assertions.assertEquals(10, t.minutesAgo.value)
Assertions.assertFalse(t.shouldRun()) // 0 == 10 -> FALSE
t = TriggerPumpLastConnection(injector).setValue(5).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
Assert.assertTrue(t.shouldRun()) // 5 => 0 -> TRUE
Assertions.assertTrue(t.shouldRun()) // 5 => 0 -> TRUE
t = TriggerPumpLastConnection(injector).setValue(310).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
Assert.assertFalse(t.shouldRun()) // 310 <= 0 -> FALSE
Assertions.assertFalse(t.shouldRun()) // 310 <= 0 -> FALSE
t = TriggerPumpLastConnection(injector).setValue(420).comparator(Comparator.Compare.IS_EQUAL)
Assert.assertFalse(t.shouldRun()) // 420 == 0 -> FALSE
Assertions.assertFalse(t.shouldRun()) // 420 == 0 -> FALSE
}
@Test fun copyConstructorTest() {
val t: TriggerPumpLastConnection = TriggerPumpLastConnection(injector).setValue(213).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
val t1 = t.duplicate() as TriggerPumpLastConnection
Assert.assertEquals(213, t1.minutesAgo.value)
Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
Assertions.assertEquals(213, t1.minutesAgo.value)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
}
private var lbJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"minutesAgo\":410},\"type\":\"TriggerPumpLastConnection\"}"
@Test fun toJSONTest() {
val t: TriggerPumpLastConnection = TriggerPumpLastConnection(injector).setValue(410).comparator(Comparator.Compare.IS_EQUAL)
Assert.assertEquals(lbJson, t.toJSON())
Assertions.assertEquals(lbJson, t.toJSON())
}
@Test
fun fromJSONTest() {
val t: TriggerPumpLastConnection = TriggerPumpLastConnection(injector).setValue(410).comparator(Comparator.Compare.IS_EQUAL)
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerPumpLastConnection
Assert.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
Assert.assertEquals(410, t2.minutesAgo.value)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
Assertions.assertEquals(410, t2.minutesAgo.value)
}
@Test fun iconTest() {
Assert.assertEquals(Optional.of(info.nightscout.core.main.R.drawable.ic_remove), TriggerPumpLastConnection(injector).icon())
Assertions.assertEquals(Optional.of(info.nightscout.core.main.R.drawable.ic_remove), TriggerPumpLastConnection(injector).icon())
}
@Test fun friendlyNameTest() {
Assert.assertEquals(R.string.automation_trigger_pump_last_connection_label, TriggerPumpLastConnection(injector).friendlyName())
Assertions.assertEquals(R.string.automation_trigger_pump_last_connection_label, TriggerPumpLastConnection(injector).friendlyName())
}
}

View file

@ -3,30 +3,28 @@ package info.nightscout.automation.triggers
import info.nightscout.interfaces.utils.MidnightTime
import info.nightscout.shared.utils.T
import org.json.JSONObject
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when`
import org.mockito.Mockito
class TriggerRecurringTimeTest : TriggerTestBase() {
var now: Long = 0L
@BeforeEach fun mock() {
now = MidnightTime.calc() + T.mins(95).msecs() // 95 min from midnight
`when`(dateUtil.now()).thenReturn(now)
Mockito.`when`(dateUtil.now()).thenReturn(now)
}
@Test fun shouldRunTest() {
var t: TriggerRecurringTime = TriggerRecurringTime(injector).time(89)
t.days.setAll(true)
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
// scheduled 1 min before
t = TriggerRecurringTime(injector).time(94)
t.days.setAll(true)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
}
private var timeJson =
@ -35,13 +33,13 @@ class TriggerRecurringTimeTest : TriggerTestBase() {
@Test
fun toJSONTest() {
val t = TriggerRecurringTime(injector).time(4444)
Assert.assertEquals(timeJson, t.toJSON())
Assertions.assertEquals(timeJson, t.toJSON())
}
@Test
fun fromJSONTest() {
val t = TriggerRecurringTime(injector).time(4444)
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerRecurringTime
Assert.assertEquals(4444, t2.time.value)
Assertions.assertEquals(4444, t2.time.value)
}
}

View file

@ -4,53 +4,45 @@ import com.google.common.base.Optional
import info.nightscout.automation.R
import info.nightscout.automation.elements.ComparatorExists
import org.json.JSONObject
import org.junit.Assert
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when`
class TriggerTempTargetTest : TriggerTestBase() {
var now = 1514766900000L
@BeforeEach fun mock() {
`when`(dateUtil.now()).thenReturn(now)
}
/*
@Test fun shouldRunTest() {
`when`(repository.getTemporaryTargetActiveAt(anyObject())).thenReturn(null)
var t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS)
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
`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())
Assertions.assertFalse(t.shouldRun())
t = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
}
*/
@Test fun copyConstructorTest() {
val t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS)
val t1 = t.duplicate() as TriggerTempTarget
Assert.assertEquals(ComparatorExists.Compare.NOT_EXISTS, t1.comparator.value)
Assertions.assertEquals(ComparatorExists.Compare.NOT_EXISTS, t1.comparator.value)
}
private var ttJson = "{\"data\":{\"comparator\":\"EXISTS\"},\"type\":\"TriggerTempTarget\"}"
@Test fun toJSONTest() {
val t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.EXISTS)
Assert.assertEquals(ttJson, t.toJSON())
Assertions.assertEquals(ttJson, t.toJSON())
}
@Test
fun fromJSONTest() {
val t: TriggerTempTarget = TriggerTempTarget(injector).comparator(ComparatorExists.Compare.NOT_EXISTS)
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerTempTarget
Assert.assertEquals(ComparatorExists.Compare.NOT_EXISTS, t2.comparator.value)
Assertions.assertEquals(ComparatorExists.Compare.NOT_EXISTS, t2.comparator.value)
}
@Test fun iconTest() {
Assert.assertEquals(Optional.of(R.drawable.ic_keyboard_tab), TriggerTempTarget(injector).icon())
Assertions.assertEquals(Optional.of(R.drawable.ic_keyboard_tab), TriggerTempTarget(injector).icon())
}
}

View file

@ -8,19 +8,16 @@ import info.nightscout.database.entities.TemporaryTarget
import info.nightscout.interfaces.GlucoseUnit
import io.reactivex.rxjava3.core.Single
import org.json.JSONObject
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when`
class TriggerTempTargetValueTest : TriggerTestBase() {
var now = 1514766900000L
@BeforeEach
fun prepare() {
`when`(profileFunction.getUnits()).thenReturn(GlucoseUnit.MGDL)
`when`(dateUtil.now()).thenReturn(now)
}
@Test
@ -39,37 +36,37 @@ class TriggerTempTargetValueTest : TriggerTestBase() {
)
)
var t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MMOL).setValue(7.7).comparator(Comparator.Compare.IS_EQUAL)
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(139.0).comparator(Comparator.Compare.IS_EQUAL)
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(141.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(141.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(139.0).comparator(Comparator.Compare.IS_EQUAL_OR_GREATER)
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(139.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
Assert.assertFalse(t.shouldRun())
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
t = TriggerTempTargetValue(injector).comparator(Comparator.Compare.IS_NOT_AVAILABLE)
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
`when`(repository.getTemporaryTargetActiveAt(dateUtil.now())).thenReturn(Single.just(ValueWrapper.Absent()))
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
}
@Test
fun copyConstructorTest() {
val t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MGDL).setValue(140.0).comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
val t1 = t.duplicate() as TriggerTempTargetValue
Assert.assertEquals(140.0, t1.ttValue.value, 0.01)
Assert.assertEquals(GlucoseUnit.MGDL, t1.ttValue.units)
Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
Assertions.assertEquals(140.0, t1.ttValue.value, 0.01)
Assertions.assertEquals(GlucoseUnit.MGDL, t1.ttValue.units)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
}
private var ttJson = "{\"data\":{\"tt\":7.7,\"comparator\":\"IS_EQUAL\",\"units\":\"mmol\"},\"type\":\"TriggerTempTargetValue\"}"
@ -77,21 +74,21 @@ class TriggerTempTargetValueTest : TriggerTestBase() {
@Test
fun toJSONTest() {
val t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MMOL).setValue(7.7).comparator(Comparator.Compare.IS_EQUAL)
Assert.assertEquals(ttJson, t.toJSON())
Assertions.assertEquals(ttJson, t.toJSON())
}
@Test
fun fromJSONTest() {
val t: TriggerTempTargetValue = TriggerTempTargetValue(injector).setUnits(GlucoseUnit.MMOL).setValue(7.7).comparator(Comparator.Compare.IS_EQUAL)
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerTempTargetValue
Assert.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
Assert.assertEquals(7.7, t2.ttValue.value, 0.01)
Assert.assertEquals(GlucoseUnit.MMOL, t2.ttValue.units)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
Assertions.assertEquals(7.7, t2.ttValue.value, 0.01)
Assertions.assertEquals(GlucoseUnit.MMOL, t2.ttValue.units)
}
@Test
fun iconTest() {
Assert.assertEquals(Optional.of(R.drawable.ic_keyboard_tab), TriggerTempTargetValue(injector).icon())
Assertions.assertEquals(Optional.of(R.drawable.ic_keyboard_tab), TriggerTempTargetValue(injector).icon())
}
}

View file

@ -1,41 +1,29 @@
package info.nightscout.automation.triggers
import android.content.Context
import dagger.android.AndroidInjector
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.TestBaseWithProfile
import info.nightscout.androidaps.TestPumpPlugin
import info.nightscout.automation.AutomationPlugin
import info.nightscout.automation.services.LastLocationDataContainer
import info.nightscout.database.impl.AppRepository
import info.nightscout.implementation.iob.GlucoseStatusProviderImpl
import info.nightscout.interfaces.aps.AutosensDataStore
import info.nightscout.interfaces.iob.IobCobCalculator
import info.nightscout.interfaces.plugin.ActivePlugin
import info.nightscout.interfaces.plugin.PluginDescription
import info.nightscout.interfaces.receivers.ReceiverStatusStore
import info.nightscout.rx.bus.RxBus
import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.sharedtests.TestBaseWithProfile
import org.junit.jupiter.api.BeforeEach
import org.mockito.Mock
import org.mockito.Mockito.`when`
open class TriggerTestBase : TestBaseWithProfile() {
@Mock lateinit var sp: SP
@Mock lateinit var locationDataContainer: LastLocationDataContainer
@Mock lateinit var activePlugin: ActivePlugin
@Mock lateinit var iobCobCalculator: IobCobCalculator
@Mock lateinit var autosensDataStore: AutosensDataStore
@Mock lateinit var context: Context
@Mock lateinit var automationPlugin: AutomationPlugin
@Mock lateinit var receiverStatusStore: ReceiverStatusStore
private val pluginDescription = PluginDescription()
lateinit var testPumpPlugin: TestPumpPlugin
@Mock lateinit var repository: AppRepository
@BeforeEach
fun prepareMock1() {
testPumpPlugin = TestPumpPlugin(pluginDescription, aapsLogger, rh, injector)
`when`(activePlugin.activePump).thenReturn(testPumpPlugin)
`when`(iobCobCalculator.ads).thenReturn(autosensDataStore)
}

View file

@ -4,67 +4,68 @@ import com.google.common.base.Optional
import info.nightscout.automation.R
import info.nightscout.interfaces.utils.MidnightTime
import org.json.JSONObject
import org.junit.Assert
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when`
class TriggerTimeRangeTest : TriggerTestBase() {
var now = 754 // in minutes from midnight
private var timeJson = "{\"data\":{\"start\":753,\"end\":784},\"type\":\"TriggerTimeRange\"}"
@BeforeEach
fun mock() {
val nowMills = MidnightTime.calcPlusMinutes(now)
now = 754 // in minutes from midnight
val nowMills = MidnightTime.calcPlusMinutes(now.toInt())
`when`(dateUtil.now()).thenReturn(nowMills)
`when`(rh.gs(R.string.timerange_value)).thenReturn("Time is between %1\$s and %2\$s")
}
@Test
fun shouldRunTest() {
// range starts 1 min in the future
var t: TriggerTimeRange = TriggerTimeRange(injector).period(now + 1, now + 30)
Assert.assertEquals(false, t.shouldRun())
var t: TriggerTimeRange = TriggerTimeRange(injector).period((now + 1).toInt(), (now + 30).toInt())
Assertions.assertEquals(false, t.shouldRun())
// range starts 30 min back
t = TriggerTimeRange(injector).period(now - 30, now + 30)
Assert.assertEquals(true, t.shouldRun())
t = TriggerTimeRange(injector).period((now - 30).toInt(), (now + 30).toInt())
Assertions.assertEquals(true, t.shouldRun())
// Period is all day long
t = TriggerTimeRange(injector).period(1, 1440)
Assert.assertEquals(true, t.shouldRun())
Assertions.assertEquals(true, t.shouldRun())
}
@Test
fun toJSONTest() {
val t: TriggerTimeRange = TriggerTimeRange(injector).period(now - 1, now + 30)
Assert.assertEquals(timeJson, t.toJSON())
val t: TriggerTimeRange = TriggerTimeRange(injector).period((now - 1).toInt(), (now + 30).toInt())
Assertions.assertEquals(timeJson, t.toJSON())
}
@Test
fun fromJSONTest() {
val t: TriggerTimeRange = TriggerTimeRange(injector).period(120, 180)
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerTimeRange
Assert.assertEquals(now - 1, t2.period(753, 360).range.start)
Assert.assertEquals(360, t2.period(753, 360).range.end)
Assertions.assertEquals((now - 1).toInt(), t2.period(753, 360).range.start)
Assertions.assertEquals(360, t2.period(753, 360).range.end)
}
@Test fun copyConstructorTest() {
val t = TriggerTimeRange(injector)
t.period(now, now + 30)
t.period(now.toInt(), (now + 30).toInt())
val t1 = t.duplicate() as TriggerTimeRange
Assert.assertEquals(now, t1.range.start)
Assertions.assertEquals(now.toInt(), t1.range.start)
}
@Test fun friendlyNameTest() {
Assert.assertEquals(R.string.time_range, TriggerTimeRange(injector).friendlyName())
Assertions.assertEquals(R.string.time_range, TriggerTimeRange(injector).friendlyName())
}
@Test fun friendlyDescriptionTest() {
Assert.assertEquals(null, TriggerTimeRange(injector).friendlyDescription()) //not mocked }
Assertions.assertEquals("Time is between 12:34PM and 12:34PM", TriggerTimeRange(injector).friendlyDescription())
}
@Test fun iconTest() {
Assert.assertEquals(Optional.of(info.nightscout.core.main.R.drawable.ic_access_alarm_24dp), TriggerTimeRange(injector).icon())
Assertions.assertEquals(Optional.of(info.nightscout.core.main.R.drawable.ic_access_alarm_24dp), TriggerTimeRange(injector).icon())
}
}

View file

@ -1,61 +1,67 @@
package info.nightscout.automation.triggers
import com.google.common.base.Optional
import info.nightscout.automation.R
import info.nightscout.shared.utils.T
import org.json.JSONException
import org.json.JSONObject
import org.junit.Assert
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when`
import org.mockito.Mockito
class TriggerTimeTest : TriggerTestBase() {
var now = 1514766900000L
@BeforeEach fun mock() {
`when`(dateUtil.now()).thenReturn(now)
fun mock() {
}
@Test fun shouldRunTest() {
@Test
fun shouldRunTest() {
Mockito.`when`(rh.gs(R.string.atspecifiedtime)).thenReturn("At %1\$s")
// scheduled 1 min before
var t: TriggerTime = TriggerTime(injector).runAt(now - T.mins(1).msecs())
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
// scheduled 1 min in the future
t = TriggerTime(injector).runAt(now + T.mins(1).msecs())
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
}
private var timeJson = "{\"data\":{\"runAt\":1514766840000},\"type\":\"TriggerTime\"}"
@Test fun toJSONTest() {
private var timeJson = "{\"data\":{\"runAt\":1656358762000},\"type\":\"TriggerTime\"}"
@Test
fun toJSONTest() {
val t: TriggerTime = TriggerTime(injector).runAt(now - T.mins(1).msecs())
Assert.assertEquals(timeJson, t.toJSON())
Assertions.assertEquals(timeJson, t.toJSON())
}
@Test @Throws(JSONException::class) fun fromJSONTest() {
@Test
fun fromJSONTest() {
val t: TriggerTime = TriggerTime(injector).runAt(now - T.mins(1).msecs())
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerTime
Assert.assertEquals(now - T.mins(1).msecs(), t2.time.value)
Assertions.assertEquals(now - T.mins(1).msecs(), t2.time.value)
}
@Test fun copyConstructorTest() {
@Test
fun copyConstructorTest() {
val t = TriggerTime(injector)
t.runAt(now)
val t1 = t.duplicate() as TriggerTime
Assert.assertEquals(now, t1.time.value)
Assertions.assertEquals(now, t1.time.value)
}
@Test fun friendlyNameTest() {
Assert.assertEquals(info.nightscout.core.ui.R.string.time, TriggerTime(injector).friendlyName())
@Test
fun friendlyNameTest() {
Assertions.assertEquals(info.nightscout.core.ui.R.string.time, TriggerTime(injector).friendlyName())
}
@Test fun friendlyDescriptionTest() {
Assert.assertEquals(null, TriggerTime(injector).friendlyDescription()) //not mocked }
@Test
fun friendlyDescriptionTest() {
Mockito.`when`(rh.gs(R.string.atspecifiedtime)).thenReturn("At %1\$s")
Assertions.assertEquals("At 6/27/22 09:40PM", TriggerTime(injector).friendlyDescription())
}
@Test fun iconTest() {
Assert.assertEquals(Optional.of(info.nightscout.core.main.R.drawable.ic_access_alarm_24dp), TriggerTime(injector).icon())
@Test
fun iconTest() {
Assertions.assertEquals(Optional.of(info.nightscout.core.main.R.drawable.ic_access_alarm_24dp), TriggerTime(injector).icon())
}
}

View file

@ -6,69 +6,62 @@ import info.nightscout.automation.elements.Comparator
import info.nightscout.rx.events.EventNetworkChange
import org.json.JSONException
import org.json.JSONObject
import org.junit.Assert
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.mockito.Mockito.`when`
class TriggerWifiSsidTest : TriggerTestBase() {
var now = 1514766900000L
@BeforeEach fun mock() {
`when`(dateUtil.now()).thenReturn(now)
}
@Test fun shouldRunTest() {
val e = EventNetworkChange()
`when`(receiverStatusStore.lastNetworkEvent).thenReturn(e)
var t: TriggerWifiSsid = TriggerWifiSsid(injector).setValue("aSSID 1").comparator(Comparator.Compare.IS_EQUAL)
e.wifiConnected = false
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
e.wifiConnected = true
e.ssid = "otherSSID"
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
e.wifiConnected = true
e.ssid = "aSSID 1"
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
t = TriggerWifiSsid(injector).setValue("aSSID 1").comparator(Comparator.Compare.IS_NOT_AVAILABLE)
e.wifiConnected = false
Assert.assertTrue(t.shouldRun())
Assertions.assertTrue(t.shouldRun())
// no network data
`when`(receiverStatusStore.lastNetworkEvent).thenReturn(null)
Assert.assertFalse(t.shouldRun())
Assertions.assertFalse(t.shouldRun())
}
@Test fun copyConstructorTest() {
val t: TriggerWifiSsid = TriggerWifiSsid(injector).setValue("aSSID").comparator(Comparator.Compare.IS_EQUAL_OR_LESSER)
val t1 = t.duplicate() as TriggerWifiSsid
Assert.assertEquals("aSSID", t1.ssid.value)
Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
Assertions.assertEquals("aSSID", t1.ssid.value)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
}
var json = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"ssid\":\"aSSID\"},\"type\":\"TriggerWifiSsid\"}"
@Test fun toJSONTest() {
val t: TriggerWifiSsid = TriggerWifiSsid(injector).setValue("aSSID").comparator(Comparator.Compare.IS_EQUAL)
Assert.assertEquals(json, t.toJSON())
Assertions.assertEquals(json, t.toJSON())
}
@Test @Throws(JSONException::class) fun fromJSONTest() {
val t: TriggerWifiSsid = TriggerWifiSsid(injector).setValue("aSSID").comparator(Comparator.Compare.IS_EQUAL)
val t2 = TriggerDummy(injector).instantiate(JSONObject(t.toJSON())) as TriggerWifiSsid
Assert.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
Assert.assertEquals("aSSID", t2.ssid.value)
Assertions.assertEquals(Comparator.Compare.IS_EQUAL, t2.comparator.value)
Assertions.assertEquals("aSSID", t2.ssid.value)
}
@Test fun iconTest() {
Assert.assertEquals(Optional.of(R.drawable.ic_network_wifi), TriggerWifiSsid(injector).icon())
Assertions.assertEquals(Optional.of(R.drawable.ic_network_wifi), TriggerWifiSsid(injector).icon())
}
@Test fun friendlyNameTest() {
Assert.assertEquals(info.nightscout.core.ui.R.string.ns_wifi_ssids, TriggerWifiSsid(injector).friendlyName())
Assertions.assertEquals(info.nightscout.core.ui.R.string.ns_wifi_ssids, TriggerWifiSsid(injector).friendlyName())
}
@Test fun friendlyDescriptionTest() {
Assert.assertEquals(null, TriggerWifiSsid(injector).friendlyDescription()) //not mocked
Assertions.assertEquals(null, TriggerWifiSsid(injector).friendlyDescription()) //not mocked
}
}