aboutsummaryrefslogtreecommitdiff
path: root/v1/src/test/java/com/xtremelabs/robolectric/shadows/PreferenceActivityTest.java
blob: 6f95f31b222eaa3c1276bed7a3df30ee5d24753d (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
package com.xtremelabs.robolectric.shadows;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;

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

import android.app.Activity;
import android.preference.PreferenceActivity;
import android.widget.ListView;

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

@RunWith(WithTestDefaultsRunner.class)
public class PreferenceActivityTest {

	private TestPreferenceActivity activity;
	private ShadowPreferenceActivity shadow;
	
    @Before
    public void setUp() throws Exception {
    	activity = new TestPreferenceActivity();
    	shadow = Robolectric.shadowOf(activity);
    }
    
    @Test
    public void shouldGetListView() {
    	shadow.setListView( new ListView( new Activity() ) );
    	assertThat( activity.getListView(), notNullValue() );    	
    }
    
	@Test
	public void shouldInheritFromListActivity() {
		assertThat(shadow, instanceOf(ShadowListActivity.class));
	}
	
	@Test
	public void shouldNotInitializePreferenceScreen() {
		assertThat(activity.getPreferenceScreen(), nullValue());
	}
    
	@Test
	public void shouldRecordPreferencesResourceId() {
		assertThat(shadow.getPreferencesResId(), equalTo(-1));
		activity.addPreferencesFromResource(R.xml.preferences);
		assertThat(shadow.getPreferencesResId(), equalTo(R.xml.preferences));		
	}
	
	@Test
	public void shouldLoadPreferenceScreen() {
		activity.addPreferencesFromResource(R.xml.preferences);
		assertThat( activity.getPreferenceScreen().getPreferenceCount(), equalTo(6));
	}
	
	private static class TestPreferenceActivity extends PreferenceActivity {		
	}
}