SmsCommunicatorPlugin -> kt

This commit is contained in:
Milos Kozak 2019-11-22 00:12:46 +01:00
parent f3f5bb0d7e
commit d227013496
9 changed files with 1070 additions and 1298 deletions

View file

@ -8,7 +8,7 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
class AuthRequest { public class AuthRequest {
private static Logger log = LoggerFactory.getLogger(L.SMS); private static Logger log = LoggerFactory.getLogger(L.SMS);
Sms requester; Sms requester;

View file

@ -5,7 +5,7 @@ import android.telephony.SmsMessage;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
class Sms { public class Sms {
String phoneNumber; String phoneNumber;
String text; String text;
long date; long date;

View file

@ -62,14 +62,14 @@ public class SmsCommunicatorFragment extends Fragment {
return (int) (object1.date - object2.date); return (int) (object1.date - object2.date);
} }
} }
Collections.sort(SmsCommunicatorPlugin.getPlugin().messages, new CustomComparator()); Collections.sort(SmsCommunicatorPlugin.getPlugin().getMessages(), new CustomComparator());
int messagesToShow = 40; int messagesToShow = 40;
int start = Math.max(0, SmsCommunicatorPlugin.getPlugin().messages.size() - messagesToShow); int start = Math.max(0, SmsCommunicatorPlugin.getPlugin().getMessages().size() - messagesToShow);
String logText = ""; String logText = "";
for (int x = start; x < SmsCommunicatorPlugin.getPlugin().messages.size(); x++) { for (int x = start; x < SmsCommunicatorPlugin.getPlugin().getMessages().size(); x++) {
Sms sms = SmsCommunicatorPlugin.getPlugin().messages.get(x); Sms sms = SmsCommunicatorPlugin.getPlugin().getMessages().get(x);
if (sms.ignored) { if (sms.ignored) {
logText += DateUtil.timeString(sms.date) + " &lt;&lt;&lt; " + "" + sms.phoneNumber + " <b>" + sms.text + "</b><br>"; logText += DateUtil.timeString(sms.date) + " &lt;&lt;&lt; " + "" + sms.phoneNumber + " <b>" + sms.text + "</b><br>";
} else if (sms.received) { } else if (sms.received) {

View file

@ -0,0 +1,812 @@
package info.nightscout.androidaps.plugins.general.smsCommunicator
import android.content.Intent
import android.preference.EditTextPreference
import android.preference.Preference
import android.preference.Preference.OnPreferenceChangeListener
import android.preference.PreferenceFragment
import android.telephony.SmsManager
import android.telephony.SmsMessage
import android.text.TextUtils
import com.andreabaccega.widget.ValidatingEditTextPreference
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.db.DatabaseHelper
import info.nightscout.androidaps.db.Source
import info.nightscout.androidaps.db.TempTarget
import info.nightscout.androidaps.events.EventPreferenceChange
import info.nightscout.androidaps.events.EventRefreshOverview
import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.interfaces.PluginBase
import info.nightscout.androidaps.interfaces.PluginDescription
import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
import info.nightscout.androidaps.plugins.bus.RxBus.send
import info.nightscout.androidaps.plugins.bus.RxBus.toObservable
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
import info.nightscout.androidaps.plugins.general.smsCommunicator.events.EventSmsCommunicatorUpdateGui
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.queue.Callback
import info.nightscout.androidaps.utils.*
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import org.apache.commons.lang3.StringUtils
import org.slf4j.LoggerFactory
import java.text.Normalizer
import java.util.*
/**
* Created by mike on 05.08.2016.
*/
class SmsCommunicatorPlugin internal constructor() : PluginBase(PluginDescription()
.mainType(PluginType.GENERAL)
.fragmentClass(SmsCommunicatorFragment::class.java.name)
.pluginName(R.string.smscommunicator)
.shortName(R.string.smscommunicator_shortname)
.preferencesId(R.xml.pref_smscommunicator)
.description(R.string.description_sms_communicator)
) {
private val disposable = CompositeDisposable()
var allowedNumbers: MutableList<String> = ArrayList()
var messageToConfirm: AuthRequest? = null
var lastRemoteBolusTime: Long = 0
var messages = ArrayList<Sms>()
override fun onStart() {
super.onStart()
disposable.add(toObservable(EventPreferenceChange::class.java)
.observeOn(Schedulers.io())
.subscribe({ event: EventPreferenceChange? -> processSettings(event) }) { throwable: Throwable? -> FabricPrivacy.logException(throwable) }
)
}
override fun onStop() {
disposable.clear()
super.onStop()
}
override fun preprocessPreferences(preferenceFragment: PreferenceFragment) {
super.preprocessPreferences(preferenceFragment)
val distance = preferenceFragment.findPreference(MainApp.gs(R.string.key_smscommunicator_remotebolusmindistance)) as ValidatingEditTextPreference
val allowedNumbers = preferenceFragment.findPreference(MainApp.gs(R.string.key_smscommunicator_allowednumbers)) as EditTextPreference
if (distance != null && allowedNumbers != null) {
if (!areMoreNumbers(allowedNumbers.text)) {
distance.title = (MainApp.gs(R.string.smscommunicator_remotebolusmindistance)
+ ".\n"
+ MainApp.gs(R.string.smscommunicator_remotebolusmindistance_caveat))
distance.isEnabled = false
} else {
distance.title = MainApp.gs(R.string.smscommunicator_remotebolusmindistance)
distance.isEnabled = true
}
allowedNumbers.onPreferenceChangeListener = OnPreferenceChangeListener { preference: Preference?, newValue: Any ->
if (!areMoreNumbers(newValue as String)) {
distance.text = (Constants.remoteBolusMinDistance / (60 * 1000L)).toString()
distance.title = (MainApp.gs(R.string.smscommunicator_remotebolusmindistance)
+ ".\n"
+ MainApp.gs(R.string.smscommunicator_remotebolusmindistance_caveat))
distance.isEnabled = false
} else {
distance.title = MainApp.gs(R.string.smscommunicator_remotebolusmindistance)
distance.isEnabled = true
}
true
}
}
}
override fun updatePreferenceSummary(pref: Preference) {
super.updatePreferenceSummary(pref)
if (pref is EditTextPreference) {
val editTextPref = pref
if (pref.getKey().contains("smscommunicator_allowednumbers") && (editTextPref.text == null || TextUtils.isEmpty(editTextPref.text.trim { it <= ' ' }))) {
pref.setSummary(MainApp.gs(R.string.smscommunicator_allowednumbers_summary))
}
}
}
private fun processSettings(ev: EventPreferenceChange?) {
if (ev == null || ev.isChanged(R.string.key_smscommunicator_allowednumbers)) {
val settings = SP.getString(R.string.key_smscommunicator_allowednumbers, "")
allowedNumbers.clear()
val substrings = settings.split(";").toTypedArray()
for (number in substrings) {
val cleaned = number.replace("\\s+".toRegex(), "")
allowedNumbers.add(cleaned)
log.debug("Found allowed number: $cleaned")
}
}
}
fun isCommand(command: String, number: String): Boolean {
when (command.toUpperCase(Locale.getDefault())) {
"BG", "LOOP", "TREATMENTS", "NSCLIENT", "PUMP", "BASAL", "BOLUS", "EXTENDED", "CAL", "PROFILE", "TARGET", "SMS" -> return true
}
return messageToConfirm?.requester?.phoneNumber == number
}
fun isAllowedNumber(number: String): Boolean {
for (num in allowedNumbers) {
if (num == number) return true
}
return false
}
fun handleNewData(intent: Intent) {
val bundle = intent.extras ?: return
val pdus = bundle["pdus"] as Array<*>
for (pdu in pdus) {
val message = SmsMessage.createFromPdu(pdu as ByteArray)
processSms(Sms(message))
}
}
fun processSms(receivedSms: Sms) {
if (!isEnabled(PluginType.GENERAL)) {
log.debug("Ignoring SMS. Plugin disabled.")
return
}
if (!isAllowedNumber(receivedSms.phoneNumber)) {
log.debug("Ignoring SMS from: " + receivedSms.phoneNumber + ". Sender not allowed")
receivedSms.ignored = true
messages.add(receivedSms)
send(EventSmsCommunicatorUpdateGui())
return
}
val pump = ConfigBuilderPlugin.getPlugin().activePump ?: return
messages.add(receivedSms)
log.debug(receivedSms.toString())
val splitted = receivedSms.text.split(Regex("\\s+")).toTypedArray()
val remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)
if (splitted.isNotEmpty() && isCommand(splitted[0].toUpperCase(Locale.getDefault()), receivedSms.phoneNumber)) {
when (splitted[0].toUpperCase(Locale.getDefault())) {
"BG" ->
if (splitted.size == 1) processBG(receivedSms)
else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
"LOOP" ->
if (!remoteCommandsAllowed) sendSMS(Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed))
else if (splitted.size == 2 || splitted.size == 3) processLOOP(splitted, receivedSms)
else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
"TREATMENTS" ->
if (splitted.size == 2) processTREATMENTS(splitted, receivedSms)
else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
"NSCLIENT" ->
if (splitted.size == 2) processNSCLIENT(splitted, receivedSms)
else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
"PUMP" ->
if (splitted.size == 1) processPUMP(receivedSms)
else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
"PROFILE" ->
if (!remoteCommandsAllowed) sendSMS(Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed))
else if (splitted.size == 2 || splitted.size == 3) processPROFILE(splitted, receivedSms)
else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
"BASAL" ->
if (!remoteCommandsAllowed) sendSMS(Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed))
else if (splitted.size == 2 || splitted.size == 3) processBASAL(splitted, receivedSms)
else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
"EXTENDED" ->
if (!remoteCommandsAllowed) sendSMS(Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed))
else if (splitted.size == 2 || splitted.size == 3) processEXTENDED(splitted, receivedSms)
else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
"BOLUS" ->
if (!remoteCommandsAllowed) sendSMS(Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed))
else if (splitted.size == 2 && DateUtil.now() - lastRemoteBolusTime < Constants.remoteBolusMinDistance) sendSMS(Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotebolusnotallowed))
else if (splitted.size == 2 && pump.isSuspended) sendSMS(Sms(receivedSms.phoneNumber, R.string.pumpsuspended))
else if (splitted.size == 2 || splitted.size == 3) processBOLUS(splitted, receivedSms) else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
"CAL" ->
if (!remoteCommandsAllowed) sendSMS(Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed))
else if (splitted.size == 2) processCAL(splitted, receivedSms)
else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
"TARGET" ->
if (!remoteCommandsAllowed) sendSMS(Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed))
else if (splitted.size == 2) processTARGET(splitted, receivedSms)
else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
"SMS" ->
if (!remoteCommandsAllowed) sendSMS(Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed))
else if (splitted.size == 2) processSMS(splitted, receivedSms) else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
else ->
if (messageToConfirm?.requester?.phoneNumber == receivedSms.phoneNumber) {
messageToConfirm?.action(splitted[0])
messageToConfirm = null
} else sendSMS(Sms(receivedSms.phoneNumber, R.string.smscommunicator_unknowncommand))
}
}
send(EventSmsCommunicatorUpdateGui())
}
private fun processBG(receivedSms: Sms) {
val actualBG = DatabaseHelper.actualBg()
val lastBG = DatabaseHelper.lastBg()
var reply = ""
val units = ProfileFunctions.getInstance().profileUnits
if (actualBG != null) {
reply = MainApp.gs(R.string.sms_actualbg) + " " + actualBG.valueToUnitsToString(units) + ", "
} else if (lastBG != null) {
val agoMsec = System.currentTimeMillis() - lastBG.date
val agoMin = (agoMsec / 60.0 / 1000.0).toInt()
reply = MainApp.gs(R.string.sms_lastbg) + " " + lastBG.valueToUnitsToString(units) + " " + String.format(MainApp.gs(R.string.sms_minago), agoMin) + ", "
}
val glucoseStatus = GlucoseStatus.getGlucoseStatusData()
if (glucoseStatus != null) reply += MainApp.gs(R.string.sms_delta) + " " + Profile.toUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + " " + units + ", "
TreatmentsPlugin.getPlugin().updateTotalIOBTreatments()
val bolusIob = TreatmentsPlugin.getPlugin().lastCalculationTreatments.round()
TreatmentsPlugin.getPlugin().updateTotalIOBTempBasals()
val basalIob = TreatmentsPlugin.getPlugin().lastCalculationTempBasals.round()
val cobInfo = IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "SMS COB")
reply += (MainApp.gs(R.string.sms_iob) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
+ MainApp.gs(R.string.sms_bolus) + " " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
+ MainApp.gs(R.string.sms_basal) + " " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U), "
+ MainApp.gs(R.string.cob) + ": " + cobInfo.generateCOBString())
sendSMS(Sms(receivedSms.phoneNumber, reply))
receivedSms.processed = true
}
private fun processLOOP(splitted: Array<String>, receivedSms: Sms) {
when (splitted[1].toUpperCase(Locale.getDefault())) {
"DISABLE", "STOP" -> {
val loopPlugin = LoopPlugin.getPlugin()
if (loopPlugin.isEnabled(PluginType.LOOP)) {
loopPlugin.setPluginEnabled(PluginType.LOOP, false)
ConfigBuilderPlugin.getPlugin().commandQueue.cancelTempBasal(true, object : Callback() {
override fun run() {
send(EventRefreshOverview("SMS_LOOP_STOP"))
val replyText = MainApp.gs(R.string.smscommunicator_loophasbeendisabled) + " " +
MainApp.gs(if (result.success) R.string.smscommunicator_tempbasalcanceled else R.string.smscommunicator_tempbasalcancelfailed)
sendSMS(Sms(receivedSms.phoneNumber, replyText))
}
})
} else {
sendSMS(Sms(receivedSms.phoneNumber, R.string.smscommunicator_loopisdisabled))
}
receivedSms.processed = true
}
"ENABLE", "START" -> {
val loopPlugin = LoopPlugin.getPlugin()
if (!loopPlugin.isEnabled(PluginType.LOOP)) {
loopPlugin.setPluginEnabled(PluginType.LOOP, true)
sendSMS(Sms(receivedSms.phoneNumber, R.string.smscommunicator_loophasbeenenabled))
send(EventRefreshOverview("SMS_LOOP_START"))
} else {
sendSMS(Sms(receivedSms.phoneNumber, R.string.smscommunicator_loopisenabled))
}
receivedSms.processed = true
}
"STATUS" -> {
val loopPlugin = LoopPlugin.getPlugin()
val reply = if (loopPlugin.isEnabled(PluginType.LOOP)) {
if (loopPlugin.isSuspended()) String.format(MainApp.gs(R.string.loopsuspendedfor), loopPlugin.minutesToEndOfSuspend()) else MainApp.gs(R.string.smscommunicator_loopisenabled)
} else {
MainApp.gs(R.string.smscommunicator_loopisdisabled)
}
sendSMS(Sms(receivedSms.phoneNumber, reply))
receivedSms.processed = true
}
"RESUME" -> {
LoopPlugin.getPlugin().suspendTo(0)
send(EventRefreshOverview("SMS_LOOP_RESUME"))
NSUpload.uploadOpenAPSOffline(0.0)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, R.string.smscommunicator_loopresumed))
}
"SUSPEND" -> {
var duration = 0
if (splitted.size == 3) duration = SafeParse.stringToInt(splitted[2])
duration = Math.max(0, duration)
duration = Math.min(180, duration)
if (duration == 0) {
receivedSms.processed = true
sendSMS(Sms(receivedSms.phoneNumber, R.string.smscommunicator_wrongduration))
return
} else {
val passCode = generatePasscode()
val reply = String.format(MainApp.gs(R.string.smscommunicator_suspendreplywithcode), duration, passCode)
receivedSms.processed = true
messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction(duration) {
override fun run() {
ConfigBuilderPlugin.getPlugin().commandQueue.cancelTempBasal(true, object : Callback() {
override fun run() {
if (result.success) {
LoopPlugin.getPlugin().suspendTo(System.currentTimeMillis() + anInteger * 60L * 1000)
NSUpload.uploadOpenAPSOffline(anInteger * 60.toDouble())
send(EventRefreshOverview("SMS_LOOP_SUSPENDED"))
val replyText = MainApp.gs(R.string.smscommunicator_loopsuspended) + " " +
MainApp.gs(if (result.success) R.string.smscommunicator_tempbasalcanceled else R.string.smscommunicator_tempbasalcancelfailed)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
} else {
var replyText = MainApp.gs(R.string.smscommunicator_tempbasalcancelfailed)
replyText += "\n" + ConfigBuilderPlugin.getPlugin().activePump?.shortStatus(true)
sendSMS(Sms(receivedSms.phoneNumber, replyText))
}
}
})
}
})
}
}
else -> sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
}
}
private fun processTREATMENTS(splitted: Array<String>, receivedSms: Sms) {
if (splitted[1].toUpperCase(Locale.getDefault()) == "REFRESH") {
TreatmentsPlugin.getPlugin().service.resetTreatments()
send(EventNSClientRestart())
sendSMS(Sms(receivedSms.phoneNumber, "TREATMENTS REFRESH SENT"))
receivedSms.processed = true
} else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
}
private fun processNSCLIENT(splitted: Array<String>, receivedSms: Sms) {
if (splitted[1].toUpperCase(Locale.getDefault()) == "RESTART") {
send(EventNSClientRestart())
sendSMS(Sms(receivedSms.phoneNumber, "NSCLIENT RESTART SENT"))
receivedSms.processed = true
} else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
}
private fun processPUMP(receivedSms: Sms) {
ConfigBuilderPlugin.getPlugin().commandQueue.readStatus("SMS", object : Callback() {
override fun run() {
val pump = ConfigBuilderPlugin.getPlugin().activePump
if (result.success) {
if (pump != null) {
val reply = pump.shortStatus(true)
sendSMS(Sms(receivedSms.phoneNumber, reply))
}
} else {
val reply = MainApp.gs(R.string.readstatusfailed)
sendSMS(Sms(receivedSms.phoneNumber, reply))
}
}
})
receivedSms.processed = true
}
private fun processPROFILE(splitted: Array<String>, receivedSms: Sms) { // load profiles
val anInterface = ConfigBuilderPlugin.getPlugin().activeProfileInterface
if (anInterface == null) {
sendSMS(Sms(receivedSms.phoneNumber, R.string.notconfigured))
receivedSms.processed = true
return
}
val store = anInterface.profile
if (store == null) {
sendSMS(Sms(receivedSms.phoneNumber, R.string.notconfigured))
receivedSms.processed = true
return
}
val list = store.profileList
if (splitted[1].toUpperCase(Locale.getDefault()) == "STATUS") {
sendSMS(Sms(receivedSms.phoneNumber, ProfileFunctions.getInstance().profileName))
} else if (splitted[1].toUpperCase(Locale.getDefault()) == "LIST") {
if (list.isEmpty()) sendSMS(Sms(receivedSms.phoneNumber, R.string.invalidprofile)) else {
var reply = ""
for (i in list.indices) {
if (i > 0) reply += "\n"
reply += (i + 1).toString() + ". "
reply += list[i]
}
sendSMS(Sms(receivedSms.phoneNumber, reply))
}
} else {
val pindex = SafeParse.stringToInt(splitted[1])
var percentage = 100
if (splitted.size > 2) percentage = SafeParse.stringToInt(splitted[2])
if (pindex > list.size) sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat)) else if (percentage == 0) sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat)) else if (pindex == 0) sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat)) else {
val profile = store.getSpecificProfile(list[pindex - 1] as String)
if (profile == null) sendSMS(Sms(receivedSms.phoneNumber, R.string.noprofile)) else {
val passCode = generatePasscode()
val reply = String.format(MainApp.gs(R.string.smscommunicator_profilereplywithcode), list[pindex - 1], percentage, passCode)
receivedSms.processed = true
val finalPercentage = percentage
messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction(list[pindex - 1] as String, finalPercentage) {
override fun run() {
ProfileFunctions.doProfileSwitch(store, list[pindex - 1] as String, 0, finalPercentage, 0)
sendSMS(Sms(receivedSms.phoneNumber, R.string.profileswitchcreated))
}
})
}
}
}
receivedSms.processed = true
}
private fun processBASAL(splitted: Array<String>, receivedSms: Sms) {
if (splitted[1].toUpperCase(Locale.getDefault()) == "CANCEL" || splitted[1].toUpperCase(Locale.getDefault()) == "STOP") {
val passCode = generatePasscode()
val reply = String.format(MainApp.gs(R.string.smscommunicator_basalstopreplywithcode), passCode)
receivedSms.processed = true
messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction() {
override fun run() {
ConfigBuilderPlugin.getPlugin().commandQueue.cancelTempBasal(true, object : Callback() {
override fun run() {
if (result.success) {
var replyText = MainApp.gs(R.string.smscommunicator_tempbasalcanceled)
replyText += "\n" + ConfigBuilderPlugin.getPlugin().activePump?.shortStatus(true)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
} else {
var replyText = MainApp.gs(R.string.smscommunicator_tempbasalcancelfailed)
replyText += "\n" + ConfigBuilderPlugin.getPlugin().activePump?.shortStatus(true)
sendSMS(Sms(receivedSms.phoneNumber, replyText))
}
}
})
}
})
} else if (splitted[1].endsWith("%")) {
var tempBasalPct = SafeParse.stringToInt(StringUtils.removeEnd(splitted[1], "%"))
var duration = 30
if (splitted.size > 2) duration = SafeParse.stringToInt(splitted[2])
val profile = ProfileFunctions.getInstance().profile
if (profile == null) sendSMS(Sms(receivedSms.phoneNumber, R.string.noprofile)) else if (tempBasalPct == 0 && splitted[1] != "0%") sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat)) else if (duration == 0) sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat)) else {
tempBasalPct = MainApp.getConstraintChecker().applyBasalPercentConstraints(Constraint(tempBasalPct), profile).value()
val passCode = generatePasscode()
val reply = String.format(MainApp.gs(R.string.smscommunicator_basalpctreplywithcode), tempBasalPct, duration, passCode)
receivedSms.processed = true
messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction(tempBasalPct, duration) {
override fun run() {
ConfigBuilderPlugin.getPlugin().commandQueue.tempBasalPercent(anInteger, secondInteger, true, profile, object : Callback() {
override fun run() {
if (result.success) {
var replyText: String
replyText = if (result.isPercent) String.format(MainApp.gs(R.string.smscommunicator_tempbasalset_percent), result.percent, result.duration) else String.format(MainApp.gs(R.string.smscommunicator_tempbasalset), result.absolute, result.duration)
replyText += "\n" + ConfigBuilderPlugin.getPlugin().activePump?.shortStatus(true)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
} else {
var replyText = MainApp.gs(R.string.smscommunicator_tempbasalfailed)
replyText += "\n" + ConfigBuilderPlugin.getPlugin().activePump?.shortStatus(true)
sendSMS(Sms(receivedSms.phoneNumber, replyText))
}
}
})
}
})
}
} else {
var tempBasal = SafeParse.stringToDouble(splitted[1])
var duration = 30
if (splitted.size > 2) duration = SafeParse.stringToInt(splitted[2])
val profile = ProfileFunctions.getInstance().profile
if (profile == null) sendSMS(Sms(receivedSms.phoneNumber, R.string.noprofile)) else if (tempBasal == 0.0 && splitted[1] != "0") sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat)) else if (duration == 0) sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat)) else {
tempBasal = MainApp.getConstraintChecker().applyBasalConstraints(Constraint(tempBasal), profile).value()
val passCode = generatePasscode()
val reply = String.format(MainApp.gs(R.string.smscommunicator_basalreplywithcode), tempBasal, duration, passCode)
receivedSms.processed = true
messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction(tempBasal, duration) {
override fun run() {
ConfigBuilderPlugin.getPlugin().commandQueue.tempBasalAbsolute(aDouble, secondInteger, true, profile, object : Callback() {
override fun run() {
if (result.success) {
var replyText = if (result.isPercent) String.format(MainApp.gs(R.string.smscommunicator_tempbasalset_percent), result.percent, result.duration) else String.format(MainApp.gs(R.string.smscommunicator_tempbasalset), result.absolute, result.duration)
replyText += "\n" + ConfigBuilderPlugin.getPlugin().activePump?.shortStatus(true)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
} else {
var replyText = MainApp.gs(R.string.smscommunicator_tempbasalfailed)
replyText += "\n" + ConfigBuilderPlugin.getPlugin().activePump?.shortStatus(true)
sendSMS(Sms(receivedSms.phoneNumber, replyText))
}
}
})
}
})
}
}
}
private fun processEXTENDED(splitted: Array<String>, receivedSms: Sms) {
if (splitted[1].toUpperCase(Locale.getDefault()) == "CANCEL" || splitted[1].toUpperCase(Locale.getDefault()) == "STOP") {
val passCode = generatePasscode()
val reply = String.format(MainApp.gs(R.string.smscommunicator_extendedstopreplywithcode), passCode)
receivedSms.processed = true
messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction() {
override fun run() {
ConfigBuilderPlugin.getPlugin().commandQueue.cancelExtended(object : Callback() {
override fun run() {
if (result.success) {
var replyText = MainApp.gs(R.string.smscommunicator_extendedcanceled)
replyText += "\n" + ConfigBuilderPlugin.getPlugin().activePump?.shortStatus(true)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
} else {
var replyText = MainApp.gs(R.string.smscommunicator_extendedcancelfailed)
replyText += "\n" + ConfigBuilderPlugin.getPlugin().activePump?.shortStatus(true)
sendSMS(Sms(receivedSms.phoneNumber, replyText))
}
}
})
}
})
} else if (splitted.size != 3) {
sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
} else {
var extended = SafeParse.stringToDouble(splitted[1])
val duration = SafeParse.stringToInt(splitted[2])
extended = MainApp.getConstraintChecker().applyExtendedBolusConstraints(Constraint(extended)).value()
if (extended == 0.0 || duration == 0) sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat)) else {
val passCode = generatePasscode()
val reply = String.format(MainApp.gs(R.string.smscommunicator_extendedreplywithcode), extended, duration, passCode)
receivedSms.processed = true
messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction(extended, duration) {
override fun run() {
ConfigBuilderPlugin.getPlugin().commandQueue.extendedBolus(aDouble, secondInteger, object : Callback() {
override fun run() {
if (result.success) {
var replyText = String.format(MainApp.gs(R.string.smscommunicator_extendedset), aDouble, duration)
replyText += "\n" + ConfigBuilderPlugin.getPlugin().activePump?.shortStatus(true)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
} else {
var replyText = MainApp.gs(R.string.smscommunicator_extendedfailed)
replyText += "\n" + ConfigBuilderPlugin.getPlugin().activePump?.shortStatus(true)
sendSMS(Sms(receivedSms.phoneNumber, replyText))
}
}
})
}
})
}
}
}
private fun processBOLUS(splitted: Array<String>, receivedSms: Sms) {
var bolus = SafeParse.stringToDouble(splitted[1])
val isMeal = splitted.size > 2 && splitted[2].equals("MEAL", ignoreCase = true)
bolus = MainApp.getConstraintChecker().applyBolusConstraints(Constraint(bolus)).value()
if (splitted.size == 3 && !isMeal) {
sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
} else if (bolus > 0.0) {
val passCode = generatePasscode()
val reply = if (isMeal) {
String.format(MainApp.gs(R.string.smscommunicator_mealbolusreplywithcode), bolus, passCode)
} else {
String.format(MainApp.gs(R.string.smscommunicator_bolusreplywithcode), bolus, passCode)
}
receivedSms.processed = true
messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction(bolus) {
override fun run() {
val detailedBolusInfo = DetailedBolusInfo()
detailedBolusInfo.insulin = aDouble
detailedBolusInfo.source = Source.USER
ConfigBuilderPlugin.getPlugin().commandQueue.bolus(detailedBolusInfo, object : Callback() {
override fun run() {
val resultSuccess = result.success
val resultBolusDelivered = result.bolusDelivered
ConfigBuilderPlugin.getPlugin().commandQueue.readStatus("SMS", object : Callback() {
override fun run() {
if (resultSuccess) {
var replyText = if (isMeal) {
String.format(MainApp.gs(R.string.smscommunicator_mealbolusdelivered), resultBolusDelivered)
} else {
String.format(MainApp.gs(R.string.smscommunicator_bolusdelivered), resultBolusDelivered)
}
replyText += "\n" + ConfigBuilderPlugin.getPlugin().activePump?.shortStatus(true)
lastRemoteBolusTime = DateUtil.now()
if (isMeal) {
ProfileFunctions.getInstance().profile?.let { currentProfile ->
var eatingSoonTTDuration = SP.getInt(R.string.key_eatingsoon_duration, Constants.defaultEatingSoonTTDuration)
eatingSoonTTDuration = if (eatingSoonTTDuration > 0) eatingSoonTTDuration else Constants.defaultEatingSoonTTDuration
var eatingSoonTT = SP.getDouble(R.string.key_eatingsoon_target, if (currentProfile.units == Constants.MMOL) Constants.defaultEatingSoonTTmmol else Constants.defaultEatingSoonTTmgdl)
eatingSoonTT = if (eatingSoonTT > 0) eatingSoonTT else if (currentProfile.units == Constants.MMOL) Constants.defaultEatingSoonTTmmol else Constants.defaultEatingSoonTTmgdl
val tempTarget = TempTarget()
.date(System.currentTimeMillis())
.duration(eatingSoonTTDuration)
.reason(MainApp.gs(R.string.eatingsoon))
.source(Source.USER)
.low(Profile.toMgdl(eatingSoonTT, currentProfile.units))
.high(Profile.toMgdl(eatingSoonTT, currentProfile.units))
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget)
val tt = if (currentProfile.units == Constants.MMOL) {
DecimalFormatter.to1Decimal(eatingSoonTT)
} else DecimalFormatter.to0Decimal(eatingSoonTT)
replyText += "\n" + String.format(MainApp.gs(R.string.smscommunicator_mealbolusdelivered_tt), tt, eatingSoonTTDuration)
}
}
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
} else {
var replyText = MainApp.gs(R.string.smscommunicator_bolusfailed)
replyText += "\n" + ConfigBuilderPlugin.getPlugin().activePump?.shortStatus(true)
sendSMS(Sms(receivedSms.phoneNumber, replyText))
}
}
})
}
})
}
})
} else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
}
private fun processTARGET(splitted: Array<String>, receivedSms: Sms) {
val isMeal = splitted[1].equals("MEAL", ignoreCase = true)
val isActivity = splitted[1].equals("ACTIVITY", ignoreCase = true)
val isHypo = splitted[1].equals("HYPO", ignoreCase = true)
if (isMeal || isActivity || isHypo) {
val passCode = generatePasscode()
val reply = String.format(MainApp.gs(R.string.smscommunicator_temptargetwithcode), splitted[1].toUpperCase(Locale.getDefault()), passCode)
receivedSms.processed = true
messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction() {
override fun run() {
val currentProfile = ProfileFunctions.getInstance().profile
if (currentProfile != null) {
var keyDuration = 0
var defaultTargetDuration = 0
var keyTarget = 0
var defaultTargetMMOL = 0.0
var defaultTargetMGDL = 0.0
if (isMeal) {
keyDuration = R.string.key_eatingsoon_duration
defaultTargetDuration = Constants.defaultEatingSoonTTDuration
keyTarget = R.string.key_eatingsoon_target
defaultTargetMMOL = Constants.defaultEatingSoonTTmmol
defaultTargetMGDL = Constants.defaultEatingSoonTTmgdl
} else if (isActivity) {
keyDuration = R.string.key_activity_duration
defaultTargetDuration = Constants.defaultActivityTTDuration
keyTarget = R.string.key_activity_target
defaultTargetMMOL = Constants.defaultActivityTTmmol
defaultTargetMGDL = Constants.defaultActivityTTmgdl
} else if (isHypo) {
keyDuration = R.string.key_hypo_duration
defaultTargetDuration = Constants.defaultHypoTTDuration
keyTarget = R.string.key_hypo_target
defaultTargetMMOL = Constants.defaultHypoTTmmol
defaultTargetMGDL = Constants.defaultHypoTTmgdl
}
var ttDuration = SP.getInt(keyDuration, defaultTargetDuration)
ttDuration = if (ttDuration > 0) ttDuration else defaultTargetDuration
var tt = SP.getDouble(keyTarget, if (currentProfile.units == Constants.MMOL) defaultTargetMMOL else defaultTargetMGDL)
tt = if (tt > 0) tt else if (currentProfile.units == Constants.MMOL) defaultTargetMMOL else defaultTargetMGDL
val tempTarget = TempTarget()
.date(System.currentTimeMillis())
.duration(ttDuration)
.reason(MainApp.gs(R.string.eatingsoon))
.source(Source.USER)
.low(Profile.toMgdl(tt, currentProfile.units))
.high(Profile.toMgdl(tt, currentProfile.units))
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget)
val ttString = if (currentProfile.units == Constants.MMOL) DecimalFormatter.to1Decimal(tt) else DecimalFormatter.to0Decimal(tt)
val replyText = String.format(MainApp.gs(R.string.smscommunicator_tt_set), ttString, ttDuration)
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
} else {
sendSMS(Sms(receivedSms.phoneNumber, R.string.smscommunicator_unknowncommand))
}
}
})
} else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
}
private fun processSMS(splitted: Array<String>, receivedSms: Sms) {
val isStop = (splitted[1].equals("STOP", ignoreCase = true)
|| splitted[1].equals("DISABLE", ignoreCase = true))
if (isStop) {
val passCode = generatePasscode()
val reply = String.format(MainApp.gs(R.string.smscommunicator_stopsmswithcode), passCode)
receivedSms.processed = true
messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction() {
override fun run() {
SP.putBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)
val replyText = String.format(MainApp.gs(R.string.smscommunicator_stoppedsms))
sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, replyText))
}
})
} else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
}
private fun processCAL(splitted: Array<String>, receivedSms: Sms) {
val cal = SafeParse.stringToDouble(splitted[1])
if (cal > 0.0) {
val passCode = generatePasscode()
val reply = String.format(MainApp.gs(R.string.smscommunicator_calibrationreplywithcode), cal, passCode)
receivedSms.processed = true
messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction(cal) {
override fun run() {
val result = XdripCalibrations.sendIntent(aDouble)
if (result) sendSMSToAllNumbers(Sms(receivedSms.phoneNumber, R.string.smscommunicator_calibrationsent)) else sendSMS(Sms(receivedSms.phoneNumber, R.string.smscommunicator_calibrationfailed))
}
})
} else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
}
fun sendNotificationToAllNumbers(text: String?): Boolean {
var result = true
for (i in allowedNumbers.indices) {
val sms = Sms(allowedNumbers[i], text)
result = result && sendSMS(sms)
}
return result
}
private fun sendSMSToAllNumbers(sms: Sms) {
for (number in allowedNumbers) {
sms.phoneNumber = number
sendSMS(sms)
}
}
fun sendSMS(sms: Sms): Boolean {
val smsManager = SmsManager.getDefault()
sms.text = stripAccents(sms.text)
try {
if (L.isEnabled(L.SMS)) log.debug("Sending SMS to " + sms.phoneNumber + ": " + sms.text)
if (sms.text.toByteArray().size <= 140) smsManager.sendTextMessage(sms.phoneNumber, null, sms.text, null, null) else {
val parts = smsManager.divideMessage(sms.text)
smsManager.sendMultipartTextMessage(sms.phoneNumber, null, parts,
null, null)
}
messages.add(sms)
} catch (e: IllegalArgumentException) {
return if (e.message == "Invalid message body") {
val notification = Notification(Notification.INVALID_MESSAGE_BODY, MainApp.gs(R.string.smscommunicator_messagebody), Notification.NORMAL)
send(EventNewNotification(notification))
false
} else {
val notification = Notification(Notification.INVALID_PHONE_NUMBER, MainApp.gs(R.string.smscommunicator_invalidphonennumber), Notification.NORMAL)
send(EventNewNotification(notification))
false
}
} catch (e: SecurityException) {
val notification = Notification(Notification.MISSING_SMS_PERMISSION, MainApp.gs(R.string.smscommunicator_missingsmspermission), Notification.NORMAL)
send(EventNewNotification(notification))
return false
}
send(EventSmsCommunicatorUpdateGui())
return true
}
private fun generatePasscode(): String {
val startChar1 = 'A'.toInt() // on iphone 1st char is uppercase :)
var passCode = Character.toString((startChar1 + Math.random() * ('z' - 'a' + 1)).toChar())
val startChar2: Int = if (Math.random() > 0.5) 'a'.toInt() else 'A'.toInt()
passCode += Character.toString((startChar2 + Math.random() * ('z' - 'a' + 1)).toChar())
val startChar3: Int = if (Math.random() > 0.5) 'a'.toInt() else 'A'.toInt()
passCode += Character.toString((startChar3 + Math.random() * ('z' - 'a' + 1)).toChar())
passCode = passCode.replace('l', 'k').replace('I', 'J')
return passCode
}
companion object {
private val log = LoggerFactory.getLogger(L.SMS)
private var smsCommunicatorPlugin: SmsCommunicatorPlugin? = null
@JvmStatic
val plugin: SmsCommunicatorPlugin?
get() {
if (smsCommunicatorPlugin == null) {
smsCommunicatorPlugin = SmsCommunicatorPlugin()
}
return smsCommunicatorPlugin
}
private fun stripAccents(str: String): String {
var s = str
s = Normalizer.normalize(s, Normalizer.Form.NFD)
s = s.replace("[\\p{InCombiningDiacriticalMarks}]".toRegex(), "")
return s
}
fun areMoreNumbers(allowednumbers: String): Boolean {
var countNumbers = 0
val substrings = allowednumbers.split(";").toTypedArray()
for (number in substrings) {
var cleaned = number.replace(Regex("\\s+"), "")
if (cleaned.length < 4) continue
if (cleaned.substring(0, 1).compareTo("+") != 0) continue
cleaned = cleaned.replace("+", "")
if (!cleaned.matches(Regex("[0-9]+"))) continue
countNumbers++
}
return countNumbers > 1
}
}
init {
processSettings(null)
}
}

