From a8a1bb793fba9680432ed531d49d6a5defe574c4 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 12 Mar 2019 18:58:26 +0100 Subject: [PATCH] SmsTest --- .../general/smsCommunicator/SmsTest.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsTest.java 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 new file mode 100644 index 0000000000..5f7af11a67 --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsTest.java @@ -0,0 +1,53 @@ +package info.nightscout.androidaps.plugins.general.smsCommunicator; + +import android.telephony.SmsMessage; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import info.AAPSMocker; +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; + +import static org.powermock.api.mockito.PowerMockito.mock; +import static org.powermock.api.mockito.PowerMockito.when; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({SmsMessage.class, MainApp.class}) + +public class SmsTest { + + @Test + public void doTests() { + SmsMessage smsMessage = mock(SmsMessage.class); + when(smsMessage.getOriginatingAddress()).thenReturn("aNumber"); + when(smsMessage.getMessageBody()).thenReturn("aBody"); + + Sms sms = new Sms(smsMessage); + Assert.assertEquals(sms.phoneNumber, "aNumber"); + Assert.assertEquals(sms.text, "aBody"); + Assert.assertTrue(sms.received); + + sms = new Sms("aNumber", "aBody"); + Assert.assertEquals(sms.phoneNumber, "aNumber"); + Assert.assertEquals(sms.text, "aBody"); + Assert.assertTrue(sms.sent); + + 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.toString(), "SMS from aNumber: U"); + } + + @Before + public void prepareTests() { + AAPSMocker.mockMainApp(); + AAPSMocker.mockStrings(); + } +}