Search in sources :

Example 66 with TestKey

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

the class BackstackDelegateTest method addStateChangeListenerAddsCompletionListener.

@Test
public void addStateChangeListenerAddsCompletionListener() {
    TestKey testKey = new TestKey("hello");
    final List<StateChange> called = new LinkedList<>();
    Backstack.CompletionListener completionListener = new Backstack.CompletionListener() {

        @Override
        public void stateChangeCompleted(@Nonnull StateChange stateChange) {
            called.add(stateChange);
        }
    };
    BackstackDelegate backstackDelegate = new BackstackDelegate();
    backstackDelegate.addStateChangeCompletionListener(completionListener);
    backstackDelegate.onCreate(null, null, History.single(testKey));
    backstackDelegate.setStateChanger(stateChanger);
    assertThat(called.get(0).topNewKey()).isSameAs(testKey);
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) Nonnull(javax.annotation.Nonnull) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 67 with TestKey

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

the class BackstackDelegateTest method getSavedStateForNullThrowsException.

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

Example 68 with TestKey

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

the class BackstackDelegateTest method getBackstackReturnsBackstack.

@Test
public void getBackstackReturnsBackstack() {
    TestKey testKey = new TestKey("Hello");
    BackstackDelegate backstackDelegate = new BackstackDelegate();
    backstackDelegate.onCreate(null, null, History.single(testKey));
    assertThat(backstackDelegate.getBackstack()).isNotNull();
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) Test(org.junit.Test)

Example 69 with TestKey

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

the class BackstackDelegateTest method onPostResumeThrowsExceptionIfStateChangerNotSet.

@Test
public void onPostResumeThrowsExceptionIfStateChangerNotSet() {
    BackstackDelegate backstackDelegate = new BackstackDelegate();
    TestKey key = new TestKey("hello");
    backstackDelegate.onCreate(null, null, History.single(key));
    // no state changer set
    try {
        backstackDelegate.onPostResume();
        Assert.fail();
    } catch (IllegalStateException e) {
    // OK
    }
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) Test(org.junit.Test)

Example 70 with TestKey

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

the class FlowTest method replaceTopDoesNotAlterHistoryLength.

@Test
public void replaceTopDoesNotAlterHistoryLength() {
    History<?> history = History.from(Arrays.asList(able, baker, charlie));
    Backstack flow = new Backstack();
    flow.setup(history);
    flow.setStateChanger(new FlowDispatcher());
    assertThat(history.size()).isEqualTo(3);
    flow.replaceTop(delta, StateChange.REPLACE);
    assertThat(lastStack.top()).isEqualTo(new TestKey("Delta"));
    assertThat(lastStack.top() == delta).isTrue();
    assertThat(lastStack.top()).isSameAs(delta);
    assertThat(lastStack.size()).isEqualTo(3);
    assertThat(lastDirection).isEqualTo(StateChange.REPLACE);
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) 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