1 package com.xtremelabs.robolectric.res; 2 3 import com.xtremelabs.robolectric.R; 4 import org.junit.Before; 5 import org.junit.Test; 6 7 import java.io.File; 8 import java.util.Arrays; 9 10 import static com.xtremelabs.robolectric.util.TestUtil.getSystemResourceDir; 11 import static com.xtremelabs.robolectric.util.TestUtil.resourceFile; 12 import static org.hamcrest.core.IsCollectionContaining.hasItems; 13 import static org.junit.Assert.assertThat; 14 15 public class StringArrayResourceLoaderTest { 16 private StringArrayResourceLoader stringArrayResourceLoader; 17 18 @Before public void setUp() throws Exception { 19 ResourceExtractor resourceExtractor = new ResourceExtractor(); 20 resourceExtractor.addLocalRClass(R.class); 21 resourceExtractor.addSystemRClass(android.R.class); 22 23 File resourceXmlDir = resourceFile("res", "values"); 24 File systemResourceXmlDir = getSystemResourceDir("values"); 25 26 StringResourceLoader stringResourceLoader = new StringResourceLoader(resourceExtractor); 27 new DocumentLoader(stringResourceLoader).loadResourceXmlDir(resourceXmlDir); 28 new DocumentLoader(stringResourceLoader).loadSystemResourceXmlDir(systemResourceXmlDir); 29 30 stringArrayResourceLoader = new StringArrayResourceLoader(resourceExtractor, stringResourceLoader); 31 new DocumentLoader(stringArrayResourceLoader).loadResourceXmlDir(resourceXmlDir); 32 new DocumentLoader(stringArrayResourceLoader).loadSystemResourceXmlDir(systemResourceXmlDir); 33 } 34 35 @Test 36 public void testStringsAreResolved() throws Exception { 37 assertThat(Arrays.asList(stringArrayResourceLoader.getArrayValue(R.array.items)), hasItems("foo", "bar")); 38 } 39 40 @Test 41 public void testStringsAreWithReferences() throws Exception { 42 assertThat(Arrays.asList(stringArrayResourceLoader.getArrayValue(R.array.greetings)), hasItems("hola", "Hello")); 43 } 44 45 @Test 46 public void shouldAddAndroidToSystemStringArrayName() throws Exception { 47 assertThat(Arrays.asList(stringArrayResourceLoader.getArrayValue(android.R.array.emailAddressTypes)), hasItems("Home", "Work", "Other", "Custom")); 48 assertThat(Arrays.asList(stringArrayResourceLoader.getArrayValue(R.array.emailAddressTypes)), hasItems("Doggy", "Catty")); 49 } 50 } 51