Search in sources :

Example 1 with PackageResourceTable

use of org.robolectric.res.PackageResourceTable in project robolectric by robolectric.

the class RobolectricTestRunner method beforeTest.

@Override
protected void beforeTest(Sandbox sandbox, FrameworkMethod method, Method bootstrappedMethod) throws Throwable {
    SdkEnvironment sdkEnvironment = (SdkEnvironment) sandbox;
    RobolectricFrameworkMethod roboMethod = (RobolectricFrameworkMethod) method;
    roboMethod.parallelUniverseInterface = getHooksInterface(sdkEnvironment);
    Class<TestLifecycle> cl = sdkEnvironment.bootstrappedClass(getTestLifecycleClass());
    roboMethod.testLifecycle = ReflectionHelpers.newInstance(cl);
    final Config config = roboMethod.config;
    final AndroidManifest appManifest = roboMethod.getAppManifest();
    roboMethod.parallelUniverseInterface.setSdkConfig((sdkEnvironment).getSdkConfig());
    roboMethod.parallelUniverseInterface.resetStaticState(config);
    SdkConfig sdkConfig = roboMethod.sdkConfig;
    Class<?> androidBuildVersionClass = (sdkEnvironment).bootstrappedClass(Build.VERSION.class);
    ReflectionHelpers.setStaticField(androidBuildVersionClass, "SDK_INT", sdkConfig.getApiLevel());
    ReflectionHelpers.setStaticField(androidBuildVersionClass, "RELEASE", sdkConfig.getAndroidVersion());
    PackageResourceTable systemResourceTable = sdkEnvironment.getSystemResourceTable(getJarResolver());
    PackageResourceTable appResourceTable = getAppResourceTable(appManifest);
    roboMethod.parallelUniverseInterface.setUpApplicationState(bootstrappedMethod, roboMethod.testLifecycle, appManifest, config, new RoutingResourceTable(getCompiletimeSdkResourceTable(), appResourceTable), new RoutingResourceTable(systemResourceTable, appResourceTable), new RoutingResourceTable(systemResourceTable));
    roboMethod.testLifecycle.beforeTest(bootstrappedMethod);
}
Also used : PackageResourceTable(org.robolectric.res.PackageResourceTable) Config(org.robolectric.annotation.Config) Build(android.os.Build) RoutingResourceTable(org.robolectric.res.RoutingResourceTable) AndroidManifest(org.robolectric.manifest.AndroidManifest)

Example 2 with PackageResourceTable

use of org.robolectric.res.PackageResourceTable in project robolectric by robolectric.

the class RobolectricTestRunner method getAppResourceTable.

private PackageResourceTable getAppResourceTable(final AndroidManifest appManifest) {
    PackageResourceTable resourceTable = appResourceTableCache.get(appManifest);
    if (resourceTable == null) {
        resourceTable = ResourceMerger.buildResourceTable(appManifest);
        appResourceTableCache.put(appManifest, resourceTable);
    }
    return resourceTable;
}
Also used : PackageResourceTable(org.robolectric.res.PackageResourceTable)

Aggregations

PackageResourceTable (org.robolectric.res.PackageResourceTable)2 Build (android.os.Build)1 Config (org.robolectric.annotation.Config)1 AndroidManifest (org.robolectric.manifest.AndroidManifest)1 RoutingResourceTable (org.robolectric.res.RoutingResourceTable)1