This commit is contained in:
Milos Kozak 2020-03-10 19:07:21 +01:00
parent 005d8e89ce
commit 4195083c05
2 changed files with 35 additions and 53 deletions

View file

@ -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();
}
}

View file

@ -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")
}
}