Search in sources :

Example 1 with TestKeyWithScope

use of com.zhuinden.simplestack.helpers.TestKeyWithScope 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 2 with TestKeyWithScope

use of com.zhuinden.simplestack.helpers.TestKeyWithScope 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 3 with TestKeyWithScope

use of com.zhuinden.simplestack.helpers.TestKeyWithScope 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 4 with TestKeyWithScope

use of com.zhuinden.simplestack.helpers.TestKeyWithScope 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 5 with TestKeyWithScope

use of com.zhuinden.simplestack.helpers.TestKeyWithScope 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)25 TestKeyWithScope (com.zhuinden.simplestack.helpers.TestKeyWithScope)25 Test (org.junit.Test)25 TestKey (com.zhuinden.simplestack.helpers.TestKey)7 Nonnull (javax.annotation.Nonnull)4 TestKeyWithExplicitParent (com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent)3 ArrayList (java.util.ArrayList)3 Parcel (android.os.Parcel)2 HasParentServices (com.zhuinden.simplestack.helpers.HasParentServices)2 Action (com.zhuinden.simplestack.helpers.Action)1 StateBundle (com.zhuinden.statebundle.StateBundle)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Nullable (javax.annotation.Nullable)1