Home | History | Annotate | Download | only in shadows
      1 package com.xtremelabs.robolectric.shadows;
      2 
      3 import junit.framework.Assert;
      4 
      5 import org.junit.After;
      6 import org.junit.Before;
      7 import org.junit.Test;
      8 import org.junit.runner.RunWith;
      9 
     10 import android.telephony.SmsManager;
     11 
     12 import com.xtremelabs.robolectric.Robolectric;
     13 import com.xtremelabs.robolectric.WithTestDefaultsRunner;
     14 
     15 @RunWith(WithTestDefaultsRunner.class)
     16 public class SmsManagerTest {
     17 
     18 	private SmsManager smsManager;
     19 	private ShadowSmsManager shadowSmsManager;
     20 
     21 	private String testDestinationAddress = "destinationAddress";
     22 	private String testScAddress = "testServiceCenterAddress";
     23 	private String testText = "testSmsBodyText";
     24 
     25 	@Before
     26 	public void setup() {
     27 		Robolectric.bindShadowClass(ShadowSmsManager.class);
     28 		smsManager = SmsManager.getDefault();
     29 		shadowSmsManager = Robolectric.shadowOf(smsManager);
     30 	}
     31 
     32 	@After
     33 	public void tearDown() {
     34 		smsManager = null;
     35 		shadowSmsManager = null;
     36 	}
     37 
     38 	@Test
     39 	public void shouldHaveShadowSmsManager() {
     40 		Assert.assertNotNull(shadowSmsManager);
     41 	}
     42 
     43 	@Test
     44 	public void shouldStoreLastSentTextMessageParameters() {
     45 
     46 		smsManager.sendTextMessage(testDestinationAddress, testScAddress, testText, null, null);
     47 
     48 		ShadowSmsManager.TextSmsParams lastParams = shadowSmsManager.getLastSentTextMessageParams();
     49 
     50 		Assert.assertEquals(testDestinationAddress, lastParams.getDestinationAddress());
     51 		Assert.assertEquals(testScAddress, lastParams.getScAddress());
     52 		Assert.assertEquals(testText, lastParams.getText());
     53 	}
     54 
     55     @Test
     56     public void shouldClearLastSentTestMessageParameters() {
     57         smsManager.sendTextMessage(testDestinationAddress, testScAddress, testText, null, null);
     58         shadowSmsManager.clearLastSentTextMessageParams();
     59         Assert.assertNull(shadowSmsManager.getLastSentTextMessageParams());
     60     }
     61 
     62 	@Test(expected=IllegalArgumentException.class)
     63 	public void sendTextMessage_shouldThrowExceptionWithEmptyDestination() {
     64 		smsManager.sendTextMessage("", testScAddress, testText, null, null);
     65 	}
     66 
     67 	@Test(expected=IllegalArgumentException.class)
     68 	public void sentTextMessage_shouldThrowExceptionWithEmptyText() {
     69 		smsManager.sendTextMessage(testDestinationAddress, testScAddress, "", null, null);
     70 	}
     71 }
     72