From 4195083c05a194c2c275ed77f0fcf47e88197c02 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 10 Mar 2020 19:07:21 +0100 Subject: [PATCH] SmsTest --- .../general/smsCommunicator/SmsTest.java | 53 ------------------- .../general/smsCommunicator/SmsTest.kt | 35 ++++++++++++ 2 files changed, 35 insertions(+), 53 deletions(-) delete mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsTest.java create mode 100644 app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsTest.kt 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 deleted file mode 100644 index a406a35f9d..0000000000 --- a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsTest.java +++ /dev/null @@ -1,53 +0,0 @@ -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.getPhoneNumber(), "aNumber"); - Assert.assertEquals(sms.getText(), "aBody"); - Assert.assertTrue(sms.getReceived()); - - sms = new Sms("aNumber", "aBody"); - 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.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"); - } - - @Before - public void prepareTests() { - AAPSMocker.mockMainApp(); - AAPSMocker.mockStrings(); - } -} diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsTest.kt new file mode 100644 index 0000000000..bf733146ca --- /dev/null +++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/smsCommunicator/SmsTest.kt @@ -0,0 +1,35 @@ +package info.nightscout.androidaps.plugins.general.smsCommunicator + +import android.telephony.SmsMessage +import info.TestBase +import info.nightscout.androidaps.R +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.powermock.api.mockito.PowerMockito +import org.powermock.core.classloader.annotations.PrepareForTest +import org.powermock.modules.junit4.PowerMockRunner + +@RunWith(PowerMockRunner::class) +@PrepareForTest(SmsMessage::class) +class SmsTest : TestBase() { + + @Test fun doTests() { + val smsMessage = PowerMockito.mock(SmsMessage::class.java) + PowerMockito.`when`(smsMessage.originatingAddress).thenReturn("aNumber") + PowerMockito.`when`(smsMessage.messageBody).thenReturn("aBody") + var sms = Sms(smsMessage) + Assert.assertEquals(sms.phoneNumber, "aNumber") + Assert.assertEquals(sms.text, "aBody") + Assert.assertTrue(sms.received) + sms = Sms("aNumber", "aBody") + Assert.assertEquals(sms.phoneNumber, "aNumber") + Assert.assertEquals(sms.text, "aBody") + Assert.assertTrue(sms.sent) + sms = Sms("aNumber", "U") + Assert.assertEquals(sms.phoneNumber, "aNumber") + Assert.assertEquals(sms.text, "U") + Assert.assertTrue(sms.sent) + Assert.assertEquals(sms.toString(), "SMS from aNumber: U") + } +} \ No newline at end of file