SmsCommunicatorPluginTest 5
This commit is contained in:
parent
4c0554f61a
commit
74391eefdc
4 changed files with 123 additions and 40 deletions
|
@ -12,7 +12,7 @@ class AuthRequest {
|
||||||
private static Logger log = LoggerFactory.getLogger(L.SMS);
|
private static Logger log = LoggerFactory.getLogger(L.SMS);
|
||||||
|
|
||||||
private Sms requester;
|
private Sms requester;
|
||||||
private String confirmCode;
|
String confirmCode;
|
||||||
private Runnable action;
|
private Runnable action;
|
||||||
|
|
||||||
private long date;
|
private long date;
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
||||||
|
|
||||||
List<String> allowedNumbers = new ArrayList<>();
|
List<String> allowedNumbers = new ArrayList<>();
|
||||||
|
|
||||||
private AuthRequest messageToConfirm = null;
|
AuthRequest messageToConfirm = null;
|
||||||
|
|
||||||
private Date lastRemoteBolusTime = new Date(0);
|
private Date lastRemoteBolusTime = new Date(0);
|
||||||
|
|
||||||
|
@ -339,7 +339,9 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
||||||
duration = Math.max(0, duration);
|
duration = Math.max(0, duration);
|
||||||
duration = Math.min(180, duration);
|
duration = Math.min(180, duration);
|
||||||
if (duration == 0) {
|
if (duration == 0) {
|
||||||
|
receivedSms.processed = true;
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_wrongduration));
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_wrongduration));
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
String passCode = generatePasscode();
|
String passCode = generatePasscode();
|
||||||
reply = String.format(MainApp.gs(R.string.smscommunicator_suspendreplywithcode), duration, passCode);
|
reply = String.format(MainApp.gs(R.string.smscommunicator_suspendreplywithcode), duration, passCode);
|
||||||
|
@ -368,6 +370,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
|
||||||
break;
|
break;
|
||||||
|
@ -388,7 +391,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processNSCLIENT(String[] splitted, Sms receivedSms) {
|
private void processNSCLIENT(String[] splitted, Sms receivedSms) {
|
||||||
if (splitted[2].toUpperCase().equals("RESTART")) {
|
if (splitted[1].toUpperCase().equals("RESTART")) {
|
||||||
Intent restartNSClient = new Intent(Intents.ACTION_RESTART);
|
Intent restartNSClient = new Intent(Intents.ACTION_RESTART);
|
||||||
MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
|
MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
|
||||||
List<ResolveInfo> q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(restartNSClient, 0);
|
List<ResolveInfo> q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(restartNSClient, 0);
|
||||||
|
|
|
@ -2,6 +2,7 @@ package info;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
|
||||||
import com.squareup.otto.Bus;
|
import com.squareup.otto.Bus;
|
||||||
|
@ -176,6 +177,8 @@ public class AAPSMocker {
|
||||||
Resources mResources = mock(Resources.class);
|
Resources mResources = mock(Resources.class);
|
||||||
when(MainApp.instance().getApplicationContext()).thenReturn(mockedContext);
|
when(MainApp.instance().getApplicationContext()).thenReturn(mockedContext);
|
||||||
when(mockedContext.getResources()).thenReturn(mResources);
|
when(mockedContext.getResources()).thenReturn(mResources);
|
||||||
|
PackageManager packageManager = mock(PackageManager.class);
|
||||||
|
when(mockedContext.getPackageManager()).thenReturn(packageManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DatabaseHelper mockDatabaseHelper() {
|
public static DatabaseHelper mockDatabaseHelper() {
|
||||||
|
@ -195,6 +198,9 @@ public class AAPSMocker {
|
||||||
when(TreatmentsPlugin.getPlugin()).thenReturn(treatmentsPlugin);
|
when(TreatmentsPlugin.getPlugin()).thenReturn(treatmentsPlugin);
|
||||||
when(treatmentsPlugin.getLastCalculationTreatments()).thenReturn(new IobTotal(0));
|
when(treatmentsPlugin.getLastCalculationTreatments()).thenReturn(new IobTotal(0));
|
||||||
when(treatmentsPlugin.getLastCalculationTempBasals()).thenReturn(new IobTotal(0));
|
when(treatmentsPlugin.getLastCalculationTempBasals()).thenReturn(new IobTotal(0));
|
||||||
|
|
||||||
|
TreatmentService treatmentService = PowerMockito.mock(TreatmentService.class);
|
||||||
|
when(treatmentsPlugin.getService()).thenReturn(treatmentService);
|
||||||
return treatmentsPlugin;
|
return treatmentsPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,6 +210,7 @@ public class AAPSMocker {
|
||||||
PowerMockito.whenNew(TreatmentService.class).withNoArguments().thenReturn(treatmentService);
|
PowerMockito.whenNew(TreatmentService.class).withNoArguments().thenReturn(treatmentService);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DanaRPlugin mockDanaRPlugin() {
|
public static DanaRPlugin mockDanaRPlugin() {
|
||||||
|
|
|
@ -57,9 +57,9 @@ public class SmsCommunicatorPluginTest {
|
||||||
@Test
|
@Test
|
||||||
public void processSettingsTest() {
|
public void processSettingsTest() {
|
||||||
// called from constructor
|
// called from constructor
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.allowedNumbers.get(0), "1234");
|
Assert.assertEquals("1234", smsCommunicatorPlugin.allowedNumbers.get(0));
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.allowedNumbers.get(1), "5678");
|
Assert.assertEquals("5678", smsCommunicatorPlugin.allowedNumbers.get(1));
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.allowedNumbers.size(), 2);
|
Assert.assertEquals(2, smsCommunicatorPlugin.allowedNumbers.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -76,20 +76,20 @@ public class SmsCommunicatorPluginTest {
|
||||||
sms = new Sms("12", "aText");
|
sms = new Sms("12", "aText");
|
||||||
smsCommunicatorPlugin.processSms(sms);
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
Assert.assertTrue(sms.ignored);
|
Assert.assertTrue(sms.ignored);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "aText");
|
Assert.assertEquals("aText", smsCommunicatorPlugin.messages.get(0).text);
|
||||||
|
|
||||||
//UNKNOWN
|
//UNKNOWN
|
||||||
smsCommunicatorPlugin.messages = new ArrayList<>();
|
smsCommunicatorPlugin.messages = new ArrayList<>();
|
||||||
sms = new Sms("1234", "UNKNOWN");
|
sms = new Sms("1234", "UNKNOWN");
|
||||||
smsCommunicatorPlugin.processSms(sms);
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "UNKNOWN");
|
Assert.assertEquals("UNKNOWN", smsCommunicatorPlugin.messages.get(0).text);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(1).text, "Uknown command or wrong reply");
|
Assert.assertEquals("Uknown command or wrong reply", smsCommunicatorPlugin.messages.get(1).text);
|
||||||
|
|
||||||
//BG
|
//BG
|
||||||
smsCommunicatorPlugin.messages = new ArrayList<>();
|
smsCommunicatorPlugin.messages = new ArrayList<>();
|
||||||
sms = new Sms("1234", "BG");
|
sms = new Sms("1234", "BG");
|
||||||
smsCommunicatorPlugin.processSms(sms);
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "BG");
|
Assert.assertEquals("BG", smsCommunicatorPlugin.messages.get(0).text);
|
||||||
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("IOB:"));
|
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("IOB:"));
|
||||||
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("Last BG: 100"));
|
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("Last BG: 100"));
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ public class SmsCommunicatorPluginTest {
|
||||||
sms = new Sms("1234", "LOOP STATUS");
|
sms = new Sms("1234", "LOOP STATUS");
|
||||||
smsCommunicatorPlugin.processSms(sms);
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
Assert.assertFalse(sms.ignored);
|
Assert.assertFalse(sms.ignored);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "LOOP STATUS");
|
Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.messages.get(0).text);
|
||||||
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("Remote command is not allowed"));
|
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("Remote command is not allowed"));
|
||||||
when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true);
|
when(SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false)).thenReturn(true);
|
||||||
|
|
||||||
|
@ -108,8 +108,8 @@ public class SmsCommunicatorPluginTest {
|
||||||
smsCommunicatorPlugin.messages = new ArrayList<>();
|
smsCommunicatorPlugin.messages = new ArrayList<>();
|
||||||
sms = new Sms("1234", "LOOP STATUS");
|
sms = new Sms("1234", "LOOP STATUS");
|
||||||
smsCommunicatorPlugin.processSms(sms);
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "LOOP STATUS");
|
Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.messages.get(0).text);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(1).text, "Loop is disabled");
|
Assert.assertEquals("Loop is disabled", smsCommunicatorPlugin.messages.get(1).text);
|
||||||
|
|
||||||
//LOOP STATUS : suspended
|
//LOOP STATUS : suspended
|
||||||
when(loopPlugin.minutesToEndOfSuspend()).thenReturn(10);
|
when(loopPlugin.minutesToEndOfSuspend()).thenReturn(10);
|
||||||
|
@ -118,8 +118,8 @@ public class SmsCommunicatorPluginTest {
|
||||||
smsCommunicatorPlugin.messages = new ArrayList<>();
|
smsCommunicatorPlugin.messages = new ArrayList<>();
|
||||||
sms = new Sms("1234", "LOOP STATUS");
|
sms = new Sms("1234", "LOOP STATUS");
|
||||||
smsCommunicatorPlugin.processSms(sms);
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "LOOP STATUS");
|
Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.messages.get(0).text);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(1).text, "Suspended (10 m)");
|
Assert.assertEquals("Suspended (10 m)", smsCommunicatorPlugin.messages.get(1).text);
|
||||||
|
|
||||||
//LOOP STATUS : enabled
|
//LOOP STATUS : enabled
|
||||||
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
|
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
|
||||||
|
@ -128,8 +128,8 @@ public class SmsCommunicatorPluginTest {
|
||||||
sms = new Sms("1234", "LOOP STATUS");
|
sms = new Sms("1234", "LOOP STATUS");
|
||||||
smsCommunicatorPlugin.processSms(sms);
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
Assert.assertFalse(sms.ignored);
|
Assert.assertFalse(sms.ignored);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "LOOP STATUS");
|
Assert.assertEquals("LOOP STATUS", smsCommunicatorPlugin.messages.get(0).text);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(1).text, "Loop is enabled");
|
Assert.assertEquals("Loop is enabled", smsCommunicatorPlugin.messages.get(1).text);
|
||||||
|
|
||||||
//LOOP : wrong format
|
//LOOP : wrong format
|
||||||
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
|
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
|
||||||
|
@ -137,8 +137,8 @@ public class SmsCommunicatorPluginTest {
|
||||||
sms = new Sms("1234", "LOOP");
|
sms = new Sms("1234", "LOOP");
|
||||||
smsCommunicatorPlugin.processSms(sms);
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
Assert.assertFalse(sms.ignored);
|
Assert.assertFalse(sms.ignored);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "LOOP");
|
Assert.assertEquals("LOOP", smsCommunicatorPlugin.messages.get(0).text);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(1).text, "Wrong format");
|
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text);
|
||||||
|
|
||||||
//LOOP DISABLE : already disabled
|
//LOOP DISABLE : already disabled
|
||||||
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(false);
|
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(false);
|
||||||
|
@ -146,8 +146,8 @@ public class SmsCommunicatorPluginTest {
|
||||||
sms = new Sms("1234", "LOOP DISABLE");
|
sms = new Sms("1234", "LOOP DISABLE");
|
||||||
smsCommunicatorPlugin.processSms(sms);
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
Assert.assertFalse(sms.ignored);
|
Assert.assertFalse(sms.ignored);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "LOOP DISABLE");
|
Assert.assertEquals("LOOP DISABLE", smsCommunicatorPlugin.messages.get(0).text);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(1).text, "Loop is disabled");
|
Assert.assertEquals("Loop is disabled", smsCommunicatorPlugin.messages.get(1).text);
|
||||||
|
|
||||||
//LOOP DISABLE : from enabled
|
//LOOP DISABLE : from enabled
|
||||||
hasBeenRun = false;
|
hasBeenRun = false;
|
||||||
|
@ -160,8 +160,8 @@ public class SmsCommunicatorPluginTest {
|
||||||
sms = new Sms("1234", "LOOP DISABLE");
|
sms = new Sms("1234", "LOOP DISABLE");
|
||||||
smsCommunicatorPlugin.processSms(sms);
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
Assert.assertFalse(sms.ignored);
|
Assert.assertFalse(sms.ignored);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "LOOP DISABLE");
|
Assert.assertEquals("LOOP DISABLE", smsCommunicatorPlugin.messages.get(0).text);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(1).text, "Loop has been disabled Temp basal canceled");
|
Assert.assertEquals("Loop has been disabled Temp basal canceled", smsCommunicatorPlugin.messages.get(1).text);
|
||||||
Assert.assertTrue(hasBeenRun);
|
Assert.assertTrue(hasBeenRun);
|
||||||
|
|
||||||
//LOOP ENABLE : already enabled
|
//LOOP ENABLE : already enabled
|
||||||
|
@ -170,8 +170,8 @@ public class SmsCommunicatorPluginTest {
|
||||||
sms = new Sms("1234", "LOOP ENABLE");
|
sms = new Sms("1234", "LOOP ENABLE");
|
||||||
smsCommunicatorPlugin.processSms(sms);
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
Assert.assertFalse(sms.ignored);
|
Assert.assertFalse(sms.ignored);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "LOOP ENABLE");
|
Assert.assertEquals("LOOP ENABLE", smsCommunicatorPlugin.messages.get(0).text);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(1).text, "Loop is enabled");
|
Assert.assertEquals("Loop is enabled", smsCommunicatorPlugin.messages.get(1).text);
|
||||||
|
|
||||||
//LOOP ENABLE : from disabled
|
//LOOP ENABLE : from disabled
|
||||||
hasBeenRun = false;
|
hasBeenRun = false;
|
||||||
|
@ -184,8 +184,8 @@ public class SmsCommunicatorPluginTest {
|
||||||
sms = new Sms("1234", "LOOP ENABLE");
|
sms = new Sms("1234", "LOOP ENABLE");
|
||||||
smsCommunicatorPlugin.processSms(sms);
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
Assert.assertFalse(sms.ignored);
|
Assert.assertFalse(sms.ignored);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "LOOP ENABLE");
|
Assert.assertEquals("LOOP ENABLE", smsCommunicatorPlugin.messages.get(0).text);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(1).text, "Loop has been enabled");
|
Assert.assertEquals("Loop has been enabled", smsCommunicatorPlugin.messages.get(1).text);
|
||||||
Assert.assertTrue(hasBeenRun);
|
Assert.assertTrue(hasBeenRun);
|
||||||
|
|
||||||
//LOOP RESUME : already enabled
|
//LOOP RESUME : already enabled
|
||||||
|
@ -193,48 +193,120 @@ public class SmsCommunicatorPluginTest {
|
||||||
sms = new Sms("1234", "LOOP RESUME");
|
sms = new Sms("1234", "LOOP RESUME");
|
||||||
smsCommunicatorPlugin.processSms(sms);
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
Assert.assertFalse(sms.ignored);
|
Assert.assertFalse(sms.ignored);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "LOOP RESUME");
|
Assert.assertEquals("LOOP RESUME", smsCommunicatorPlugin.messages.get(0).text);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(1).text, "Loop resumed");
|
Assert.assertEquals("Loop resumed", smsCommunicatorPlugin.messages.get(1).text);
|
||||||
|
|
||||||
//LOOP SUSPEND 1 2: wrong format
|
//LOOP SUSPEND 1 2: wrong format
|
||||||
smsCommunicatorPlugin.messages = new ArrayList<>();
|
smsCommunicatorPlugin.messages = new ArrayList<>();
|
||||||
sms = new Sms("1234", "LOOP SUSPEND 1 2");
|
sms = new Sms("1234", "LOOP SUSPEND 1 2");
|
||||||
smsCommunicatorPlugin.processSms(sms);
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
Assert.assertFalse(sms.ignored);
|
Assert.assertFalse(sms.ignored);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "LOOP SUSPEND 1 2");
|
Assert.assertEquals("LOOP SUSPEND 1 2", smsCommunicatorPlugin.messages.get(0).text);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(1).text, "Wrong format");
|
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text);
|
||||||
|
|
||||||
//LOOP SUSPEND 0 : wrong duration
|
//LOOP SUSPEND 0 : wrong duration
|
||||||
smsCommunicatorPlugin.messages = new ArrayList<>();
|
smsCommunicatorPlugin.messages = new ArrayList<>();
|
||||||
sms = new Sms("1234", "LOOP SUSPEND 0");
|
sms = new Sms("1234", "LOOP SUSPEND 0");
|
||||||
smsCommunicatorPlugin.processSms(sms);
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
Assert.assertFalse(sms.ignored);
|
Assert.assertFalse(sms.ignored);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "LOOP SUSPEND 0");
|
Assert.assertEquals("LOOP SUSPEND 0", smsCommunicatorPlugin.messages.get(0).text);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(1).text, "Wrong duration");
|
Assert.assertEquals("Wrong duration", smsCommunicatorPlugin.messages.get(1).text);
|
||||||
|
|
||||||
//LOOP SUSPEND 100 : suspend for 100 min
|
//LOOP SUSPEND 100 : suspend for 100 min + correct answer
|
||||||
smsCommunicatorPlugin.messages = new ArrayList<>();
|
smsCommunicatorPlugin.messages = new ArrayList<>();
|
||||||
sms = new Sms("1234", "LOOP SUSPEND 100");
|
sms = new Sms("1234", "LOOP SUSPEND 100");
|
||||||
smsCommunicatorPlugin.processSms(sms);
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
Assert.assertFalse(sms.ignored);
|
Assert.assertFalse(sms.ignored);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "LOOP SUSPEND 100");
|
Assert.assertEquals("LOOP SUSPEND 100", smsCommunicatorPlugin.messages.get(0).text);
|
||||||
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("To suspend loop for 100 minutes reply with code "));
|
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("To suspend loop for 100 minutes reply with code "));
|
||||||
|
String passCode = smsCommunicatorPlugin.messageToConfirm.confirmCode;
|
||||||
|
smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
|
||||||
|
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages.get(2).text);
|
||||||
|
Assert.assertEquals("Loop suspended Temp basal canceled", smsCommunicatorPlugin.messages.get(3).text);
|
||||||
|
|
||||||
//LOOP SUSPEND 200 : limit to 180 min
|
//LOOP SUSPEND 200 : limit to 180 min + wrong answer
|
||||||
smsCommunicatorPlugin.messages = new ArrayList<>();
|
smsCommunicatorPlugin.messages = new ArrayList<>();
|
||||||
sms = new Sms("1234", "LOOP SUSPEND 200");
|
sms = new Sms("1234", "LOOP SUSPEND 200");
|
||||||
smsCommunicatorPlugin.processSms(sms);
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
Assert.assertFalse(sms.ignored);
|
Assert.assertFalse(sms.ignored);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "LOOP SUSPEND 200");
|
Assert.assertEquals("LOOP SUSPEND 200", smsCommunicatorPlugin.messages.get(0).text);
|
||||||
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("To suspend loop for 180 minutes reply with code "));
|
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("To suspend loop for 180 minutes reply with code "));
|
||||||
|
passCode = smsCommunicatorPlugin.messageToConfirm.confirmCode;
|
||||||
|
smsCommunicatorPlugin.processSms(new Sms("1234", "XXXX"));
|
||||||
|
Assert.assertEquals("XXXX", smsCommunicatorPlugin.messages.get(2).text);
|
||||||
|
Assert.assertEquals("Wrong code. Command cancelled.", smsCommunicatorPlugin.messages.get(3).text);
|
||||||
|
//then correct code should not work
|
||||||
|
smsCommunicatorPlugin.processSms(new Sms("1234", passCode));
|
||||||
|
Assert.assertEquals(passCode, smsCommunicatorPlugin.messages.get(4).text);
|
||||||
|
Assert.assertEquals("Uknown command or wrong reply", smsCommunicatorPlugin.messages.get(5).text);
|
||||||
|
|
||||||
//LOOP BLABLA
|
//LOOP BLABLA
|
||||||
smsCommunicatorPlugin.messages = new ArrayList<>();
|
smsCommunicatorPlugin.messages = new ArrayList<>();
|
||||||
sms = new Sms("1234", "LOOP BLABLA");
|
sms = new Sms("1234", "LOOP BLABLA");
|
||||||
smsCommunicatorPlugin.processSms(sms);
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
Assert.assertFalse(sms.ignored);
|
Assert.assertFalse(sms.ignored);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(0).text, "LOOP BLABLA");
|
Assert.assertEquals("LOOP BLABLA", smsCommunicatorPlugin.messages.get(0).text);
|
||||||
Assert.assertEquals(smsCommunicatorPlugin.messages.get(1).text, "Wrong format");
|
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text);
|
||||||
|
|
||||||
|
//TREATMENTS REFRESH
|
||||||
|
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
|
||||||
|
when(loopPlugin.isSuspended()).thenReturn(false);
|
||||||
|
smsCommunicatorPlugin.messages = new ArrayList<>();
|
||||||
|
sms = new Sms("1234", "TREATMENTS REFRESH");
|
||||||
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
|
Assert.assertFalse(sms.ignored);
|
||||||
|
Assert.assertEquals("TREATMENTS REFRESH", smsCommunicatorPlugin.messages.get(0).text);
|
||||||
|
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("TREATMENTS REFRESH"));
|
||||||
|
|
||||||
|
//TREATMENTS BLA BLA
|
||||||
|
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
|
||||||
|
when(loopPlugin.isSuspended()).thenReturn(false);
|
||||||
|
smsCommunicatorPlugin.messages = new ArrayList<>();
|
||||||
|
sms = new Sms("1234", "TREATMENTS BLA BLA");
|
||||||
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
|
Assert.assertFalse(sms.ignored);
|
||||||
|
Assert.assertEquals("TREATMENTS BLA BLA", smsCommunicatorPlugin.messages.get(0).text);
|
||||||
|
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text);
|
||||||
|
|
||||||
|
//TREATMENTS BLABLA
|
||||||
|
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
|
||||||
|
when(loopPlugin.isSuspended()).thenReturn(false);
|
||||||
|
smsCommunicatorPlugin.messages = new ArrayList<>();
|
||||||
|
sms = new Sms("1234", "TREATMENTS BLABLA");
|
||||||
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
|
Assert.assertFalse(sms.ignored);
|
||||||
|
Assert.assertEquals("TREATMENTS BLABLA", smsCommunicatorPlugin.messages.get(0).text);
|
||||||
|
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text);
|
||||||
|
|
||||||
|
//NSCLIENT RESTART
|
||||||
|
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
|
||||||
|
when(loopPlugin.isSuspended()).thenReturn(false);
|
||||||
|
smsCommunicatorPlugin.messages = new ArrayList<>();
|
||||||
|
sms = new Sms("1234", "NSCLIENT RESTART");
|
||||||
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
|
Assert.assertFalse(sms.ignored);
|
||||||
|
Assert.assertEquals("NSCLIENT RESTART", smsCommunicatorPlugin.messages.get(0).text);
|
||||||
|
Assert.assertTrue(smsCommunicatorPlugin.messages.get(1).text.contains("NSCLIENT RESTART"));
|
||||||
|
|
||||||
|
//NSCLIENT BLA BLA
|
||||||
|
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
|
||||||
|
when(loopPlugin.isSuspended()).thenReturn(false);
|
||||||
|
smsCommunicatorPlugin.messages = new ArrayList<>();
|
||||||
|
sms = new Sms("1234", "NSCLIENT BLA BLA");
|
||||||
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
|
Assert.assertFalse(sms.ignored);
|
||||||
|
Assert.assertEquals("NSCLIENT BLA BLA", smsCommunicatorPlugin.messages.get(0).text);
|
||||||
|
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text);
|
||||||
|
|
||||||
|
//NSCLIENT BLABLA
|
||||||
|
when(loopPlugin.isEnabled(PluginType.LOOP)).thenReturn(true);
|
||||||
|
when(loopPlugin.isSuspended()).thenReturn(false);
|
||||||
|
smsCommunicatorPlugin.messages = new ArrayList<>();
|
||||||
|
sms = new Sms("1234", "NSCLIENT BLABLA");
|
||||||
|
smsCommunicatorPlugin.processSms(sms);
|
||||||
|
Assert.assertFalse(sms.ignored);
|
||||||
|
Assert.assertEquals("NSCLIENT BLABLA", smsCommunicatorPlugin.messages.get(0).text);
|
||||||
|
Assert.assertEquals("Wrong format", smsCommunicatorPlugin.messages.get(1).text);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,6 +320,7 @@ public class SmsCommunicatorPluginTest {
|
||||||
AAPSMocker.mockBus();
|
AAPSMocker.mockBus();
|
||||||
AAPSMocker.mockProfileFunctions();
|
AAPSMocker.mockProfileFunctions();
|
||||||
AAPSMocker.mockTreatmentPlugin();
|
AAPSMocker.mockTreatmentPlugin();
|
||||||
|
AAPSMocker.mockTreatmentService();
|
||||||
AAPSMocker.mockIobCobCalculatorPlugin();
|
AAPSMocker.mockIobCobCalculatorPlugin();
|
||||||
AAPSMocker.mockConfigBuilder();
|
AAPSMocker.mockConfigBuilder();
|
||||||
AAPSMocker.mockCommandQueue();
|
AAPSMocker.mockCommandQueue();
|
||||||
|
@ -265,7 +338,7 @@ public class SmsCommunicatorPluginTest {
|
||||||
when(SmsManager.getDefault()).thenReturn(smsManager);
|
when(SmsManager.getDefault()).thenReturn(smsManager);
|
||||||
|
|
||||||
when(SP.getString(R.string.key_smscommunicator_allowednumbers, "")).thenReturn("1234;5678");
|
when(SP.getString(R.string.key_smscommunicator_allowednumbers, "")).thenReturn("1234;5678");
|
||||||
smsCommunicatorPlugin = new SmsCommunicatorPlugin();
|
smsCommunicatorPlugin = SmsCommunicatorPlugin.getPlugin();
|
||||||
smsCommunicatorPlugin.setPluginEnabled(PluginType.GENERAL, true);
|
smsCommunicatorPlugin.setPluginEnabled(PluginType.GENERAL, true);
|
||||||
|
|
||||||
loopPlugin = mock(LoopPlugin.class);
|
loopPlugin = mock(LoopPlugin.class);
|
||||||
|
|
Loading…
Reference in a new issue