some cleanup and kotlin conversion

This commit is contained in:
Milos Kozak 2019-11-25 18:07:16 +01:00
parent 1ea25b68a8
commit c33e3994b6
12 changed files with 430 additions and 419 deletions

View file

@ -105,7 +105,7 @@ object ObjectivesPlugin : PluginBase(PluginDescription()
val requestCode = SP.getString(R.string.key_objectives_request_code, "") val requestCode = SP.getString(R.string.key_objectives_request_code, "")
var url = SP.getString(R.string.key_nsclientinternal_url, "").toLowerCase() var url = SP.getString(R.string.key_nsclientinternal_url, "").toLowerCase()
if (!url.endsWith("\"")) url = "$url/" if (!url.endsWith("\"")) url = "$url/"
val hashNS = Hashing.sha1().hashString(url + BuildConfig.APPLICATION_ID + "/" + requestCode, Charsets.UTF_8).toString() @Suppress("DEPRECATION") val hashNS = Hashing.sha1().hashString(url + BuildConfig.APPLICATION_ID + "/" + requestCode, Charsets.UTF_8).toString()
if (request.equals(hashNS.substring(0, 10), ignoreCase = true)) { if (request.equals(hashNS.substring(0, 10), ignoreCase = true)) {
SP.putLong("Objectives_" + "openloop" + "_started", DateUtil.now()) SP.putLong("Objectives_" + "openloop" + "_started", DateUtil.now())
SP.putLong("Objectives_" + "openloop" + "_accomplished", DateUtil.now()) SP.putLong("Objectives_" + "openloop" + "_accomplished", DateUtil.now())

View file

@ -1,60 +0,0 @@
package info.nightscout.androidaps.plugins.general.smsCommunicator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.utils.DateUtil;
public class AuthRequest {
private static Logger log = LoggerFactory.getLogger(L.SMS);
Sms requester;
String confirmCode;
private Runnable action;
private long date;
private boolean processed;
private SmsCommunicatorPlugin plugin;
AuthRequest(SmsCommunicatorPlugin plugin, Sms requester, String requestText, String confirmCode, SmsAction action) {
this.requester = requester;
this.confirmCode = confirmCode;
this.action = action;
this.plugin = plugin;
this.date = DateUtil.now();
plugin.sendSMS(new Sms(requester.phoneNumber, requestText));
}
void action(String codeReceived) {
if (processed) {
if (L.isEnabled(L.SMS))
log.debug("Already processed");
return;
}
//if (false) { //F. Casellato - I test SMS with master phone that sends commands to itself. I found only this way to di this...
if (!confirmCode.equals(codeReceived)) {
processed = true;
if (L.isEnabled(L.SMS))
log.debug("Wrong code");
plugin.sendSMS(new Sms(requester.phoneNumber, R.string.sms_wrongcode));
return;
}
if (DateUtil.now() - date < Constants.SMS_CONFIRM_TIMEOUT) {
processed = true;
if (L.isEnabled(L.SMS))
log.debug("Processing confirmed SMS: " + requester.text);
if (action != null)
action.run();
return;
}
if (L.isEnabled(L.SMS))
log.debug("Timed out SMS: " + requester.text);
}
}

View file

@ -0,0 +1,38 @@
package info.nightscout.androidaps.plugins.general.smsCommunicator
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R
import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.utils.DateUtil
import org.slf4j.LoggerFactory
class AuthRequest internal constructor(val plugin: SmsCommunicatorPlugin, var requester: Sms, requestText: String, var confirmCode: String, val action: SmsAction) {
private val log = LoggerFactory.getLogger(L.SMS)
private val date = DateUtil.now()
private var processed = false
init {
plugin.sendSMS(Sms(requester.phoneNumber, requestText))
}
fun action(codeReceived: String) {
if (processed) {
if (L.isEnabled(L.SMS)) log.debug("Already processed")
return
}
if (confirmCode != codeReceived) {
processed = true
if (L.isEnabled(L.SMS)) log.debug("Wrong code")
plugin.sendSMS(Sms(requester.phoneNumber, R.string.sms_wrongcode))
return
}
if (DateUtil.now() - date < Constants.SMS_CONFIRM_TIMEOUT) {
processed = true
if (L.isEnabled(L.SMS)) log.debug("Processing confirmed SMS: " + requester.text)
action.run()
return
}
if (L.isEnabled(L.SMS)) log.debug("Timed out SMS: " + requester.text)
}
}

View file

@ -1,42 +0,0 @@
package info.nightscout.androidaps.plugins.general.smsCommunicator;
import android.telephony.SmsMessage;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.utils.DateUtil;
public class Sms {
String phoneNumber;
String text;
long date;
boolean received = false;
boolean sent = false;
boolean processed = false;
boolean ignored = false;
Sms(SmsMessage message) {
phoneNumber = message.getOriginatingAddress();
text = message.getMessageBody();
date = message.getTimestampMillis();
received = true;
}
Sms(String phoneNumber, String text) {
this.phoneNumber = phoneNumber;
this.text = text;
this.date = DateUtil.now();
sent = true;
}
Sms(String phoneNumber, int textId) {
this.phoneNumber = phoneNumber;
this.text = MainApp.gs(textId);
this.date = DateUtil.now();
sent = true;
}
public String toString() {
return "SMS from " + phoneNumber + ": " + text;
}
}

View file

@ -0,0 +1,40 @@
package info.nightscout.androidaps.plugins.general.smsCommunicator
import android.telephony.SmsMessage
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.utils.DateUtil
class Sms {
var phoneNumber: String
var text: String
var date: Long
var received = false
var sent = false
var processed = false
var ignored = false
internal constructor(message: SmsMessage) {
phoneNumber = message.originatingAddress ?: ""
text = message.messageBody
date = message.timestampMillis
received = true
}
internal constructor(phoneNumber: String, text: String) {
this.phoneNumber = phoneNumber
this.text = text
date = DateUtil.now()
sent = true
}
internal constructor(phoneNumber: String, textId: Int) {
this.phoneNumber = phoneNumber
text = MainApp.gs(textId)
date = DateUtil.now()
sent = true
}
override fun toString(): String {
return "SMS from $phoneNumber: $text"
}
}

View file

@ -1,38 +0,0 @@
package info.nightscout.androidaps.plugins.general.smsCommunicator;
abstract class SmsAction implements Runnable {
Double aDouble;
Integer anInteger;
Integer secondInteger;
Long secondLong;
String aString;
SmsAction() {}
SmsAction(Double aDouble) {
this.aDouble = aDouble;
}
SmsAction(Double aDouble, Integer secondInteger) {
this.aDouble = aDouble;
this.secondInteger = secondInteger;
}
SmsAction(String aString, Integer secondInteger) {
this.aString = aString;
this.secondInteger = secondInteger;
}
SmsAction(Integer anInteger) {
this.anInteger = anInteger;
}
SmsAction(Integer anInteger, Integer secondInteger) {
this.anInteger = anInteger;
this.secondInteger = secondInteger;
}
SmsAction(Integer anInteger, Long secondLong) {
this.anInteger = anInteger;
this.secondLong = secondLong;
}
}

View file

@ -0,0 +1,68 @@
package info.nightscout.androidaps.plugins.general.smsCommunicator
abstract class SmsAction : Runnable {
var aDouble: Double? = null
var anInteger: Int? = null
var secondInteger: Int? = null
var secondLong: Long? = null
var aString: String? = null
internal constructor()
internal constructor(aDouble: Double) {
this.aDouble = aDouble
}
internal constructor(aDouble: Double, secondInteger: Int) {
this.aDouble = aDouble
this.secondInteger = secondInteger
}
internal constructor(aString: String, secondInteger: Int) {
this.aString = aString
this.secondInteger = secondInteger
}
internal constructor(anInteger: Int) {
this.anInteger = anInteger
}
internal constructor(anInteger: Int, secondInteger: Int) {
this.anInteger = anInteger
this.secondInteger = secondInteger
}
internal constructor(anInteger: Int, secondLong: Long) {
this.anInteger = anInteger
this.secondLong = secondLong
}
fun aDouble(): Double {
return aDouble?.let {
aDouble
} ?: throw IllegalStateException()
}
fun anInteger(): Int {
return anInteger?.let {
anInteger
} ?: throw IllegalStateException()
}
fun secondInteger(): Int {
return secondInteger?.let {
secondInteger
} ?: throw IllegalStateException()
}
fun secondLong(): Long {
return secondLong?.let {
secondLong
} ?: throw IllegalStateException()
}
fun aString(): String {
return aString?.let {
aString
} ?: throw IllegalStateException()
}
}

View file

@ -110,7 +110,7 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
distance.title = MainApp.gs(R.string.smscommunicator_remotebolusmindistance) distance.title = MainApp.gs(R.string.smscommunicator_remotebolusmindistance)
distance.isEnabled = true distance.isEnabled = true
} }
allowedNumbers.onPreferenceChangeListener = OnPreferenceChangeListener { preference: Preference?, newValue: Any -> allowedNumbers.onPreferenceChangeListener = OnPreferenceChangeListener { _: Preference?, newValue: Any ->
if (!areMoreNumbers(newValue as String)) { if (!areMoreNumbers(newValue as String)) {
distance.text = (Constants.remoteBolusMinDistance / (60 * 1000L)).toString() distance.text = (Constants.remoteBolusMinDistance / (60 * 1000L)).toString()
distance.title = (MainApp.gs(R.string.smscommunicator_remotebolusmindistance) distance.title = (MainApp.gs(R.string.smscommunicator_remotebolusmindistance)
@ -344,8 +344,8 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
ConfigBuilderPlugin.getPlugin().commandQueue.cancelTempBasal(true, object : Callback() { ConfigBuilderPlugin.getPlugin().commandQueue.cancelTempBasal(true, object : Callback() {
override fun run() { override fun run() {
if (result.success) { if (result.success) {
LoopPlugin.getPlugin().suspendTo(System.currentTimeMillis() + anInteger * 60L * 1000) LoopPlugin.getPlugin().suspendTo(System.currentTimeMillis() + anInteger() * 60L * 1000)
NSUpload.uploadOpenAPSOffline(anInteger * 60.toDouble()) NSUpload.uploadOpenAPSOffline(anInteger() * 60.toDouble())
send(EventRefreshOverview("SMS_LOOP_SUSPENDED")) send(EventRefreshOverview("SMS_LOOP_SUSPENDED"))
val replyText = MainApp.gs(R.string.smscommunicator_loopsuspended) + " " + val replyText = MainApp.gs(R.string.smscommunicator_loopsuspended) + " " +
MainApp.gs(if (result.success) R.string.smscommunicator_tempbasalcanceled else R.string.smscommunicator_tempbasalcancelfailed) MainApp.gs(if (result.success) R.string.smscommunicator_tempbasalcanceled else R.string.smscommunicator_tempbasalcancelfailed)
@ -389,8 +389,10 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
sendSMS(Sms(receivedSms.phoneNumber, commands.keys.toString().replace("[", "").replace("]", ""))) sendSMS(Sms(receivedSms.phoneNumber, commands.keys.toString().replace("[", "").replace("]", "")))
receivedSms.processed = true receivedSms.processed = true
} else if (isCommand(splitted[1].toUpperCase(Locale.getDefault()), receivedSms.phoneNumber)) { } else if (isCommand(splitted[1].toUpperCase(Locale.getDefault()), receivedSms.phoneNumber)) {
sendSMS(Sms(receivedSms.phoneNumber, commands[splitted[1].toUpperCase(Locale.getDefault())])) commands[splitted[1].toUpperCase(Locale.getDefault())]?.let {
sendSMS(Sms(receivedSms.phoneNumber, it))
receivedSms.processed = true receivedSms.processed = true
}
} else } else
sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat)) sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
} }
@ -504,7 +506,7 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
receivedSms.processed = true receivedSms.processed = true
messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction(tempBasalPct, duration) { messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction(tempBasalPct, duration) {
override fun run() { override fun run() {
ConfigBuilderPlugin.getPlugin().commandQueue.tempBasalPercent(anInteger, secondInteger, true, profile, object : Callback() { ConfigBuilderPlugin.getPlugin().commandQueue.tempBasalPercent(anInteger(), secondInteger(), true, profile, object : Callback() {
override fun run() { override fun run() {
if (result.success) { if (result.success) {
var replyText: String var replyText: String
@ -536,7 +538,7 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
receivedSms.processed = true receivedSms.processed = true
messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction(tempBasal, duration) { messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction(tempBasal, duration) {
override fun run() { override fun run() {
ConfigBuilderPlugin.getPlugin().commandQueue.tempBasalAbsolute(aDouble, secondInteger, true, profile, object : Callback() { ConfigBuilderPlugin.getPlugin().commandQueue.tempBasalAbsolute(aDouble(), secondInteger(), true, profile, object : Callback() {
override fun run() { override fun run() {
if (result.success) { if (result.success) {
var replyText = if (result.isPercent) String.format(MainApp.gs(R.string.smscommunicator_tempbasalset_percent), result.percent, result.duration) var replyText = if (result.isPercent) String.format(MainApp.gs(R.string.smscommunicator_tempbasalset_percent), result.percent, result.duration)
@ -591,7 +593,7 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
receivedSms.processed = true receivedSms.processed = true
messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction(extended, duration) { messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction(extended, duration) {
override fun run() { override fun run() {
ConfigBuilderPlugin.getPlugin().commandQueue.extendedBolus(aDouble, secondInteger, object : Callback() { ConfigBuilderPlugin.getPlugin().commandQueue.extendedBolus(aDouble(), secondInteger(), object : Callback() {
override fun run() { override fun run() {
if (result.success) { if (result.success) {
var replyText = String.format(MainApp.gs(R.string.smscommunicator_extendedset), aDouble, duration) var replyText = String.format(MainApp.gs(R.string.smscommunicator_extendedset), aDouble, duration)
@ -626,7 +628,7 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction(bolus) { messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction(bolus) {
override fun run() { override fun run() {
val detailedBolusInfo = DetailedBolusInfo() val detailedBolusInfo = DetailedBolusInfo()
detailedBolusInfo.insulin = aDouble detailedBolusInfo.insulin = aDouble()
detailedBolusInfo.source = Source.USER detailedBolusInfo.source = Source.USER
ConfigBuilderPlugin.getPlugin().commandQueue.bolus(detailedBolusInfo, object : Callback() { ConfigBuilderPlugin.getPlugin().commandQueue.bolus(detailedBolusInfo, object : Callback() {
override fun run() { override fun run() {
@ -702,8 +704,8 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction(grams, time) { messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction(grams, time) {
override fun run() { override fun run() {
val detailedBolusInfo = DetailedBolusInfo() val detailedBolusInfo = DetailedBolusInfo()
detailedBolusInfo.carbs = anInteger.toDouble() detailedBolusInfo.carbs = anInteger().toDouble()
detailedBolusInfo.date = secondLong detailedBolusInfo.date = secondLong()
ConfigBuilderPlugin.getPlugin().commandQueue.bolus(detailedBolusInfo, object : Callback() { ConfigBuilderPlugin.getPlugin().commandQueue.bolus(detailedBolusInfo, object : Callback() {
override fun run() { override fun run() {
if (result.success) { if (result.success) {
@ -837,7 +839,7 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
} else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat)) } else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat))
} }
fun sendNotificationToAllNumbers(text: String?): Boolean { fun sendNotificationToAllNumbers(text: String): Boolean {
var result = true var result = true
for (i in allowedNumbers.indices) { for (i in allowedNumbers.indices) {
val sms = Sms(allowedNumbers[i], text) val sms = Sms(allowedNumbers[i], text)
@ -902,16 +904,19 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription()
return s return s
} }
fun areMoreNumbers(allowednumbers: String): Boolean { fun areMoreNumbers(allowednumbers: String?): Boolean {
return allowednumbers?.let {
var countNumbers = 0 var countNumbers = 0
val substrings = allowednumbers.split(";").toTypedArray() val substrings = it.split(";").toTypedArray()
for (number in substrings) { for (number in substrings) {
var cleaned = number.replace(Regex("\\s+"), "") var cleaned = number.replace(Regex("\\s+"), "")
if (cleaned.length < 4) continue if (cleaned.length < 4) continue
cleaned = cleaned.replace("+", "") cleaned = cleaned.replace("+", "")
cleaned = cleaned.replace("-", "")
if (!cleaned.matches(Regex("[0-9]+"))) continue if (!cleaned.matches(Regex("[0-9]+"))) continue
countNumbers++ countNumbers++
} }
return countNumbers > 1 countNumbers > 1
} ?: false
} }
} }

View file

@ -43,14 +43,14 @@ public class AuthRequestTest {
// Check if SMS requesting code is sent // Check if SMS requesting code is sent
AuthRequest authRequest = new AuthRequest(smsCommunicatorPlugin, requester, "Request text", "ABC", action); AuthRequest authRequest = new AuthRequest(smsCommunicatorPlugin, requester, "Request text", "ABC", action);
Assert.assertEquals(sentSms.phoneNumber, "aNumber"); Assert.assertEquals(sentSms.getPhoneNumber(), "aNumber");
Assert.assertEquals(sentSms.text, "Request text"); Assert.assertEquals(sentSms.getText(), "Request text");
// wrong reply // wrong reply
actionCalled = false; actionCalled = false;
authRequest.action("EFG"); authRequest.action("EFG");
Assert.assertEquals(sentSms.phoneNumber, "aNumber"); Assert.assertEquals(sentSms.getPhoneNumber(), "aNumber");
Assert.assertEquals(sentSms.text, "Wrong code. Command cancelled."); Assert.assertEquals(sentSms.getText(), "Wrong code. Command cancelled.");
Assert.assertFalse(actionCalled); Assert.assertFalse(actionCalled);
// correct reply // correct reply

View file

@ -41,7 +41,7 @@ public class SmsActionTest {
}; };
smsAction.run(); smsAction.run();
Assert.assertEquals(result, "B"); Assert.assertEquals(result, "B");
Assert.assertEquals(smsAction.aDouble, 1d, 0.000001d); Assert.assertEquals(smsAction.aDouble(), 1d, 0.000001d);
smsAction = new SmsAction(1d, 2) { smsAction = new SmsAction(1d, 2) {
@Override @Override
@ -51,8 +51,8 @@ public class SmsActionTest {
}; };
smsAction.run(); smsAction.run();
Assert.assertEquals(result, "C"); Assert.assertEquals(result, "C");
Assert.assertEquals(smsAction.aDouble, 1d, 0.000001d); Assert.assertEquals(smsAction.aDouble(), 1d, 0.000001d);
Assert.assertEquals(smsAction.secondInteger.intValue(), 2); Assert.assertEquals(smsAction.secondInteger(), 2);
smsAction = new SmsAction("aString", 3) { smsAction = new SmsAction("aString", 3) {
@Override @Override
@ -62,8 +62,8 @@ public class SmsActionTest {
}; };
smsAction.run(); smsAction.run();
Assert.assertEquals(result, "D"); Assert.assertEquals(result, "D");
Assert.assertEquals(smsAction.aString, "aString"); Assert.assertEquals(smsAction.aString(), "aString");
Assert.assertEquals(smsAction.secondInteger.intValue(), 3); Assert.assertEquals(smsAction.secondInteger(), 3);
smsAction = new SmsAction(4) { smsAction = new SmsAction(4) {
@Override @Override
@ -73,7 +73,7 @@ public class SmsActionTest {
}; };
smsAction.run(); smsAction.run();
Assert.assertEquals(result, "E"); Assert.assertEquals(result, "E");
Assert.assertEquals(smsAction.anInteger.intValue(), 4); Assert.assertEquals(smsAction.anInteger(), 4);
smsAction = new SmsAction(5, 6) { smsAction = new SmsAction(5, 6) {
@Override @Override
@ -83,8 +83,8 @@ public class SmsActionTest {
}; };
smsAction.run(); smsAction.run();
Assert.assertEquals(result, "F"); Assert.assertEquals(result, "F");
Assert.assertEquals(smsAction.anInteger.intValue(), 5); Assert.assertEquals(smsAction.anInteger(), 5);
Assert.assertEquals(smsAction.secondInteger.intValue(), 6); Assert.assertEquals(smsAction.secondInteger(), 6);
} }
} }

View file

@ -106,32 +106,32 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getIgnored());
Assert.assertEquals("aText", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("aText", smsCommunicatorPlugin.getMessages().get(0).getText());
//UNKNOWN //UNKNOWN
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("UNKNOWN", smsCommunicatorPlugin.getMessages().get(0).getText());
//BG //BG
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("BG", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("IOB:")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("IOB:"));
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("Last BG: 100")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("Last BG: 100"));
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("COB: 10(2)g")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().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.setMessages(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.getIgnored());
Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("Remote command is not allowed")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().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
@ -139,8 +139,8 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Loop is disabled", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Loop is disabled", smsCommunicatorPlugin.getMessages().get(1).getText());
//LOOP STATUS : suspended //LOOP STATUS : suspended
when(loopPlugin.minutesToEndOfSuspend()).thenReturn(10); when(loopPlugin.minutesToEndOfSuspend()).thenReturn(10);
@ -149,8 +149,8 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Suspended (10 m)", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Suspended (10 m)", smsCommunicatorPlugin.getMessages().get(1).getText());
//LOOP STATUS : enabled //LOOP STATUS : enabled
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
@ -158,27 +158,27 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getIgnored());
Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Loop is enabled", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Loop is enabled", smsCommunicatorPlugin.getMessages().get(1).getText());
//LOOP : wrong format //LOOP : wrong format
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
smsCommunicatorPlugin.setMessages(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.getIgnored());
Assert.assertEquals("LOOP", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("LOOP", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
//LOOP DISABLE : already disabled //LOOP DISABLE : already disabled
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(false); when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(false);
smsCommunicatorPlugin.setMessages(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.getIgnored());
Assert.assertEquals("LOOP DISABLE", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("LOOP DISABLE", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Loop is disabled", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Loop is disabled", smsCommunicatorPlugin.getMessages().get(1).getText());
//LOOP DISABLE : from enabled //LOOP DISABLE : from enabled
hasBeenRun = false; hasBeenRun = false;
@ -190,9 +190,9 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getIgnored());
Assert.assertEquals("LOOP DISABLE", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("LOOP DISABLE", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Loop has been disabled Temp basal canceled", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Loop has been disabled Temp basal canceled", smsCommunicatorPlugin.getMessages().get(1).getText());
Assert.assertTrue(hasBeenRun); Assert.assertTrue(hasBeenRun);
//LOOP ENABLE : already enabled //LOOP ENABLE : already enabled
@ -200,9 +200,9 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getIgnored());
Assert.assertEquals("LOOP ENABLE", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("LOOP ENABLE", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Loop is enabled", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Loop is enabled", smsCommunicatorPlugin.getMessages().get(1).getText());
//LOOP ENABLE : from disabled //LOOP ENABLE : from disabled
hasBeenRun = false; hasBeenRun = false;
@ -214,72 +214,72 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getIgnored());
Assert.assertEquals("LOOP ENABLE", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("LOOP ENABLE", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Loop has been enabled", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Loop has been enabled", smsCommunicatorPlugin.getMessages().get(1).getText());
Assert.assertTrue(hasBeenRun); Assert.assertTrue(hasBeenRun);
//LOOP RESUME : already enabled //LOOP RESUME : already enabled
smsCommunicatorPlugin.setMessages(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.getIgnored());
Assert.assertEquals("LOOP RESUME", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("LOOP RESUME", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Loop resumed", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Loop resumed", smsCommunicatorPlugin.getMessages().get(1).getText());
//LOOP SUSPEND 1 2: wrong format //LOOP SUSPEND 1 2: wrong format
smsCommunicatorPlugin.setMessages(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.getIgnored());
Assert.assertEquals("LOOP SUSPEND 1 2", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("LOOP SUSPEND 1 2", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
//LOOP SUSPEND 0 : wrong duration //LOOP SUSPEND 0 : wrong duration
smsCommunicatorPlugin.setMessages(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.getIgnored());
Assert.assertEquals("LOOP SUSPEND 0", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("LOOP SUSPEND 0", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong duration", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong duration", smsCommunicatorPlugin.getMessages().get(1).getText());
//LOOP SUSPEND 100 : suspend for 100 min + correct answer //LOOP SUSPEND 100 : suspend for 100 min + correct answer
smsCommunicatorPlugin.setMessages(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.getIgnored());
Assert.assertEquals("LOOP SUSPEND 100", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("LOOP SUSPEND 100", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To suspend loop for 100 minutes reply with code ")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To suspend loop for 100 minutes reply with code "));
String passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; String passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode();
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText());
Assert.assertEquals("Loop suspended Temp basal canceled", smsCommunicatorPlugin.getMessages().get(3).text); Assert.assertEquals("Loop suspended Temp basal canceled", smsCommunicatorPlugin.getMessages().get(3).getText());
//LOOP SUSPEND 200 : limit to 180 min + wrong answer //LOOP SUSPEND 200 : limit to 180 min + wrong answer
smsCommunicatorPlugin.setMessages(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.getIgnored());
Assert.assertEquals("LOOP SUSPEND 200", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("LOOP SUSPEND 200", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To suspend loop for 180 minutes reply with code ")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To suspend loop for 180 minutes reply with code "));
passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode();
// 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.getMessages().get(3).text); Assert.assertEquals("XXXX", smsCommunicatorPlugin.getMessages().get(3).getText());
Assert.assertEquals("Wrong code. Command cancelled.", smsCommunicatorPlugin.getMessages().get(4).text); Assert.assertEquals("Wrong code. Command cancelled.", smsCommunicatorPlugin.getMessages().get(4).getText());
//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.getMessages().get(5).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(5).getText());
Assert.assertEquals(6, smsCommunicatorPlugin.getMessages().size()); // processed as common message Assert.assertEquals(6, smsCommunicatorPlugin.getMessages().size()); // processed as common message
//LOOP BLABLA //LOOP BLABLA
smsCommunicatorPlugin.setMessages(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.getIgnored());
Assert.assertEquals("LOOP BLABLA", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("LOOP BLABLA", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
//TREATMENTS REFRESH //TREATMENTS REFRESH
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
@ -287,9 +287,9 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getIgnored());
Assert.assertEquals("TREATMENTS REFRESH", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("TREATMENTS REFRESH", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("TREATMENTS REFRESH")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("TREATMENTS REFRESH"));
//TREATMENTS BLA BLA //TREATMENTS BLA BLA
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
@ -297,9 +297,9 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getIgnored());
Assert.assertEquals("TREATMENTS BLA BLA", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("TREATMENTS BLA BLA", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
//TREATMENTS BLABLA //TREATMENTS BLABLA
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
@ -307,9 +307,9 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getIgnored());
Assert.assertEquals("TREATMENTS BLABLA", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("TREATMENTS BLABLA", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
//NSCLIENT RESTART //NSCLIENT RESTART
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
@ -317,9 +317,9 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getIgnored());
Assert.assertEquals("NSCLIENT RESTART", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("NSCLIENT RESTART", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("NSCLIENT RESTART")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("NSCLIENT RESTART"));
//NSCLIENT BLA BLA //NSCLIENT BLA BLA
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
@ -327,9 +327,9 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getIgnored());
Assert.assertEquals("NSCLIENT BLA BLA", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("NSCLIENT BLA BLA", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
//NSCLIENT BLABLA //NSCLIENT BLABLA
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
@ -337,79 +337,79 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getIgnored());
Assert.assertEquals("NSCLIENT BLABLA", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("NSCLIENT BLABLA", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
//PUMP //PUMP
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("PUMP", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Virtual Pump", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Virtual Pump", smsCommunicatorPlugin.getMessages().get(1).getText());
//HELP //HELP
smsCommunicatorPlugin.setMessages(new ArrayList<>()); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "HELP"); sms = new Sms("1234", "HELP");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("HELP", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("HELP", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("PUMP")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("PUMP"));
//HELP PUMP //HELP PUMP
smsCommunicatorPlugin.setMessages(new ArrayList<>()); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "HELP PUMP"); sms = new Sms("1234", "HELP PUMP");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("HELP PUMP", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("HELP PUMP", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("PUMP")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("PUMP"));
//SMS : wrong format //SMS : wrong format
smsCommunicatorPlugin.setMessages(new ArrayList<>()); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "SMS"); sms = new Sms("1234", "SMS");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertFalse(sms.ignored); Assert.assertFalse(sms.getIgnored());
Assert.assertEquals("SMS", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("SMS", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
//SMS STOP //SMS STOP
smsCommunicatorPlugin.setMessages(new ArrayList<>()); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "SMS DISABLE"); sms = new Sms("1234", "SMS DISABLE");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("SMS DISABLE", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("SMS DISABLE", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To disable the SMS Remote Service reply with code")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To disable the SMS Remote Service reply with code"));
passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode();
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.contains("SMS Remote Service stopped. To reactivate it, use AAPS on master smartphone.")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).getText().contains("SMS Remote Service stopped. To reactivate it, use AAPS on master smartphone."));
//TARGET : wrong format //TARGET : wrong format
smsCommunicatorPlugin.setMessages(new ArrayList<>()); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "TARGET"); sms = new Sms("1234", "TARGET");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertFalse(sms.ignored); Assert.assertFalse(sms.getIgnored());
Assert.assertEquals("TARGET", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("TARGET", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
//TARGET MEAL //TARGET MEAL
smsCommunicatorPlugin.setMessages(new ArrayList<>()); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "TARGET MEAL"); sms = new Sms("1234", "TARGET MEAL");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("TARGET MEAL", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("TARGET MEAL", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To set the Temp Target")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To set the Temp Target"));
passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode();
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.contains("set successfully")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).getText().contains("set successfully"));
//TARGET STOP/CANCEL //TARGET STOP/CANCEL
smsCommunicatorPlugin.setMessages(new ArrayList<>()); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "TARGET STOP"); sms = new Sms("1234", "TARGET STOP");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("TARGET STOP", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("TARGET STOP", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To cancel Temp Target reply with code")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To cancel Temp Target reply with code"));
passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode();
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.contains("Temp Target canceled successfully")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).getText().contains("Temp Target canceled successfully"));
} }
@Test @Test
@ -420,8 +420,8 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("PROFILE", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).getText());
when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true); when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true);
@ -429,15 +429,15 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("PROFILE", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
//PROFILE LIST (no profile interface) //PROFILE LIST (no profile interface)
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("PROFILE LIST", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Not configured", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Not configured", smsCommunicatorPlugin.getMessages().get(1).getText());
ProfileInterface profileInterface = mock(SimpleProfilePlugin.class); ProfileInterface profileInterface = mock(SimpleProfilePlugin.class);
when(ConfigBuilderPlugin.getPlugin().getActiveProfileInterface()).thenReturn(profileInterface); when(ConfigBuilderPlugin.getPlugin().getActiveProfileInterface()).thenReturn(profileInterface);
@ -446,8 +446,8 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("PROFILE LIST", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Not configured", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Not configured", smsCommunicatorPlugin.getMessages().get(1).getText());
when(profileInterface.getProfile()).thenReturn(AAPSMocker.getValidProfileStore()); when(profileInterface.getProfile()).thenReturn(AAPSMocker.getValidProfileStore());
@ -455,54 +455,54 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("PROFILE STATUS", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals(AAPSMocker.TESTPROFILENAME, smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals(AAPSMocker.TESTPROFILENAME, smsCommunicatorPlugin.getMessages().get(1).getText());
//PROFILE LIST //PROFILE LIST
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("PROFILE LIST", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("1. " + AAPSMocker.TESTPROFILENAME, smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("1. " + AAPSMocker.TESTPROFILENAME, smsCommunicatorPlugin.getMessages().get(1).getText());
//PROFILE 2 (non existing) //PROFILE 2 (non existing)
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("PROFILE 2", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
//PROFILE 1 0(wrong percentage) //PROFILE 1 0(wrong percentage)
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("PROFILE 1 0", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
//PROFILE 0(wrong index) //PROFILE 0(wrong index)
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("PROFILE 0", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
//PROFILE 1(OK) //PROFILE 1(OK)
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("PROFILE 1", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To switch profile to someProfile 100% reply with code")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To switch profile to someProfile 100% reply with code"));
//PROFILE 1 90(OK) //PROFILE 1 90(OK)
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("PROFILE 1 90", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To switch profile to someProfile 90% reply with code")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To switch profile to someProfile 90% reply with code"));
String passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; String passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode();
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText());
Assert.assertEquals("Profile switch created", smsCommunicatorPlugin.getMessages().get(3).text); Assert.assertEquals("Profile switch created", smsCommunicatorPlugin.getMessages().get(3).getText());
} }
@Test @Test
@ -513,8 +513,8 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("BASAL", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).getText());
when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true); when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true);
@ -522,33 +522,33 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("BASAL", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
//BASAL CANCEL //BASAL CANCEL
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("BASAL CANCEL", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To stop temp basal reply with code")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To stop temp basal reply with code"));
String passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; String passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode();
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.contains("Temp basal canceled")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).getText().contains("Temp basal canceled"));
//BASAL a% //BASAL a%
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("BASAL a%", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
//BASAL 10% 0 //BASAL 10% 0
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("BASAL 10% 0", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
when(MainApp.getConstraintChecker().applyBasalPercentConstraints(any(), any())).thenReturn(new Constraint<>(20)); when(MainApp.getConstraintChecker().applyBasalPercentConstraints(any(), any())).thenReturn(new Constraint<>(20));
@ -556,26 +556,26 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("BASAL 20% 20", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To start basal 20% for 20 min reply with code")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To start basal 20% for 20 min reply with code"));
passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode();
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText());
Assert.assertEquals("Temp basal 20% for 20 min started successfully\nVirtual Pump", smsCommunicatorPlugin.getMessages().get(3).text); Assert.assertEquals("Temp basal 20% for 20 min started successfully\nVirtual Pump", smsCommunicatorPlugin.getMessages().get(3).getText());
//BASAL a //BASAL a
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("BASAL a", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
//BASAL 1 0 //BASAL 1 0
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("BASAL 1 0", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
when(MainApp.getConstraintChecker().applyBasalConstraints(any(), any())).thenReturn(new Constraint<>(1d)); when(MainApp.getConstraintChecker().applyBasalConstraints(any(), any())).thenReturn(new Constraint<>(1d));
@ -583,12 +583,12 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("BASAL 1 20", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To start basal 1.00U/h for 20 min reply with code")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To start basal 1.00U/h for 20 min reply with code"));
passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode();
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText());
Assert.assertEquals("Temp basal 1.00U/h for 20 min started successfully\nVirtual Pump", smsCommunicatorPlugin.getMessages().get(3).text); Assert.assertEquals("Temp basal 1.00U/h for 20 min started successfully\nVirtual Pump", smsCommunicatorPlugin.getMessages().get(3).getText());
} }
@ -600,8 +600,8 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("EXTENDED", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).getText());
when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true); when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true);
@ -609,26 +609,26 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("EXTENDED", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
//EXTENDED CANCEL //EXTENDED CANCEL
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("EXTENDED CANCEL", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To stop extended bolus reply with code")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To stop extended bolus reply with code"));
String passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; String passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode();
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.contains("Extended bolus canceled")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).getText().contains("Extended bolus canceled"));
//EXTENDED a% //EXTENDED a%
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("EXTENDED a%", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
when(MainApp.getConstraintChecker().applyExtendedBolusConstraints(any())).thenReturn(new Constraint<>(1d)); when(MainApp.getConstraintChecker().applyExtendedBolusConstraints(any())).thenReturn(new Constraint<>(1d));
@ -636,19 +636,19 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("EXTENDED 1 0", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
//EXTENDED 1 20 //EXTENDED 1 20
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("EXTENDED 1 20", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To start extended bolus 1.00U for 20 min reply with code")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To start extended bolus 1.00U for 20 min reply with code"));
passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode();
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText());
Assert.assertEquals("Extended bolus 1.00U for 20 min started successfully\nVirtual Pump", smsCommunicatorPlugin.getMessages().get(3).text); Assert.assertEquals("Extended bolus 1.00U for 20 min started successfully\nVirtual Pump", smsCommunicatorPlugin.getMessages().get(3).getText());
} }
@Test @Test
@ -659,8 +659,8 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("BOLUS", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).getText());
when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true); when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true);
@ -668,8 +668,8 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("BOLUS", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
when(MainApp.getConstraintChecker().applyBolusConstraints(any())).thenReturn(new Constraint<>(1d)); when(MainApp.getConstraintChecker().applyBolusConstraints(any())).thenReturn(new Constraint<>(1d));
@ -678,8 +678,8 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Remote bolus not available. Try again later.", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Remote bolus not available. Try again later.", smsCommunicatorPlugin.getMessages().get(1).getText());
when(MainApp.getConstraintChecker().applyBolusConstraints(any())).thenReturn(new Constraint<>(0d)); when(MainApp.getConstraintChecker().applyBolusConstraints(any())).thenReturn(new Constraint<>(0d));
@ -689,15 +689,15 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("BOLUS 0", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
//BOLUS a //BOLUS a
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("BOLUS a", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
when(MainApp.getConstraintChecker().applyExtendedBolusConstraints(any())).thenReturn(new Constraint<>(1d)); when(MainApp.getConstraintChecker().applyExtendedBolusConstraints(any())).thenReturn(new Constraint<>(1d));
@ -707,12 +707,12 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To deliver bolus 1.00U reply with code")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To deliver bolus 1.00U reply with code"));
String passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; String passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode();
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.contains("Bolus 1.00U delivered successfully")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).getText().contains("Bolus 1.00U delivered successfully"));
//BOLUS 1 (Suspended pump) //BOLUS 1 (Suspended pump)
smsCommunicatorPlugin.setLastRemoteBolusTime(0); smsCommunicatorPlugin.setLastRemoteBolusTime(0);
@ -720,27 +720,27 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Pump suspended", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Pump suspended", smsCommunicatorPlugin.getMessages().get(1).getText());
when(virtualPumpPlugin.isSuspended()).thenReturn(false); when(virtualPumpPlugin.isSuspended()).thenReturn(false);
//BOLUS 1 a //BOLUS 1 a
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("BOLUS 1 a", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
//BOLUS 1 MEAL //BOLUS 1 MEAL
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("BOLUS 1 MEAL", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To deliver meal bolus 1.00U reply with code")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To deliver meal bolus 1.00U reply with code"));
passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode();
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText());
Assert.assertEquals("Meal Bolus 1.00U delivered successfully\nVirtual Pump\nTarget 5.0 for 45 minutes", smsCommunicatorPlugin.getMessages().get(3).text); Assert.assertEquals("Meal Bolus 1.00U delivered successfully\nVirtual Pump\nTarget 5.0 for 45 minutes", smsCommunicatorPlugin.getMessages().get(3).getText());
} }
@Test @Test
@ -751,8 +751,8 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("CAL", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).getText());
when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true); when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true);
@ -760,27 +760,27 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("CAL", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
//CAL 0 //CAL 0
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("CAL 0", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
when(XdripCalibrations.sendIntent(any())).thenReturn(true); when(XdripCalibrations.sendIntent(any())).thenReturn(true);
//CAL 1 //CAL 1
smsCommunicatorPlugin.setMessages(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.getMessages().get(0).text); Assert.assertEquals("CAL 1", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To send calibration 1.00 reply with code")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To send calibration 1.00 reply with code"));
String passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; String passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode();
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText());
Assert.assertEquals("Calibration sent. Receiving must be enabled in xDrip.", smsCommunicatorPlugin.getMessages().get(3).text); Assert.assertEquals("Calibration sent. Receiving must be enabled in xDrip.", smsCommunicatorPlugin.getMessages().get(3).getText());
} }
@Test @Test
@ -793,8 +793,8 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(new ArrayList<>()); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "CARBS"); sms = new Sms("1234", "CARBS");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("CARBS", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("CARBS", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).getText());
when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true); when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true);
@ -802,8 +802,8 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(new ArrayList<>()); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "CARBS"); sms = new Sms("1234", "CARBS");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("CARBS", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("CARBS", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
when(MainApp.getConstraintChecker().applyCarbsConstraints(any())).thenReturn(new Constraint<>(0)); when(MainApp.getConstraintChecker().applyCarbsConstraints(any())).thenReturn(new Constraint<>(0));
@ -811,8 +811,8 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(new ArrayList<>()); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "CARBS 0"); sms = new Sms("1234", "CARBS 0");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("CARBS 0", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("CARBS 0", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText());
when(MainApp.getConstraintChecker().applyCarbsConstraints(any())).thenReturn(new Constraint<>(1)); when(MainApp.getConstraintChecker().applyCarbsConstraints(any())).thenReturn(new Constraint<>(1));
@ -820,56 +820,56 @@ public class SmsCommunicatorPluginTest {
smsCommunicatorPlugin.setMessages(new ArrayList<>()); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "CARBS 1"); sms = new Sms("1234", "CARBS 1");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("CARBS 1", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("CARBS 1", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To enter 1g at")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To enter 1g at"));
String passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; String passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode();
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.startsWith("Carbs 1g entered successfully")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).getText().startsWith("Carbs 1g entered successfully"));
//CARBS 1 a //CARBS 1 a
smsCommunicatorPlugin.setMessages(new ArrayList<>()); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "CARBS 1 a"); sms = new Sms("1234", "CARBS 1 a");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("CARBS 1 a", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("CARBS 1 a", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("Wrong format")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("Wrong format"));
//CARBS 1 00 //CARBS 1 00
smsCommunicatorPlugin.setMessages(new ArrayList<>()); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "CARBS 1 00"); sms = new Sms("1234", "CARBS 1 00");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("CARBS 1 00", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("CARBS 1 00", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("Wrong format")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("Wrong format"));
//CARBS 1 12:01 //CARBS 1 12:01
smsCommunicatorPlugin.setMessages(new ArrayList<>()); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "CARBS 1 12:01"); sms = new Sms("1234", "CARBS 1 12:01");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("CARBS 1 12:01", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("CARBS 1 12:01", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To enter 1g at 12:01PM reply with code")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To enter 1g at 12:01PM reply with code"));
passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode();
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.startsWith("Carbs 1g entered successfully")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).getText().startsWith("Carbs 1g entered successfully"));
//CARBS 1 3:01AM //CARBS 1 3:01AM
smsCommunicatorPlugin.setMessages(new ArrayList<>()); smsCommunicatorPlugin.setMessages(new ArrayList<>());
sms = new Sms("1234", "CARBS 1 3:01AM"); sms = new Sms("1234", "CARBS 1 3:01AM");
smsCommunicatorPlugin.processSms(sms); smsCommunicatorPlugin.processSms(sms);
Assert.assertEquals("CARBS 1 3:01AM", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("CARBS 1 3:01AM", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To enter 1g at 03:01AM reply with code")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To enter 1g at 03:01AM reply with code"));
passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode();
smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText());
Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.startsWith("Carbs 1g entered successfully")); Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).getText().startsWith("Carbs 1g entered successfully"));
} }
@Test @Test
public void sendNotificationToAllNumbers() { public void sendNotificationToAllNumbers() {
smsCommunicatorPlugin.setMessages(new ArrayList<>()); smsCommunicatorPlugin.setMessages(new ArrayList<>());
smsCommunicatorPlugin.sendNotificationToAllNumbers("abc"); smsCommunicatorPlugin.sendNotificationToAllNumbers("abc");
Assert.assertEquals("abc", smsCommunicatorPlugin.getMessages().get(0).text); Assert.assertEquals("abc", smsCommunicatorPlugin.getMessages().get(0).getText());
Assert.assertEquals("abc", smsCommunicatorPlugin.getMessages().get(1).text); Assert.assertEquals("abc", smsCommunicatorPlugin.getMessages().get(1).getText());
} }
@Before @Before

View file

@ -28,19 +28,19 @@ public class SmsTest {
when(smsMessage.getMessageBody()).thenReturn("aBody"); when(smsMessage.getMessageBody()).thenReturn("aBody");
Sms sms = new Sms(smsMessage); Sms sms = new Sms(smsMessage);
Assert.assertEquals(sms.phoneNumber, "aNumber"); Assert.assertEquals(sms.getPhoneNumber(), "aNumber");
Assert.assertEquals(sms.text, "aBody"); Assert.assertEquals(sms.getText(), "aBody");
Assert.assertTrue(sms.received); Assert.assertTrue(sms.getReceived());
sms = new Sms("aNumber", "aBody"); sms = new Sms("aNumber", "aBody");
Assert.assertEquals(sms.phoneNumber, "aNumber"); Assert.assertEquals(sms.getPhoneNumber(), "aNumber");
Assert.assertEquals(sms.text, "aBody"); Assert.assertEquals(sms.getText(), "aBody");
Assert.assertTrue(sms.sent); Assert.assertTrue(sms.getSent());
sms = new Sms("aNumber", R.string.insulin_unit_shortname); sms = new Sms("aNumber", R.string.insulin_unit_shortname);
Assert.assertEquals(sms.phoneNumber, "aNumber"); Assert.assertEquals(sms.getPhoneNumber(), "aNumber");
Assert.assertEquals(sms.text, MainApp.gs(R.string.insulin_unit_shortname)); Assert.assertEquals(sms.getText(), MainApp.gs(R.string.insulin_unit_shortname));
Assert.assertTrue(sms.sent); Assert.assertTrue(sms.getSent());
Assert.assertEquals(sms.toString(), "SMS from aNumber: U"); Assert.assertEquals(sms.toString(), "SMS from aNumber: U");
} }