Search in sources :

Example 1 with ResourceTable

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);
}
Also used : XmlBlock(org.robolectric.res.builder.XmlBlock) ResName(org.robolectric.res.ResName) ResourceTable(org.robolectric.res.ResourceTable)

Example 2 with ResourceTable

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.");
}
Also used : ResName(org.robolectric.res.ResName) Robolectric(org.robolectric.Robolectric) ResourceTable(org.robolectric.res.ResourceTable) Test(org.junit.Test)

Aggregations

ResName (org.robolectric.res.ResName)2 ResourceTable (org.robolectric.res.ResourceTable)2 Test (org.junit.Test)1 Robolectric (org.robolectric.Robolectric)1 XmlBlock (org.robolectric.res.builder.XmlBlock)1