Search in sources :

Example 16 with MockApplication

use of android.test.mock.MockApplication in project android_frameworks_base by ParanoidAndroid.

the class ActivityUnitTestCase method startActivity.

/**
     * Start the activity under test, in the same way as if it was started by
     * {@link android.content.Context#startActivity Context.startActivity()}, providing the 
     * arguments it supplied.  When you use this method to start the activity, it will automatically
     * be stopped by {@link #tearDown}.
     * 
     * <p>This method will call onCreate(), but if you wish to further exercise Activity life 
     * cycle methods, you must call them yourself from your test case.
     * 
     * <p><i>Do not call from your setUp() method.  You must call this method from each of your
     * test methods.</i>
     *  
     * @param intent The Intent as if supplied to {@link android.content.Context#startActivity}.
     * @param savedInstanceState The instance state, if you are simulating this part of the life
     * cycle.  Typically null.
     * @param lastNonConfigurationInstance This Object will be available to the 
     * Activity if it calls {@link android.app.Activity#getLastNonConfigurationInstance()}.  
     * Typically null.
     * @return Returns the Activity that was created
     */
protected T startActivity(Intent intent, Bundle savedInstanceState, Object lastNonConfigurationInstance) {
    assertFalse("Activity already created", mCreated);
    if (!mAttached) {
        assertNotNull(mActivityClass);
        setActivity(null);
        T newActivity = null;
        try {
            IBinder token = null;
            if (mApplication == null) {
                setApplication(new MockApplication());
            }
            ComponentName cn = new ComponentName(mActivityClass.getPackage().getName(), mActivityClass.getName());
            intent.setComponent(cn);
            ActivityInfo info = new ActivityInfo();
            CharSequence title = mActivityClass.getName();
            mMockParent = new MockParent();
            String id = null;
            newActivity = (T) getInstrumentation().newActivity(mActivityClass, mActivityContext, token, mApplication, intent, info, title, mMockParent, id, lastNonConfigurationInstance);
        } catch (Exception e) {
            assertNotNull(newActivity);
        }
        assertNotNull(newActivity);
        setActivity(newActivity);
        mAttached = true;
    }
    T result = getActivity();
    if (result != null) {
        getInstrumentation().callActivityOnCreate(getActivity(), savedInstanceState);
        mCreated = true;
    }
    return result;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) IBinder(android.os.IBinder) MockApplication(android.test.mock.MockApplication) ComponentName(android.content.ComponentName)

Example 17 with MockApplication

use of android.test.mock.MockApplication in project AndroidTraining by mixi-inc.

the class StateRecoveryTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mMockApplication = new MockApplication();
    Proton.initialize(mMockApplication, new DefaultModule() {

        @Override
        protected void configure() {
            super.configure();
            bind(Aaa.class);
        }
    });
    mInjector = Proton.getInjector(new MockContext(mMockApplication));
    mObserverManager = mInjector.getInstance(ObserverManager.class);
    mStateEventObserver = mInjector.getInstance(StateEventObserver.class);
}
Also used : MockContext(proton.inject.MockContext) MockApplication(android.test.mock.MockApplication) DefaultModule(proton.inject.DefaultModule) ObserverManager(proton.inject.observer.ObserverManager)

Example 18 with MockApplication

use of android.test.mock.MockApplication in project AndroidTraining by mixi-inc.

the class ApplicationInjectionTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mMockApplication = new MockApplication();
    Proton.initialize(mMockApplication);
    mInjector = Proton.getInjector(new MockContext(mMockApplication));
}
Also used : MockApplication(android.test.mock.MockApplication)

Example 19 with MockApplication

use of android.test.mock.MockApplication in project AndroidTraining by mixi-inc.

the class ContextInjectionTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mMockApplication = new MockApplication();
    Proton.initialize(mMockApplication, new DefaultModule() {

        @Override
        protected void configure() {
            super.configure();
            bind(Client.class);
        }
    });
}
Also used : MockApplication(android.test.mock.MockApplication)

Example 20 with MockApplication

use of android.test.mock.MockApplication in project AndroidTraining by mixi-inc.

the class ContextScopedInjectionTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    mMockApplication = new MockApplication();
    Proton.initialize(mMockApplication, new DefaultModule() {

        @Override
        protected void configure() {
            super.configure();
            bind(Client.class);
            bind(ContextScopedClass.class);
        }
    });
}
Also used : MockApplication(android.test.mock.MockApplication)

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