Search in sources :

Example 1 with TestKeyWithOnlyParentServices

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

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

the class ScopingTest method navigationIsPossibleAndEnqueuedDuringActivationDispatch.

@Test
public void navigationIsPossibleAndEnqueuedDuringActivationDispatch() {
    final TestKey destination = new TestKey("destination");
    Backstack backstack = new Backstack();
    backstack.setScopedServices(new ServiceProvider());
    class MyService implements ScopedServices.Activated {

        private final Backstack backstack;

        public MyService(Backstack backstack) {
            this.backstack = backstack;
        }

        @Override
        public void onServiceActive() {
            backstack.setHistory(History.of(destination), StateChange.REPLACE);
        }

        @Override
        public void onServiceInactive() {
        }
    }
    final MyService service = new MyService(backstack);
    TestKeyWithOnlyParentServices beep = new TestKeyWithOnlyParentServices("beep", History.of("registration")) {

        @Override
        public void bindServices(ServiceBinder serviceBinder) {
            if (serviceBinder.getScopeTag().equals("registration")) {
                serviceBinder.addService("SERVICE", service);
            }
        }
    };
    TestKeyWithScope boop = new TestKeyWithScope("boop") {

        @Override
        public void bindServices(ServiceBinder serviceBinder) {
        }
    };
    backstack.setup(History.of(boop));
    backstack.setStateChanger(stateChanger);
    backstack.setHistory(History.of(beep), StateChange.REPLACE);
    assertThat(backstack.getHistory()).containsExactly(destination);
}
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 3 with TestKeyWithOnlyParentServices

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

the class BackstackTest method exitScopeToExitsExplicitScopeCorrectlyAndGoesBackIfFound.

@Test
public void exitScopeToExitsExplicitScopeCorrectlyAndGoesBackIfFound() {
    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 TestKeyWithOnlyParentServices("key", History.of("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) ServiceProvider(com.zhuinden.simplestack.helpers.ServiceProvider) TestKeyWithOnlyParentServices(com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices) Test(org.junit.Test)

Example 4 with TestKeyWithOnlyParentServices

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

the class BackstackTest method exitScopeToExitsExplicitScopeCorrectlyAndAppendsIfNotFound.

@Test
public void exitScopeToExitsExplicitScopeCorrectlyAndAppendsIfNotFound() {
    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 TestKeyWithOnlyParentServices("key", History.of("blah")) {

        @Override
        public void bindServices(ServiceBinder serviceBinder) {
        }
    };
    Object targetKey = new TestKey("targetKey");
    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", targetKey, StateChange.FORWARD);
    assertThat(backstack.getHistory()).containsExactly(firstKey, secondKey, thirdKey, targetKey);
}
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 5 with TestKeyWithOnlyParentServices

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

the class ScopingBackEventDispatchTest method onBackDispatchHandlesBackHandlesInActiveParentScopeEvenIfTopIsNotScopeKey.

@Test
public void onBackDispatchHandlesBackHandlesInActiveParentScopeEvenIfTopIsNotScopeKey() {
    final HandlesBackOnce parentService = new HandlesBackOnce();
    Object key = new TestKeyWithOnlyParentServices("key", History.of("parentScope")) {

        @Override
        public void bindServices(ServiceBinder serviceBinder) {
            if ("parentScope".equals(serviceBinder.getScopeTag())) {
                serviceBinder.addService("parentService", parentService);
            }
        }
    };
    Backstack backstack = new Backstack();
    backstack.setScopedServices(new ServiceProvider());
    backstack.setup(History.of(key));
    backstack.setStateChanger(new StateChanger() {

        @Override
        public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) {
            completionCallback.stateChangeComplete();
        }
    });
    assertThat(backstack.lookupService("parentService")).isSameAs(parentService);
    assertThat(parentService.handledBackOnce).isFalse();
    boolean handled = backstack.goBack();
    assertThat(handled).isTrue();
    assertThat(parentService.handledBackOnce).isTrue();
    handled = backstack.goBack();
    assertThat(handled).isFalse();
}
Also used : TestKeyWithOnlyParentServices(com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices) ServiceProvider(com.zhuinden.simplestack.helpers.ServiceProvider) Test(org.junit.Test)

Aggregations

ServiceProvider (com.zhuinden.simplestack.helpers.ServiceProvider)6 TestKeyWithOnlyParentServices (com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices)6 Test (org.junit.Test)6 TestKey (com.zhuinden.simplestack.helpers.TestKey)4