Search in sources :

Example 1 with ShadowInstrumentation

use of org.robolectric.shadows.ShadowInstrumentation in project robolectric by robolectric.

the class AndroidTestEnvironment method createInstrumentation.

private Instrumentation createInstrumentation() {
    final ActivityThread activityThread = (ActivityThread) RuntimeEnvironment.getActivityThread();
    final _ActivityThread_ activityThreadReflector = reflector(_ActivityThread_.class, activityThread);
    Instrumentation androidInstrumentation = new RoboMonitoringInstrumentation();
    activityThreadReflector.setInstrumentation(androidInstrumentation);
    Application dummyInitialApplication = new Application();
    final ComponentName dummyInitialComponent = new ComponentName("", androidInstrumentation.getClass().getSimpleName());
    // TODO Move the API check into a helper method inside ShadowInstrumentation
    if (RuntimeEnvironment.getApiLevel() <= VERSION_CODES.JELLY_BEAN_MR1) {
        reflector(_Instrumentation_.class, androidInstrumentation).init(activityThread, dummyInitialApplication, dummyInitialApplication, dummyInitialComponent, null);
    } else {
        reflector(_Instrumentation_.class, androidInstrumentation).init(activityThread, dummyInitialApplication, dummyInitialApplication, dummyInitialComponent, null, null);
    }
    androidInstrumentation.onCreate(new Bundle());
    return androidInstrumentation;
}
Also used : Bundle(android.os.Bundle) Instrumentation(android.app.Instrumentation) ShadowInstrumentation(org.robolectric.shadows.ShadowInstrumentation) ShadowActivityThread(org.robolectric.shadows.ShadowActivityThread) ActivityThread(android.app.ActivityThread) ComponentName(android.content.ComponentName) ShadowActivityThread._ActivityThread_(org.robolectric.shadows.ShadowActivityThread._ActivityThread_) ShadowApplication(org.robolectric.shadows.ShadowApplication) Application(android.app.Application) ShadowInstrumentation._Instrumentation_(org.robolectric.shadows.ShadowInstrumentation._Instrumentation_)

Aggregations

ActivityThread (android.app.ActivityThread)1 Application (android.app.Application)1 Instrumentation (android.app.Instrumentation)1 ComponentName (android.content.ComponentName)1 Bundle (android.os.Bundle)1 ShadowActivityThread (org.robolectric.shadows.ShadowActivityThread)1 ShadowActivityThread._ActivityThread_ (org.robolectric.shadows.ShadowActivityThread._ActivityThread_)1 ShadowApplication (org.robolectric.shadows.ShadowApplication)1 ShadowInstrumentation (org.robolectric.shadows.ShadowInstrumentation)1 ShadowInstrumentation._Instrumentation_ (org.robolectric.shadows.ShadowInstrumentation._Instrumentation_)1