Search in sources :

Example 91 with TestKey

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

the class BackstackDelegateTest method onCreateRestoresBackstackKeys.

@Test
public void onCreateRestoresBackstackKeys() {
    BackstackDelegate backstackDelegate = new BackstackDelegate();
    TestKey testKey = new TestKey("hello");
    final TestKey restoredKey = new TestKey("world");
    ArrayList<Parcelable> restoredKeys = new ArrayList<Parcelable>() {

        {
            add(restoredKey);
        }
    };
    StateBundle stateBundle = new StateBundle();
    stateBundle.putParcelableArrayList(Backstack.getHistoryTag(), restoredKeys);
    Mockito.when(savedInstanceState.getParcelable(backstackDelegate.getHistoryTag())).thenReturn(stateBundle);
    backstackDelegate.onCreate(savedInstanceState, null, History.single(testKey));
    assertThat(backstackDelegate.getBackstack()).isNotNull();
    backstackDelegate.setStateChanger(stateChanger);
    assertThat(backstackDelegate.getBackstack().getHistory()).containsExactly(restoredKey);
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) ArrayList(java.util.ArrayList) Parcelable(android.os.Parcelable) StateBundle(com.zhuinden.statebundle.StateBundle) Test(org.junit.Test)

Example 92 with TestKey

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

the class BackstackDelegateTest method globalServicesWorks.

@Test
public void globalServicesWorks() {
    BackstackDelegate backstackDelegate = new BackstackDelegate();
    final Object service = new Object();
    backstackDelegate.setGlobalServices(null, GlobalServices.builder().addService("service", service).addAlias("alias", service).build());
    TestKey testKey = new TestKey("hello");
    backstackDelegate.onCreate(null, null, History.of(testKey));
    backstackDelegate.setStateChanger(new StateChanger() {

        @Override
        public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) {
            completionCallback.stateChangeComplete();
        }
    });
    assertThat(backstackDelegate.canFindService("service")).isTrue();
    assertThat(backstackDelegate.lookupService("service")).isSameAs(service);
    assertThat(backstackDelegate.canFindService("alias")).isTrue();
    assertThat(backstackDelegate.lookupService("alias")).isSameAs(service);
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) Test(org.junit.Test)

Example 93 with TestKey

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

the class BackstackDelegateTest method onPauseRemovesStateChanger.

@Test
public void onPauseRemovesStateChanger() {
    BackstackDelegate backstackDelegate = new BackstackDelegate();
    TestKey key = new TestKey("hello");
    backstackDelegate.onCreate(null, null, History.single(key));
    backstackDelegate.setStateChanger(stateChanger);
    backstackDelegate.onPause();
    assertThat(backstackDelegate.getBackstack().hasStateChanger()).isFalse();
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) Test(org.junit.Test)

Example 94 with TestKey

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

the class BackstackDelegateTest method onCreateInvalidNonConfigurationThrowsException.

@Test
public void onCreateInvalidNonConfigurationThrowsException() {
    BackstackDelegate backstackDelegate = new BackstackDelegate();
    try {
        backstackDelegate.onCreate(null, new TestKey("crashpls"), History.single(new TestKey("hello")));
        Assert.fail();
    } catch (IllegalArgumentException e) {
    // OK
    }
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) Test(org.junit.Test)

Example 95 with TestKey

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

the class BackstackDelegateTest method addStateChangeListenerAfterOnCreateThrows.

@Test
public void addStateChangeListenerAfterOnCreateThrows() {
    TestKey testKey = new TestKey("hello");
    Backstack.CompletionListener completionListener = new Backstack.CompletionListener() {

        @Override
        public void stateChangeCompleted(@Nonnull StateChange stateChange) {
        // do nothing
        }
    };
    BackstackDelegate backstackDelegate = new BackstackDelegate();
    backstackDelegate.onCreate(null, null, History.single(testKey));
    try {
        backstackDelegate.addStateChangeCompletionListener(completionListener);
        Assert.fail();
    } catch (IllegalStateException e) {
    // OK
    }
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) Nonnull(javax.annotation.Nonnull) 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