Home | History | Annotate | Download | only in shadows
      1 package com.xtremelabs.robolectric.shadows;
      2 
      3 import android.app.Activity;
      4 import android.preference.ListPreference;
      5 import com.xtremelabs.robolectric.R;
      6 import com.xtremelabs.robolectric.Robolectric;
      7 import com.xtremelabs.robolectric.WithTestDefaultsRunner;
      8 import org.junit.Before;
      9 import org.junit.Test;
     10 import org.junit.runner.RunWith;
     11 
     12 import static org.hamcrest.CoreMatchers.equalTo;
     13 import static org.hamcrest.CoreMatchers.instanceOf;
     14 import static org.hamcrest.CoreMatchers.notNullValue;
     15 import static org.hamcrest.CoreMatchers.nullValue;
     16 import static org.hamcrest.CoreMatchers.sameInstance;
     17 import static org.junit.Assert.assertThat;
     18 
     19 @RunWith(WithTestDefaultsRunner.class)
     20 public class ListPreferenceTest {
     21 
     22 	private ListPreference listPreference;
     23 	private ShadowListPreference shadow;
     24 
     25 	@Before
     26 	public void setUp() throws Exception {
     27 		listPreference = new ListPreference(new Activity());
     28 		shadow = Robolectric.shadowOf(listPreference);
     29     }
     30 
     31 	@Test
     32 	public void shouldInheritFromDialogPreference() {
     33 		assertThat(shadow, instanceOf(ShadowDialogPreference.class));
     34 	}
     35 
     36 	@Test
     37 	public void shouldHaveEntries() {
     38 		CharSequence[] entries = { "this", "is", "only", "a", "test" };
     39 
     40 		assertThat(listPreference.getEntries(), nullValue());
     41 		listPreference.setEntries(entries);
     42 		assertThat(listPreference.getEntries(), sameInstance(entries));
     43 	}
     44 
     45 	@Test
     46 	public void shouldSetEntriesByResourceId() {
     47 		assertThat(listPreference.getEntries(), nullValue());
     48 		listPreference.setEntries(R.array.greetings);
     49 		assertThat(listPreference.getEntries(), notNullValue());
     50 	}
     51 
     52 	@Test
     53 	public void shouldHaveEntryValues() {
     54 		CharSequence[] entryValues = { "this", "is", "only", "a", "test" };
     55 
     56 		assertThat(listPreference.getEntryValues(), nullValue());
     57 		listPreference.setEntryValues(entryValues);
     58 		assertThat(listPreference.getEntryValues(), sameInstance(entryValues));
     59 	}
     60 
     61 	@Test
     62 	public void shouldSetEntryValuesByResourceId() {
     63 		assertThat(listPreference.getEntryValues(), nullValue());
     64 		listPreference.setEntryValues(R.array.greetings);
     65 		assertThat(listPreference.getEntryValues(), notNullValue());
     66 	}
     67 
     68 	@Test
     69 	public void shouldSetValue() {
     70 		assertThat(listPreference.getValue(), nullValue());
     71 		listPreference.setValue("testing");
     72 		assertThat(listPreference.getValue(), equalTo("testing"));
     73 	}
     74 }
     75