shared-tests #11
This commit is contained in:
parent
3c5a58b2c7
commit
8032cd8f42
32 changed files with 251 additions and 525 deletions
|
@ -29,5 +29,6 @@ dependencies {
|
||||||
implementation project(':pump:pump-common')
|
implementation project(':pump:pump-common')
|
||||||
implementation project(':core:utils')
|
implementation project(':core:utils')
|
||||||
|
|
||||||
|
testImplementation project(':app-wear-shared:shared-tests')
|
||||||
testImplementation project(':core:main')
|
testImplementation project(':core:main')
|
||||||
}
|
}
|
||||||
|
|
|
@ -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(injector: HasAndroidInjector, override val data: JSONObject, val dateUtil: DateUtil) : ProfileStore {
|
|
||||||
|
|
||||||
@Inject lateinit var aapsLogger: AAPSLogger
|
|
||||||
@Inject lateinit var activePlugin: ActivePlugin
|
|
||||||
@Inject lateinit var config: Config
|
|
||||||
@Inject lateinit var rh: ResourceHelper
|
|
||||||
@Inject lateinit var rxBus: RxBus
|
|
||||||
@Inject lateinit var hardLimits: HardLimits
|
|
||||||
|
|
||||||
init {
|
|
||||||
injector.androidInjector().inject(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val cachedObjects = ArrayMap<String, PureProfile>()
|
|
||||||
|
|
||||||
private fun storeUnits(): String? = JsonHelper.safeGetStringAllowNull(data, "units", null)
|
|
||||||
|
|
||||||
private fun getStore(): JSONObject? {
|
|
||||||
try {
|
|
||||||
if (data.has("store")) return data.getJSONObject("store")
|
|
||||||
} catch (e: JSONException) {
|
|
||||||
aapsLogger.error("Unhandled exception", e)
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getStartDate(): Long {
|
|
||||||
val iso = JsonHelper.safeGetString(data, "startDate") ?: return 0
|
|
||||||
return try {
|
|
||||||
dateUtil.fromISODateString(iso)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getDefaultProfile(): PureProfile? = getDefaultProfileName()?.let { getSpecificProfile(it) }
|
|
||||||
override fun getDefaultProfileJson(): JSONObject? = getDefaultProfileName()?.let { getSpecificProfileJson(it) }
|
|
||||||
|
|
||||||
override fun getDefaultProfileName(): String? {
|
|
||||||
val defaultProfileName = data.optString("defaultProfile")
|
|
||||||
return if (defaultProfileName.isNotEmpty()) getStore()?.has(defaultProfileName)?.let { defaultProfileName } else null
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getProfileList(): ArrayList<CharSequence> {
|
|
||||||
val ret = ArrayList<CharSequence>()
|
|
||||||
getStore()?.keys()?.let { keys ->
|
|
||||||
while (keys.hasNext()) {
|
|
||||||
val profileName = keys.next() as String
|
|
||||||
ret.add(profileName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
@Synchronized
|
|
||||||
override fun getSpecificProfile(profileName: String): PureProfile? {
|
|
||||||
var profile: PureProfile? = null
|
|
||||||
val units = JsonHelper.safeGetStringAllowNull(data, "units", storeUnits())
|
|
||||||
getStore()?.let { store ->
|
|
||||||
if (store.has(profileName)) {
|
|
||||||
profile = cachedObjects[profileName]
|
|
||||||
if (profile == null) {
|
|
||||||
JsonHelper.safeGetJSONObject(store, profileName, null)?.let { profileObject ->
|
|
||||||
profile = pureProfileFromJson(profileObject, dateUtil, units)
|
|
||||||
profile?.let { cachedObjects[profileName] = profile }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return profile
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getSpecificProfileJson(profileName: String): JSONObject? {
|
|
||||||
getStore()?.let { store ->
|
|
||||||
if (store.has(profileName))
|
|
||||||
return JsonHelper.safeGetJSONObject(store, profileName, null)
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
override val allProfilesValid: Boolean
|
|
||||||
get() = getProfileList()
|
|
||||||
.asSequence()
|
|
||||||
.map { profileName -> getSpecificProfile(profileName.toString()) }
|
|
||||||
.map { pureProfile -> pureProfile?.let { ProfileSealed.Pure(pureProfile).isValid("allProfilesValid", activePlugin.activePump, config, rh, rxBus, hardLimits, false) } }
|
|
||||||
.all { it?.isValid == true }
|
|
||||||
}
|
|
|
@ -1,38 +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
|
|
||||||
|
|
||||||
@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()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("Unchecked_Cast")
|
|
||||||
fun <T> uninitialized(): T = null as T
|
|
||||||
}
|
|
|
@ -1,177 +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
|
|
||||||
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)!!)
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,8 +3,8 @@ package info.nightscout.pump.medtrum
|
||||||
import info.nightscout.core.extensions.pureProfileFromJson
|
import info.nightscout.core.extensions.pureProfileFromJson
|
||||||
import info.nightscout.core.profile.ProfileSealed
|
import info.nightscout.core.profile.ProfileSealed
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import java.time.LocalTime
|
import java.time.LocalTime
|
||||||
import java.time.ZoneId
|
import java.time.ZoneId
|
||||||
|
@ -33,7 +33,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
val expectedByteArray = byteArrayOf(7, 0, -96, 2, -16, 96, 2, 104, 33, 2, -32, -31, 1, -64, 3, 2, -20, 36, 2, 100, -123, 2)
|
val expectedByteArray = byteArrayOf(7, 0, -96, 2, -16, 96, 2, 104, 33, 2, -32, -31, 1, -64, 3, 2, -20, 36, 2, 100, -123, 2)
|
||||||
assertEquals(expectedByteArray.contentToString(), result?.contentToString())
|
Assertions.assertEquals(expectedByteArray.contentToString(), result?.contentToString())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun buildMedtrumProfileArrayGiveProfileWhenValuesTooHighThenReturnNull() {
|
@Test fun buildMedtrumProfileArrayGiveProfileWhenValuesTooHighThenReturnNull() {
|
||||||
|
@ -50,7 +50,7 @@ class MedtrumPumpTest : MedtrumTestBase() {
|
||||||
val result = medtrumPump.buildMedtrumProfileArray(profile)
|
val result = medtrumPump.buildMedtrumProfileArray(profile)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertNull(result)
|
Assertions.assertNull(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun getCurrentHourlyBasalFromMedtrumProfileArrayGivenProfileWhenValuesSetThenReturnCorrectValue() {
|
@Test fun getCurrentHourlyBasalFromMedtrumProfileArrayGivenProfileWhenValuesSetThenReturnCorrectValue() {
|
||||||
|
@ -78,27 +78,27 @@ class MedtrumPumpTest : MedtrumTestBase() {
|
||||||
val zonedDateTime0399 = localDate.atTime(localTime0399).atZone(ZoneId.systemDefault())
|
val zonedDateTime0399 = localDate.atTime(localTime0399).atZone(ZoneId.systemDefault())
|
||||||
val time0399 = zonedDateTime0399.toInstant().toEpochMilli()
|
val time0399 = zonedDateTime0399.toInstant().toEpochMilli()
|
||||||
val result = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray!!, time0399)
|
val result = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray!!, time0399)
|
||||||
assertEquals(2.1, result, 0.01)
|
Assertions.assertEquals(2.1, result, 0.01)
|
||||||
|
|
||||||
// For 22:30
|
// For 22:30
|
||||||
val localTime2230 = LocalTime.of(22, 30)
|
val localTime2230 = LocalTime.of(22, 30)
|
||||||
val zonedDateTime2230 = localDate.atTime(localTime2230).atZone(ZoneId.systemDefault())
|
val zonedDateTime2230 = localDate.atTime(localTime2230).atZone(ZoneId.systemDefault())
|
||||||
val time2230 = zonedDateTime2230.toInstant().toEpochMilli()
|
val time2230 = zonedDateTime2230.toInstant().toEpochMilli()
|
||||||
val result1 = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray, time2230)
|
val result1 = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray, time2230)
|
||||||
assertEquals(1.7, result1, 0.01)
|
Assertions.assertEquals(1.7, result1, 0.01)
|
||||||
|
|
||||||
// For 23:59
|
// For 23:59
|
||||||
val localTime2359 = LocalTime.of(23, 59)
|
val localTime2359 = LocalTime.of(23, 59)
|
||||||
val zonedDateTime2359 = localDate.atTime(localTime2359).atZone(ZoneId.systemDefault())
|
val zonedDateTime2359 = localDate.atTime(localTime2359).atZone(ZoneId.systemDefault())
|
||||||
val time2359 = zonedDateTime2359.toInstant().toEpochMilli()
|
val time2359 = zonedDateTime2359.toInstant().toEpochMilli()
|
||||||
val result2 = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray, time2359)
|
val result2 = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray, time2359)
|
||||||
assertEquals(2.0, result2, 0.01)
|
Assertions.assertEquals(2.0, result2, 0.01)
|
||||||
|
|
||||||
// For 00:00
|
// For 00:00
|
||||||
val localTime0000 = LocalTime.of(0, 0)
|
val localTime0000 = LocalTime.of(0, 0)
|
||||||
val zonedDateTime0000 = localDate.atTime(localTime0000).atZone(ZoneId.systemDefault())
|
val zonedDateTime0000 = localDate.atTime(localTime0000).atZone(ZoneId.systemDefault())
|
||||||
val time0000 = zonedDateTime0000.toInstant().toEpochMilli()
|
val time0000 = zonedDateTime0000.toInstant().toEpochMilli()
|
||||||
val result3 = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray, time0000)
|
val result3 = medtrumPump.getHourlyBasalFromMedtrumProfileArray(profileArray, time0000)
|
||||||
assertEquals(2.1, result3, 0.01)
|
Assertions.assertEquals(2.1, result3, 0.01)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
package info.nightscout.pump.medtrum
|
package info.nightscout.pump.medtrum
|
||||||
|
|
||||||
import info.nightscout.androidaps.TestBaseWithProfile
|
|
||||||
import info.nightscout.shared.sharedPreferences.SP
|
|
||||||
import info.nightscout.interfaces.pump.PumpSync
|
import info.nightscout.interfaces.pump.PumpSync
|
||||||
import info.nightscout.interfaces.pump.TemporaryBasalStorage
|
import info.nightscout.interfaces.pump.TemporaryBasalStorage
|
||||||
import info.nightscout.interfaces.stats.TddCalculator
|
import info.nightscout.interfaces.stats.TddCalculator
|
||||||
|
import info.nightscout.sharedtests.TestBaseWithProfile
|
||||||
import org.junit.jupiter.api.BeforeEach
|
import org.junit.jupiter.api.BeforeEach
|
||||||
import org.mockito.Mock
|
import org.mockito.Mock
|
||||||
import org.mockito.Mockito
|
import org.mockito.Mockito
|
||||||
|
|
||||||
open class MedtrumTestBase : TestBaseWithProfile() {
|
open class MedtrumTestBase : TestBaseWithProfile() {
|
||||||
|
|
||||||
@Mock lateinit var sp: SP
|
|
||||||
@Mock lateinit var tddCalculator: TddCalculator
|
@Mock lateinit var tddCalculator: TddCalculator
|
||||||
@Mock lateinit var pumpSync: PumpSync
|
@Mock lateinit var pumpSync: PumpSync
|
||||||
@Mock lateinit var temporaryBasalStorage: TemporaryBasalStorage
|
@Mock lateinit var temporaryBasalStorage: TemporaryBasalStorage
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package info.nightscout.pump.medtrum.comm
|
package info.nightscout.pump.medtrum.comm
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class WriteCommandPacketsTest {
|
class WriteCommandPacketsTest {
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ class WriteCommandPacketsTest {
|
||||||
val cmdPackets = WriteCommandPackets(input, sequence)
|
val cmdPackets = WriteCommandPackets(input, sequence)
|
||||||
val output = cmdPackets.getNextPacket()
|
val output = cmdPackets.getNextPacket()
|
||||||
|
|
||||||
assertEquals(expect.contentToString(), output.contentToString())
|
Assertions.assertEquals(expect.contentToString(), output.contentToString())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -31,10 +31,10 @@ class WriteCommandPacketsTest {
|
||||||
val output4 = cmdPackets.getNextPacket()
|
val output4 = cmdPackets.getNextPacket()
|
||||||
|
|
||||||
|
|
||||||
assertEquals(expect1.contentToString(), output1.contentToString())
|
Assertions.assertEquals(expect1.contentToString(), output1.contentToString())
|
||||||
assertEquals(expect2.contentToString(), output2.contentToString())
|
Assertions.assertEquals(expect2.contentToString(), output2.contentToString())
|
||||||
assertEquals(expect3.contentToString(), output3.contentToString())
|
Assertions.assertEquals(expect3.contentToString(), output3.contentToString())
|
||||||
assertNull(output4)
|
Assertions.assertNull(output4)
|
||||||
assertEquals(true, cmdPackets.allPacketsConsumed())
|
Assertions.assertEquals(true, cmdPackets.allPacketsConsumed())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
import info.nightscout.pump.medtrum.comm.enums.AlarmSetting
|
import info.nightscout.pump.medtrum.comm.enums.AlarmSetting
|
||||||
import info.nightscout.pump.medtrum.comm.enums.BasalType
|
import info.nightscout.pump.medtrum.comm.enums.BasalType
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class ActivatePacketTest : MedtrumTestBase() {
|
class ActivatePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class ActivatePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
val expectedByteArray = byteArrayOf(18, 0, 12, 1, 6, 0, 0, 30, 32, 3, 16, 14, 0, 0, 1, 3, 16, 14, 0, 0, 1, 2, 12, 12, 12)
|
val expectedByteArray = byteArrayOf(18, 0, 12, 1, 6, 0, 0, 30, 32, 3, 16, 14, 0, 0, 1, 3, 16, 14, 0, 0, 1, 2, 12, 12, 12)
|
||||||
assertEquals(expectedByteArray.contentToString(), result.contentToString())
|
Assertions.assertEquals(expectedByteArray.contentToString(), result.contentToString())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
|
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
|
||||||
|
@ -64,15 +64,15 @@ class ActivatePacketTest : MedtrumTestBase() {
|
||||||
val expectedBasalPatchId = 41L
|
val expectedBasalPatchId = 41L
|
||||||
val expectedBasalStart = 1675605528000L
|
val expectedBasalStart = 1675605528000L
|
||||||
|
|
||||||
assertEquals(true, result)
|
Assertions.assertEquals(true, result)
|
||||||
assertEquals(expectedPatchId, medtrumPump.patchId)
|
Assertions.assertEquals(expectedPatchId, medtrumPump.patchId)
|
||||||
assertEquals(expectedTime, medtrumPump.lastTimeReceivedFromPump)
|
Assertions.assertEquals(expectedTime, medtrumPump.lastTimeReceivedFromPump)
|
||||||
assertEquals(expectedBasalType, medtrumPump.lastBasalType)
|
Assertions.assertEquals(expectedBasalType, medtrumPump.lastBasalType)
|
||||||
assertEquals(expectedBasalRate, medtrumPump.lastBasalRate, 0.01)
|
Assertions.assertEquals(expectedBasalRate, medtrumPump.lastBasalRate, 0.01)
|
||||||
assertEquals(expectedBasalSequence, medtrumPump.lastBasalSequence)
|
Assertions.assertEquals(expectedBasalSequence, medtrumPump.lastBasalSequence)
|
||||||
assertEquals(expectedBasalPatchId, medtrumPump.lastBasalPatchId)
|
Assertions.assertEquals(expectedBasalPatchId, medtrumPump.lastBasalPatchId)
|
||||||
assertEquals(expectedBasalStart, medtrumPump.lastBasalStartTime)
|
Assertions.assertEquals(expectedBasalStart, medtrumPump.lastBasalStartTime)
|
||||||
assertEquals(basalProfile, medtrumPump.actualBasalProfile)
|
Assertions.assertEquals(basalProfile, medtrumPump.actualBasalProfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
||||||
|
@ -84,6 +84,6 @@ class ActivatePacketTest : MedtrumTestBase() {
|
||||||
val result = packet.handleResponse(response)
|
val result = packet.handleResponse(response)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertFalse(result)
|
Assertions.assertFalse(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.MedtrumPump
|
import info.nightscout.pump.medtrum.MedtrumPump
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
import info.nightscout.pump.medtrum.extension.toByteArray
|
import info.nightscout.pump.medtrum.extension.toByteArray
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class AuthorizePacketTest : MedtrumTestBase() {
|
class AuthorizePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
|
@ -37,8 +37,8 @@ class AuthorizePacketTest : MedtrumTestBase() {
|
||||||
val key = 3364239851
|
val key = 3364239851
|
||||||
val type = 2
|
val type = 2
|
||||||
val expectedByteArray = byteArrayOf(opCode.toByte()) + type.toByte() + medtrumPump.patchSessionToken.toByteArray(4) + key.toByteArray(4)
|
val expectedByteArray = byteArrayOf(opCode.toByte()) + type.toByte() + medtrumPump.patchSessionToken.toByteArray(4) + key.toByteArray(4)
|
||||||
assertEquals(10, result.size)
|
Assertions.assertEquals(10, result.size)
|
||||||
assertEquals(expectedByteArray.contentToString(), result.contentToString())
|
Assertions.assertEquals(expectedByteArray.contentToString(), result.contentToString())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenResponseWhenMessageIsCorrectLengthThenResultTrue() {
|
@Test fun handleResponseGivenResponseWhenMessageIsCorrectLengthThenResultTrue() {
|
||||||
|
@ -57,10 +57,10 @@ class AuthorizePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
val swString = "$swVerX.$swVerY.$swVerZ"
|
val swString = "$swVerX.$swVerY.$swVerZ"
|
||||||
assertTrue(result)
|
Assertions.assertTrue(result)
|
||||||
assertFalse(packet.failed)
|
Assertions.assertFalse(packet.failed)
|
||||||
assertEquals(deviceType, medtrumPump.deviceType)
|
Assertions.assertEquals(deviceType, medtrumPump.deviceType)
|
||||||
assertEquals(swString, medtrumPump.swVersion)
|
Assertions.assertEquals(swString, medtrumPump.swVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
||||||
|
@ -75,7 +75,7 @@ class AuthorizePacketTest : MedtrumTestBase() {
|
||||||
val result = packet.handleResponse(response)
|
val result = packet.handleResponse(response)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertFalse(result)
|
Assertions.assertFalse(result)
|
||||||
assertTrue(packet.failed)
|
Assertions.assertTrue(packet.failed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,8 @@ package info.nightscout.pump.medtrum.comm.packets
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class CancelBolusPacketTest : MedtrumTestBase() {
|
class CancelBolusPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ class CancelBolusPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
val expectedByteArray = byteArrayOf(opCode.toByte()) + 1.toByte()
|
val expectedByteArray = byteArrayOf(opCode.toByte()) + 1.toByte()
|
||||||
assertEquals(2, result.size)
|
Assertions.assertEquals(2, result.size)
|
||||||
assertEquals(expectedByteArray.contentToString(), result.contentToString())
|
Assertions.assertEquals(expectedByteArray.contentToString(), result.contentToString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
import info.nightscout.pump.medtrum.comm.enums.BasalType
|
import info.nightscout.pump.medtrum.comm.enums.BasalType
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class CancelTempBasalPacketTest : MedtrumTestBase() {
|
class CancelTempBasalPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
|
@ -30,8 +30,8 @@ class CancelTempBasalPacketTest : MedtrumTestBase() {
|
||||||
val result = packet.getRequest()
|
val result = packet.getRequest()
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(1, result.size)
|
Assertions.assertEquals(1, result.size)
|
||||||
assertEquals(opCode.toByte(), result[0])
|
Assertions.assertEquals(opCode.toByte(), result[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
|
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
|
||||||
|
@ -49,12 +49,12 @@ class CancelTempBasalPacketTest : MedtrumTestBase() {
|
||||||
val expectedStartTime = 1679575392000L
|
val expectedStartTime = 1679575392000L
|
||||||
val expectedPatchId = 146L
|
val expectedPatchId = 146L
|
||||||
|
|
||||||
assertTrue(result)
|
Assertions.assertTrue(result)
|
||||||
assertEquals(expectedBasalType, medtrumPump.lastBasalType)
|
Assertions.assertEquals(expectedBasalType, medtrumPump.lastBasalType)
|
||||||
assertEquals(expectedBasalRate, medtrumPump.lastBasalRate, 0.01)
|
Assertions.assertEquals(expectedBasalRate, medtrumPump.lastBasalRate, 0.01)
|
||||||
assertEquals(expectedBasalSequence, medtrumPump.lastBasalSequence)
|
Assertions.assertEquals(expectedBasalSequence, medtrumPump.lastBasalSequence)
|
||||||
assertEquals(expectedStartTime, medtrumPump.lastBasalStartTime)
|
Assertions.assertEquals(expectedStartTime, medtrumPump.lastBasalStartTime)
|
||||||
assertEquals(expectedPatchId, medtrumPump.lastBasalPatchId)
|
Assertions.assertEquals(expectedPatchId, medtrumPump.lastBasalPatchId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
||||||
|
@ -66,7 +66,7 @@ class CancelTempBasalPacketTest : MedtrumTestBase() {
|
||||||
val result = packet.handleResponse(response)
|
val result = packet.handleResponse(response)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertFalse(result)
|
Assertions.assertFalse(result)
|
||||||
assertTrue(packet.failed)
|
Assertions.assertTrue(packet.failed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
import info.nightscout.pump.medtrum.extension.toInt
|
import info.nightscout.pump.medtrum.extension.toInt
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class ClearPumpAlarmPacketTest : MedtrumTestBase() {
|
class ClearPumpAlarmPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ class ClearPumpAlarmPacketTest : MedtrumTestBase() {
|
||||||
val result = packet.getRequest()
|
val result = packet.getRequest()
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(3, result.size)
|
Assertions.assertEquals(3, result.size)
|
||||||
assertEquals(opCode.toByte(), result[0])
|
Assertions.assertEquals(opCode.toByte(), result[0])
|
||||||
assertEquals(clearCode, result.copyOfRange(1, 3).toInt())
|
Assertions.assertEquals(clearCode, result.copyOfRange(1, 3).toInt())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
import info.nightscout.pump.medtrum.extension.toByteArray
|
import info.nightscout.pump.medtrum.extension.toByteArray
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class GetDeviceTypePacketTest : MedtrumTestBase() {
|
class GetDeviceTypePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
|
@ -28,8 +28,8 @@ class GetDeviceTypePacketTest : MedtrumTestBase() {
|
||||||
val result = packet.getRequest()
|
val result = packet.getRequest()
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(1, result.size)
|
Assertions.assertEquals(1, result.size)
|
||||||
assertEquals(opCode.toByte(), result[0])
|
Assertions.assertEquals(opCode.toByte(), result[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenResponseWhenMessageIsCorrectLengthThenResultTrue() {
|
@Test fun handleResponseGivenResponseWhenMessageIsCorrectLengthThenResultTrue() {
|
||||||
|
@ -45,10 +45,10 @@ class GetDeviceTypePacketTest : MedtrumTestBase() {
|
||||||
val result = packet.handleResponse(response)
|
val result = packet.handleResponse(response)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(true, result)
|
Assertions.assertEquals(true, result)
|
||||||
assertEquals(false, packet.failed)
|
Assertions.assertEquals(false, packet.failed)
|
||||||
assertEquals(deviceType, packet.deviceType)
|
Assertions.assertEquals(deviceType, packet.deviceType)
|
||||||
assertEquals(deviceSN, packet.deviceSN)
|
Assertions.assertEquals(deviceSN, packet.deviceSN)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,9 +65,9 @@ class GetDeviceTypePacketTest : MedtrumTestBase() {
|
||||||
val result = packet.handleResponse(response.sliceArray(0..response.size - 2))
|
val result = packet.handleResponse(response.sliceArray(0..response.size - 2))
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(false, result)
|
Assertions.assertEquals(false, result)
|
||||||
assertEquals(true, packet.failed)
|
Assertions.assertEquals(true, packet.failed)
|
||||||
assertEquals(0, packet.deviceType)
|
Assertions.assertEquals(0, packet.deviceType)
|
||||||
assertEquals(0, packet.deviceSN)
|
Assertions.assertEquals(0, packet.deviceSN)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,8 @@ package info.nightscout.pump.medtrum.comm.packets
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class GetRecordPacketTest : MedtrumTestBase() {
|
class GetRecordPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ class GetRecordPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
val expected = byteArrayOf(99, 4, 0, -110, 0)
|
val expected = byteArrayOf(99, 4, 0, -110, 0)
|
||||||
assertEquals(expected.contentToString(), result.contentToString())
|
Assertions.assertEquals(expected.contentToString(), result.contentToString())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
|
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
|
||||||
|
@ -42,8 +42,8 @@ class GetRecordPacketTest : MedtrumTestBase() {
|
||||||
val result = packet.handleResponse(data)
|
val result = packet.handleResponse(data)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(true, result)
|
Assertions.assertEquals(true, result)
|
||||||
assertEquals(false, packet.failed)
|
Assertions.assertEquals(false, packet.failed)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
||||||
|
@ -55,7 +55,7 @@ class GetRecordPacketTest : MedtrumTestBase() {
|
||||||
val result = packet.handleResponse(data)
|
val result = packet.handleResponse(data)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(false, result)
|
Assertions.assertEquals(false, result)
|
||||||
assertEquals(true, packet.failed)
|
Assertions.assertEquals(true, packet.failed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
import info.nightscout.pump.medtrum.extension.toByteArray
|
import info.nightscout.pump.medtrum.extension.toByteArray
|
||||||
import info.nightscout.pump.medtrum.util.MedtrumTimeUtil
|
import info.nightscout.pump.medtrum.util.MedtrumTimeUtil
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class GetTimePacketTest : MedtrumTestBase() {
|
class GetTimePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
|
@ -30,8 +30,8 @@ class GetTimePacketTest : MedtrumTestBase() {
|
||||||
val result = packet.getRequest()
|
val result = packet.getRequest()
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(1, result.size)
|
Assertions.assertEquals(1, result.size)
|
||||||
assertEquals(opCode.toByte(), result[0])
|
Assertions.assertEquals(opCode.toByte(), result[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenResponseWhenMessageIsCorrectLengthThenResultTrue() {
|
@Test fun handleResponseGivenResponseWhenMessageIsCorrectLengthThenResultTrue() {
|
||||||
|
@ -46,9 +46,9 @@ class GetTimePacketTest : MedtrumTestBase() {
|
||||||
val result = packet.handleResponse(response)
|
val result = packet.handleResponse(response)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(true, result)
|
Assertions.assertEquals(true, result)
|
||||||
assertEquals(false, packet.failed)
|
Assertions.assertEquals(false, packet.failed)
|
||||||
assertEquals(MedtrumTimeUtil().convertPumpTimeToSystemTimeMillis(time), medtrumPump.lastTimeReceivedFromPump)
|
Assertions.assertEquals(MedtrumTimeUtil().convertPumpTimeToSystemTimeMillis(time), medtrumPump.lastTimeReceivedFromPump)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
||||||
|
@ -63,8 +63,8 @@ class GetTimePacketTest : MedtrumTestBase() {
|
||||||
val result = packet.handleResponse(response.sliceArray(0..response.size - 2))
|
val result = packet.handleResponse(response.sliceArray(0..response.size - 2))
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(false, result)
|
Assertions.assertEquals(false, result)
|
||||||
assertEquals(true, packet.failed)
|
Assertions.assertEquals(true, packet.failed)
|
||||||
assertEquals(0, medtrumPump.lastTimeReceivedFromPump)
|
Assertions.assertEquals(0, medtrumPump.lastTimeReceivedFromPump)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
import info.nightscout.pump.medtrum.extension.toByteArray
|
import info.nightscout.pump.medtrum.extension.toByteArray
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class MedtrumPacketTest : MedtrumTestBase() {
|
class MedtrumPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ class MedtrumPacketTest : MedtrumTestBase() {
|
||||||
val result = packet.getRequest()
|
val result = packet.getRequest()
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(result.size, 1)
|
Assertions.assertEquals(result.size, 1)
|
||||||
assertEquals(result[0], opCode.toByte())
|
Assertions.assertEquals(result[0], opCode.toByte())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenResponseWhenOpcodeIsCorrectThenResultTrue() {
|
@Test fun handleResponseGivenResponseWhenOpcodeIsCorrectThenResultTrue() {
|
||||||
|
@ -45,8 +45,8 @@ class MedtrumPacketTest : MedtrumTestBase() {
|
||||||
val result = packet.handleResponse(response)
|
val result = packet.handleResponse(response)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(result, true)
|
Assertions.assertEquals(result, true)
|
||||||
assertEquals(packet.failed, false)
|
Assertions.assertEquals(packet.failed, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenResponseWhenOpcodeIsIncorrectThenResultFalse() {
|
@Test fun handleResponseGivenResponseWhenOpcodeIsIncorrectThenResultFalse() {
|
||||||
|
@ -61,8 +61,8 @@ class MedtrumPacketTest : MedtrumTestBase() {
|
||||||
val result = packet.handleResponse(response)
|
val result = packet.handleResponse(response)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(result, false)
|
Assertions.assertEquals(result, false)
|
||||||
assertEquals(packet.failed, true)
|
Assertions.assertEquals(packet.failed, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenResponseWhenResponseCodeIsWaitingThenResultFalse() {
|
@Test fun handleResponseGivenResponseWhenResponseCodeIsWaitingThenResultFalse() {
|
||||||
|
@ -77,8 +77,8 @@ class MedtrumPacketTest : MedtrumTestBase() {
|
||||||
val result = packet.handleResponse(response)
|
val result = packet.handleResponse(response)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(result, false)
|
Assertions.assertEquals(result, false)
|
||||||
assertEquals(packet.failed, false)
|
Assertions.assertEquals(packet.failed, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenResponseWhenResponseCodeIsErrorThenResultFalse() {
|
@Test fun handleResponseGivenResponseWhenResponseCodeIsErrorThenResultFalse() {
|
||||||
|
@ -93,8 +93,8 @@ class MedtrumPacketTest : MedtrumTestBase() {
|
||||||
val result = packet.handleResponse(response)
|
val result = packet.handleResponse(response)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(false, result)
|
Assertions.assertEquals(false, result)
|
||||||
assertEquals(true, packet.failed)
|
Assertions.assertEquals(true, packet.failed)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
||||||
|
@ -108,7 +108,7 @@ class MedtrumPacketTest : MedtrumTestBase() {
|
||||||
val result = packet.handleResponse(response)
|
val result = packet.handleResponse(response)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(false, result)
|
Assertions.assertEquals(false, result)
|
||||||
assertEquals(true, packet.failed)
|
Assertions.assertEquals(true, packet.failed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@ import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
import info.nightscout.pump.medtrum.comm.enums.BasalType
|
import info.nightscout.pump.medtrum.comm.enums.BasalType
|
||||||
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
|
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
|
||||||
import info.nightscout.rx.events.EventOverviewBolusProgress
|
import info.nightscout.rx.events.EventOverviewBolusProgress
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class NotificationPacketTest : MedtrumTestBase() {
|
class NotificationPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ class NotificationPacketTest : MedtrumTestBase() {
|
||||||
NotificationPacket(packetInjector).handleNotification(byteArrayOf(state))
|
NotificationPacket(packetInjector).handleNotification(byteArrayOf(state))
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(medtrumPump.pumpState, MedtrumPumpState.fromByte(state))
|
Assertions.assertEquals(medtrumPump.pumpState, MedtrumPumpState.fromByte(state))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleNotificationGivenBasalDataThenDataSaved() {
|
@Test fun handleNotificationGivenBasalDataThenDataSaved() {
|
||||||
|
@ -41,12 +41,12 @@ class NotificationPacketTest : MedtrumTestBase() {
|
||||||
NotificationPacket(packetInjector).handleNotification(data)
|
NotificationPacket(packetInjector).handleNotification(data)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(BasalType.ABSOLUTE_TEMP, medtrumPump.lastBasalType)
|
Assertions.assertEquals(BasalType.ABSOLUTE_TEMP, medtrumPump.lastBasalType)
|
||||||
assertEquals(0.85, medtrumPump.lastBasalRate, 0.01)
|
Assertions.assertEquals(0.85, medtrumPump.lastBasalRate, 0.01)
|
||||||
assertEquals(25, medtrumPump.lastBasalSequence)
|
Assertions.assertEquals(25, medtrumPump.lastBasalSequence)
|
||||||
assertEquals(14, medtrumPump.lastBasalPatchId)
|
Assertions.assertEquals(14, medtrumPump.lastBasalPatchId)
|
||||||
assertEquals(1685126612000, medtrumPump.lastBasalStartTime)
|
Assertions.assertEquals(1685126612000, medtrumPump.lastBasalStartTime)
|
||||||
assertEquals(186.80, medtrumPump.reservoir, 0.01)
|
Assertions.assertEquals(186.80, medtrumPump.reservoir, 0.01)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleNotificationGivenSequenceAndOtherDataThenDataSaved() {
|
@Test fun handleNotificationGivenSequenceAndOtherDataThenDataSaved() {
|
||||||
|
@ -57,7 +57,7 @@ class NotificationPacketTest : MedtrumTestBase() {
|
||||||
NotificationPacket(packetInjector).handleNotification(data)
|
NotificationPacket(packetInjector).handleNotification(data)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(167, medtrumPump.currentSequenceNumber)
|
Assertions.assertEquals(167, medtrumPump.currentSequenceNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleNotificationGivenBolusInProgressThenDataSaved() {
|
@Test fun handleNotificationGivenBolusInProgressThenDataSaved() {
|
||||||
|
@ -69,9 +69,9 @@ class NotificationPacketTest : MedtrumTestBase() {
|
||||||
NotificationPacket(packetInjector).handleNotification(data)
|
NotificationPacket(packetInjector).handleNotification(data)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(false, medtrumPump.bolusDone)
|
Assertions.assertEquals(false, medtrumPump.bolusDone)
|
||||||
assertEquals(0.15, medtrumPump.bolusingTreatment!!.insulin, 0.01)
|
Assertions.assertEquals(0.15, medtrumPump.bolusingTreatment!!.insulin, 0.01)
|
||||||
assertEquals(163.5, medtrumPump.reservoir, 0.01)
|
Assertions.assertEquals(163.5, medtrumPump.reservoir, 0.01)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleNotificationGivenBolusFinishedThenDataSaved() {
|
@Test fun handleNotificationGivenBolusFinishedThenDataSaved() {
|
||||||
|
@ -83,8 +83,8 @@ class NotificationPacketTest : MedtrumTestBase() {
|
||||||
NotificationPacket(packetInjector).handleNotification(data)
|
NotificationPacket(packetInjector).handleNotification(data)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(true, medtrumPump.bolusDone)
|
Assertions.assertEquals(true, medtrumPump.bolusDone)
|
||||||
assertEquals(1.65, medtrumPump.bolusingTreatment!!.insulin, 0.01)
|
Assertions.assertEquals(1.65, medtrumPump.bolusingTreatment!!.insulin, 0.01)
|
||||||
assertEquals(161.95, medtrumPump.reservoir, 0.01)
|
Assertions.assertEquals(161.95, medtrumPump.reservoir, 0.01)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,8 @@ package info.nightscout.pump.medtrum.comm.packets
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class PollPatchPacketTest : MedtrumTestBase() {
|
class PollPatchPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class PollPatchPacketTest : MedtrumTestBase() {
|
||||||
val result = packet.getRequest()
|
val result = packet.getRequest()
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(1, result.size)
|
Assertions.assertEquals(1, result.size)
|
||||||
assertEquals(opCode.toByte(), result[0])
|
Assertions.assertEquals(opCode.toByte(), result[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,8 @@ package info.nightscout.pump.medtrum.comm.packets
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class PrimePacketTest : MedtrumTestBase() {
|
class PrimePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class PrimePacketTest : MedtrumTestBase() {
|
||||||
val result = packet.getRequest()
|
val result = packet.getRequest()
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(1, result.size)
|
Assertions.assertEquals(1, result.size)
|
||||||
assertEquals(opCode.toByte(), result[0])
|
Assertions.assertEquals(opCode.toByte(), result[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
import info.nightscout.pump.medtrum.extension.toByteArray
|
import info.nightscout.pump.medtrum.extension.toByteArray
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class ReadBolusStatePacketTest : MedtrumTestBase() {
|
class ReadBolusStatePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
|
@ -31,9 +31,9 @@ class ReadBolusStatePacketTest : MedtrumTestBase() {
|
||||||
val result = packet.handleResponse(response)
|
val result = packet.handleResponse(response)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertTrue(result)
|
Assertions.assertTrue(result)
|
||||||
assertFalse(packet.failed)
|
Assertions.assertFalse(packet.failed)
|
||||||
assertEquals(bolusData.contentToString(), packet.bolusData.contentToString())
|
Assertions.assertEquals(bolusData.contentToString(), packet.bolusData.contentToString())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
||||||
|
@ -47,8 +47,8 @@ class ReadBolusStatePacketTest : MedtrumTestBase() {
|
||||||
val result = packet.handleResponse(response)
|
val result = packet.handleResponse(response)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(false, result)
|
Assertions.assertEquals(false, result)
|
||||||
assertEquals(true, packet.failed)
|
Assertions.assertEquals(true, packet.failed)
|
||||||
assertEquals(byteArrayOf().contentToString(), packet.bolusData.contentToString())
|
Assertions.assertEquals(byteArrayOf().contentToString(), packet.bolusData.contentToString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,8 @@ package info.nightscout.pump.medtrum.comm.packets
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class ResumePumpPacketTest : MedtrumTestBase() {
|
class ResumePumpPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class ResumePumpPacketTest : MedtrumTestBase() {
|
||||||
val result = packet.getRequest()
|
val result = packet.getRequest()
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(1, result.size)
|
Assertions.assertEquals(1, result.size)
|
||||||
assertEquals(opCode.toByte(), result[0])
|
Assertions.assertEquals(opCode.toByte(), result[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
import info.nightscout.pump.medtrum.comm.enums.BasalType
|
import info.nightscout.pump.medtrum.comm.enums.BasalType
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class SetBasalProfilePacketTest : MedtrumTestBase() {
|
class SetBasalProfilePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ class SetBasalProfilePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
val expected = byteArrayOf(opCode.toByte()) + 1.toByte() + basalProfile
|
val expected = byteArrayOf(opCode.toByte()) + 1.toByte() + basalProfile
|
||||||
assertEquals(expected.contentToString(), result.contentToString())
|
Assertions.assertEquals(expected.contentToString(), result.contentToString())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
|
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
|
||||||
|
@ -50,13 +50,13 @@ class SetBasalProfilePacketTest : MedtrumTestBase() {
|
||||||
val expectedStartTime = 1679575392000L
|
val expectedStartTime = 1679575392000L
|
||||||
val expectedPatchId = 146L
|
val expectedPatchId = 146L
|
||||||
|
|
||||||
assertTrue(result)
|
Assertions.assertTrue(result)
|
||||||
assertEquals(expectedBasalType, medtrumPump.lastBasalType)
|
Assertions.assertEquals(expectedBasalType, medtrumPump.lastBasalType)
|
||||||
assertEquals(expectedBasalRate, medtrumPump.lastBasalRate, 0.01)
|
Assertions.assertEquals(expectedBasalRate, medtrumPump.lastBasalRate, 0.01)
|
||||||
assertEquals(expectedBasalSequence, medtrumPump.lastBasalSequence)
|
Assertions.assertEquals(expectedBasalSequence, medtrumPump.lastBasalSequence)
|
||||||
assertEquals(expectedStartTime, medtrumPump.lastBasalStartTime)
|
Assertions.assertEquals(expectedStartTime, medtrumPump.lastBasalStartTime)
|
||||||
assertEquals(expectedPatchId, medtrumPump.lastBasalPatchId)
|
Assertions.assertEquals(expectedPatchId, medtrumPump.lastBasalPatchId)
|
||||||
assertEquals(basalProfile, medtrumPump.actualBasalProfile)
|
Assertions.assertEquals(basalProfile, medtrumPump.actualBasalProfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
||||||
|
@ -69,7 +69,7 @@ class SetBasalProfilePacketTest : MedtrumTestBase() {
|
||||||
val result = packet.handleResponse(response)
|
val result = packet.handleResponse(response)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertFalse(result)
|
Assertions.assertFalse(result)
|
||||||
assertTrue(packet.failed)
|
Assertions.assertTrue(packet.failed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,8 @@ package info.nightscout.pump.medtrum.comm.packets
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class SetBolusMotorPacketTest : MedtrumTestBase() {
|
class SetBolusMotorPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ class SetBolusMotorPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
val expectedByteArray = byteArrayOf(opCode.toByte()) + 0.toByte()
|
val expectedByteArray = byteArrayOf(opCode.toByte()) + 0.toByte()
|
||||||
assertEquals(2, result.size)
|
Assertions.assertEquals(2, result.size)
|
||||||
assertEquals(expectedByteArray.contentToString(), result.contentToString())
|
Assertions.assertEquals(expectedByteArray.contentToString(), result.contentToString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,8 @@ package info.nightscout.pump.medtrum.comm.packets
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class SetBolusPacketTest : MedtrumTestBase() {
|
class SetBolusPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
|
@ -28,6 +28,6 @@ class SetBolusPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
val expected = byteArrayOf(19, 1, 47, 0, 0)
|
val expected = byteArrayOf(19, 1, 47, 0, 0)
|
||||||
assertEquals(expected.contentToString(), result.contentToString())
|
Assertions.assertEquals(expected.contentToString(), result.contentToString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
import info.nightscout.pump.medtrum.comm.enums.AlarmSetting
|
import info.nightscout.pump.medtrum.comm.enums.AlarmSetting
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class SetPatchPacketTest : MedtrumTestBase() {
|
class SetPatchPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
|
@ -33,6 +33,6 @@ class SetPatchPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
val expected = byteArrayOf(35, 1, 32, 3, 16, 14, 0, 0, 12, 0, 0, 30)
|
val expected = byteArrayOf(35, 1, 32, 3, 16, 14, 0, 0, 12, 0, 0, 30)
|
||||||
assertEquals(expected.contentToString(), result.contentToString())
|
Assertions.assertEquals(expected.contentToString(), result.contentToString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
import info.nightscout.pump.medtrum.comm.enums.BasalType
|
import info.nightscout.pump.medtrum.comm.enums.BasalType
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class SetTempBasalPacketTest : MedtrumTestBase() {
|
class SetTempBasalPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ class SetTempBasalPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
val expected = byteArrayOf(24, 6, 25, 0, 60, 0)
|
val expected = byteArrayOf(24, 6, 25, 0, 60, 0)
|
||||||
assertEquals(expected.contentToString(), result.contentToString())
|
Assertions.assertEquals(expected.contentToString(), result.contentToString())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
|
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
|
||||||
|
@ -52,12 +52,12 @@ class SetTempBasalPacketTest : MedtrumTestBase() {
|
||||||
val expectedStartTime = 1679575112000L
|
val expectedStartTime = 1679575112000L
|
||||||
val expectedPatchId = 146L
|
val expectedPatchId = 146L
|
||||||
|
|
||||||
assertTrue(result)
|
Assertions.assertTrue(result)
|
||||||
assertEquals(expectedBasalType, medtrumPump.lastBasalType)
|
Assertions.assertEquals(expectedBasalType, medtrumPump.lastBasalType)
|
||||||
assertEquals(expectedBasalRate, medtrumPump.lastBasalRate, 0.01)
|
Assertions.assertEquals(expectedBasalRate, medtrumPump.lastBasalRate, 0.01)
|
||||||
assertEquals(expectedBasalSequence, medtrumPump.lastBasalSequence)
|
Assertions.assertEquals(expectedBasalSequence, medtrumPump.lastBasalSequence)
|
||||||
assertEquals(expectedStartTime, medtrumPump.lastBasalStartTime)
|
Assertions.assertEquals(expectedStartTime, medtrumPump.lastBasalStartTime)
|
||||||
assertEquals(expectedPatchId, medtrumPump.lastBasalPatchId)
|
Assertions.assertEquals(expectedPatchId, medtrumPump.lastBasalPatchId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
||||||
|
@ -72,6 +72,6 @@ class SetTempBasalPacketTest : MedtrumTestBase() {
|
||||||
val result = packet.handleResponse(response)
|
val result = packet.handleResponse(response)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertFalse(result)
|
Assertions.assertFalse(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
import info.nightscout.pump.medtrum.extension.toByteArray
|
import info.nightscout.pump.medtrum.extension.toByteArray
|
||||||
import info.nightscout.pump.medtrum.util.MedtrumTimeUtil
|
import info.nightscout.pump.medtrum.util.MedtrumTimeUtil
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class SetTimePacketTest : MedtrumTestBase() {
|
class SetTimePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ class SetTimePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
val expectedByteArray = byteArrayOf(opCode.toByte()) + 2.toByte() + time.toByteArray(4)
|
val expectedByteArray = byteArrayOf(opCode.toByte()) + 2.toByte() + time.toByteArray(4)
|
||||||
assertEquals(6, result.size)
|
Assertions.assertEquals(6, result.size)
|
||||||
assertEquals(expectedByteArray.contentToString(), result.contentToString())
|
Assertions.assertEquals(expectedByteArray.contentToString(), result.contentToString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
import info.nightscout.pump.medtrum.extension.toByteArray
|
import info.nightscout.pump.medtrum.extension.toByteArray
|
||||||
import info.nightscout.pump.medtrum.util.MedtrumTimeUtil
|
import info.nightscout.pump.medtrum.util.MedtrumTimeUtil
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class SetTimeZonePacketTest : MedtrumTestBase() {
|
class SetTimeZonePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
|
@ -36,8 +36,8 @@ class SetTimeZonePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
val expectedByteArray = byteArrayOf(opCode.toByte()) + offsetMinutes.toByteArray(2) + time.toByteArray(4)
|
val expectedByteArray = byteArrayOf(opCode.toByte()) + offsetMinutes.toByteArray(2) + time.toByteArray(4)
|
||||||
assertEquals(7, result.size)
|
Assertions.assertEquals(7, result.size)
|
||||||
assertEquals(expectedByteArray.contentToString(), result.contentToString())
|
Assertions.assertEquals(expectedByteArray.contentToString(), result.contentToString())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
|
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
|
||||||
|
@ -51,7 +51,7 @@ class SetTimeZonePacketTest : MedtrumTestBase() {
|
||||||
// Expected values
|
// Expected values
|
||||||
val expectedOffsetMinutes = 0
|
val expectedOffsetMinutes = 0
|
||||||
|
|
||||||
assertTrue(result)
|
Assertions.assertTrue(result)
|
||||||
assertEquals(expectedOffsetMinutes, medtrumPump.pumpTimeZoneOffset)
|
Assertions.assertEquals(expectedOffsetMinutes, medtrumPump.pumpTimeZoneOffset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,8 @@ package info.nightscout.pump.medtrum.comm.packets
|
||||||
import dagger.android.AndroidInjector
|
import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class StopPatchPacketTest : MedtrumTestBase() {
|
class StopPatchPacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
|
@ -28,8 +28,8 @@ class StopPatchPacketTest : MedtrumTestBase() {
|
||||||
val result = packet.getRequest()
|
val result = packet.getRequest()
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(1, result.size)
|
Assertions.assertEquals(1, result.size)
|
||||||
assertEquals(opCode.toByte(), result[0])
|
Assertions.assertEquals(opCode.toByte(), result[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
|
@Test fun handleResponseGivenPacketWhenValuesSetThenReturnCorrectValues() {
|
||||||
|
@ -43,9 +43,9 @@ class StopPatchPacketTest : MedtrumTestBase() {
|
||||||
// Expected values
|
// Expected values
|
||||||
val expectedPatchId = 146L
|
val expectedPatchId = 146L
|
||||||
val expectedStopSequence = 23
|
val expectedStopSequence = 23
|
||||||
assertTrue(result)
|
Assertions.assertTrue(result)
|
||||||
assertEquals(expectedPatchId, medtrumPump.lastStopPatchId)
|
Assertions.assertEquals(expectedPatchId, medtrumPump.lastStopPatchId)
|
||||||
assertEquals(expectedStopSequence, medtrumPump.lastStopSequence)
|
Assertions.assertEquals(expectedStopSequence, medtrumPump.lastStopSequence)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
||||||
|
@ -57,7 +57,7 @@ class StopPatchPacketTest : MedtrumTestBase() {
|
||||||
val result = packet.handleResponse(response)
|
val result = packet.handleResponse(response)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertFalse(result)
|
Assertions.assertFalse(result)
|
||||||
assertTrue(packet.failed)
|
Assertions.assertTrue(packet.failed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ import dagger.android.AndroidInjector
|
||||||
import dagger.android.HasAndroidInjector
|
import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.pump.medtrum.MedtrumTestBase
|
import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
import info.nightscout.pump.medtrum.extension.toByteArray
|
import info.nightscout.pump.medtrum.extension.toByteArray
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class SubscribePacketTest : MedtrumTestBase() {
|
class SubscribePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ class SubscribePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
val expectedByteArray = byteArrayOf(opCode.toByte()) + 4095.toByteArray(2)
|
val expectedByteArray = byteArrayOf(opCode.toByte()) + 4095.toByteArray(2)
|
||||||
assertEquals(3, result.size)
|
Assertions.assertEquals(3, result.size)
|
||||||
assertEquals(expectedByteArray.contentToString(), result.contentToString())
|
Assertions.assertEquals(expectedByteArray.contentToString(), result.contentToString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@ import info.nightscout.pump.medtrum.MedtrumTestBase
|
||||||
import info.nightscout.pump.medtrum.comm.enums.BasalType
|
import info.nightscout.pump.medtrum.comm.enums.BasalType
|
||||||
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
|
import info.nightscout.pump.medtrum.comm.enums.MedtrumPumpState
|
||||||
import info.nightscout.pump.medtrum.extension.toByteArray
|
import info.nightscout.pump.medtrum.extension.toByteArray
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class SynchronizePacketTest : MedtrumTestBase() {
|
class SynchronizePacketTest : MedtrumTestBase() {
|
||||||
|
|
||||||
|
@ -35,8 +35,8 @@ class SynchronizePacketTest : MedtrumTestBase() {
|
||||||
val result = packet.getRequest()
|
val result = packet.getRequest()
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(1, result.size)
|
Assertions.assertEquals(1, result.size)
|
||||||
assertEquals(opCode.toByte(), result[0])
|
Assertions.assertEquals(opCode.toByte(), result[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenResponseWhenMessageIsCorrectLengthThenResultTrue() {
|
@Test fun handleResponseGivenResponseWhenMessageIsCorrectLengthThenResultTrue() {
|
||||||
|
@ -53,9 +53,9 @@ class SynchronizePacketTest : MedtrumTestBase() {
|
||||||
val result = packet.handleResponse(response)
|
val result = packet.handleResponse(response)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(true, result)
|
Assertions.assertEquals(true, result)
|
||||||
assertEquals(false, packet.failed)
|
Assertions.assertEquals(false, packet.failed)
|
||||||
assertEquals(state, packet.medtrumPump.pumpState.state)
|
Assertions.assertEquals(state, packet.medtrumPump.pumpState.state)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
@Test fun handleResponseGivenResponseWhenMessageTooShortThenResultFalse() {
|
||||||
|
@ -71,31 +71,80 @@ class SynchronizePacketTest : MedtrumTestBase() {
|
||||||
val result = packet.handleResponse(response)
|
val result = packet.handleResponse(response)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(false, result)
|
Assertions.assertEquals(false, result)
|
||||||
assertEquals(true, packet.failed)
|
Assertions.assertEquals(true, packet.failed)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun handleResponseContainingSyncDataThenDataSaved() {
|
@Test fun handleResponseContainingSyncDataThenDataSaved() {
|
||||||
// Inputs
|
// Inputs
|
||||||
val data = byteArrayOf(47, 3, 3, 1, 0, 0, 32, -18, 13, -128, 5, 0, -128, 0, 0, 6, 25, 0, 14, 0, 84, -93, -83, 17, 17, 64, 0, -104, 14, -8, -119, -83, 17, -16, 11, 90, 26, 0, 14, 0, -69, 31, 0, 0, -116, 14, -56)
|
val data =
|
||||||
|
byteArrayOf(
|
||||||
|
47,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
32,
|
||||||
|
-18,
|
||||||
|
13,
|
||||||
|
-128,
|
||||||
|
5,
|
||||||
|
0,
|
||||||
|
-128,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
6,
|
||||||
|
25,
|
||||||
|
0,
|
||||||
|
14,
|
||||||
|
0,
|
||||||
|
84,
|
||||||
|
-93,
|
||||||
|
-83,
|
||||||
|
17,
|
||||||
|
17,
|
||||||
|
64,
|
||||||
|
0,
|
||||||
|
-104,
|
||||||
|
14,
|
||||||
|
-8,
|
||||||
|
-119,
|
||||||
|
-83,
|
||||||
|
17,
|
||||||
|
-16,
|
||||||
|
11,
|
||||||
|
90,
|
||||||
|
26,
|
||||||
|
0,
|
||||||
|
14,
|
||||||
|
0,
|
||||||
|
-69,
|
||||||
|
31,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
-116,
|
||||||
|
14,
|
||||||
|
-56
|
||||||
|
)
|
||||||
|
|
||||||
// Call
|
// Call
|
||||||
val packet = SynchronizePacket(packetInjector)
|
val packet = SynchronizePacket(packetInjector)
|
||||||
val result = packet.handleResponse(data)
|
val result = packet.handleResponse(data)
|
||||||
|
|
||||||
// Expected values
|
// Expected values
|
||||||
assertEquals(true, result)
|
Assertions.assertEquals(true, result)
|
||||||
assertEquals(false, packet.failed)
|
Assertions.assertEquals(false, packet.failed)
|
||||||
assertEquals(MedtrumPumpState.ACTIVE, packet.medtrumPump.pumpState)
|
Assertions.assertEquals(MedtrumPumpState.ACTIVE, packet.medtrumPump.pumpState)
|
||||||
assertEquals(BasalType.ABSOLUTE_TEMP, packet.medtrumPump.lastBasalType)
|
Assertions.assertEquals(BasalType.ABSOLUTE_TEMP, packet.medtrumPump.lastBasalType)
|
||||||
assertEquals(0.85, packet.medtrumPump.lastBasalRate, 0.01)
|
Assertions.assertEquals(0.85, packet.medtrumPump.lastBasalRate, 0.01)
|
||||||
assertEquals(25, packet.medtrumPump.lastBasalSequence)
|
Assertions.assertEquals(25, packet.medtrumPump.lastBasalSequence)
|
||||||
assertEquals(14, packet.medtrumPump.lastBasalPatchId)
|
Assertions.assertEquals(14, packet.medtrumPump.lastBasalPatchId)
|
||||||
assertEquals(1685126612000, packet.medtrumPump.lastBasalStartTime)
|
Assertions.assertEquals(1685126612000, packet.medtrumPump.lastBasalStartTime)
|
||||||
assertEquals(8123, packet.medtrumPump.patchAge)
|
Assertions.assertEquals(8123, packet.medtrumPump.patchAge)
|
||||||
assertEquals(186.80, packet.medtrumPump.reservoir, 0.01)
|
Assertions.assertEquals(186.80, packet.medtrumPump.reservoir, 0.01)
|
||||||
assertEquals(1685120120000, packet.medtrumPump.patchStartTime)
|
Assertions.assertEquals(1685120120000, packet.medtrumPump.patchStartTime)
|
||||||
assertEquals(5.96875, packet.medtrumPump.batteryVoltage_A, 0.01)
|
Assertions.assertEquals(5.96875, packet.medtrumPump.batteryVoltage_A, 0.01)
|
||||||
assertEquals(2.8125, packet.medtrumPump.batteryVoltage_B, 0.01)
|
Assertions.assertEquals(2.8125, packet.medtrumPump.batteryVoltage_B, 0.01)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package info.nightscout.pump.medtrum.encryption
|
package info.nightscout.pump.medtrum.encryption
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.Assert.*
|
|
||||||
|
|
||||||
class CryptTest {
|
class CryptTest {
|
||||||
|
|
||||||
|
@ -9,19 +9,19 @@ class CryptTest {
|
||||||
fun givenSNExpectKey() {
|
fun givenSNExpectKey() {
|
||||||
val crypt = Crypt()
|
val crypt = Crypt()
|
||||||
|
|
||||||
val input: Long = 2859923929
|
val input = 2859923929
|
||||||
val expect: Long = 3364239851
|
val expect = 3364239851
|
||||||
val output: Long = crypt.keyGen(input)
|
val output: Long = crypt.keyGen(input)
|
||||||
assertEquals(expect, output)
|
Assertions.assertEquals(expect, output)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun givenSNExpectReal() {
|
fun givenSNExpectReal() {
|
||||||
val crypt = Crypt()
|
val crypt = Crypt()
|
||||||
|
|
||||||
val input: Long = 2859923929
|
val input = 2859923929
|
||||||
val expect: Long = 126009121
|
val expect: Long = 126009121
|
||||||
val output: Long = crypt.simpleDecrypt(input)
|
val output: Long = crypt.simpleDecrypt(input)
|
||||||
assertEquals(expect, output)
|
Assertions.assertEquals(expect, output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue