Search in sources :

Example 36 with TestKey

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

the class HistoryTest method buildUpon.

@Test
public void buildUpon() throws Exception {
    TestKey testKey1 = new TestKey("Hello");
    TestKey testKey2 = new TestKey("World");
    TestKey testKey3 = new TestKey("Kappa");
    History history = History.of(testKey1, testKey2);
    assertThat(history.buildUpon().add(testKey3).build()).containsExactly(testKey1, testKey2, testKey3);
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) Test(org.junit.Test)

Example 37 with TestKey

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

the class HistoryTest method builderFromObjects.

@Test
public void builderFromObjects() throws Exception {
    TestKey testKey1 = new TestKey("Hello");
    TestKey testKey2 = new TestKey("World");
    assertThat(History.builderOf(testKey1, testKey2).build()).containsExactly(testKey1, testKey2);
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) Test(org.junit.Test)

Example 38 with TestKey

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

the class HistoryTest method builderFromList.

@Test
public void builderFromList() throws Exception {
    TestKey testKey1 = new TestKey("Hello");
    TestKey testKey2 = new TestKey("World");
    TestKey testKey3 = new TestKey("Kappa");
    List<TestKey> list = new ArrayList<>(3);
    list.add(testKey1);
    list.add(testKey2);
    list.add(testKey3);
    assertThat(History.builderFrom(list)).containsExactly(testKey1, testKey2, testKey3);
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 39 with TestKey

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

the class HistoryTest method contains.

@Test
public void contains() throws Exception {
    TestKey testKey1 = new TestKey("Hello");
    TestKey testKey2 = new TestKey("World");
    TestKey testKey3 = new TestKey("Kappa");
    History history = History.of(testKey1, testKey2);
    assertThat(history.contains(testKey2)).isTrue();
    assertThat(history.contains(testKey3)).isFalse();
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) Test(org.junit.Test)

Example 40 with TestKey

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

the class ScopeLookupModeTest method findScopesForKeyWorks.

@Test
public void findScopesForKeyWorks() {
    final Backstack backstack = new Backstack();
    backstack.setScopedServices(new ServiceProvider());
    final Object parentService1 = new Object();
    final Object parentService2 = new Object();
    final Object service1 = new Object();
    final Object service2 = new Object();
    class Key1 extends TestKey implements HasServices, HasParentServices {

        Key1(String name) {
            super(name);
        }

        protected Key1(Parcel in) {
            super(in);
        }

        @Override
        public void bindServices(ServiceBinder serviceBinder) {
            if ("parent1".equals(serviceBinder.getScopeTag())) {
                serviceBinder.addService("parentService1", parentService1);
            } else if (name.equals(serviceBinder.getScopeTag())) {
                serviceBinder.addService("service1", service1);
            }
        }

        @Nonnull
        @Override
        public String getScopeTag() {
            return name;
        }

        @Nonnull
        @Override
        public List<String> getParentScopes() {
            return History.of("parent1");
        }
    }
    class Key2 extends TestKey implements HasServices, HasParentServices {

        Key2(String name) {
            super(name);
        }

        protected Key2(Parcel in) {
            super(in);
        }

        @Override
        public void bindServices(ServiceBinder serviceBinder) {
            if ("parent2".equals(serviceBinder.getScopeTag())) {
                serviceBinder.addService("parentService2", parentService2);
            } else if (name.equals(serviceBinder.getScopeTag())) {
                serviceBinder.addService("service2", service2);
            }
        }

        @Nonnull
        @Override
        public String getScopeTag() {
            return name;
        }

        @Nonnull
        @Override
        public List<String> getParentScopes() {
            return History.of("parent2", "parent3");
        }
    }
    Object key1 = new Key1("beep");
    Object key2 = new Key2("boop");
    backstack.setup(History.of(key1, key2));
    assertThat(backstack.findScopesForKey(key1, ScopeLookupMode.EXPLICIT)).isEmpty();
    assertThat(backstack.findScopesForKey(key2, ScopeLookupMode.EXPLICIT)).isEmpty();
    assertThat(backstack.findScopesForKey(key1, ScopeLookupMode.ALL)).isEmpty();
    assertThat(backstack.findScopesForKey(key2, ScopeLookupMode.ALL)).isEmpty();
    backstack.setStateChanger(new StateChanger() {

        @Override
        public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) {
            completionCallback.stateChangeComplete();
        }
    });
    assertThat(backstack.findScopesForKey(key1, ScopeLookupMode.EXPLICIT)).containsExactly("beep", "parent1");
    assertThat(backstack.findScopesForKey(key2, ScopeLookupMode.EXPLICIT)).containsExactly("boop", "parent3", "parent2");
    assertThat(backstack.findScopesForKey(key1, ScopeLookupMode.ALL)).containsExactly("beep", "parent1");
    assertThat(backstack.findScopesForKey(key2, ScopeLookupMode.ALL)).containsExactly("boop", "parent3", "parent2", "beep", "parent1");
    backstack.moveToTop(key1);
    assertThat(backstack.findScopesForKey(key1, ScopeLookupMode.EXPLICIT)).containsExactly("beep", "parent1");
    assertThat(backstack.findScopesForKey(key2, ScopeLookupMode.EXPLICIT)).containsExactly("boop", "parent3", "parent2");
    assertThat(backstack.findScopesForKey(key1, ScopeLookupMode.ALL)).containsExactly("beep", "parent1", "boop", "parent3", "parent2");
    assertThat(backstack.findScopesForKey(key2, ScopeLookupMode.ALL)).containsExactly("boop", "parent3", "parent2");
    backstack.moveToTop(key2);
    assertThat(backstack.findScopesForKey(key1, ScopeLookupMode.EXPLICIT)).containsExactly("beep", "parent1");
    assertThat(backstack.findScopesForKey(key2, ScopeLookupMode.EXPLICIT)).containsExactly("boop", "parent3", "parent2");
    assertThat(backstack.findScopesForKey(key1, ScopeLookupMode.ALL)).containsExactly("beep", "parent1");
    assertThat(backstack.findScopesForKey(key2, ScopeLookupMode.ALL)).containsExactly("boop", "parent3", "parent2", "beep", "parent1");
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) HasParentServices(com.zhuinden.simplestack.helpers.HasParentServices) Parcel(android.os.Parcel) HasServices(com.zhuinden.simplestack.helpers.HasServices) ServiceProvider(com.zhuinden.simplestack.helpers.ServiceProvider) Test(org.junit.Test)

Aggregations

TestKey (com.zhuinden.simplestack.helpers.TestKey)148 Test (org.junit.Test)148 Nonnull (javax.annotation.Nonnull)43 ServiceProvider (com.zhuinden.simplestack.helpers.ServiceProvider)26 ArrayList (java.util.ArrayList)22 StateBundle (com.zhuinden.statebundle.StateBundle)11 Parcel (android.os.Parcel)10 HasServices (com.zhuinden.simplestack.helpers.HasServices)7 TestKeyWithScope (com.zhuinden.simplestack.helpers.TestKeyWithScope)7 HasParentServices (com.zhuinden.simplestack.helpers.HasParentServices)6 Parcelable (android.os.Parcelable)5 TestKeyWithOnlyParentServices (com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 List (java.util.List)3 Nullable (javax.annotation.Nullable)3 Activity (android.app.Activity)2 TestKeyWithExplicitParent (com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent)2 Application (android.app.Application)1 Context (android.content.Context)1 View (android.view.View)1