Search in sources :

Example 16 with MortarScope

use of mortar.MortarScope in project mortar by square.

the class BundleServiceTest method endScopeEndBundle.

// Make sure that when a scope dies, a new scope with the same name doesn't
// accidentally receive the old one's bundle.
@Test
public void endScopeEndBundle() {
    MyBundler fooBundler = new MyBundler("fooBundler") {

        @Override
        public void onLoad(Bundle savedInstanceState) {
            assertThat(savedInstanceState).isNull();
        }

        @Override
        public void onSave(Bundle outState) {
            outState.putString("baz", "bang");
        }
    };
    // First visit to the foo screen, bundle will be null.
    MortarScope fooScope = activityScope.buildChild().build("fooScope");
    getBundleService(fooScope).register(fooBundler);
    // Android saves state
    Bundle state = new Bundle();
    getBundleServiceRunner(activityScope).onSaveInstanceState(state);
    // We leave the foo screen.
    fooScope.destroy();
    // And now we come back to it. New instance's onLoad should also get a null bundle.
    fooScope = activityScope.buildChild().build("fooScope");
    getBundleService(fooScope).register(fooBundler);
}
Also used : Bundle(android.os.Bundle) MortarScope(mortar.MortarScope) Test(org.junit.Test)

Aggregations

MortarScope (mortar.MortarScope)16 Test (org.junit.Test)12 Bundle (android.os.Bundle)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 BundleService.getBundleService (mortar.bundler.BundleService.getBundleService)4 BundleServiceRunner.getBundleServiceRunner (mortar.bundler.BundleServiceRunner.getBundleServiceRunner)3 Matchers.anyString (org.mockito.Matchers.anyString)3 Context (android.content.Context)2 ChatListScreen (com.example.mortar.screen.ChatListScreen)1 GsonParceler (com.example.mortar.screen.GsonParceler)1 Gson (com.google.gson.Gson)1 FlowDelegate (flow.FlowDelegate)1 ArrayList (java.util.ArrayList)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 BundleServiceRunner (mortar.bundler.BundleServiceRunner)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1