use of org.robolectric.res.ResourceTable in project robolectric by robolectric.
the class ShadowAssetManager method loadXmlResourceParser.
public XmlResourceParser loadXmlResourceParser(int resId, String type) throws Resources.NotFoundException {
ResName resName = getResName(resId);
ResName resolvedResName = resolveResName(resName, RuntimeEnvironment.getQualifiers());
if (resolvedResName == null) {
throw new RuntimeException("couldn't resolve " + resName.getFullyQualifiedName());
}
resName = resolvedResName;
XmlBlock block = resourceTable.getXml(resName, RuntimeEnvironment.getQualifiers());
if (block == null) {
throw new Resources.NotFoundException(resName.getFullyQualifiedName());
}
ResourceTable resourceProvider = ResourceIds.isFrameworkResource(resId) ? RuntimeEnvironment.getSystemResourceTable() : RuntimeEnvironment.getCompileTimeResourceTable();
return getXmlResourceParser(resourceProvider, block, resName.packageName);
}
use of org.robolectric.res.ResourceTable in project robolectric by robolectric.
the class ResourceLoaderTest method shouldMakeInternalResourcesAvailable.
@Test
public void shouldMakeInternalResourcesAvailable() throws Exception {
ResourceTable resourceProvider = RuntimeEnvironment.getSystemResourceTable();
ResName internalResource = new ResName("android", "string", "badPin");
Integer resId = resourceProvider.getResourceId(internalResource);
assertThat(resId).isNotNull();
assertThat(resourceProvider.getResName(resId)).isEqualTo(internalResource);
Class<?> internalRIdClass = Robolectric.class.getClassLoader().loadClass("com.android.internal.R$" + internalResource.type);
int internalResourceId;
internalResourceId = (Integer) internalRIdClass.getDeclaredField(internalResource.name).get(null);
assertThat(resId).isEqualTo(internalResourceId);
assertThat(RuntimeEnvironment.application.getResources().getString(resId)).isEqualTo("The old PIN you typed isn't correct.");
}
Aggregations