fix tests, removed Trigger reflection
This commit is contained in:
parent
e4d70a7303
commit
d898a374e6
|
@ -53,7 +53,7 @@ import java.util.*
|
|||
@PrepareForTest(
|
||||
ConfigBuilderPlugin::class, ConstraintChecker::class, SP::class, Context::class,
|
||||
OpenAPSAMAPlugin::class, OpenAPSSMBPlugin::class, TreatmentsPlugin::class, TreatmentService::class,
|
||||
VirtualPumpPlugin::class, DetailedBolusInfoStorage::class, GlimpPlugin::class, Profiler::class,
|
||||
VirtualPumpPlugin::class, DetailedBolusInfoStorage::class, TemporaryBasalStorage::class, GlimpPlugin::class, Profiler::class,
|
||||
UserEntryLogger::class, IobCobCalculatorPlugin::class, LoggerUtils::class, AppRepository::class)
|
||||
class ConstraintsCheckerTest : TestBaseWithProfile() {
|
||||
|
||||
|
|
|
@ -139,17 +139,17 @@ class SmsCommunicatorPluginTest : TestBaseWithProfile() {
|
|||
null
|
||||
}.`when`(commandQueue).bolus(anyObject(), ArgumentMatchers.any(Callback::class.java))
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val callback = invocation.getArgument<Callback>(4)
|
||||
val callback = invocation.getArgument<Callback>(5)
|
||||
callback.result = PumpEnactResult(injector).success(true).isPercent(true).percent(invocation.getArgument(0)).duration(invocation.getArgument(1))
|
||||
callback.run()
|
||||
null
|
||||
}.`when`(commandQueue).tempBasalPercent(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt(), ArgumentMatchers.anyBoolean(), anyObject(), ArgumentMatchers.any(PumpSync.TemporaryBasalType::class.java), ArgumentMatchers.any(Callback::class.java))
|
||||
}.`when`(commandQueue).tempBasalPercent(ArgumentMatchers.anyInt(), ArgumentMatchers.anyInt(), ArgumentMatchers.anyBoolean(), anyObject(), anyObject(), ArgumentMatchers.any(Callback::class.java))
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val callback = invocation.getArgument<Callback>(4)
|
||||
val callback = invocation.getArgument<Callback>(5)
|
||||
callback.result = PumpEnactResult(injector).success(true).isPercent(false).absolute(invocation.getArgument(0)).duration(invocation.getArgument(1))
|
||||
callback.run()
|
||||
null
|
||||
}.`when`(commandQueue).tempBasalAbsolute(ArgumentMatchers.anyDouble(), ArgumentMatchers.anyInt(), ArgumentMatchers.anyBoolean(), anyObject(), ArgumentMatchers.any(PumpSync.TemporaryBasalType::class.java), ArgumentMatchers.any(Callback::class.java))
|
||||
}.`when`(commandQueue).tempBasalAbsolute(ArgumentMatchers.anyDouble(), ArgumentMatchers.anyInt(), ArgumentMatchers.anyBoolean(), anyObject(), anyObject(), ArgumentMatchers.any(Callback::class.java))
|
||||
Mockito.doAnswer { invocation: InvocationOnMock ->
|
||||
val callback = invocation.getArgument<Callback>(2)
|
||||
callback.result = PumpEnactResult(injector).success(true).isPercent(false).absolute(invocation.getArgument(0)).duration(invocation.getArgument(1))
|
||||
|
|
|
@ -121,7 +121,7 @@ class IobCobCalculatorPluginTest : TestBase() {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun createBucketedData5minTest() {
|
||||
fun createBucketedData5minTest1() {
|
||||
val bgReadingList: MutableList<GlucoseValue> = ArrayList()
|
||||
|
||||
// Super data should not be touched
|
||||
|
@ -205,6 +205,11 @@ class IobCobCalculatorPluginTest : TestBase() {
|
|||
Assert.assertEquals(90.0, iobCobCalculatorPlugin.bucketedData!![1].value, 1.0)
|
||||
Assert.assertEquals(50.0, iobCobCalculatorPlugin.bucketedData!![5].value, 1.0)
|
||||
Assert.assertEquals(40.0, iobCobCalculatorPlugin.bucketedData!![6].value, 1.0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun createBucketedData5minTest2() {
|
||||
val bgReadingList: MutableList<GlucoseValue> = ArrayList()
|
||||
|
||||
//bucketed data should be null if no bg data available
|
||||
iobCobCalculatorPlugin.bgReadings = ArrayList()
|
||||
|
|
|
@ -48,6 +48,8 @@ class TreatmentsPluginTest : TestBaseWithProfile() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun dumy() {}
|
||||
/*
|
||||
private lateinit var insulinOrefRapidActingPlugin: InsulinOrefRapidActingPlugin
|
||||
private lateinit var sot: TreatmentsPlugin
|
||||
|
|
|
@ -14,7 +14,6 @@ import info.nightscout.androidaps.database.AppRepository
|
|||
import info.nightscout.androidaps.interfaces.ActivePluginProvider
|
||||
import info.nightscout.androidaps.interfaces.IobCobCalculator
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.general.automation.dialogs.ChooseTriggerDialog
|
||||
|
@ -26,10 +25,8 @@ import info.nightscout.androidaps.services.LastLocationDataContainer
|
|||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
import javax.inject.Inject
|
||||
import kotlin.reflect.full.primaryConstructor
|
||||
|
||||
abstract class Trigger(val injector: HasAndroidInjector) {
|
||||
|
||||
|
@ -50,7 +47,7 @@ abstract class Trigger(val injector: HasAndroidInjector) {
|
|||
}
|
||||
|
||||
abstract fun shouldRun(): Boolean
|
||||
abstract fun toJSON(): String
|
||||
abstract fun dataJSON(): JSONObject
|
||||
abstract fun fromJSON(data: String): Trigger
|
||||
|
||||
abstract fun friendlyName(): Int
|
||||
|
@ -77,23 +74,56 @@ abstract class Trigger(val injector: HasAndroidInjector) {
|
|||
root.addView(title)
|
||||
}
|
||||
|
||||
fun toJSON(): String =
|
||||
JSONObject()
|
||||
.put("type", this::class.java.simpleName)
|
||||
.put("data", dataJSON())
|
||||
.toString()
|
||||
|
||||
fun instantiate(obj: JSONObject): Trigger? {
|
||||
try {
|
||||
val type = obj.getString("type")
|
||||
val data = obj.getJSONObject("data")
|
||||
val clazz = Class.forName(type).kotlin
|
||||
return (clazz.primaryConstructor?.call(injector) as Trigger).fromJSON(data?.toString()
|
||||
?: "")
|
||||
} catch (e: ClassNotFoundException) {
|
||||
aapsLogger.error("Unhandled exception", e)
|
||||
} catch (e: InstantiationException) {
|
||||
aapsLogger.error("Unhandled exception", e)
|
||||
} catch (e: IllegalAccessException) {
|
||||
aapsLogger.error("Unhandled exception", e)
|
||||
} catch (e: JSONException) {
|
||||
aapsLogger.error("Unhandled exception", e)
|
||||
val type = obj.getString("type")
|
||||
val data = obj.getJSONObject("data")
|
||||
//val clazz = Class.forName(type).kotlin
|
||||
//return (clazz.primaryConstructor?.call(injector) as Trigger).fromJSON(data?.toString() ?: "")
|
||||
return when (type) {
|
||||
TriggerAutosensValue::class.java.name, // backward compatibility
|
||||
TriggerAutosensValue::class.java.simpleName -> TriggerAutosensValue(injector).fromJSON(data?.toString() ?: "")
|
||||
TriggerBg::class.java.name,
|
||||
TriggerBg::class.java.simpleName -> TriggerBg(injector).fromJSON(data?.toString() ?: "")
|
||||
TriggerBolusAgo::class.java.name,
|
||||
TriggerBolusAgo::class.java.simpleName -> TriggerBolusAgo(injector).fromJSON(data?.toString() ?: "")
|
||||
TriggerBTDevice::class.java.name,
|
||||
TriggerBTDevice::class.java.simpleName -> TriggerBTDevice(injector).fromJSON(data?.toString() ?: "")
|
||||
TriggerIob::class.java.name,
|
||||
TriggerIob::class.java.simpleName -> TriggerIob(injector).fromJSON(data?.toString() ?: "")
|
||||
TriggerCOB::class.java.name,
|
||||
TriggerCOB::class.java.simpleName -> TriggerCOB(injector).fromJSON(data?.toString() ?: "")
|
||||
TriggerConnector::class.java.name,
|
||||
TriggerConnector::class.java.simpleName -> TriggerConnector(injector).fromJSON(data?.toString() ?: "")
|
||||
TriggerDelta::class.java.name,
|
||||
TriggerDelta::class.java.simpleName -> TriggerDelta(injector).fromJSON(data?.toString() ?: "")
|
||||
TriggerDummy::class.java.name,
|
||||
TriggerDummy::class.java.simpleName -> TriggerDummy(injector).fromJSON(data?.toString() ?: "")
|
||||
TriggerIob::class.java.name,
|
||||
TriggerIob::class.java.simpleName -> TriggerIob(injector).fromJSON(data?.toString() ?: "")
|
||||
TriggerLocation::class.java.name,
|
||||
TriggerLocation::class.java.simpleName -> TriggerLocation(injector).fromJSON(data?.toString() ?: "")
|
||||
TriggerProfilePercent::class.java.name,
|
||||
TriggerProfilePercent::class.java.simpleName -> TriggerProfilePercent(injector).fromJSON(data?.toString() ?: "")
|
||||
TriggerPumpLastConnection::class.java.name,
|
||||
TriggerPumpLastConnection::class.java.simpleName -> TriggerPumpLastConnection(injector).fromJSON(data?.toString() ?: "")
|
||||
TriggerRecurringTime::class.java.name,
|
||||
TriggerRecurringTime::class.java.simpleName -> TriggerRecurringTime(injector).fromJSON(data?.toString() ?: "")
|
||||
TriggerTempTarget::class.java.name,
|
||||
TriggerTempTarget::class.java.simpleName -> TriggerTempTarget(injector).fromJSON(data?.toString() ?: "")
|
||||
TriggerTime::class.java.name,
|
||||
TriggerTime::class.java.simpleName -> TriggerTime(injector).fromJSON(data?.toString() ?: "")
|
||||
TriggerTimeRange::class.java.name,
|
||||
TriggerTimeRange::class.java.simpleName -> TriggerTimeRange(injector).fromJSON(data?.toString() ?: "")
|
||||
TriggerWifiSsid::class.java.name,
|
||||
TriggerWifiSsid::class.java.simpleName -> TriggerWifiSsid(injector).fromJSON(data?.toString() ?: "")
|
||||
else -> throw ClassNotFoundException(type)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
fun createAddButton(context: Context, trigger: TriggerConnector): ImageButton {
|
||||
|
|
|
@ -46,15 +46,10 @@ class TriggerAutosensValue(injector: HasAndroidInjector) : Trigger(injector) {
|
|||
return false
|
||||
}
|
||||
|
||||
override fun toJSON(): String {
|
||||
val data = JSONObject()
|
||||
override fun dataJSON(): JSONObject =
|
||||
JSONObject()
|
||||
.put("value", autosens.value)
|
||||
.put("comparator", comparator.value.toString())
|
||||
return JSONObject()
|
||||
.put("type", this::class.java.name)
|
||||
.put("data", data)
|
||||
.toString()
|
||||
}
|
||||
|
||||
override fun fromJSON(data: String): Trigger {
|
||||
val d = JSONObject(data)
|
||||
|
|
|
@ -39,15 +39,10 @@ class TriggerBTDevice(injector: HasAndroidInjector) : Trigger(injector) {
|
|||
return false
|
||||
}
|
||||
|
||||
@Synchronized override fun toJSON(): String {
|
||||
val data = JSONObject()
|
||||
override fun dataJSON(): JSONObject =
|
||||
JSONObject()
|
||||
.put("comparator", comparator.value.toString())
|
||||
.put("name", btDevice.value)
|
||||
return JSONObject()
|
||||
.put("type", this::class.java.name)
|
||||
.put("data", data)
|
||||
.toString()
|
||||
}
|
||||
|
||||
override fun fromJSON(data: String): Trigger {
|
||||
val d = JSONObject(data)
|
||||
|
|
|
@ -63,16 +63,11 @@ class TriggerBg(injector: HasAndroidInjector) : Trigger(injector) {
|
|||
return false
|
||||
}
|
||||
|
||||
override fun toJSON(): String {
|
||||
val data = JSONObject()
|
||||
override fun dataJSON(): JSONObject =
|
||||
JSONObject()
|
||||
.put("bg", bg.value)
|
||||
.put("comparator", comparator.value.toString())
|
||||
.put("units", bg.units)
|
||||
return JSONObject()
|
||||
.put("type", this::class.java.name)
|
||||
.put("data", data)
|
||||
.toString()
|
||||
}
|
||||
|
||||
override fun fromJSON(data: String): Trigger {
|
||||
val d = JSONObject(data)
|
||||
|
|
|
@ -56,15 +56,10 @@ class TriggerBolusAgo(injector: HasAndroidInjector) : Trigger(injector) {
|
|||
return false
|
||||
}
|
||||
|
||||
override fun toJSON(): String {
|
||||
val data = JSONObject()
|
||||
override fun dataJSON(): JSONObject =
|
||||
JSONObject()
|
||||
.put("minutesAgo", minutesAgo.value)
|
||||
.put("comparator", comparator.value.toString())
|
||||
return JSONObject()
|
||||
.put("type", this::class.java.name)
|
||||
.put("data", data)
|
||||
.toString()
|
||||
}
|
||||
|
||||
override fun fromJSON(data: String): Trigger {
|
||||
val d = JSONObject(data)
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.json.JSONObject
|
|||
import java.text.DecimalFormat
|
||||
|
||||
class TriggerCOB(injector: HasAndroidInjector) : Trigger(injector) {
|
||||
|
||||
private val minValue = 0
|
||||
private val maxValue = sp.getInt(R.string.key_treatmentssafety_maxcarbs, 48)
|
||||
var cob: InputDouble = InputDouble(0.0, minValue.toDouble(), maxValue.toDouble(), 1.0, DecimalFormat("1"))
|
||||
|
@ -26,12 +27,12 @@ class TriggerCOB(injector: HasAndroidInjector) : Trigger(injector) {
|
|||
comparator = Comparator(resourceHelper, triggerCOB.comparator.value)
|
||||
}
|
||||
|
||||
fun setValue(value:Double) : TriggerCOB {
|
||||
fun setValue(value: Double): TriggerCOB {
|
||||
cob.value = value
|
||||
return this
|
||||
}
|
||||
|
||||
fun comparator(comparator: Comparator.Compare) : TriggerCOB {
|
||||
fun comparator(comparator: Comparator.Compare): TriggerCOB {
|
||||
this.comparator.value = comparator
|
||||
return this
|
||||
}
|
||||
|
@ -55,15 +56,10 @@ class TriggerCOB(injector: HasAndroidInjector) : Trigger(injector) {
|
|||
return false
|
||||
}
|
||||
|
||||
@Synchronized override fun toJSON(): String {
|
||||
val data = JSONObject()
|
||||
override fun dataJSON(): JSONObject =
|
||||
JSONObject()
|
||||
.put("carbs", cob.value)
|
||||
.put("comparator", comparator.value.toString())
|
||||
return JSONObject()
|
||||
.put("type", this::class.java.name)
|
||||
.put("data", data)
|
||||
.toString()
|
||||
}
|
||||
|
||||
override fun fromJSON(data: String): Trigger {
|
||||
val d = JSONObject(data)
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.json.JSONObject
|
|||
import java.util.*
|
||||
|
||||
class TriggerConnector(injector: HasAndroidInjector) : Trigger(injector) {
|
||||
|
||||
var list: MutableList<Trigger> = ArrayList()
|
||||
private var connectorType: Type = Type.AND
|
||||
|
||||
|
@ -40,6 +41,7 @@ class TriggerConnector(injector: HasAndroidInjector) : Trigger(injector) {
|
|||
}
|
||||
|
||||
companion object {
|
||||
|
||||
fun labels(resourceHelper: ResourceHelper): List<String> {
|
||||
val list: MutableList<String> = ArrayList()
|
||||
for (t in values()) {
|
||||
|
@ -79,16 +81,12 @@ class TriggerConnector(injector: HasAndroidInjector) : Trigger(injector) {
|
|||
return result
|
||||
}
|
||||
|
||||
@Synchronized override fun toJSON(): String {
|
||||
override fun dataJSON(): JSONObject {
|
||||
val array = JSONArray()
|
||||
for (t in list) array.put(t.toJSON())
|
||||
val data = JSONObject()
|
||||
return JSONObject()
|
||||
.put("connectorType", connectorType.toString())
|
||||
.put("triggerList", array)
|
||||
return JSONObject()
|
||||
.put("type", TriggerConnector::class.java.name)
|
||||
.put("data", data)
|
||||
.toString()
|
||||
}
|
||||
|
||||
override fun fromJSON(data: String): Trigger {
|
||||
|
|
|
@ -13,7 +13,6 @@ import info.nightscout.androidaps.plugins.general.automation.elements.InputDelta
|
|||
import info.nightscout.androidaps.plugins.general.automation.elements.LabelWithElement
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.LayoutBuilder
|
||||
import info.nightscout.androidaps.plugins.general.automation.elements.StaticLabel
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
||||
import info.nightscout.androidaps.utils.JsonHelper
|
||||
import org.json.JSONObject
|
||||
import java.text.DecimalFormat
|
||||
|
@ -25,6 +24,7 @@ class TriggerDelta(injector: HasAndroidInjector) : Trigger(injector) {
|
|||
var comparator: Comparator = Comparator(resourceHelper)
|
||||
|
||||
companion object {
|
||||
|
||||
private const val MMOL_MAX = 4.0
|
||||
private const val MGDL_MAX = 72.0
|
||||
}
|
||||
|
@ -85,17 +85,12 @@ class TriggerDelta(injector: HasAndroidInjector) : Trigger(injector) {
|
|||
return false
|
||||
}
|
||||
|
||||
override fun toJSON(): String {
|
||||
val data = JSONObject()
|
||||
override fun dataJSON(): JSONObject =
|
||||
JSONObject()
|
||||
.put("value", delta.value)
|
||||
.put("units", units)
|
||||
.put("deltaType", delta.deltaType)
|
||||
.put("comparator", comparator.value.toString())
|
||||
return JSONObject()
|
||||
.put("type", this::class.java.name)
|
||||
.put("data", data)
|
||||
.toString()
|
||||
}
|
||||
|
||||
override fun fromJSON(data: String): Trigger {
|
||||
val d = JSONObject(data)
|
||||
|
|
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.general.automation.triggers
|
|||
|
||||
import com.google.common.base.Optional
|
||||
import dagger.android.HasAndroidInjector
|
||||
import org.json.JSONObject
|
||||
|
||||
// Used for instantiation of other triggers only
|
||||
class TriggerDummy(injector: HasAndroidInjector, val shouldRun: Boolean = false) : Trigger(injector) {
|
||||
|
@ -10,7 +11,7 @@ class TriggerDummy(injector: HasAndroidInjector, val shouldRun: Boolean = false)
|
|||
return shouldRun
|
||||
}
|
||||
|
||||
override fun toJSON(): String {
|
||||
override fun dataJSON(): JSONObject {
|
||||
throw NotImplementedError("An operation is not implemented")
|
||||
}
|
||||
|
||||
|
|
|
@ -44,15 +44,10 @@ class TriggerIob(injector: HasAndroidInjector) : Trigger(injector) {
|
|||
return false
|
||||
}
|
||||
|
||||
@Synchronized override fun toJSON(): String {
|
||||
val data = JSONObject()
|
||||
override fun dataJSON(): JSONObject =
|
||||
JSONObject()
|
||||
.put("insulin", insulin.value)
|
||||
.put("comparator", comparator.value.toString())
|
||||
return JSONObject()
|
||||
.put("type", this::class.java.name)
|
||||
.put("data", data)
|
||||
.toString()
|
||||
}
|
||||
|
||||
override fun fromJSON(data: String): Trigger {
|
||||
val d = JSONObject(data)
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.json.JSONObject
|
|||
import java.text.DecimalFormat
|
||||
|
||||
class TriggerLocation(injector: HasAndroidInjector) : Trigger(injector) {
|
||||
|
||||
var latitude = InputDouble(0.0, -90.0, +90.0, 0.000001, DecimalFormat("0.000000"))
|
||||
var longitude = InputDouble(0.0, -180.0, +180.0, 0.000001, DecimalFormat("0.000000"))
|
||||
var distance = InputDouble(200.0, 0.0, 100000.0, 10.0, DecimalFormat("0"))
|
||||
|
@ -56,18 +57,13 @@ class TriggerLocation(injector: HasAndroidInjector) : Trigger(injector) {
|
|||
return false
|
||||
}
|
||||
|
||||
override fun toJSON(): String {
|
||||
val data = JSONObject()
|
||||
override fun dataJSON(): JSONObject =
|
||||
JSONObject()
|
||||
.put("latitude", latitude.value)
|
||||
.put("longitude", longitude.value)
|
||||
.put("distance", distance.value)
|
||||
.put("name", name.value)
|
||||
.put("mode", modeSelected.value)
|
||||
return JSONObject()
|
||||
.put("type", this::class.java.name)
|
||||
.put("data", data)
|
||||
.toString()
|
||||
}
|
||||
|
||||
override fun fromJSON(data: String): Trigger {
|
||||
val d = JSONObject(data)
|
||||
|
|
|
@ -14,11 +14,12 @@ import info.nightscout.androidaps.utils.JsonHelper
|
|||
import org.json.JSONObject
|
||||
|
||||
class TriggerProfilePercent(injector: HasAndroidInjector) : Trigger(injector) {
|
||||
|
||||
var pct = InputPercent()
|
||||
var comparator = Comparator(resourceHelper)
|
||||
|
||||
constructor(injector: HasAndroidInjector, value: Double, compare: Comparator.Compare) : this(injector) {
|
||||
pct = InputPercent( value)
|
||||
pct = InputPercent(value)
|
||||
comparator = Comparator(resourceHelper, compare)
|
||||
}
|
||||
|
||||
|
@ -55,15 +56,10 @@ class TriggerProfilePercent(injector: HasAndroidInjector) : Trigger(injector) {
|
|||
return false
|
||||
}
|
||||
|
||||
@Synchronized override fun toJSON(): String {
|
||||
val data = JSONObject()
|
||||
override fun dataJSON(): JSONObject =
|
||||
JSONObject()
|
||||
.put("percentage", pct.value)
|
||||
.put("comparator", comparator.value.toString())
|
||||
return JSONObject()
|
||||
.put("type", this::class.java.name)
|
||||
.put("data", data)
|
||||
.toString()
|
||||
}
|
||||
|
||||
override fun fromJSON(data: String): Trigger {
|
||||
val d = JSONObject(data)
|
||||
|
|
|
@ -16,6 +16,7 @@ import info.nightscout.androidaps.utils.JsonHelper.safeGetString
|
|||
import org.json.JSONObject
|
||||
|
||||
class TriggerPumpLastConnection(injector: HasAndroidInjector) : Trigger(injector) {
|
||||
|
||||
var minutesAgo = InputDuration()
|
||||
var comparator = Comparator(resourceHelper)
|
||||
|
||||
|
@ -56,15 +57,10 @@ class TriggerPumpLastConnection(injector: HasAndroidInjector) : Trigger(injector
|
|||
return false
|
||||
}
|
||||
|
||||
override fun toJSON(): String {
|
||||
val data = JSONObject()
|
||||
override fun dataJSON(): JSONObject =
|
||||
JSONObject()
|
||||
.put("minutesAgo", minutesAgo.value)
|
||||
.put("comparator", comparator.value.toString())
|
||||
return JSONObject()
|
||||
.put("type", this::class.java.name)
|
||||
.put("data", data)
|
||||
.toString()
|
||||
}
|
||||
|
||||
override fun fromJSON(data: String): Trigger {
|
||||
val d = JSONObject(data)
|
||||
|
|
|
@ -44,16 +44,13 @@ class TriggerRecurringTime(injector: HasAndroidInjector) : Trigger(injector) {
|
|||
return false
|
||||
}
|
||||
|
||||
override fun toJSON(): String {
|
||||
override fun dataJSON(): JSONObject {
|
||||
val data = JSONObject()
|
||||
.put("time", time.value)
|
||||
for (i in days.weekdays.indices) {
|
||||
data.put(InputWeekDay.DayOfWeek.values()[i].name, days.weekdays[i])
|
||||
}
|
||||
return JSONObject()
|
||||
.put("type", TriggerRecurringTime::class.java.name)
|
||||
.put("data", data)
|
||||
.toString()
|
||||
return data
|
||||
}
|
||||
|
||||
override fun fromJSON(data: String): Trigger {
|
||||
|
|
|
@ -43,14 +43,9 @@ class TriggerTempTarget(injector: HasAndroidInjector) : Trigger(injector) {
|
|||
return false
|
||||
}
|
||||
|
||||
override fun toJSON(): String {
|
||||
val data = JSONObject()
|
||||
override fun dataJSON(): JSONObject =
|
||||
JSONObject()
|
||||
.put("comparator", comparator.value.toString())
|
||||
return JSONObject()
|
||||
.put("type", TriggerTempTarget::class.java.name)
|
||||
.put("data", data)
|
||||
.toString()
|
||||
}
|
||||
|
||||
override fun fromJSON(data: String): Trigger {
|
||||
val d = JSONObject(data)
|
||||
|
|
|
@ -41,14 +41,9 @@ class TriggerTime(injector: HasAndroidInjector) : Trigger(injector) {
|
|||
return false
|
||||
}
|
||||
|
||||
override fun toJSON(): String {
|
||||
val data = JSONObject()
|
||||
override fun dataJSON(): JSONObject =
|
||||
JSONObject()
|
||||
.put("runAt", time.value)
|
||||
return JSONObject()
|
||||
.put("type", this::class.java.name)
|
||||
.put("data", data)
|
||||
.toString()
|
||||
}
|
||||
|
||||
override fun fromJSON(data: String): Trigger {
|
||||
val o = JSONObject(data)
|
||||
|
|
|
@ -50,15 +50,10 @@ class TriggerTimeRange(injector: HasAndroidInjector) : Trigger(injector) {
|
|||
return false
|
||||
}
|
||||
|
||||
override fun toJSON(): String {
|
||||
val data = JSONObject()
|
||||
override fun dataJSON(): JSONObject =
|
||||
JSONObject()
|
||||
.put("start", range.start)
|
||||
.put("end", range.end)
|
||||
return JSONObject()
|
||||
.put("type", this::class.java.name)
|
||||
.put("data", data)
|
||||
.toString()
|
||||
}
|
||||
|
||||
override fun fromJSON(data: String): TriggerTimeRange {
|
||||
val o = JSONObject(data)
|
||||
|
|
|
@ -16,12 +16,14 @@ import org.json.JSONObject
|
|||
import javax.inject.Inject
|
||||
|
||||
class TriggerWifiSsid(injector: HasAndroidInjector) : Trigger(injector) {
|
||||
|
||||
@Inject lateinit var receiverStatusStore: ReceiverStatusStore
|
||||
|
||||
var ssid = InputString()
|
||||
var comparator = Comparator(resourceHelper)
|
||||
|
||||
@Suppress("unused") constructor(injector: HasAndroidInjector, ssid: String, compare: Comparator.Compare) : this(injector) {
|
||||
@Suppress("unused")
|
||||
constructor(injector: HasAndroidInjector, ssid: String, compare: Comparator.Compare) : this(injector) {
|
||||
this.ssid = InputString(ssid)
|
||||
comparator = Comparator(resourceHelper, compare)
|
||||
}
|
||||
|
@ -55,15 +57,10 @@ class TriggerWifiSsid(injector: HasAndroidInjector) : Trigger(injector) {
|
|||
return false
|
||||
}
|
||||
|
||||
override fun toJSON(): String {
|
||||
val data = JSONObject()
|
||||
override fun dataJSON(): JSONObject =
|
||||
JSONObject()
|
||||
.put("ssid", ssid.value)
|
||||
.put("comparator", comparator.value.toString())
|
||||
return JSONObject()
|
||||
.put("type", this::class.java.name)
|
||||
.put("data", data)
|
||||
.toString()
|
||||
}
|
||||
|
||||
override fun fromJSON(data: String): Trigger {
|
||||
val d = JSONObject(data)
|
||||
|
|
|
@ -48,7 +48,7 @@ class AutomationEventTest : TestBase() {
|
|||
event.addAction(ActionLoopEnable(injector))
|
||||
|
||||
// export to json
|
||||
val eventJsonExpected = "{\"autoRemove\":false,\"readOnly\":false,\"trigger\":\"{\\\"data\\\":{\\\"connectorType\\\":\\\"AND\\\",\\\"triggerList\\\":[\\\"{\\\\\\\"data\\\\\\\":{\\\\\\\"connectorType\\\\\\\":\\\\\\\"AND\\\\\\\",\\\\\\\"triggerList\\\\\\\":[]},\\\\\\\"type\\\\\\\":\\\\\\\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector\\\\\\\"}\\\"]},\\\"type\\\":\\\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector\\\"}\",\"title\":\"Test\",\"systemAction\":false,\"actions\":[\"{\\\"type\\\":\\\"info.nightscout.androidaps.plugins.general.automation.actions.ActionLoopEnable\\\"}\"],\"enabled\":true}"
|
||||
val eventJsonExpected = "{\"autoRemove\":false,\"readOnly\":false,\"trigger\":\"{\\\"data\\\":{\\\"connectorType\\\":\\\"AND\\\",\\\"triggerList\\\":[\\\"{\\\\\\\"data\\\\\\\":{\\\\\\\"connectorType\\\\\\\":\\\\\\\"AND\\\\\\\",\\\\\\\"triggerList\\\\\\\":[]},\\\\\\\"type\\\\\\\":\\\\\\\"TriggerConnector\\\\\\\"}\\\"]},\\\"type\\\":\\\"TriggerConnector\\\"}\",\"title\":\"Test\",\"systemAction\":false,\"actions\":[\"{\\\"type\\\":\\\"info.nightscout.androidaps.plugins.general.automation.actions.ActionLoopEnable\\\"}\"],\"enabled\":true}"
|
||||
Assert.assertEquals(eventJsonExpected, event.toJSON())
|
||||
|
||||
// clone
|
||||
|
|
|
@ -3,34 +3,15 @@ package info.nightscout.androidaps.plugins.general.automation.triggers
|
|||
import com.google.common.base.Optional
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import org.json.JSONObject
|
||||
|
||||
class DummyTrigger(var result: Boolean) : Trigger(HasAndroidInjector { AndroidInjector { } }) {
|
||||
|
||||
override fun shouldRun(): Boolean {
|
||||
return result
|
||||
}
|
||||
|
||||
override fun toJSON(): String {
|
||||
return ""
|
||||
}
|
||||
|
||||
override fun fromJSON(data: String): Trigger {
|
||||
return DummyTrigger(result)
|
||||
}
|
||||
|
||||
override fun friendlyName(): Int {
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun friendlyDescription(): String {
|
||||
return " "
|
||||
}
|
||||
|
||||
override fun icon(): Optional<Int?> {
|
||||
return Optional.absent()
|
||||
}
|
||||
|
||||
override fun duplicate(): Trigger {
|
||||
return DummyTrigger(result)
|
||||
}
|
||||
override fun shouldRun(): Boolean = result
|
||||
override fun dataJSON(): JSONObject = JSONObject()
|
||||
override fun fromJSON(data: String): Trigger = DummyTrigger(result)
|
||||
override fun friendlyName(): Int = 0
|
||||
override fun friendlyDescription(): String = " "
|
||||
override fun icon(): Optional<Int?> = Optional.absent()
|
||||
override fun duplicate(): Trigger = DummyTrigger(result)
|
||||
}
|
|
@ -88,7 +88,7 @@ class TriggerAutosensValueTest : TriggerTestBase() {
|
|||
Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
||||
}
|
||||
|
||||
private var asJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"value\":410},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerAutosensValue\"}"
|
||||
private var asJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"value\":410},\"type\":\"TriggerAutosensValue\"}"
|
||||
|
||||
@Test
|
||||
fun toJSONTest() {
|
||||
|
|
|
@ -15,7 +15,7 @@ class TriggerBTDeviceTest : TriggerTestBase() {
|
|||
|
||||
var now = 1514766900000L
|
||||
private var someName = "Headset"
|
||||
private var btJson = "{\"data\":{\"comparator\":\"ON_CONNECT\",\"name\":\"Headset\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerBTDevice\"}"
|
||||
private var btJson = "{\"data\":{\"comparator\":\"ON_CONNECT\",\"name\":\"Headset\"},\"type\":\"TriggerBTDevice\"}"
|
||||
|
||||
@Test fun shouldRun() {
|
||||
@Suppress("UNUSED_VARIABLE")
|
||||
|
|
|
@ -69,7 +69,7 @@ class TriggerBgTest : TriggerTestBase() {
|
|||
Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
||||
}
|
||||
|
||||
private var bgJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"bg\":4.1,\"units\":\"mmol\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerBg\"}"
|
||||
private var bgJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"bg\":4.1,\"units\":\"mmol\"},\"type\":\"TriggerBg\"}"
|
||||
|
||||
@Test
|
||||
fun toJSONTest() {
|
||||
|
|
|
@ -77,7 +77,7 @@ class TriggerBolusAgoTest : TriggerTestBase() {
|
|||
Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
||||
}
|
||||
|
||||
private var lbJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"minutesAgo\":410},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerBolusAgo\"}"
|
||||
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())
|
||||
|
|
|
@ -54,7 +54,7 @@ class TriggerCOBTest : TriggerTestBase() {
|
|||
Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
||||
}
|
||||
|
||||
private var bgJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"carbs\":4},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerCOB\"}"
|
||||
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())
|
||||
|
|
|
@ -77,7 +77,7 @@ class TriggerConnectorTest : TriggerTestBase() {
|
|||
}
|
||||
|
||||
companion object {
|
||||
const val empty = "{\"data\":{\"connectorType\":\"AND\",\"triggerList\":[]},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector\"}"
|
||||
const val oneItem = "{\"data\":{\"connectorType\":\"AND\",\"triggerList\":[\"{\\\"data\\\":{\\\"connectorType\\\":\\\"AND\\\",\\\"triggerList\\\":[]},\\\"type\\\":\\\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector\\\"}\"]},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerConnector\"}"
|
||||
const val empty = "{\"data\":{\"connectorType\":\"AND\",\"triggerList\":[]},\"type\":\"TriggerConnector\"}"
|
||||
const val oneItem = "{\"data\":{\"connectorType\":\"AND\",\"triggerList\":[\"{\\\"data\\\":{\\\"connectorType\\\":\\\"AND\\\",\\\"triggerList\\\":[]},\\\"type\\\":\\\"TriggerConnector\\\"}\"]},\"type\":\"TriggerConnector\"}"
|
||||
}
|
||||
}
|
|
@ -72,7 +72,7 @@ class TriggerDeltaTest : TriggerTestBase() {
|
|||
Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
||||
}
|
||||
|
||||
private var deltaJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"deltaType\":\"DELTA\",\"units\":\"mg/dl\",\"value\":4.1},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerDelta\"}"
|
||||
private var deltaJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"deltaType\":\"DELTA\",\"units\":\"mg/dl\",\"value\":4.1},\"type\":\"TriggerDelta\"}"
|
||||
|
||||
@Test
|
||||
fun toJSONTest() {
|
||||
|
|
|
@ -57,7 +57,7 @@ class TriggerIobTest : TriggerTestBase() {
|
|||
Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
||||
}
|
||||
|
||||
private var bgJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"insulin\":4.1},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerIob\"}"
|
||||
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())
|
||||
|
|
|
@ -73,7 +73,7 @@ class TriggerLocationTest : TriggerTestBase() {
|
|||
// Currently unavailable due to problems with Location mocking
|
||||
}
|
||||
|
||||
private var locationJson = "{\"data\":{\"mode\":\"OUTSIDE\",\"distance\":2,\"latitude\":213,\"name\":\"\",\"longitude\":212},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerLocation\"}"
|
||||
private var locationJson = "{\"data\":{\"mode\":\"OUTSIDE\",\"distance\":2,\"latitude\":213,\"name\":\"\",\"longitude\":212},\"type\":\"TriggerLocation\"}"
|
||||
@Test fun toJSONTest() {
|
||||
val t = TriggerLocation(injector)
|
||||
t.latitude.setValue(213.0)
|
||||
|
|
|
@ -55,7 +55,7 @@ class TriggerProfilePercentTest : TriggerTestBase() {
|
|||
Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
||||
}
|
||||
|
||||
private val bgJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"percentage\":110},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerProfilePercent\"}"
|
||||
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())
|
||||
|
|
|
@ -53,7 +53,7 @@ class TriggerPumpLastConnectionTest : TriggerTestBase() {
|
|||
Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
||||
}
|
||||
|
||||
private var lbJson = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"minutesAgo\":410},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerPumpLastConnection\"}"
|
||||
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())
|
||||
|
|
|
@ -35,7 +35,7 @@ class TriggerRecurringTimeTest : TriggerTestBase() {
|
|||
Assert.assertTrue(t.shouldRun())
|
||||
}
|
||||
|
||||
private var timeJson = "{\"data\":{\"WEDNESDAY\":false,\"MONDAY\":false,\"THURSDAY\":false,\"SUNDAY\":false,\"TUESDAY\":false,\"FRIDAY\":false,\"SATURDAY\":false,\"time\":4444},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerRecurringTime\"}"
|
||||
private var timeJson = "{\"data\":{\"WEDNESDAY\":false,\"MONDAY\":false,\"THURSDAY\":false,\"SUNDAY\":false,\"TUESDAY\":false,\"FRIDAY\":false,\"SATURDAY\":false,\"time\":4444},\"type\":\"TriggerRecurringTime\"}"
|
||||
|
||||
@Test
|
||||
fun toJSONTest() {
|
||||
|
|
|
@ -43,7 +43,7 @@ class TriggerTempTargetTest : TriggerTestBase() {
|
|||
Assert.assertEquals(ComparatorExists.Compare.NOT_EXISTS, t1.comparator.value)
|
||||
}
|
||||
|
||||
private var ttJson = "{\"data\":{\"comparator\":\"EXISTS\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTempTarget\"}"
|
||||
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())
|
||||
|
|
|
@ -18,7 +18,7 @@ import org.powermock.modules.junit4.PowerMockRunner
|
|||
class TriggerTimeRangeTest : TriggerTestBase() {
|
||||
|
||||
var now = 754 // in minutes from midnight
|
||||
private var timeJson = "{\"data\":{\"start\":753,\"end\":784},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTimeRange\"}"
|
||||
private var timeJson = "{\"data\":{\"start\":753,\"end\":784},\"type\":\"TriggerTimeRange\"}"
|
||||
|
||||
@Before
|
||||
fun mock() {
|
||||
|
|
|
@ -36,7 +36,7 @@ class TriggerTimeTest : TriggerTestBase() {
|
|||
Assert.assertFalse(t.shouldRun())
|
||||
}
|
||||
|
||||
private var timeJson = "{\"data\":{\"runAt\":1514766840000},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerTime\"}"
|
||||
private var timeJson = "{\"data\":{\"runAt\":1514766840000},\"type\":\"TriggerTime\"}"
|
||||
@Test fun toJSONTest() {
|
||||
val t: TriggerTime = TriggerTime(injector).runAt(now - T.mins(1).msecs())
|
||||
Assert.assertEquals(timeJson, t.toJSON())
|
||||
|
|
|
@ -56,7 +56,7 @@ class TriggerWifiSsidTest : TriggerTestBase() {
|
|||
Assert.assertEquals(Comparator.Compare.IS_EQUAL_OR_LESSER, t.comparator.value)
|
||||
}
|
||||
|
||||
var json = "{\"data\":{\"comparator\":\"IS_EQUAL\",\"ssid\":\"aSSID\"},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerWifiSsid\"}"
|
||||
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())
|
||||
|
|
Loading…
Reference in a new issue