Home | History | Annotate | Download | only in shadows
      1 package com.xtremelabs.robolectric.shadows;
      2 
      3 import static org.hamcrest.CoreMatchers.equalTo;
      4 import static org.hamcrest.CoreMatchers.instanceOf;
      5 import static org.hamcrest.CoreMatchers.nullValue;
      6 import static org.hamcrest.CoreMatchers.notNullValue;
      7 import static org.junit.Assert.assertThat;
      8 
      9 import org.junit.Before;
     10 import org.junit.Test;
     11 import org.junit.runner.RunWith;
     12 
     13 import android.app.Activity;
     14 import android.preference.PreferenceActivity;
     15 import android.widget.ListView;
     16 
     17 import com.xtremelabs.robolectric.R;
     18 import com.xtremelabs.robolectric.Robolectric;
     19 import com.xtremelabs.robolectric.WithTestDefaultsRunner;
     20 
     21 @RunWith(WithTestDefaultsRunner.class)
     22 public class PreferenceActivityTest {
     23 
     24 	private TestPreferenceActivity activity;
     25 	private ShadowPreferenceActivity shadow;
     26 
     27     @Before
     28     public void setUp() throws Exception {
     29     	activity = new TestPreferenceActivity();
     30     	shadow = Robolectric.shadowOf(activity);
     31     }
     32 
     33     @Test
     34     public void shouldGetListView() {
     35     	shadow.setListView( new ListView( new Activity() ) );
     36     	assertThat( activity.getListView(), notNullValue() );
     37     }
     38 
     39 	@Test
     40 	public void shouldInheritFromListActivity() {
     41 		assertThat(shadow, instanceOf(ShadowListActivity.class));
     42 	}
     43 
     44 	@Test
     45 	public void shouldNotInitializePreferenceScreen() {
     46 		assertThat(activity.getPreferenceScreen(), nullValue());
     47 	}
     48 
     49 	@Test
     50 	public void shouldRecordPreferencesResourceId() {
     51 		assertThat(shadow.getPreferencesResId(), equalTo(-1));
     52 		activity.addPreferencesFromResource(R.xml.preferences);
     53 		assertThat(shadow.getPreferencesResId(), equalTo(R.xml.preferences));
     54 	}
     55 
     56 	@Test
     57 	public void shouldLoadPreferenceScreen() {
     58 		activity.addPreferencesFromResource(R.xml.preferences);
     59 		assertThat( activity.getPreferenceScreen().getPreferenceCount(), equalTo(6));
     60 	}
     61 
     62 	private static class TestPreferenceActivity extends PreferenceActivity {
     63 	}
     64 }
     65