View file

@ -307,7 +307,7 @@
<string name="smscommunicator_bolusdelivered">Bolus %1$.2fU delivered successfully</string> <string name="smscommunicator_bolusdelivered">Bolus %1$.2fU delivered successfully</string>
<string name="smscommunicator_mealbolusdelivered">Meal Bolus %1$.2fU delivered successfully</string> <string name="smscommunicator_mealbolusdelivered">Meal Bolus %1$.2fU delivered successfully</string>
<string name="smscommunicator_mealbolusdelivered_tt">Target %1$s for %2$d minutes</string> <string name="smscommunicator_mealbolusdelivered_tt">Target %1$s for %2$d minutes</string>
<string name="smscommunicator_tt_set">Target %1$s for %2$d minutes set succesfully</string> <string name="smscommunicator_tt_set">Target %1$s for %2$d minutes set successfully</string>
<string name="bolusdelivering">Delivering %1$.2fU</string> <string name="bolusdelivering">Delivering %1$.2fU</string>
<string name="smscommunicator_remotecommandsallowed">Allow remote commands via SMS</string> <string name="smscommunicator_remotecommandsallowed">Allow remote commands via SMS</string>
<string name="glucosetype_finger">Finger</string> <string name="glucosetype_finger">Finger</string>

View file

@ -155,6 +155,9 @@ public class AAPSMocker {
when(MainApp.gs(R.string.pumpNotInitialized)).thenReturn("Pump not initialized!"); when(MainApp.gs(R.string.pumpNotInitialized)).thenReturn("Pump not initialized!");
when(MainApp.gs(R.string.increasingmaxbasal)).thenReturn("Increasing max basal value because setting is lower than your max basal in profile"); when(MainApp.gs(R.string.increasingmaxbasal)).thenReturn("Increasing max basal value because setting is lower than your max basal in profile");
when(MainApp.gs(R.string.overview_bolusprogress_delivered)).thenReturn("Delivered"); when(MainApp.gs(R.string.overview_bolusprogress_delivered)).thenReturn("Delivered");
when(MainApp.gs(R.string.smscommunicator_mealbolusreplywithcode)).thenReturn("To deliver meal bolus %1$.2fU reply with code %2$s");
when(MainApp.gs(R.string.smscommunicator_mealbolusdelivered)).thenReturn("Meal Bolus %1$.2fU delivered successfully");
when(MainApp.gs(R.string.smscommunicator_mealbolusdelivered_tt)).thenReturn("Target %1$s for %2$d minutes");
} }
public static MainApp mockMainApp() { public static MainApp mockMainApp() {

View file

@ -8,8 +8,6 @@ import org.mockito.stubbing.Answer;
import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import java.util.Date;
import info.AAPSMocker; import info.AAPSMocker;
import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
@ -28,9 +26,9 @@ import static org.powermock.api.mockito.PowerMockito.when;
@PrepareForTest({SmsCommunicatorPlugin.class, L.class, SP.class, MainApp.class, DateUtil.class}) @PrepareForTest({SmsCommunicatorPlugin.class, L.class, SP.class, MainApp.class, DateUtil.class})
public class AuthRequestTest { public class AuthRequestTest {
SmsCommunicatorPlugin smsCommunicatorPlugin; private SmsCommunicatorPlugin smsCommunicatorPlugin;
Sms sentSms; private Sms sentSms;
boolean actionCalled = false; private boolean actionCalled = false;
@Test @Test
public void doTests() { public void doTests() {

View file

@ -25,7 +25,6 @@ import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.interfaces.Constraint; import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
@ -67,27 +66,29 @@ public class SmsCommunicatorPluginTest {
private boolean hasBeenRun = false; private boolean hasBeenRun = false;
private VirtualPumpPlugin virtualPumpPlugin;
@Test @Test
public void processSettingsTest() { public void processSettingsTest() {
// called from constructor // called from constructor
Assert.assertEquals("1234", smsCommunicatorPlugin.allowedNumbers.get(0)); Assert.assertEquals("1234", smsCommunicatorPlugin.getAllowedNumbers().get(0));
Assert.assertEquals("5678", smsCommunicatorPlugin.allowedNumbers.get(1)); Assert.assertEquals("5678", smsCommunicatorPlugin.getAllowedNumbers().get(1));
Assert.assertEquals(2, smsCommunicatorPlugin.allowedNumbers.size()); Assert.assertEquals(2, smsCommunicatorPlugin.getAllowedNumbers().size());
} }
@Test @Test
public void isCommandTest() { public void isCommandTest() {
Assert.assertTrue(smsCommunicatorPlugin.isCommand("BOLUS", "")); Assert.assertTrue(smsCommunicatorPlugin.isCommand("BOLUS", ""));
smsCommunicatorPlugin.messageToConfirm = null; smsCommunicatorPlugin.setMessageToConfirm(null);
Assert.assertFalse(smsCommunicatorPlugin.isCommand("BLB", "")); Assert.assertFalse(smsCommunicatorPlugin.isCommand("BLB", ""));
smsCommunicatorPlugin.messageToConfirm = new AuthRequest(smsCommunicatorPlugin, new Sms("1234", "ddd"), "RequestText", "ccode", new SmsAction() { smsCommunicatorPlugin.setMessageToConfirm(new AuthRequest(smsCommunicatorPlugin, new Sms("1234", "ddd"), "RequestText", "ccode", new SmsAction() {
@Override @Override
public void run() { public void run() {
} }
}); }));
Assert.assertTrue(smsCommunicatorPlugin.isCommand("BLB", "1234")); Assert.assertTrue(smsCommunicatorPlugin.isCommand("BLB", "1234"));
Assert.assertFalse(smsCommunicatorPlugin.isCommand("BLB", "2345")); Assert.assertFalse(smsCommunicatorPlugin.isCommand("BLB", "2345"));
smsCommunicatorPlugin.messageToConfirm = null; smsCommunicatorPlugin.setMessageToConfirm(null);
} }
@Test @Test
@ -101,82 +102,82 @@ public class SmsCommunicatorPluginTest {
Sms sms; Sms sms;
// SMS from not allowed number should be ignored // SMS from not allowed number should be ignored
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("12", "aText"); sms = new Sms("12", "aText");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertTrue(sms.ignored); Assert.assertTrue(sms.ignored);
Assert.assertEquals("aText", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("aText", smsCommunicatorPlugin.getMessages().get(0).text);
//UNKNOWN //UNKNOWN
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "UNKNOWN"); sms = new Sms("1234", "UNKNOWN");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("UNKNOWN", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("UNKNOWN", smsCommunicatorPlugin.getMessages().get(0).text);
//BG //BG
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "BG"); sms = new Sms("1234", "BG");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("BG", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("BG", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("IOB:")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("IOB:"));
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("Last BG: 100")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("Last BG: 100"));
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("COB: 10(2)g")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("COB: 10(2)g"));
// LOOP : test remote control disabled // LOOP : test remote control disabled
when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(false); when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(false);
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "LOOP STATUS"); sms = new Sms("1234", "LOOP STATUS");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertFalse(sms.ignored); Assert.assertFalse(sms.ignored);
Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("Remote command is not allowed")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("Remote command is not allowed"));
when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true); when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true);
//LOOP STATUS : disabled //LOOP STATUS : disabled
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(false); when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(false);
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "LOOP STATUS"); sms = new Sms("1234", "LOOP STATUS");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Loop is disabled", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Loop is disabled", smsCommunicatorPlugin.getMessages().get(1).text);
//LOOP STATUS : suspended //LOOP STATUS : suspended
when(loopPlugin.minutesToEndOfSuspend()).thenReturn(10); when(loopPlugin.minutesToEndOfSuspend()).thenReturn(10);
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
when(loopPlugin.isSuspended()).thenReturn(true); when(loopPlugin.isSuspended()).thenReturn(true);
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "LOOP STATUS"); sms = new Sms("1234", "LOOP STATUS");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Suspended (10 m)", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Suspended (10 m)", smsCommunicatorPlugin.getMessages().get(1).text);
//LOOP STATUS : enabled //LOOP STATUS : enabled
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
when(loopPlugin.isSuspended()).thenReturn(false); when(loopPlugin.isSuspended()).thenReturn(false);
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "LOOP STATUS"); sms = new Sms("1234", "LOOP STATUS");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertFalse(sms.ignored); Assert.assertFalse(sms.ignored);
Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Loop is enabled", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Loop is enabled", smsCommunicatorPlugin.getMessages().get(1).text);
//LOOP : wrong format //LOOP : wrong format
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "LOOP"); sms = new Sms("1234", "LOOP");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertFalse(sms.ignored); Assert.assertFalse(sms.ignored);
Assert.assertEquals("LOOP", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("LOOP", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
//LOOP DISABLE : already disabled //LOOP DISABLE : already disabled
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(false); when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(false);
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "LOOP DISABLE"); sms = new Sms("1234", "LOOP DISABLE");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertFalse(sms.ignored); Assert.assertFalse(sms.ignored);
Assert.assertEquals("LOOP DISABLE", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("LOOP DISABLE", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Loop is disabled", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Loop is disabled", smsCommunicatorPlugin.getMessages().get(1).text);
//LOOP DISABLE : from enabled //LOOP DISABLE : from enabled
hasBeenRun = false; hasBeenRun = false;
@ -185,22 +186,22 @@ public class SmsCommunicatorPluginTest {
hasBeenRun = true; hasBeenRun = true;
return null; return null;
}).when(loopPlugin).setPluginEnabled(PluginType.LOOP, false); }).when(loopPlugin).setPluginEnabled(PluginType.LOOP, false);
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "LOOP DISABLE"); sms = new Sms("1234", "LOOP DISABLE");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertFalse(sms.ignored); Assert.assertFalse(sms.ignored);
Assert.assertEquals("LOOP DISABLE", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("LOOP DISABLE", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Loop has been disabled Temp basal canceled", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Loop has been disabled Temp basal canceled", smsCommunicatorPlugin.getMessages().get(1).text);
Assert.assertTrue(hasBeenRun); Assert.assertTrue(hasBeenRun);
//LOOP ENABLE : already enabled //LOOP ENABLE : already enabled
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "LOOP ENABLE"); sms = new Sms("1234", "LOOP ENABLE");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertFalse(sms.ignored); Assert.assertFalse(sms.ignored);
Assert.assertEquals("LOOP ENABLE", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("LOOP ENABLE", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Loop is enabled", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Loop is enabled", smsCommunicatorPlugin.getMessages().get(1).text);
//LOOP ENABLE : from disabled //LOOP ENABLE : from disabled
hasBeenRun = false; hasBeenRun = false;
@ -209,142 +210,142 @@ public class SmsCommunicatorPluginTest {
hasBeenRun = true; hasBeenRun = true;
return null; return null;
}).when(loopPlugin).setPluginEnabled(PluginType.LOOP, true); }).when(loopPlugin).setPluginEnabled(PluginType.LOOP, true);
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "LOOP ENABLE"); sms = new Sms("1234", "LOOP ENABLE");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertFalse(sms.ignored); Assert.assertFalse(sms.ignored);
Assert.assertEquals("LOOP ENABLE", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("LOOP ENABLE", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Loop has been enabled", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Loop has been enabled", smsCommunicatorPlugin.getMessages().get(1).text);
Assert.assertTrue(hasBeenRun); Assert.assertTrue(hasBeenRun);
//LOOP RESUME : already enabled //LOOP RESUME : already enabled
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "LOOP RESUME"); sms = new Sms("1234", "LOOP RESUME");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertFalse(sms.ignored); Assert.assertFalse(sms.ignored);
Assert.assertEquals("LOOP RESUME", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("LOOP RESUME", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Loop resumed", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Loop resumed", smsCommunicatorPlugin.getMessages().get(1).text);
//LOOP SUSPEND 1 2: wrong format //LOOP SUSPEND 1 2: wrong format
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "LOOP SUSPEND 1 2"); sms = new Sms("1234", "LOOP SUSPEND 1 2");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertFalse(sms.ignored); Assert.assertFalse(sms.ignored);
Assert.assertEquals("LOOP SUSPEND 1 2", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("LOOP SUSPEND 1 2", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
//LOOP SUSPEND 0 : wrong duration //LOOP SUSPEND 0 : wrong duration
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "LOOP SUSPEND 0"); sms = new Sms("1234", "LOOP SUSPEND 0");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertFalse(sms.ignored); Assert.assertFalse(sms.ignored);
Assert.assertEquals("LOOP SUSPEND 0", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("LOOP SUSPEND 0", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong duration", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong duration", smsCommunicatorPlugin.getMessages().get(1).text);
//LOOP SUSPEND 100 : suspend for 100 min + correct answer //LOOP SUSPEND 100 : suspend for 100 min + correct answer
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "LOOP SUSPEND 100"); sms = new Sms("1234", "LOOP SUSPEND 100");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertFalse(sms.ignored); Assert.assertFalse(sms.ignored);
Assert.assertEquals("LOOP SUSPEND 100", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("LOOP SUSPEND 100", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("To suspend loop for 100 minutes reply with code ")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To suspend loop for 100 minutes reply with code "));
String passCode = smsCommunicatorPlugin.messageToConfirm.confirmCode; String passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode;
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages.get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text);
Assert.assertEquals("Loop suspended Temp basal canceled", smsCommunicatorPlugin.messages.get(3).text); Assert.assertEquals("Loop suspended Temp basal canceled", smsCommunicatorPlugin.getMessages().get(3).text);
//LOOP SUSPEND 200 : limit to 180 min + wrong answer //LOOP SUSPEND 200 : limit to 180 min + wrong answer
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "LOOP SUSPEND 200"); sms = new Sms("1234", "LOOP SUSPEND 200");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertFalse(sms.ignored); Assert.assertFalse(sms.ignored);
Assert.assertEquals("LOOP SUSPEND 200", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("LOOP SUSPEND 200", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("To suspend loop for 180 minutes reply with code ")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To suspend loop for 180 minutes reply with code "));
passCode = smsCommunicatorPlugin.messageToConfirm.confirmCode; passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode;
// ignore from other number // ignore from other number
smsCommunicatorPlugin.processSms(new Sms("5678", passCode)); smsCommunicatorPlugin.processSms(new Sms("5678", passCode));
smsCommunicatorPlugin.processSms(new Sms("1234", "XXXX")); smsCommunicatorPlugin.processSms(new Sms("1234", "XXXX"));
Assert.assertEquals("XXXX", smsCommunicatorPlugin.messages.get(3).text); Assert.assertEquals("XXXX", smsCommunicatorPlugin.getMessages().get(3).text);
Assert.assertEquals("Wrong code. Command cancelled.", smsCommunicatorPlugin.messages.get(4).text); Assert.assertEquals("Wrong code. Command cancelled.", smsCommunicatorPlugin.getMessages().get(4).text);
//then correct code should not work //then correct code should not work
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages.get(5).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(5).text);
Assert.assertEquals(6, smsCommunicatorPlugin.messages.size()); // processed as common message Assert.assertEquals(6, smsCommunicatorPlugin.getMessages().size()); // processed as common message
//LOOP BLABLA //LOOP BLABLA
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "LOOP BLABLA"); sms = new Sms("1234", "LOOP BLABLA");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertFalse(sms.ignored); Assert.assertFalse(sms.ignored);
Assert.assertEquals("LOOP BLABLA", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("LOOP BLABLA", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
//TREATMENTS REFRESH //TREATMENTS REFRESH
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
when(loopPlugin.isSuspended()).thenReturn(false); when(loopPlugin.isSuspended()).thenReturn(false);
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "TREATMENTS REFRESH"); sms = new Sms("1234", "TREATMENTS REFRESH");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertFalse(sms.ignored); Assert.assertFalse(sms.ignored);
Assert.assertEquals("TREATMENTS REFRESH", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("TREATMENTS REFRESH", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("TREATMENTS REFRESH")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("TREATMENTS REFRESH"));
//TREATMENTS BLA BLA //TREATMENTS BLA BLA
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
when(loopPlugin.isSuspended()).thenReturn(false); when(loopPlugin.isSuspended()).thenReturn(false);
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "TREATMENTS BLA BLA"); sms = new Sms("1234", "TREATMENTS BLA BLA");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertFalse(sms.ignored); Assert.assertFalse(sms.ignored);
Assert.assertEquals("TREATMENTS BLA BLA", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("TREATMENTS BLA BLA", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
//TREATMENTS BLABLA //TREATMENTS BLABLA
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
when(loopPlugin.isSuspended()).thenReturn(false); when(loopPlugin.isSuspended()).thenReturn(false);
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "TREATMENTS BLABLA"); sms = new Sms("1234", "TREATMENTS BLABLA");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertFalse(sms.ignored); Assert.assertFalse(sms.ignored);
Assert.assertEquals("TREATMENTS BLABLA", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("TREATMENTS BLABLA", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
//NSCLIENT RESTART //NSCLIENT RESTART
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
when(loopPlugin.isSuspended()).thenReturn(false); when(loopPlugin.isSuspended()).thenReturn(false);
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "NSCLIENT RESTART"); sms = new Sms("1234", "NSCLIENT RESTART");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertFalse(sms.ignored); Assert.assertFalse(sms.ignored);
Assert.assertEquals("NSCLIENT RESTART", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("NSCLIENT RESTART", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("NSCLIENT RESTART")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("NSCLIENT RESTART"));
//NSCLIENT BLA BLA //NSCLIENT BLA BLA
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
when(loopPlugin.isSuspended()).thenReturn(false); when(loopPlugin.isSuspended()).thenReturn(false);
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "NSCLIENT BLA BLA"); sms = new Sms("1234", "NSCLIENT BLA BLA");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertFalse(sms.ignored); Assert.assertFalse(sms.ignored);
Assert.assertEquals("NSCLIENT BLA BLA", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("NSCLIENT BLA BLA", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
//NSCLIENT BLABLA //NSCLIENT BLABLA
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
when(loopPlugin.isSuspended()).thenReturn(false); when(loopPlugin.isSuspended()).thenReturn(false);
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "NSCLIENT BLABLA"); sms = new Sms("1234", "NSCLIENT BLABLA");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertFalse(sms.ignored); Assert.assertFalse(sms.ignored);
Assert.assertEquals("NSCLIENT BLABLA", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("NSCLIENT BLABLA", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
//PUMP //PUMP
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "PUMP"); sms = new Sms("1234", "PUMP");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("PUMP", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("PUMP", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Virtual Pump", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Virtual Pump", smsCommunicatorPlugin.getMessages().get(1).text);
} }
@ -353,92 +354,92 @@ public class SmsCommunicatorPluginTest {
Sms sms; Sms sms;
//PROFILE //PROFILE
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "PROFILE"); sms = new Sms("1234", "PROFILE");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("PROFILE", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("PROFILE", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).text);
when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true); when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true);
//PROFILE //PROFILE
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "PROFILE"); sms = new Sms("1234", "PROFILE");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("PROFILE", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("PROFILE", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
//PROFILE LIST (no profile interface) //PROFILE LIST (no profile interface)
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "PROFILE LIST"); sms = new Sms("1234", "PROFILE LIST");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("PROFILE LIST", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("PROFILE LIST", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Not configured", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Not configured", smsCommunicatorPlugin.getMessages().get(1).text);
ProfileInterface profileInterface = mock(SimpleProfilePlugin.class); ProfileInterface profileInterface = mock(SimpleProfilePlugin.class);
when(ConfigBuilderPlugin.getPlugin().getActiveProfileInterface()).thenReturn(profileInterface); when(ConfigBuilderPlugin.getPlugin().getActiveProfileInterface()).thenReturn(profileInterface);
//PROFILE LIST (no profile defined) //PROFILE LIST (no profile defined)
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "PROFILE LIST"); sms = new Sms("1234", "PROFILE LIST");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("PROFILE LIST", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("PROFILE LIST", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Not configured", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Not configured", smsCommunicatorPlugin.getMessages().get(1).text);
when(profileInterface.getProfile()).thenReturn(AAPSMocker.getValidProfileStore()); when(profileInterface.getProfile()).thenReturn(AAPSMocker.getValidProfileStore());
//PROFILE STATUS //PROFILE STATUS
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "PROFILE STATUS"); sms = new Sms("1234", "PROFILE STATUS");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("PROFILE STATUS", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("PROFILE STATUS", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals(AAPSMocker.TESTPROFILENAME, smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals(AAPSMocker.TESTPROFILENAME, smsCommunicatorPlugin.getMessages().get(1).text);
//PROFILE LIST //PROFILE LIST
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "PROFILE LIST"); sms = new Sms("1234", "PROFILE LIST");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("PROFILE LIST", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("PROFILE LIST", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("1. " + AAPSMocker.TESTPROFILENAME, smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("1. " + AAPSMocker.TESTPROFILENAME, smsCommunicatorPlugin.getMessages().get(1).text);
//PROFILE 2 (non existing) //PROFILE 2 (non existing)
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "PROFILE 2"); sms = new Sms("1234", "PROFILE 2");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("PROFILE 2", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("PROFILE 2", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
//PROFILE 1 0(wrong percentage) //PROFILE 1 0(wrong percentage)
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "PROFILE 1 0"); sms = new Sms("1234", "PROFILE 1 0");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("PROFILE 1 0", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("PROFILE 1 0", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
//PROFILE 0(wrong index) //PROFILE 0(wrong index)
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "PROFILE 0"); sms = new Sms("1234", "PROFILE 0");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("PROFILE 0", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("PROFILE 0", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
//PROFILE 1(OK) //PROFILE 1(OK)
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "PROFILE 1"); sms = new Sms("1234", "PROFILE 1");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("PROFILE 1", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("PROFILE 1", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("To switch profile to someProfile 100% reply with code")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To switch profile to someProfile 100% reply with code"));
//PROFILE 1 90(OK) //PROFILE 1 90(OK)
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "PROFILE 1 90"); sms = new Sms("1234", "PROFILE 1 90");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("PROFILE 1 90", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("PROFILE 1 90", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("To switch profile to someProfile 90% reply with code")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To switch profile to someProfile 90% reply with code"));
String passCode = smsCommunicatorPlugin.messageToConfirm.confirmCode; String passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode;
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages.get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text);
Assert.assertEquals("Profile switch created", smsCommunicatorPlugin.messages.get(3).text); Assert.assertEquals("Profile switch created", smsCommunicatorPlugin.getMessages().get(3).text);
} }
@Test @Test
@ -446,85 +447,85 @@ public class SmsCommunicatorPluginTest {
Sms sms; Sms sms;
//BASAL //BASAL
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "BASAL"); sms = new Sms("1234", "BASAL");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("BASAL", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("BASAL", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).text);
when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true); when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true);
//BASAL //BASAL
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "BASAL"); sms = new Sms("1234", "BASAL");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("BASAL", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("BASAL", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
//BASAL CANCEL //BASAL CANCEL
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "BASAL CANCEL"); sms = new Sms("1234", "BASAL CANCEL");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("BASAL CANCEL", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("BASAL CANCEL", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("To stop temp basal reply with code")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To stop temp basal reply with code"));
String passCode = smsCommunicatorPlugin.messageToConfirm.confirmCode; String passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode;
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages.get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text);
Assert.assertEquals("Temp basal canceled\nVirtual Pump", smsCommunicatorPlugin.messages.get(3).text); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.contains("Temp basal canceled"));
//BASAL a% //BASAL a%
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "BASAL a%"); sms = new Sms("1234", "BASAL a%");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("BASAL a%", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("BASAL a%", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
//BASAL 10% 0 //BASAL 10% 0
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "BASAL 10% 0"); sms = new Sms("1234", "BASAL 10% 0");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("BASAL 10% 0", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("BASAL 10% 0", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
when(MainApp.getConstraintChecker().applyBasalPercentConstraints(any(), any())).thenReturn(new Constraint<>(20)); when(MainApp.getConstraintChecker().applyBasalPercentConstraints(any(), any())).thenReturn(new Constraint<>(20));
//BASAL 20% 20 //BASAL 20% 20
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "BASAL 20% 20"); sms = new Sms("1234", "BASAL 20% 20");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("BASAL 20% 20", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("BASAL 20% 20", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("To start basal 20% for 20 min reply with code")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To start basal 20% for 20 min reply with code"));
passCode = smsCommunicatorPlugin.messageToConfirm.confirmCode; passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode;
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages.get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text);
Assert.assertEquals("Temp basal 20% for 20 min started successfully\nVirtual Pump", smsCommunicatorPlugin.messages.get(3).text); Assert.assertEquals("Temp basal 20% for 20 min started successfully\nVirtual Pump", smsCommunicatorPlugin.getMessages().get(3).text);
//BASAL a //BASAL a
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "BASAL a"); sms = new Sms("1234", "BASAL a");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("BASAL a", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("BASAL a", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
//BASAL 1 0 //BASAL 1 0
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "BASAL 1 0"); sms = new Sms("1234", "BASAL 1 0");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("BASAL 1 0", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("BASAL 1 0", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
when(MainApp.getConstraintChecker().applyBasalConstraints(any(), any())).thenReturn(new Constraint<>(1d)); when(MainApp.getConstraintChecker().applyBasalConstraints(any(), any())).thenReturn(new Constraint<>(1d));
//BASAL 1 20 //BASAL 1 20
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "BASAL 1 20"); sms = new Sms("1234", "BASAL 1 20");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("BASAL 1 20", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("BASAL 1 20", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("To start basal 1.00U/h for 20 min reply with code")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To start basal 1.00U/h for 20 min reply with code"));
passCode = smsCommunicatorPlugin.messageToConfirm.confirmCode; passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode;
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages.get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text);
Assert.assertEquals("Temp basal 1.00U/h for 20 min started successfully\nVirtual Pump", smsCommunicatorPlugin.messages.get(3).text); Assert.assertEquals("Temp basal 1.00U/h for 20 min started successfully\nVirtual Pump", smsCommunicatorPlugin.getMessages().get(3).text);
} }
@ -533,58 +534,58 @@ public class SmsCommunicatorPluginTest {
Sms sms; Sms sms;
//EXTENDED //EXTENDED
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "EXTENDED"); sms = new Sms("1234", "EXTENDED");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("EXTENDED", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("EXTENDED", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).text);
when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true); when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true);
//EXTENDED //EXTENDED
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "EXTENDED"); sms = new Sms("1234", "EXTENDED");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("EXTENDED", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("EXTENDED", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
//EXTENDED CANCEL //EXTENDED CANCEL
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "EXTENDED CANCEL"); sms = new Sms("1234", "EXTENDED CANCEL");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("EXTENDED CANCEL", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("EXTENDED CANCEL", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("To stop extended bolus reply with code")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To stop extended bolus reply with code"));
String passCode = smsCommunicatorPlugin.messageToConfirm.confirmCode; String passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode;
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages.get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text);
Assert.assertEquals("Extended bolus canceled\nVirtual Pump", smsCommunicatorPlugin.messages.get(3).text); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.contains("Extended bolus canceled"));
//EXTENDED a% //EXTENDED a%
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "EXTENDED a%"); sms = new Sms("1234", "EXTENDED a%");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("EXTENDED a%", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("EXTENDED a%", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
when(MainApp.getConstraintChecker().applyExtendedBolusConstraints(any())).thenReturn(new Constraint<>(1d)); when(MainApp.getConstraintChecker().applyExtendedBolusConstraints(any())).thenReturn(new Constraint<>(1d));
//EXTENDED 1 0 //EXTENDED 1 0
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "EXTENDED 1 0"); sms = new Sms("1234", "EXTENDED 1 0");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("EXTENDED 1 0", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("EXTENDED 1 0", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
//EXTENDED 1 20 //EXTENDED 1 20
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "EXTENDED 1 20"); sms = new Sms("1234", "EXTENDED 1 20");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("EXTENDED 1 20", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("EXTENDED 1 20", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("To start extended bolus 1.00U for 20 min reply with code")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To start extended bolus 1.00U for 20 min reply with code"));
passCode = smsCommunicatorPlugin.messageToConfirm.confirmCode; passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode;
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages.get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text);
Assert.assertEquals("Extended bolus 1.00U for 20 min started successfully\nVirtual Pump", smsCommunicatorPlugin.messages.get(3).text); Assert.assertEquals("Extended bolus 1.00U for 20 min started successfully\nVirtual Pump", smsCommunicatorPlugin.getMessages().get(3).text);
} }
@Test @Test
@ -592,104 +593,91 @@ public class SmsCommunicatorPluginTest {
Sms sms; Sms sms;
//BOLUS //BOLUS
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "BOLUS"); sms = new Sms("1234", "BOLUS");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("BOLUS", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("BOLUS", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).text);
when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true); when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true);
//BOLUS //BOLUS
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "BOLUS"); sms = new Sms("1234", "BOLUS");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("BOLUS", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("BOLUS", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
when(MainApp.getConstraintChecker().applyBolusConstraints(any())).thenReturn(new Constraint<>(1d)); when(MainApp.getConstraintChecker().applyBolusConstraints(any())).thenReturn(new Constraint<>(1d));
when(DateUtil.now()).thenReturn(1000L); when(DateUtil.now()).thenReturn(1000L);
//BOLUS 1 //BOLUS 1
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "BOLUS 1"); sms = new Sms("1234", "BOLUS 1");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Remote bolus not available. Try again later.", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Remote bolus not available. Try again later.", smsCommunicatorPlugin.getMessages().get(1).text);
when(MainApp.getConstraintChecker().applyBolusConstraints(any())).thenReturn(new Constraint<>(0d)); when(MainApp.getConstraintChecker().applyBolusConstraints(any())).thenReturn(new Constraint<>(0d));
when(DateUtil.now()).thenReturn(Constants.remoteBolusMinDistance + 1002L); when(DateUtil.now()).thenReturn(Constants.remoteBolusMinDistance + 1002L);
//BOLUS 0 //BOLUS 0
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "BOLUS 0"); sms = new Sms("1234", "BOLUS 0");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("BOLUS 0", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("BOLUS 0", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
//BOLUS a //BOLUS a
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "BOLUS a"); sms = new Sms("1234", "BOLUS a");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("BOLUS a", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("BOLUS a", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
when(MainApp.getConstraintChecker().applyExtendedBolusConstraints(any())).thenReturn(new Constraint<>(1d)); when(MainApp.getConstraintChecker().applyExtendedBolusConstraints(any())).thenReturn(new Constraint<>(1d));
when(MainApp.getConstraintChecker().applyBolusConstraints(any())).thenReturn(new Constraint<>(1d)); when(MainApp.getConstraintChecker().applyBolusConstraints(any())).thenReturn(new Constraint<>(1d));
//BOLUS 1 //BOLUS 1
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "BOLUS 1"); sms = new Sms("1234", "BOLUS 1");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("To deliver bolus 1.00U reply with code")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To deliver bolus 1.00U reply with code"));
String passCode = smsCommunicatorPlugin.messageToConfirm.confirmCode; String passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode;
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages.get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text);
Assert.assertEquals("Bolus 1.00U delivered successfully\nVirtual Pump", smsCommunicatorPlugin.messages.get(3).text); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.contains("Bolus 1.00U delivered successfully"));
//BOLUS 1 (Suspended pump) //BOLUS 1 (Suspended pump)
smsCommunicatorPlugin.lastRemoteBolusTime = 0; smsCommunicatorPlugin.setLastRemoteBolusTime(0);
PumpInterface pump = mock(VirtualPumpPlugin.class); when(virtualPumpPlugin.isSuspended()).thenReturn(true);
when(ConfigBuilderPlugin.getPlugin().getActivePump()).thenReturn(pump); smsCommunicatorPlugin.setMessages(new ArrayList<>());
when(pump.isSuspended()).thenReturn(true);
smsCommunicatorPlugin.messages = new ArrayList<>();
sms = new Sms("1234", "BOLUS 1"); sms = new Sms("1234", "BOLUS 1");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Pump suspended", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Pump suspended", smsCommunicatorPlugin.getMessages().get(1).text);
when(pump.isSuspended()).thenReturn(false); when(virtualPumpPlugin.isSuspended()).thenReturn(false);
//BOLUS 1 a //BOLUS 1 a
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "BOLUS 1 a"); sms = new Sms("1234", "BOLUS 1 a");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("BOLUS 1 a", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("BOLUS 1 a", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
//BOLUS 1 MEAL //BOLUS 1 MEAL
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "BOLUS 1 MEAL"); sms = new Sms("1234", "BOLUS 1 MEAL");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("BOLUS 1 MEAL", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("BOLUS 1 MEAL", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("To deliver meal bolus 1.00U reply with code")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To deliver meal bolus 1.00U reply with code"));
passCode = smsCommunicatorPlugin.messageToConfirm.confirmCode; passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode;
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages.get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text);
Assert.assertEquals("Meal Bolus 1.00U delivered successfully\nVirtual Pump", smsCommunicatorPlugin.messages.get(3).text); Assert.assertEquals("Meal Bolus 1.00U delivered successfully\nVirtual Pump\nTarget 5.0 for 45 minutes", smsCommunicatorPlugin.getMessages().get(3).text);
//BOLUS 1 MEAL (Suspended pump)
smsCommunicatorPlugin.lastRemoteBolusTime = 0;
when(ConfigBuilderPlugin.getPlugin().getActivePump()).thenReturn(pump);
when(pump.isSuspended()).thenReturn(true);
smsCommunicatorPlugin.messages = new ArrayList<>();
sms = new Sms("1234", "BOLUS 1 MEAL");
smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("BOLUS 1 MEAL", smsCommunicatorPlugin.messages.get(0).text);
Assert.assertEquals("Pump suspended", smsCommunicatorPlugin.messages.get(1).text);
when(pump.isSuspended()).thenReturn(false);
} }
@Test @Test
@ -697,47 +685,47 @@ public class SmsCommunicatorPluginTest {
Sms sms; Sms sms;
//CAL //CAL
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "CAL"); sms = new Sms("1234", "CAL");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("CAL", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("CAL", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).text);
when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true); when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true);
//CAL //CAL
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "CAL"); sms = new Sms("1234", "CAL");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("CAL", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("CAL", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
//CAL 0 //CAL 0
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "CAL 0"); sms = new Sms("1234", "CAL 0");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("CAL 0", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("CAL 0", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text);
when(XdripCalibrations.sendIntent(any())).thenReturn(true); when(XdripCalibrations.sendIntent(any())).thenReturn(true);
//CAL 1 //CAL 1
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "CAL 1"); sms = new Sms("1234", "CAL 1");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("CAL 1", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("CAL 1", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("To send calibration 1.00 reply with code")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To send calibration 1.00 reply with code"));
String passCode = smsCommunicatorPlugin.messageToConfirm.confirmCode; String passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode;
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages.get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text);
Assert.assertEquals("Calibration sent. Receiving must be enabled in xDrip.", smsCommunicatorPlugin.messages.get(3).text); Assert.assertEquals("Calibration sent. Receiving must be enabled in xDrip.", smsCommunicatorPlugin.getMessages().get(3).text);
} }
@Test @Test
public void sendNotificationToAllNumbers() { public void sendNotificationToAllNumbers() {
smsCommunicatorPlugin.messages = new ArrayList<>(); smsCommunicatorPlugin.setMessages(new ArrayList<>());
smsCommunicatorPlugin.sendNotificationToAllNumbers("abc"); smsCommunicatorPlugin.sendNotificationToAllNumbers("abc");
Assert.assertEquals("abc", smsCommunicatorPlugin.messages.get(0).text); Assert.assertEquals("abc", smsCommunicatorPlugin.getMessages().get(0).text);
Assert.assertEquals("abc", smsCommunicatorPlugin.messages.get(1).text); Assert.assertEquals("abc", smsCommunicatorPlugin.getMessages().get(1).text);
} }
@Before @Before
@ -826,8 +814,10 @@ public class SmsCommunicatorPluginTest {
return null; return null;
}).when(AAPSMocker.queue).extendedBolus(anyDouble(), anyInt(), any(Callback.class)); }).when(AAPSMocker.queue).extendedBolus(anyDouble(), anyInt(), any(Callback.class));
VirtualPumpPlugin virtualPumpPlugin = VirtualPumpPlugin.getPlugin(); virtualPumpPlugin = mock(VirtualPumpPlugin.class);
when(ConfigBuilderPlugin.getPlugin().getActivePump()).thenReturn(virtualPumpPlugin); when(ConfigBuilderPlugin.getPlugin().getActivePump()).thenReturn(virtualPumpPlugin);
when(virtualPumpPlugin.shortStatus(anyBoolean())).thenReturn("Virtual Pump");
when(virtualPumpPlugin.isSuspended()).thenReturn(false);
} }
} }