Search in sources :

Example 26 with MockApplication

use of android.test.mock.MockApplication in project platform_frameworks_base by android.

the class ServiceTestCase method setupService.

/**
     * Creates the service under test and attaches all injected dependencies
     * (Context, Application) to it.  This is called automatically by {@link #startService} or
     * by {@link #bindService}.
     * If you need to call {@link AndroidTestCase#setContext(Context) setContext()} or
     * {@link #setApplication setApplication()}, do so before calling this method.
     */
protected void setupService() {
    mService = null;
    try {
        mService = mServiceClass.newInstance();
    } catch (Exception e) {
        assertNotNull(mService);
    }
    if (getApplication() == null) {
        setApplication(new MockApplication());
    }
    mService.attach(getContext(), // ActivityThread not actually used in Service
    null, mServiceClass.getName(), // token not needed when not talking with the activity manager
    null, getApplication(), // mocked services don't talk with the activity manager
    null);
    assertNotNull(mService);
    mServiceId = new Random().nextInt();
    mServiceAttached = true;
}
Also used : MockApplication(android.test.mock.MockApplication) Random(java.util.Random)

Aggregations

MockApplication (android.test.mock.MockApplication)26 ComponentName (android.content.ComponentName)5 ActivityInfo (android.content.pm.ActivityInfo)5 IBinder (android.os.IBinder)5 Random (java.util.Random)5 DefaultModule (proton.inject.DefaultModule)4 MockContext (proton.inject.MockContext)4 ApplicationScoped (proton.inject.scope.ApplicationScoped)3 ActivityNotFoundException (android.content.ActivityNotFoundException)1 TypedArray (android.content.res.TypedArray)1 RemoteException (android.os.RemoteException)1 ActionBarActivity (android.support.v7.app.ActionBarActivity)1 SuperStartActivity (org.holoeverywhere.ThemeManager.SuperStartActivity)1 IAddonActivity (org.holoeverywhere.addon.IAddonActivity)1 Activity (org.holoeverywhere.app.Activity)1 Application (org.holoeverywhere.app.Application)1 ObserverManager (proton.inject.observer.ObserverManager)1 Dependent (proton.inject.scope.Dependent)1