Search in sources :

Example 1 with MockContext

use of proton.inject.MockContext in project AndroidTraining by mixi-inc.

the class FieldListenerTest method setUp.

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

        @Override
        protected void configure() {
            super.configure();
            bindFieldListener(TestAnnotation.class, FieldListenerTest.this);
        }
    });
    mInjector = Proton.getInjector(new MockContext(mMockApplication));
}
Also used : MockContext(proton.inject.MockContext) MockApplication(android.test.mock.MockApplication) DefaultModule(proton.inject.DefaultModule)

Example 2 with MockContext

use of proton.inject.MockContext in project AndroidTraining by mixi-inc.

the class ProviderListenerTest method setUp.

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

        @Override
        protected void configure() {
            super.configure();
            bindProviderListener(ProviderListenerTest.this);
            bind(Aaa.class);
        }
    });
    mInjector = Proton.getInjector(new MockContext(mMockApplication));
}
Also used : MockContext(proton.inject.MockContext) MockApplication(android.test.mock.MockApplication) DefaultModule(proton.inject.DefaultModule)

Example 3 with MockContext

use of proton.inject.MockContext in project AndroidTraining by mixi-inc.

the class ObserverTest 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(Observer.class);
        }
    });
    mInjector = Proton.getInjector(new MockContext(mMockApplication));
}
Also used : MockContext(proton.inject.MockContext) MockApplication(android.test.mock.MockApplication) DefaultModule(proton.inject.DefaultModule)

Example 4 with MockContext

use of proton.inject.MockContext 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 5 with MockContext

use of proton.inject.MockContext in project AndroidTraining by mixi-inc.

the class StateRecoveryTest method testRecovery.

public void testRecovery() {
    mObserverManager.fire(new OnCreateEvent(null));
    Aaa a1 = mInjector.getInstance(Aaa.class);
    a1.intState = 1;
    a1.integerState = Integer.valueOf(1);
    a1.intArrayState[0] = 1;
    ArrayList<Integer> integerList = new ArrayList<Integer>();
    integerList.add(1);
    a1.integerListState = integerList;
    a1.stringState = "a";
    a1.stringArrayState = new String[] { "aa" };
    ParcelableClass parcelable = new ParcelableClass("a");
    a1.parcelableState = parcelable;
    ParcelableClass[] parcelableArray = new ParcelableClass[1];
    parcelableArray[0] = new ParcelableClass("a");
    a1.parcelableArrayState = parcelableArray;
    Bundle outState = new Bundle();
    mObserverManager.fire(new OnSaveInstanceStateEvent(outState));
    mObserverManager.fire(new OnDestroyEvent());
    Injector injector = Proton.getInjector(new MockContext(mMockApplication));
    injector.getInstance(StateEventObserver.class);
    injector.getInstance(ObserverManager.class).fire(new OnCreateEvent(outState));
    Aaa a2 = injector.getInstance(Aaa.class);
    assertNotSame(a1, a2);
    assertEquals(1, a2.intState);
    assertEquals(Integer.valueOf(1), a2.integerState);
    assertEquals(1, a2.intArrayState[0]);
    assertEquals("a", a2.stringState);
    assertEquals("aa", a2.stringArrayState[0]);
    assertEquals(integerList, a2.integerListState);
    assertEquals("a", a2.parcelableState.string);
    assertEquals("a", a2.parcelableArrayState[0].string);
    injector.getInstance(ObserverManager.class).fire(new OnDestroyEvent());
}
Also used : MockContext(proton.inject.MockContext) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) OnCreateEvent(proton.inject.observer.event.OnCreateEvent) OnSaveInstanceStateEvent(proton.inject.observer.event.OnSaveInstanceStateEvent) Injector(proton.inject.Injector) OnDestroyEvent(proton.inject.observer.event.OnDestroyEvent) ObserverManager(proton.inject.observer.ObserverManager)

Aggregations

MockContext (proton.inject.MockContext)5 MockApplication (android.test.mock.MockApplication)4 DefaultModule (proton.inject.DefaultModule)4 ObserverManager (proton.inject.observer.ObserverManager)2 Bundle (android.os.Bundle)1 ArrayList (java.util.ArrayList)1 Injector (proton.inject.Injector)1 OnCreateEvent (proton.inject.observer.event.OnCreateEvent)1 OnDestroyEvent (proton.inject.observer.event.OnDestroyEvent)1 OnSaveInstanceStateEvent (proton.inject.observer.event.OnSaveInstanceStateEvent)1