Permalink
Browse files

Fixed bug to prevent it from an NPE when the ColorResolver can't reso…

…lve a drawable
  • Loading branch information...
1 parent d51b9b2 commit f647512bd80162f9cb6b2fac8c7b0db984266967 Amrit Thakur & Chris Perry committed May 22, 2012
View
7 src/main/java/com/xtremelabs/robolectric/res/ColorResourceLoader.java
@@ -30,7 +30,12 @@ public ColorResourceLoader(ResourceExtractor resourceExtractor) {
public int getValue(int colorId) {
String resourceName = resourceExtractor.getResourceName(colorId);
- return resourceName == null ? -1 : colorResolver.getValue(resourceName);
+ if (resourceName == null) {
+ return -1;
+ }
+
+ Integer colorResolverValue = colorResolver.getValue(resourceName);
+ return colorResolverValue == null ? -1 : colorResolverValue;
}
@Override
View
5 src/test/java/com/xtremelabs/robolectric/res/ColorResourceLoaderTest.java
@@ -23,6 +23,11 @@
}
@Test
+ public void shouldHandleNonColorResourcesWithoutCrashing() throws Exception {
+ assertThat(colorResourceLoader.getValue(R.drawable.l0_red), equalTo(-0x000001));
+ }
+
+ @Test
public void testStringsAreResolved() throws Exception {
assertThat(colorResourceLoader.getValue(R.color.black), equalTo(0x000000));
assertThat(colorResourceLoader.getValue(R.color.white), equalTo(0xffffff));

0 comments on commit f647512

Please sign in to comment.