Search in sources :

Example 71 with ServiceProvider

use of com.zhuinden.simplestack.helpers.ServiceProvider in project simple-stack by Zhuinden.

the class ScopingTest method scopeServicesArePersistedToStateBundleDelayedScopedServicesCall.

@Test
public void scopeServicesArePersistedToStateBundleDelayedScopedServicesCall() {
    final Backstack backstack = new Backstack();
    final Service service = new Service();
    TestKeyWithScope testKeyWithScope = new TestKeyWithScope("blah") {

        @Override
        public void bindServices(ServiceBinder serviceBinder) {
            assertThat(serviceBinder.getScopeTag()).isEqualTo(getScopeTag());
            serviceBinder.addService(SERVICE_TAG, service);
        }

        @Nonnull
        @Override
        public String getScopeTag() {
            return "beep";
        }
    };
    backstack.setup(History.of(testKeyWithScope));
    // !
    backstack.setScopedServices(new ServiceProvider());
    backstack.setStateChanger(new StateChanger() {

        @Override
        public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) {
            completionCallback.stateChangeComplete();
        }
    });
    assertThat(backstack.hasService(testKeyWithScope.getScopeTag(), SERVICE_TAG)).isTrue();
    StateBundle stateBundle = backstack.toBundle();
    // noinspection ConstantConditions
    // backstack.getScopesTag() is internal
    assertThat(stateBundle.getBundle(Backstack.getScopesTag()).getBundle(testKeyWithScope.getScopeTag()).getBundle(SERVICE_TAG).getInt("blah")).isEqualTo(5);
}
Also used : ServiceProvider(com.zhuinden.simplestack.helpers.ServiceProvider) StateBundle(com.zhuinden.statebundle.StateBundle) Test(org.junit.Test)

Example 72 with ServiceProvider

use of com.zhuinden.simplestack.helpers.ServiceProvider in project simple-stack by Zhuinden.

the class ScopingTest method canFindServiceNoOverlapsWorks.

@Test
public void canFindServiceNoOverlapsWorks() {
    Backstack backstack = new Backstack();
    backstack.setScopedServices(new ServiceProvider());
    final Service service = new Service();
    TestKeyWithScope beep = new TestKeyWithScope("beep") {

        @Override
        public void bindServices(ServiceBinder serviceBinder) {
            assertThat(serviceBinder.getScopeTag()).isEqualTo(getScopeTag());
            serviceBinder.addService(SERVICE_TAG, service);
        }

        @Nonnull
        @Override
        public String getScopeTag() {
            return "beep";
        }
    };
    TestKeyWithScope boop = new TestKeyWithScope("boop") {

        @Override
        public void bindServices(ServiceBinder serviceBinder) {
        }

        @Nonnull
        @Override
        public String getScopeTag() {
            return "boop";
        }
    };
    backstack.setup(History.of(beep, boop));
    assertThat(backstack.hasService("beep", SERVICE_TAG)).isFalse();
    backstack.setStateChanger(stateChanger);
    assertThat(backstack.hasService("beep", SERVICE_TAG)).isTrue();
    assertThat(backstack.hasService("boop", SERVICE_TAG)).isFalse();
    assertThat(backstack.<Object>canFindService(SERVICE_TAG)).isTrue();
    backstack.goBack();
    assertThat(backstack.hasService("beep", SERVICE_TAG)).isTrue();
    assertThat(backstack.<Object>canFindService(SERVICE_TAG)).isTrue();
    backstack.setHistory(History.single(testKey1), StateChange.REPLACE);
    assertThat(backstack.hasService("beep", SERVICE_TAG)).isFalse();
    assertThat(backstack.canFindService(SERVICE_TAG)).isFalse();
}
Also used : ServiceProvider(com.zhuinden.simplestack.helpers.ServiceProvider) Test(org.junit.Test)

Aggregations

ServiceProvider (com.zhuinden.simplestack.helpers.ServiceProvider)72 Test (org.junit.Test)72 TestKey (com.zhuinden.simplestack.helpers.TestKey)26 TestKeyWithScope (com.zhuinden.simplestack.helpers.TestKeyWithScope)25 ArrayList (java.util.ArrayList)13 Parcel (android.os.Parcel)9 Nonnull (javax.annotation.Nonnull)9 HasParentServices (com.zhuinden.simplestack.helpers.HasParentServices)8 HasServices (com.zhuinden.simplestack.helpers.HasServices)7 TestKeyWithOnlyParentServices (com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices)6 TestKeyWithExplicitParent (com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent)4 StateBundle (com.zhuinden.statebundle.StateBundle)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Activity (android.app.Activity)2 Action (com.zhuinden.simplestack.helpers.Action)2 Nullable (javax.annotation.Nullable)1