1 package org.robolectric.res; 2 3 import static com.google.common.truth.Truth.assertThat; 4 import static java.util.Arrays.asList; 5 6 import org.junit.Before; 7 import org.junit.Test; 8 import org.junit.runner.RunWith; 9 import org.junit.runners.JUnit4; 10 11 @RunWith(JUnit4.class) 12 public class ThemeStyleSetTest { 13 14 private ThemeStyleSet themeStyleSet; 15 16 @Before setUp()17 public void setUp() throws Exception { 18 themeStyleSet = new ThemeStyleSet(); 19 } 20 21 @Test shouldFindAttributesFromAnAppliedStyle()22 public void shouldFindAttributesFromAnAppliedStyle() throws Exception { 23 themeStyleSet = new ThemeStyleSet(); 24 themeStyleSet.apply(createStyle("style1", 25 createAttribute("string1", "string1 value from style1"), 26 createAttribute("string2", "string2 value from style1") 27 ), false); 28 themeStyleSet.apply(createStyle("style2", createAttribute("string2", "string2 value from style2")), false); 29 assertThat(themeStyleSet.getAttrValue(attrName("string1")).value).isEqualTo("string1 value from style1"); 30 assertThat(themeStyleSet.getAttrValue(attrName("string2")).value).isEqualTo("string2 value from style1"); 31 } 32 33 @Test shouldFindAttributesFromAnAppliedFromForcedStyle()34 public void shouldFindAttributesFromAnAppliedFromForcedStyle() throws Exception { 35 themeStyleSet.apply(createStyle("style1", 36 createAttribute("string1", "string1 value from style1"), 37 createAttribute("string2", "string2 value from style1") 38 ), false); 39 themeStyleSet.apply(createStyle("style2", createAttribute("string1", "string1 value from style2")), true); 40 assertThat(themeStyleSet.getAttrValue(attrName("string1")).value).isEqualTo("string1 value from style2"); 41 assertThat(themeStyleSet.getAttrValue(attrName("string2")).value).isEqualTo("string2 value from style1"); 42 } 43 createStyle(String styleName, AttributeResource... attributeResources)44 private StyleData createStyle(String styleName, AttributeResource... attributeResources) { 45 return new StyleData("package", styleName, null, asList(attributeResources)); 46 } 47 createAttribute(String attrName, String value)48 private AttributeResource createAttribute(String attrName, String value) { 49 return new AttributeResource(attrName(attrName), value, "package"); 50 } 51 attrName(String attrName)52 private ResName attrName(String attrName) { 53 return new ResName("package", "attr", attrName); 54 } 55 }