1 package com.xtremelabs.robolectric.res; 2 3 import static com.xtremelabs.robolectric.util.TestUtil.resourceFile; 4 import static org.hamcrest.CoreMatchers.equalTo; 5 import static org.junit.Assert.assertThat; 6 7 import com.xtremelabs.robolectric.R; 8 import org.junit.Before; 9 import org.junit.Test; 10 11 public class PluralResourceLoaderTest { 12 private PluralResourceLoader pluralResourceLoader; 13 14 @Before 15 public void setUp() throws Exception { 16 ResourceExtractor resourceExtractor = new ResourceExtractor(); 17 resourceExtractor.addLocalRClass(R.class); 18 19 StringResourceLoader stringResourceLoader = new StringResourceLoader(resourceExtractor); 20 pluralResourceLoader = new PluralResourceLoader(resourceExtractor, stringResourceLoader); 21 22 new DocumentLoader(stringResourceLoader).loadResourceXmlDir(resourceFile("res", "values")); 23 new DocumentLoader(pluralResourceLoader).loadResourceXmlDir(resourceFile("res", "values")); 24 } 25 26 @Test 27 public void testPluralsAreResolved() throws Exception { 28 assertThat(pluralResourceLoader.getValue(R.plurals.beer, 0), equalTo("Howdy")); 29 assertThat(pluralResourceLoader.getValue(R.plurals.beer, 1), equalTo("One beer")); 30 assertThat(pluralResourceLoader.getValue(R.plurals.beer, 2), equalTo("Two beers")); 31 assertThat(pluralResourceLoader.getValue(R.plurals.beer, 3), equalTo("%d beers, yay!")); 32 } 33 } 34