aboutsummaryrefslogtreecommitdiff
path: root/v1/src/test/java/com/xtremelabs/robolectric/shadows/SmsManagerTest.java
blob: 34c367ff64e96df9ed9ea76a955196cd4d5f27a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.xtremelabs.robolectric.shadows;

import junit.framework.Assert;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import android.telephony.SmsManager;

import com.xtremelabs.robolectric.Robolectric;
import com.xtremelabs.robolectric.WithTestDefaultsRunner;

@RunWith(WithTestDefaultsRunner.class)
public class SmsManagerTest {
	
	private SmsManager smsManager;
	private ShadowSmsManager shadowSmsManager;
	
	private String testDestinationAddress = "destinationAddress";
	private String testScAddress = "testServiceCenterAddress";
	private String testText = "testSmsBodyText";
	
	@Before
	public void setup() {
		Robolectric.bindShadowClass(ShadowSmsManager.class);
		smsManager = SmsManager.getDefault();
		shadowSmsManager = Robolectric.shadowOf(smsManager);
	}
	
	@After
	public void tearDown() {
		smsManager = null;
		shadowSmsManager = null;
	}
	
	@Test
	public void shouldHaveShadowSmsManager() {
		Assert.assertNotNull(shadowSmsManager);
	}
	
	@Test
	public void shouldStoreLastSentTextMessageParameters() {
		
		smsManager.sendTextMessage(testDestinationAddress, testScAddress, testText, null, null);
		
		ShadowSmsManager.TextSmsParams lastParams = shadowSmsManager.getLastSentTextMessageParams();
		
		Assert.assertEquals(testDestinationAddress, lastParams.getDestinationAddress());
		Assert.assertEquals(testScAddress, lastParams.getScAddress());
		Assert.assertEquals(testText, lastParams.getText());
	}

    @Test
    public void shouldClearLastSentTestMessageParameters() {
        smsManager.sendTextMessage(testDestinationAddress, testScAddress, testText, null, null);
        shadowSmsManager.clearLastSentTextMessageParams();
        Assert.assertNull(shadowSmsManager.getLastSentTextMessageParams());
    }
	
	@Test(expected=IllegalArgumentException.class)
	public void sendTextMessage_shouldThrowExceptionWithEmptyDestination() {
		smsManager.sendTextMessage("", testScAddress, testText, null, null);
	}
	
	@Test(expected=IllegalArgumentException.class)
	public void sentTextMessage_shouldThrowExceptionWithEmptyText() {
		smsManager.sendTextMessage(testDestinationAddress, testScAddress, "", null, null);
	}
}