Search in sources :

Example 6 with ServiceProvider

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

the class BackstackTest method exitScopeToExitsImplicitScopeCorrectlyAndGoesBackIfFound.

@Test
public void exitScopeToExitsImplicitScopeCorrectlyAndGoesBackIfFound() {
    Backstack backstack = new Backstack();
    backstack.setScopedServices(new ServiceProvider());
    Object firstKey = new TestKey("firstKey");
    Object secondKey = new TestKey("secondKey");
    Object thirdKey = new TestKey("thirdKey");
    Object lastKey = new TestKey("lastKey");
    Object key = new TestKeyWithScope("blah") {

        @Override
        public void bindServices(ServiceBinder serviceBinder) {
        }
    };
    backstack.setup(History.of(firstKey, secondKey, thirdKey, key, lastKey));
    backstack.setStateChanger(new StateChanger() {

        @Override
        public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) {
            completionCallback.stateChangeComplete();
        }
    });
    backstack.exitScopeTo("blah", secondKey, StateChange.BACKWARD);
    assertThat(backstack.getHistory()).containsExactly(firstKey, secondKey);
}
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 7 with ServiceProvider

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

the class BackstackTest method exitScopeExitsExplicitScopeCorrectly.

@Test
public void exitScopeExitsExplicitScopeCorrectly() {
    Backstack backstack = new Backstack();
    backstack.setScopedServices(new ServiceProvider());
    Object firstKey = new TestKey("firstKey");
    Object lastKey = new TestKey("lastKey");
    Object key = new TestKeyWithOnlyParentServices("key", History.of("blah")) {

        @Override
        public void bindServices(ServiceBinder serviceBinder) {
        }
    };
    backstack.setup(History.of(firstKey, key, 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);
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) ServiceProvider(com.zhuinden.simplestack.helpers.ServiceProvider) TestKeyWithOnlyParentServices(com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices) Test(org.junit.Test)

Example 8 with ServiceProvider

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

the class BackstackTest method exitScopeDefaultsToJumpToRootIfRootHasScope.

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

        @Override
        public void bindServices(ServiceBinder serviceBinder) {
        }
    };
    backstack.setup(History.of(key));
    backstack.setStateChanger(new StateChanger() {

        @Override
        public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) {
            completionCallback.stateChangeComplete();
        }
    });
    backstack.exitScope("blah");
    assertThat(backstack.getHistory()).containsExactly(key);
}
Also used : TestKeyWithScope(com.zhuinden.simplestack.helpers.TestKeyWithScope) ServiceProvider(com.zhuinden.simplestack.helpers.ServiceProvider) Test(org.junit.Test)

Example 9 with ServiceProvider

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

the class BackstackTest method exitScopeThrowsWhenBackstackIsEmpty.

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

        @Override
        public void bindServices(ServiceBinder serviceBinder) {
        }
    };
    backstack.setup(History.of(key));
    try {
        backstack.exitScope("blah");
        Assert.fail();
    } catch (IllegalStateException e) {
    // OK!
    }
}
Also used : TestKeyWithScope(com.zhuinden.simplestack.helpers.TestKeyWithScope) ServiceProvider(com.zhuinden.simplestack.helpers.ServiceProvider) Test(org.junit.Test)

Example 10 with ServiceProvider

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

the class BackstackTest method exitScopeToWorks.

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

        @Override
        public void bindServices(ServiceBinder serviceBinder) {
        }
    };
    Object targetKey = new TestKey("targetKey");
    backstack.setup(History.of(key));
    backstack.setStateChanger(new StateChanger() {

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