diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt index ca3e1d3126..5882f84d61 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt @@ -105,7 +105,7 @@ object ObjectivesPlugin : PluginBase(PluginDescription() val requestCode = SP.getString(R.string.key_objectives_request_code, "") var url = SP.getString(R.string.key_nsclientinternal_url, "").toLowerCase() 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)) { SP.putLong("Objectives_" + "openloop" + "_started", DateUtil.now()) SP.putLong("Objectives_" + "openloop" + "_accomplished", DateUtil.now()) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequest.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequest.java deleted file mode 100644 index 40216dda30..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequest.java +++ /dev/null @@ -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); - } - -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequest.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequest.kt new file mode 100644 index 0000000000..48e816928f --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequest.kt @@ -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) + } +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/Sms.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/Sms.java deleted file mode 100644 index 8efeb909fc..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/Sms.java +++ /dev/null @@ -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; - } -} - diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/Sms.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/Sms.kt new file mode 100644 index 0000000000..868620be2e --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/Sms.kt @@ -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" + } +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsAction.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsAction.java deleted file mode 100644 index 7785b33c7c..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsAction.java +++ /dev/null @@ -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; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsAction.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsAction.kt new file mode 100644 index 0000000000..98c892d918 --- /dev/null +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsAction.kt @@ -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() + } +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt index c614d9cea9..e40ed8b1df 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPlugin.kt @@ -110,7 +110,7 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription() distance.title = MainApp.gs(R.string.smscommunicator_remotebolusmindistance) distance.isEnabled = true } - allowedNumbers.onPreferenceChangeListener = OnPreferenceChangeListener { preference: Preference?, newValue: Any -> + allowedNumbers.onPreferenceChangeListener = OnPreferenceChangeListener { _: Preference?, newValue: Any -> if (!areMoreNumbers(newValue as String)) { distance.text = (Constants.remoteBolusMinDistance / (60 * 1000L)).toString() distance.title = (MainApp.gs(R.string.smscommunicator_remotebolusmindistance) @@ -344,8 +344,8 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription() ConfigBuilderPlugin.getPlugin().commandQueue.cancelTempBasal(true, object : Callback() { override fun run() { if (result.success) { - LoopPlugin.getPlugin().suspendTo(System.currentTimeMillis() + anInteger * 60L * 1000) - NSUpload.uploadOpenAPSOffline(anInteger * 60.toDouble()) + LoopPlugin.getPlugin().suspendTo(System.currentTimeMillis() + anInteger() * 60L * 1000) + NSUpload.uploadOpenAPSOffline(anInteger() * 60.toDouble()) send(EventRefreshOverview("SMS_LOOP_SUSPENDED")) val replyText = MainApp.gs(R.string.smscommunicator_loopsuspended) + " " + MainApp.gs(if (result.success) R.string.smscommunicator_tempbasalcanceled else R.string.smscommunicator_tempbasalcancelfailed) @@ -389,8 +389,10 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription() sendSMS(Sms(receivedSms.phoneNumber, commands.keys.toString().replace("[", "").replace("]", ""))) receivedSms.processed = true } else if (isCommand(splitted[1].toUpperCase(Locale.getDefault()), receivedSms.phoneNumber)) { - sendSMS(Sms(receivedSms.phoneNumber, commands[splitted[1].toUpperCase(Locale.getDefault())])) - receivedSms.processed = true + commands[splitted[1].toUpperCase(Locale.getDefault())]?.let { + sendSMS(Sms(receivedSms.phoneNumber, it)) + receivedSms.processed = true + } } else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat)) } @@ -504,7 +506,7 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription() receivedSms.processed = true messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction(tempBasalPct, duration) { override fun run() { - ConfigBuilderPlugin.getPlugin().commandQueue.tempBasalPercent(anInteger, secondInteger, true, profile, object : Callback() { + ConfigBuilderPlugin.getPlugin().commandQueue.tempBasalPercent(anInteger(), secondInteger(), true, profile, object : Callback() { override fun run() { if (result.success) { var replyText: String @@ -536,7 +538,7 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription() receivedSms.processed = true messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction(tempBasal, duration) { override fun run() { - ConfigBuilderPlugin.getPlugin().commandQueue.tempBasalAbsolute(aDouble, secondInteger, true, profile, object : Callback() { + ConfigBuilderPlugin.getPlugin().commandQueue.tempBasalAbsolute(aDouble(), secondInteger(), true, profile, object : Callback() { override fun run() { if (result.success) { var replyText = if (result.isPercent) String.format(MainApp.gs(R.string.smscommunicator_tempbasalset_percent), result.percent, result.duration) @@ -591,7 +593,7 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription() receivedSms.processed = true messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction(extended, duration) { override fun run() { - ConfigBuilderPlugin.getPlugin().commandQueue.extendedBolus(aDouble, secondInteger, object : Callback() { + ConfigBuilderPlugin.getPlugin().commandQueue.extendedBolus(aDouble(), secondInteger(), object : Callback() { override fun run() { if (result.success) { var replyText = String.format(MainApp.gs(R.string.smscommunicator_extendedset), aDouble, duration) @@ -626,7 +628,7 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription() messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction(bolus) { override fun run() { val detailedBolusInfo = DetailedBolusInfo() - detailedBolusInfo.insulin = aDouble + detailedBolusInfo.insulin = aDouble() detailedBolusInfo.source = Source.USER ConfigBuilderPlugin.getPlugin().commandQueue.bolus(detailedBolusInfo, object : Callback() { override fun run() { @@ -702,8 +704,8 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription() messageToConfirm = AuthRequest(this, receivedSms, reply, passCode, object : SmsAction(grams, time) { override fun run() { val detailedBolusInfo = DetailedBolusInfo() - detailedBolusInfo.carbs = anInteger.toDouble() - detailedBolusInfo.date = secondLong + detailedBolusInfo.carbs = anInteger().toDouble() + detailedBolusInfo.date = secondLong() ConfigBuilderPlugin.getPlugin().commandQueue.bolus(detailedBolusInfo, object : Callback() { override fun run() { if (result.success) { @@ -837,7 +839,7 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription() } else sendSMS(Sms(receivedSms.phoneNumber, R.string.wrongformat)) } - fun sendNotificationToAllNumbers(text: String?): Boolean { + fun sendNotificationToAllNumbers(text: String): Boolean { var result = true for (i in allowedNumbers.indices) { val sms = Sms(allowedNumbers[i], text) @@ -902,16 +904,19 @@ object SmsCommunicatorPlugin : PluginBase(PluginDescription() return s } - fun areMoreNumbers(allowednumbers: String): Boolean { - var countNumbers = 0 - val substrings = allowednumbers.split(";").toTypedArray() - for (number in substrings) { - var cleaned = number.replace(Regex("\\s+"), "") - if (cleaned.length < 4) continue - cleaned = cleaned.replace("+", "") - if (!cleaned.matches(Regex("[0-9]+"))) continue - countNumbers++ - } - return countNumbers > 1 + fun areMoreNumbers(allowednumbers: String?): Boolean { + return allowednumbers?.let { + var countNumbers = 0 + val substrings = it.split(";").toTypedArray() + for (number in substrings) { + var cleaned = number.replace(Regex("\\s+"), "") + if (cleaned.length < 4) continue + cleaned = cleaned.replace("+", "") + cleaned = cleaned.replace("-", "") + if (!cleaned.matches(Regex("[0-9]+"))) continue + countNumbers++ + } + countNumbers > 1 + } ?: false } } \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequestTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequestTest.java index 5bd3cae874..4d0ed00415 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequestTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/AuthRequestTest.java @@ -43,14 +43,14 @@ public class AuthRequestTest { // Check if SMS requesting code is sent AuthRequest authRequest = new AuthRequest(smsCommunicatorPlugin, requester, "Request text", "ABC", action); - Assert.assertEquals(sentSms.phoneNumber, "aNumber"); - Assert.assertEquals(sentSms.text, "Request text"); + Assert.assertEquals(sentSms.getPhoneNumber(), "aNumber"); + Assert.assertEquals(sentSms.getText(), "Request text"); // wrong reply actionCalled = false; authRequest.action("EFG"); - Assert.assertEquals(sentSms.phoneNumber, "aNumber"); - Assert.assertEquals(sentSms.text, "Wrong code. Command cancelled."); + Assert.assertEquals(sentSms.getPhoneNumber(), "aNumber"); + Assert.assertEquals(sentSms.getText(), "Wrong code. Command cancelled."); Assert.assertFalse(actionCalled); // correct reply diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsActionTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsActionTest.java index f4d61e56eb..f6a4712b72 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsActionTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsActionTest.java @@ -41,7 +41,7 @@ public class SmsActionTest { }; smsAction.run(); Assert.assertEquals(result, "B"); - Assert.assertEquals(smsAction.aDouble, 1d, 0.000001d); + Assert.assertEquals(smsAction.aDouble(), 1d, 0.000001d); smsAction = new SmsAction(1d, 2) { @Override @@ -51,8 +51,8 @@ public class SmsActionTest { }; smsAction.run(); Assert.assertEquals(result, "C"); - Assert.assertEquals(smsAction.aDouble, 1d, 0.000001d); - Assert.assertEquals(smsAction.secondInteger.intValue(), 2); + Assert.assertEquals(smsAction.aDouble(), 1d, 0.000001d); + Assert.assertEquals(smsAction.secondInteger(), 2); smsAction = new SmsAction("aString", 3) { @Override @@ -62,8 +62,8 @@ public class SmsActionTest { }; smsAction.run(); Assert.assertEquals(result, "D"); - Assert.assertEquals(smsAction.aString, "aString"); - Assert.assertEquals(smsAction.secondInteger.intValue(), 3); + Assert.assertEquals(smsAction.aString(), "aString"); + Assert.assertEquals(smsAction.secondInteger(), 3); smsAction = new SmsAction(4) { @Override @@ -73,7 +73,7 @@ public class SmsActionTest { }; smsAction.run(); Assert.assertEquals(result, "E"); - Assert.assertEquals(smsAction.anInteger.intValue(), 4); + Assert.assertEquals(smsAction.anInteger(), 4); smsAction = new SmsAction(5, 6) { @Override @@ -83,8 +83,8 @@ public class SmsActionTest { }; smsAction.run(); Assert.assertEquals(result, "F"); - Assert.assertEquals(smsAction.anInteger.intValue(), 5); - Assert.assertEquals(smsAction.secondInteger.intValue(), 6); + Assert.assertEquals(smsAction.anInteger(), 5); + Assert.assertEquals(smsAction.secondInteger(), 6); } } diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.java index 2076991c89..c757840c1f 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsCommunicatorPluginTest.java @@ -106,32 +106,32 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("12", "aText"); smsCommunicatorPlugin.processSms(sms); - Assert.assertTrue(sms.ignored); - Assert.assertEquals("aText", smsCommunicatorPlugin.getMessages().get(0).text); + Assert.assertTrue(sms.getIgnored()); + Assert.assertEquals("aText", smsCommunicatorPlugin.getMessages().get(0).getText()); //UNKNOWN smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "UNKNOWN"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("UNKNOWN", smsCommunicatorPlugin.getMessages().get(0).text); + Assert.assertEquals("UNKNOWN", smsCommunicatorPlugin.getMessages().get(0).getText()); //BG smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "BG"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("BG", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("IOB:")); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("Last BG: 100")); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("COB: 10(2)g")); + Assert.assertEquals("BG", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("IOB:")); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("Last BG: 100")); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("COB: 10(2)g")); // LOOP : test remote control disabled when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(false); smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "LOOP STATUS"); smsCommunicatorPlugin.processSms(sms); - Assert.assertFalse(sms.ignored); - Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("Remote command is not allowed")); + Assert.assertFalse(sms.getIgnored()); + Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("Remote command is not allowed")); when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true); //LOOP STATUS : disabled @@ -139,8 +139,8 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "LOOP STATUS"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Loop is disabled", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Loop is disabled", smsCommunicatorPlugin.getMessages().get(1).getText()); //LOOP STATUS : suspended when(loopPlugin.minutesToEndOfSuspend()).thenReturn(10); @@ -149,8 +149,8 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "LOOP STATUS"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Suspended (10 m)", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Suspended (10 m)", smsCommunicatorPlugin.getMessages().get(1).getText()); //LOOP STATUS : enabled when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); @@ -158,27 +158,27 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "LOOP STATUS"); smsCommunicatorPlugin.processSms(sms); - Assert.assertFalse(sms.ignored); - Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Loop is enabled", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertFalse(sms.getIgnored()); + Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Loop is enabled", smsCommunicatorPlugin.getMessages().get(1).getText()); //LOOP : wrong format when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "LOOP"); smsCommunicatorPlugin.processSms(sms); - Assert.assertFalse(sms.ignored); - Assert.assertEquals("LOOP", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertFalse(sms.getIgnored()); + Assert.assertEquals("LOOP", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); //LOOP DISABLE : already disabled when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(false); smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "LOOP DISABLE"); smsCommunicatorPlugin.processSms(sms); - Assert.assertFalse(sms.ignored); - Assert.assertEquals("LOOP DISABLE", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Loop is disabled", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertFalse(sms.getIgnored()); + Assert.assertEquals("LOOP DISABLE", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Loop is disabled", smsCommunicatorPlugin.getMessages().get(1).getText()); //LOOP DISABLE : from enabled hasBeenRun = false; @@ -190,9 +190,9 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "LOOP DISABLE"); smsCommunicatorPlugin.processSms(sms); - Assert.assertFalse(sms.ignored); - Assert.assertEquals("LOOP DISABLE", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Loop has been disabled Temp basal canceled", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertFalse(sms.getIgnored()); + Assert.assertEquals("LOOP DISABLE", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Loop has been disabled Temp basal canceled", smsCommunicatorPlugin.getMessages().get(1).getText()); Assert.assertTrue(hasBeenRun); //LOOP ENABLE : already enabled @@ -200,9 +200,9 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "LOOP ENABLE"); smsCommunicatorPlugin.processSms(sms); - Assert.assertFalse(sms.ignored); - Assert.assertEquals("LOOP ENABLE", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Loop is enabled", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertFalse(sms.getIgnored()); + Assert.assertEquals("LOOP ENABLE", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Loop is enabled", smsCommunicatorPlugin.getMessages().get(1).getText()); //LOOP ENABLE : from disabled hasBeenRun = false; @@ -214,72 +214,72 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "LOOP ENABLE"); smsCommunicatorPlugin.processSms(sms); - Assert.assertFalse(sms.ignored); - Assert.assertEquals("LOOP ENABLE", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Loop has been enabled", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertFalse(sms.getIgnored()); + Assert.assertEquals("LOOP ENABLE", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Loop has been enabled", smsCommunicatorPlugin.getMessages().get(1).getText()); Assert.assertTrue(hasBeenRun); //LOOP RESUME : already enabled smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "LOOP RESUME"); smsCommunicatorPlugin.processSms(sms); - Assert.assertFalse(sms.ignored); - Assert.assertEquals("LOOP RESUME", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Loop resumed", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertFalse(sms.getIgnored()); + Assert.assertEquals("LOOP RESUME", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Loop resumed", smsCommunicatorPlugin.getMessages().get(1).getText()); //LOOP SUSPEND 1 2: wrong format smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "LOOP SUSPEND 1 2"); smsCommunicatorPlugin.processSms(sms); - Assert.assertFalse(sms.ignored); - Assert.assertEquals("LOOP SUSPEND 1 2", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertFalse(sms.getIgnored()); + Assert.assertEquals("LOOP SUSPEND 1 2", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); //LOOP SUSPEND 0 : wrong duration smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "LOOP SUSPEND 0"); smsCommunicatorPlugin.processSms(sms); - Assert.assertFalse(sms.ignored); - Assert.assertEquals("LOOP SUSPEND 0", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong duration", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertFalse(sms.getIgnored()); + Assert.assertEquals("LOOP SUSPEND 0", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong duration", smsCommunicatorPlugin.getMessages().get(1).getText()); //LOOP SUSPEND 100 : suspend for 100 min + correct answer smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "LOOP SUSPEND 100"); smsCommunicatorPlugin.processSms(sms); - Assert.assertFalse(sms.ignored); - Assert.assertEquals("LOOP SUSPEND 100", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To suspend loop for 100 minutes reply with code ")); - String passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; + Assert.assertFalse(sms.getIgnored()); + Assert.assertEquals("LOOP SUSPEND 100", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To suspend loop for 100 minutes reply with code ")); + String passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode(); smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); - Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); - Assert.assertEquals("Loop suspended Temp basal canceled", smsCommunicatorPlugin.getMessages().get(3).text); + Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText()); + Assert.assertEquals("Loop suspended Temp basal canceled", smsCommunicatorPlugin.getMessages().get(3).getText()); //LOOP SUSPEND 200 : limit to 180 min + wrong answer smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "LOOP SUSPEND 200"); smsCommunicatorPlugin.processSms(sms); - Assert.assertFalse(sms.ignored); - Assert.assertEquals("LOOP SUSPEND 200", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To suspend loop for 180 minutes reply with code ")); - passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; + Assert.assertFalse(sms.getIgnored()); + Assert.assertEquals("LOOP SUSPEND 200", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To suspend loop for 180 minutes reply with code ")); + passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode(); // ignore from other number smsCommunicatorPlugin.processSms(new Sms("5678", passCode)); smsCommunicatorPlugin.processSms(new Sms("1234", "XXXX")); - Assert.assertEquals("XXXX", smsCommunicatorPlugin.getMessages().get(3).text); - Assert.assertEquals("Wrong code. Command cancelled.", smsCommunicatorPlugin.getMessages().get(4).text); + Assert.assertEquals("XXXX", smsCommunicatorPlugin.getMessages().get(3).getText()); + Assert.assertEquals("Wrong code. Command cancelled.", smsCommunicatorPlugin.getMessages().get(4).getText()); //then correct code should not work 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 //LOOP BLABLA smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "LOOP BLABLA"); smsCommunicatorPlugin.processSms(sms); - Assert.assertFalse(sms.ignored); - Assert.assertEquals("LOOP BLABLA", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertFalse(sms.getIgnored()); + Assert.assertEquals("LOOP BLABLA", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); //TREATMENTS REFRESH when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); @@ -287,9 +287,9 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "TREATMENTS REFRESH"); smsCommunicatorPlugin.processSms(sms); - Assert.assertFalse(sms.ignored); - Assert.assertEquals("TREATMENTS REFRESH", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("TREATMENTS REFRESH")); + Assert.assertFalse(sms.getIgnored()); + Assert.assertEquals("TREATMENTS REFRESH", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("TREATMENTS REFRESH")); //TREATMENTS BLA BLA when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); @@ -297,9 +297,9 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "TREATMENTS BLA BLA"); smsCommunicatorPlugin.processSms(sms); - Assert.assertFalse(sms.ignored); - Assert.assertEquals("TREATMENTS BLA BLA", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertFalse(sms.getIgnored()); + Assert.assertEquals("TREATMENTS BLA BLA", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); //TREATMENTS BLABLA when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); @@ -307,9 +307,9 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "TREATMENTS BLABLA"); smsCommunicatorPlugin.processSms(sms); - Assert.assertFalse(sms.ignored); - Assert.assertEquals("TREATMENTS BLABLA", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertFalse(sms.getIgnored()); + Assert.assertEquals("TREATMENTS BLABLA", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); //NSCLIENT RESTART when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); @@ -317,9 +317,9 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "NSCLIENT RESTART"); smsCommunicatorPlugin.processSms(sms); - Assert.assertFalse(sms.ignored); - Assert.assertEquals("NSCLIENT RESTART", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("NSCLIENT RESTART")); + Assert.assertFalse(sms.getIgnored()); + Assert.assertEquals("NSCLIENT RESTART", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("NSCLIENT RESTART")); //NSCLIENT BLA BLA when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); @@ -327,9 +327,9 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "NSCLIENT BLA BLA"); smsCommunicatorPlugin.processSms(sms); - Assert.assertFalse(sms.ignored); - Assert.assertEquals("NSCLIENT BLA BLA", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertFalse(sms.getIgnored()); + Assert.assertEquals("NSCLIENT BLA BLA", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); //NSCLIENT BLABLA when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true); @@ -337,79 +337,79 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "NSCLIENT BLABLA"); smsCommunicatorPlugin.processSms(sms); - Assert.assertFalse(sms.ignored); - Assert.assertEquals("NSCLIENT BLABLA", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertFalse(sms.getIgnored()); + Assert.assertEquals("NSCLIENT BLABLA", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); //PUMP smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "PUMP"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("PUMP", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Virtual Pump", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("PUMP", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Virtual Pump", smsCommunicatorPlugin.getMessages().get(1).getText()); //HELP smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "HELP"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("HELP", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("PUMP")); + Assert.assertEquals("HELP", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("PUMP")); //HELP PUMP smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "HELP PUMP"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("HELP PUMP", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("PUMP")); + Assert.assertEquals("HELP PUMP", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("PUMP")); //SMS : wrong format smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "SMS"); smsCommunicatorPlugin.processSms(sms); - Assert.assertFalse(sms.ignored); - Assert.assertEquals("SMS", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertFalse(sms.getIgnored()); + Assert.assertEquals("SMS", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); //SMS STOP smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "SMS DISABLE"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("SMS DISABLE", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To disable the SMS Remote Service reply with code")); - passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; + Assert.assertEquals("SMS DISABLE", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To disable the SMS Remote Service reply with code")); + passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode(); smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); - Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.contains("SMS Remote Service stopped. To reactivate it, use AAPS on master smartphone.")); + Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).getText().contains("SMS Remote Service stopped. To reactivate it, use AAPS on master smartphone.")); //TARGET : wrong format smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "TARGET"); smsCommunicatorPlugin.processSms(sms); - Assert.assertFalse(sms.ignored); - Assert.assertEquals("TARGET", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertFalse(sms.getIgnored()); + Assert.assertEquals("TARGET", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); //TARGET MEAL smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "TARGET MEAL"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("TARGET MEAL", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To set the Temp Target")); - passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; + Assert.assertEquals("TARGET MEAL", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To set the Temp Target")); + passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode(); smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); - Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.contains("set successfully")); + Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).getText().contains("set successfully")); //TARGET STOP/CANCEL smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "TARGET STOP"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("TARGET STOP", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To cancel Temp Target reply with code")); - passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; + Assert.assertEquals("TARGET STOP", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To cancel Temp Target reply with code")); + passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode(); smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); - Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.contains("Temp Target canceled successfully")); + Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).getText().contains("Temp Target canceled successfully")); } @Test @@ -420,8 +420,8 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "PROFILE"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("PROFILE", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("PROFILE", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).getText()); when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true); @@ -429,15 +429,15 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "PROFILE"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("PROFILE", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("PROFILE", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); //PROFILE LIST (no profile interface) smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "PROFILE LIST"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("PROFILE LIST", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Not configured", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("PROFILE LIST", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Not configured", smsCommunicatorPlugin.getMessages().get(1).getText()); ProfileInterface profileInterface = mock(SimpleProfilePlugin.class); when(ConfigBuilderPlugin.getPlugin().getActiveProfileInterface()).thenReturn(profileInterface); @@ -446,8 +446,8 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "PROFILE LIST"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("PROFILE LIST", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Not configured", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("PROFILE LIST", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Not configured", smsCommunicatorPlugin.getMessages().get(1).getText()); when(profileInterface.getProfile()).thenReturn(AAPSMocker.getValidProfileStore()); @@ -455,54 +455,54 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "PROFILE STATUS"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("PROFILE STATUS", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals(AAPSMocker.TESTPROFILENAME, smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("PROFILE STATUS", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals(AAPSMocker.TESTPROFILENAME, smsCommunicatorPlugin.getMessages().get(1).getText()); //PROFILE LIST smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "PROFILE LIST"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("PROFILE LIST", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("1. " + AAPSMocker.TESTPROFILENAME, smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("PROFILE LIST", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("1. " + AAPSMocker.TESTPROFILENAME, smsCommunicatorPlugin.getMessages().get(1).getText()); //PROFILE 2 (non existing) smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "PROFILE 2"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("PROFILE 2", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("PROFILE 2", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); //PROFILE 1 0(wrong percentage) smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "PROFILE 1 0"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("PROFILE 1 0", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("PROFILE 1 0", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); //PROFILE 0(wrong index) smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "PROFILE 0"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("PROFILE 0", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("PROFILE 0", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); //PROFILE 1(OK) smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "PROFILE 1"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("PROFILE 1", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To switch profile to someProfile 100% reply with code")); + Assert.assertEquals("PROFILE 1", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To switch profile to someProfile 100% reply with code")); //PROFILE 1 90(OK) smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "PROFILE 1 90"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("PROFILE 1 90", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To switch profile to someProfile 90% reply with code")); - String passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; + Assert.assertEquals("PROFILE 1 90", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To switch profile to someProfile 90% reply with code")); + String passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode(); smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); - Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); - Assert.assertEquals("Profile switch created", smsCommunicatorPlugin.getMessages().get(3).text); + Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText()); + Assert.assertEquals("Profile switch created", smsCommunicatorPlugin.getMessages().get(3).getText()); } @Test @@ -513,8 +513,8 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "BASAL"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("BASAL", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("BASAL", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).getText()); when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true); @@ -522,33 +522,33 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "BASAL"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("BASAL", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("BASAL", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); //BASAL CANCEL smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "BASAL CANCEL"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("BASAL CANCEL", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To stop temp basal reply with code")); - String passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; + Assert.assertEquals("BASAL CANCEL", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To stop temp basal reply with code")); + String passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode(); smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); - Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.contains("Temp basal canceled")); + Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).getText().contains("Temp basal canceled")); //BASAL a% smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "BASAL a%"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("BASAL a%", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("BASAL a%", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); //BASAL 10% 0 smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "BASAL 10% 0"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("BASAL 10% 0", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("BASAL 10% 0", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); when(MainApp.getConstraintChecker().applyBasalPercentConstraints(any(), any())).thenReturn(new Constraint<>(20)); @@ -556,26 +556,26 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "BASAL 20% 20"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("BASAL 20% 20", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To start basal 20% for 20 min reply with code")); - passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; + Assert.assertEquals("BASAL 20% 20", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To start basal 20% for 20 min reply with code")); + passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode(); smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); - Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); - Assert.assertEquals("Temp basal 20% for 20 min started successfully\nVirtual Pump", smsCommunicatorPlugin.getMessages().get(3).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).getText()); //BASAL a smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "BASAL a"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("BASAL a", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("BASAL a", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); //BASAL 1 0 smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "BASAL 1 0"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("BASAL 1 0", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("BASAL 1 0", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); when(MainApp.getConstraintChecker().applyBasalConstraints(any(), any())).thenReturn(new Constraint<>(1d)); @@ -583,12 +583,12 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "BASAL 1 20"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("BASAL 1 20", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To start basal 1.00U/h for 20 min reply with code")); - passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; + Assert.assertEquals("BASAL 1 20", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To start basal 1.00U/h for 20 min reply with code")); + passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode(); smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); - Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); - Assert.assertEquals("Temp basal 1.00U/h for 20 min started successfully\nVirtual Pump", smsCommunicatorPlugin.getMessages().get(3).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).getText()); } @@ -600,8 +600,8 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "EXTENDED"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("EXTENDED", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("EXTENDED", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).getText()); when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true); @@ -609,26 +609,26 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "EXTENDED"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("EXTENDED", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("EXTENDED", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); //EXTENDED CANCEL smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "EXTENDED CANCEL"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("EXTENDED CANCEL", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To stop extended bolus reply with code")); - String passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; + Assert.assertEquals("EXTENDED CANCEL", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To stop extended bolus reply with code")); + String passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode(); smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); - Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.contains("Extended bolus canceled")); + Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).getText().contains("Extended bolus canceled")); //EXTENDED a% smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "EXTENDED a%"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("EXTENDED a%", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("EXTENDED a%", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); when(MainApp.getConstraintChecker().applyExtendedBolusConstraints(any())).thenReturn(new Constraint<>(1d)); @@ -636,19 +636,19 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "EXTENDED 1 0"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("EXTENDED 1 0", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("EXTENDED 1 0", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); //EXTENDED 1 20 smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "EXTENDED 1 20"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("EXTENDED 1 20", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To start extended bolus 1.00U for 20 min reply with code")); - passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; + Assert.assertEquals("EXTENDED 1 20", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To start extended bolus 1.00U for 20 min reply with code")); + passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode(); smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); - Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); - Assert.assertEquals("Extended bolus 1.00U for 20 min started successfully\nVirtual Pump", smsCommunicatorPlugin.getMessages().get(3).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).getText()); } @Test @@ -659,8 +659,8 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "BOLUS"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("BOLUS", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("BOLUS", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).getText()); when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true); @@ -668,8 +668,8 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "BOLUS"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("BOLUS", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("BOLUS", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); when(MainApp.getConstraintChecker().applyBolusConstraints(any())).thenReturn(new Constraint<>(1d)); @@ -678,8 +678,8 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "BOLUS 1"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Remote bolus not available. Try again later.", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Remote bolus not available. Try again later.", smsCommunicatorPlugin.getMessages().get(1).getText()); when(MainApp.getConstraintChecker().applyBolusConstraints(any())).thenReturn(new Constraint<>(0d)); @@ -689,15 +689,15 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "BOLUS 0"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("BOLUS 0", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("BOLUS 0", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); //BOLUS a smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "BOLUS a"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("BOLUS a", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("BOLUS a", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); when(MainApp.getConstraintChecker().applyExtendedBolusConstraints(any())).thenReturn(new Constraint<>(1d)); @@ -707,12 +707,12 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "BOLUS 1"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To deliver bolus 1.00U reply with code")); - String passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; + Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To deliver bolus 1.00U reply with code")); + String passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode(); smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); - Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.contains("Bolus 1.00U delivered successfully")); + Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).getText().contains("Bolus 1.00U delivered successfully")); //BOLUS 1 (Suspended pump) smsCommunicatorPlugin.setLastRemoteBolusTime(0); @@ -720,27 +720,27 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "BOLUS 1"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Pump suspended", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("BOLUS 1", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Pump suspended", smsCommunicatorPlugin.getMessages().get(1).getText()); when(virtualPumpPlugin.isSuspended()).thenReturn(false); //BOLUS 1 a smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "BOLUS 1 a"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("BOLUS 1 a", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("BOLUS 1 a", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); //BOLUS 1 MEAL smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "BOLUS 1 MEAL"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("BOLUS 1 MEAL", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To deliver meal bolus 1.00U reply with code")); - passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; + Assert.assertEquals("BOLUS 1 MEAL", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To deliver meal bolus 1.00U reply with code")); + passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode(); smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); - Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); - Assert.assertEquals("Meal Bolus 1.00U delivered successfully\nVirtual Pump\nTarget 5.0 for 45 minutes", smsCommunicatorPlugin.getMessages().get(3).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).getText()); } @Test @@ -751,8 +751,8 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "CAL"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("CAL", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("CAL", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).getText()); when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true); @@ -760,27 +760,27 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "CAL"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("CAL", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("CAL", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); //CAL 0 smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "CAL 0"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("CAL 0", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("CAL 0", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); when(XdripCalibrations.sendIntent(any())).thenReturn(true); //CAL 1 smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "CAL 1"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("CAL 1", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To send calibration 1.00 reply with code")); - String passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; + Assert.assertEquals("CAL 1", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To send calibration 1.00 reply with code")); + String passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode(); smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); - Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); - Assert.assertEquals("Calibration sent. Receiving must be enabled in xDrip.", smsCommunicatorPlugin.getMessages().get(3).text); + Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText()); + Assert.assertEquals("Calibration sent. Receiving must be enabled in xDrip.", smsCommunicatorPlugin.getMessages().get(3).getText()); } @Test @@ -793,8 +793,8 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "CARBS"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("CARBS", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("CARBS", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Remote command is not allowed", smsCommunicatorPlugin.getMessages().get(1).getText()); when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true); @@ -802,8 +802,8 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "CARBS"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("CARBS", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("CARBS", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); when(MainApp.getConstraintChecker().applyCarbsConstraints(any())).thenReturn(new Constraint<>(0)); @@ -811,8 +811,8 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "CARBS 0"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("CARBS 0", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("CARBS 0", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("Wrong format", smsCommunicatorPlugin.getMessages().get(1).getText()); when(MainApp.getConstraintChecker().applyCarbsConstraints(any())).thenReturn(new Constraint<>(1)); @@ -820,56 +820,56 @@ public class SmsCommunicatorPluginTest { smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "CARBS 1"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("CARBS 1", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To enter 1g at")); - String passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; + Assert.assertEquals("CARBS 1", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To enter 1g at")); + String passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode(); smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); - Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.startsWith("Carbs 1g entered successfully")); + Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).getText().startsWith("Carbs 1g entered successfully")); //CARBS 1 a smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "CARBS 1 a"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("CARBS 1 a", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("Wrong format")); + Assert.assertEquals("CARBS 1 a", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("Wrong format")); //CARBS 1 00 smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "CARBS 1 00"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("CARBS 1 00", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("Wrong format")); + Assert.assertEquals("CARBS 1 00", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("Wrong format")); //CARBS 1 12:01 smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "CARBS 1 12:01"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("CARBS 1 12:01", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To enter 1g at 12:01PM reply with code")); - passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; + Assert.assertEquals("CARBS 1 12:01", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To enter 1g at 12:01PM reply with code")); + passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode(); smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); - Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.startsWith("Carbs 1g entered successfully")); + Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).getText().startsWith("Carbs 1g entered successfully")); //CARBS 1 3:01AM smsCommunicatorPlugin.setMessages(new ArrayList<>()); sms = new Sms("1234", "CARBS 1 3:01AM"); smsCommunicatorPlugin.processSms(sms); - Assert.assertEquals("CARBS 1 3:01AM", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).text.contains("To enter 1g at 03:01AM reply with code")); - passCode = smsCommunicatorPlugin.getMessageToConfirm().confirmCode; + Assert.assertEquals("CARBS 1 3:01AM", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(1).getText().contains("To enter 1g at 03:01AM reply with code")); + passCode = smsCommunicatorPlugin.getMessageToConfirm().getConfirmCode(); smsCommunicatorPlugin.processSms(new Sms("1234", passCode)); - Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).text); - Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).text.startsWith("Carbs 1g entered successfully")); + Assert.assertEquals(passCode, smsCommunicatorPlugin.getMessages().get(2).getText()); + Assert.assertTrue(smsCommunicatorPlugin.getMessages().get(3).getText().startsWith("Carbs 1g entered successfully")); } @Test public void sendNotificationToAllNumbers() { smsCommunicatorPlugin.setMessages(new ArrayList<>()); smsCommunicatorPlugin.sendNotificationToAllNumbers("abc"); - Assert.assertEquals("abc", smsCommunicatorPlugin.getMessages().get(0).text); - Assert.assertEquals("abc", smsCommunicatorPlugin.getMessages().get(1).text); + Assert.assertEquals("abc", smsCommunicatorPlugin.getMessages().get(0).getText()); + Assert.assertEquals("abc", smsCommunicatorPlugin.getMessages().get(1).getText()); } @Before diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsTest.java index 5f7af11a67..a406a35f9d 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsTest.java @@ -28,19 +28,19 @@ public class SmsTest { when(smsMessage.getMessageBody()).thenReturn("aBody"); Sms sms = new Sms(smsMessage); - Assert.assertEquals(sms.phoneNumber, "aNumber"); - Assert.assertEquals(sms.text, "aBody"); - Assert.assertTrue(sms.received); + Assert.assertEquals(sms.getPhoneNumber(), "aNumber"); + Assert.assertEquals(sms.getText(), "aBody"); + Assert.assertTrue(sms.getReceived()); sms = new Sms("aNumber", "aBody"); - Assert.assertEquals(sms.phoneNumber, "aNumber"); - Assert.assertEquals(sms.text, "aBody"); - Assert.assertTrue(sms.sent); + Assert.assertEquals(sms.getPhoneNumber(), "aNumber"); + Assert.assertEquals(sms.getText(), "aBody"); + Assert.assertTrue(sms.getSent()); sms = new Sms("aNumber", R.string.insulin_unit_shortname); - Assert.assertEquals(sms.phoneNumber, "aNumber"); - Assert.assertEquals(sms.text, MainApp.gs(R.string.insulin_unit_shortname)); - Assert.assertTrue(sms.sent); + Assert.assertEquals(sms.getPhoneNumber(), "aNumber"); + Assert.assertEquals(sms.getText(), MainApp.gs(R.string.insulin_unit_shortname)); + Assert.assertTrue(sms.getSent()); Assert.assertEquals(sms.toString(), "SMS from aNumber: U"); }