Search in sources :

Example 1 with ServiceProvider

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

the class ScopingTest method serviceBinderAddThrowsForNullService.

@Test
public void serviceBinderAddThrowsForNullService() {
    final String serviceTag = "serviceTag";
    final Object nullService = null;
    TestKeyWithScope testKeyWithScope = new TestKeyWithScope("blah") {

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

        @Nonnull
        @Override
        public String getScopeTag() {
            return "beep";
        }
    };
    Backstack backstack = new Backstack();
    backstack.setScopedServices(new ServiceProvider());
    backstack.setup(History.of(testKeyWithScope));
    try {
        backstack.setStateChanger(stateChanger);
        Assert.fail();
    } catch (Exception e) {
        assertThat(e.getMessage()).isEqualTo("service cannot be null!");
    }
}
Also used : ServiceProvider(com.zhuinden.simplestack.helpers.ServiceProvider) Test(org.junit.Test)

Example 2 with ServiceProvider

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

the class ScopingTest method serviceBinderAddThrowsForNullServiceTag.

@Test
public void serviceBinderAddThrowsForNullServiceTag() {
    final String nullTag = null;
    final Object service = new Service();
    TestKeyWithScope testKeyWithScope = new TestKeyWithScope("blah") {

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

        @Nonnull
        @Override
        public String getScopeTag() {
            return "beep";
        }
    };
    Backstack backstack = new Backstack();
    backstack.setScopedServices(new ServiceProvider());
    backstack.setup(History.of(testKeyWithScope));
    try {
        backstack.setStateChanger(stateChanger);
        Assert.fail();
    } catch (Exception e) {
        assertThat(e.getMessage()).isEqualTo("serviceTag cannot be null!");
    }
}
Also used : ServiceProvider(com.zhuinden.simplestack.helpers.ServiceProvider) Test(org.junit.Test)

Example 3 with ServiceProvider

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

the class ScopingTest method serviceBinderMethodsWork.

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

        @Override
        public void bindServices(ServiceBinder serviceBinder) {
            assertThat(serviceBinder.getScopeTag()).isEqualTo(getScopeTag());
            assertThat(serviceBinder.hasService("SERVICE1")).isFalse();
            assertThat(serviceBinder.canFindService("SERVICE1")).isFalse();
            serviceBinder.addService("SERVICE1", service1);
            assertThat(serviceBinder.hasService("SERVICE1")).isTrue();
            assertThat(serviceBinder.canFindService("SERVICE1")).isTrue();
            assertThat(serviceBinder.lookupService("SERVICE1")).isSameAs(service1);
        }

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

        @Override
        public void bindServices(ServiceBinder serviceBinder) {
            assertThat(serviceBinder.getScopeTag()).isEqualTo(getScopeTag());
            assertThat(serviceBinder.hasService("SERVICE1")).isFalse();
            assertThat(serviceBinder.canFindService("SERVICE1")).isTrue();
            assertThat(serviceBinder.hasService("SERVICE2")).isFalse();
            serviceBinder.addService("SERVICE2", service2);
            assertThat(serviceBinder.hasService("SERVICE2")).isTrue();
            assertThat(serviceBinder.canFindService("SERVICE2")).isTrue();
            assertThat(serviceBinder.hasService("SERVICE2")).isTrue();
            assertThat(serviceBinder.lookupService("SERVICE1")).isSameAs(service1);
            assertThat(serviceBinder.lookupService("SERVICE2")).isSameAs(service2);
        }

        @Nonnull
        @Override
        public String getScopeTag() {
            return "boop";
        }
    };
    backstack.setup(History.of(beep, boop));
    backstack.setStateChanger(stateChanger);
}
Also used : ServiceProvider(com.zhuinden.simplestack.helpers.ServiceProvider) Test(org.junit.Test)

Example 4 with ServiceProvider

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

the class BackstackTest method exitScopeToThrowsWhenBackstackIsEmpty.

@Test
public void exitScopeToThrowsWhenBackstackIsEmpty() {
    Backstack backstack = new Backstack();
    backstack.setScopedServices(new ServiceProvider());
    Object key = new TestKeyWithScope("blah") {

        @Override
        public void bindServices(ServiceBinder serviceBinder) {
        }
    };
    backstack.setup(History.of(key));
    Object targetKey = new TestKey("target");
    try {
        backstack.exitScopeTo("blah", targetKey, StateChange.FORWARD);
        Assert.fail();
    } catch (IllegalStateException e) {
    // OK!
    }
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) TestKeyWithScope(com.zhuinden.simplestack.helpers.TestKeyWithScope) ServiceProvider(com.zhuinden.simplestack.helpers.ServiceProvider) Test(org.junit.Test)

Example 5 with ServiceProvider

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

the class BackstackTest method exitScopeExitsExplicitScopesCorrectly.

@Test
public void exitScopeExitsExplicitScopesCorrectly() {
    Backstack backstack = new Backstack();
    backstack.setScopedServices(new ServiceProvider());
    Object firstKey = new TestKey("firstKey");
    Object secondKey = new TestKey("secondKey");
    Object lastKey = new TestKey("lastKey");
    Object key1 = new TestKeyWithExplicitParent("key1") {

        @Nonnull
        @Override
        public List<String> getParentScopes() {
            return History.of("blah", "parentKey1");
        }

        @Override
        protected void bindParentServices(ServiceBinder serviceBinder) {
        }

        @Override
        protected void bindOwnServices(ServiceBinder serviceBinder) {
        }
    };
    Object key2 = new TestKeyWithExplicitParent("key2") {

        @Nonnull
        @Override
        public List<String> getParentScopes() {
            return History.of("blah", "parentKey2");
        }

        @Override
        protected void bindParentServices(ServiceBinder serviceBinder) {
        }

        @Override
        protected void bindOwnServices(ServiceBinder serviceBinder) {
        }
    };
    backstack.setup(History.of(firstKey, secondKey, key1, key2, lastKey));
    backstack.setStateChanger(new StateChanger() {

        @Override
        public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) {
            completionCallback.stateChangeComplete();
        }
    });
    backstack.exitScope("blah");
    assertThat(backstack.getHistory()).containsExactly(firstKey, secondKey);
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) ServiceProvider(com.zhuinden.simplestack.helpers.ServiceProvider) TestKeyWithExplicitParent(com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent) 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