Search in sources :

Example 71 with TestKey

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

the class FlowTest method replaceHistoryResultsInLengthOneHistory.

@Test
public void replaceHistoryResultsInLengthOneHistory() {
    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.setHistory(History.single(delta), StateChange.REPLACE);
    assertThat(lastStack.top()).isEqualTo(new TestKey("Delta"));
    assertThat(lastStack.top() == delta).isTrue();
    assertThat(lastStack.top()).isSameAs(delta);
    assertThat(lastStack.size()).isEqualTo(1);
    assertThat(lastDirection).isEqualTo(StateChange.REPLACE);
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) Test(org.junit.Test)

Example 72 with TestKey

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

the class FlowTest method setObjectKeepsOriginal.

@Test
public void setObjectKeepsOriginal() {
    History<?> history = History.from(Arrays.asList(able, baker));
    Backstack flow = new Backstack();
    flow.setup(history);
    flow.setStateChanger(new FlowDispatcher());
    assertThat(history.size()).isEqualTo(2);
    flow.goTo(new TestKey("Able"));
    assertThat(lastStack.top()).isEqualTo(new TestKey("Able"));
    assertThat(lastStack.top() == able).isTrue();
    assertThat(lastStack.top()).isSameAs(able);
    assertThat(lastStack.size()).isEqualTo(1);
    assertThat(lastDirection).isEqualTo(StateChange.BACKWARD);
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) Test(org.junit.Test)

Example 73 with TestKey

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

the class FlowTest method setHistoryKeepsOriginals.

@SuppressWarnings({ "CheckResult" })
@Test
public void setHistoryKeepsOriginals() {
    TestKey able = new TestKey("Able");
    TestKey baker = new TestKey("Baker");
    TestKey charlie = new TestKey("Charlie");
    TestKey delta = new TestKey("Delta");
    History<?> history = History.from(Arrays.asList(able, baker, charlie, delta));
    Backstack flow = new Backstack();
    flow.setup(history);
    flow.setStateChanger(new FlowDispatcher());
    assertThat(history.size()).isEqualTo(4);
    TestKey echo = new TestKey("Echo");
    TestKey foxtrot = new TestKey("Foxtrot");
    History<?> newHistory = History.from(Arrays.asList(able, baker, echo, foxtrot));
    flow.setHistory(newHistory, StateChange.REPLACE);
    assertThat(lastStack.size()).isEqualTo(4);
    assertThat(lastStack.top()).isEqualTo(foxtrot);
    flow.goBack();
    assertThat(lastStack.size()).isEqualTo(3);
    assertThat(lastStack.top()).isEqualTo(echo);
    flow.goBack();
    assertThat(lastStack.size()).isEqualTo(2);
    assertThat(lastStack.top()).isSameAs(baker);
    flow.goBack();
    assertThat(lastStack.size()).isEqualTo(1);
    assertThat(lastStack.top()).isSameAs(able);
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) Test(org.junit.Test)

Example 74 with TestKey

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

the class HistoryTest method equals.

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

Example 75 with TestKey

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

the class HistoryTest method iterator.

@Test
public void iterator() throws Exception {
    TestKey testKey1 = new TestKey("Hello");
    TestKey testKey2 = new TestKey("World");
    TestKey testKey3 = new TestKey("Kappa");
    History history = History.of(testKey1, testKey2, testKey3);
    for (Object key : history) {
        assertThat(key).isIn(testKey1, testKey2, testKey3);
    }
}
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