Search in sources :

Example 96 with TestKey

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

the class BackstackDelegateTest method onCreateRestoresFromNonConfigInstance.

@Test
public void onCreateRestoresFromNonConfigInstance() {
    BackstackDelegate.NonConfigurationInstance nonConfigurationInstance = new BackstackDelegate.NonConfigurationInstance(backstack);
    BackstackDelegate backstackDelegate = new BackstackDelegate();
    TestKey testKey = new TestKey("hello");
    backstackDelegate.onCreate(null, nonConfigurationInstance, History.single(testKey));
    assertThat(backstackDelegate.getBackstack()).isSameAs(backstack);
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) Test(org.junit.Test)

Example 97 with TestKey

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

the class BackstackDelegateTest method onCreateChoosesInitialKeysIfRestoredHistoryIsEmpty.

@Test
public void onCreateChoosesInitialKeysIfRestoredHistoryIsEmpty() {
    BackstackDelegate backstackDelegate = new BackstackDelegate();
    TestKey testKey = new TestKey("hello");
    backstackDelegate.onCreate(savedInstanceState, null, History.single(testKey));
    assertThat(backstackDelegate.getBackstack()).isNotNull();
    backstackDelegate.setStateChanger(stateChanger);
    assertThat(backstackDelegate.getBackstack().getHistory()).containsExactly(testKey);
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) Test(org.junit.Test)

Example 98 with TestKey

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

the class BackstackDelegateTest method testRestoreViewFromState.

@Test
public void testRestoreViewFromState() {
    BackstackDelegate backstackDelegate = new BackstackDelegate();
    TestKey key = new TestKey("hello");
    backstackDelegate.onCreate(null, null, History.single(key));
    backstackDelegate.setStateChanger(stateChanger);
    Mockito.when(view.getContext()).thenReturn(context);
    StateBundle stateBundle = new StateBundle();
    Mockito.when(((Bundleable) view).toBundle()).thenReturn(stateBundle);
    // noinspection ResourceType
    Mockito.when(context.getSystemService(KeyContextWrapper.TAG)).thenReturn(key);
    backstackDelegate.persistViewToState(view);
    backstackDelegate.restoreViewFromState(view);
    ((Bundleable) Mockito.verify(view, Mockito.times(1))).fromBundle(stateBundle);
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) StateBundle(com.zhuinden.statebundle.StateBundle) Test(org.junit.Test)

Example 99 with TestKey

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

the class HistoryTest method addAllAt.

@Test
public void addAllAt() throws Exception {
    TestKey testKey1 = new TestKey("Hello");
    TestKey testKey2 = new TestKey("World");
    TestKey testKey3 = new TestKey("Kappa");
    History history = History.of(testKey1, testKey2);
    List<Object> objects = new ArrayList<>(1);
    objects.add(testKey3);
    try {
        history.addAll(1, objects);
        fail();
    } catch (UnsupportedOperationException e) {
    // OK!
    }
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 100 with TestKey

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

the class HistoryTest method top.

@Test
public void top() throws Exception {
    TestKey testKey1 = new TestKey("Hello");
    TestKey testKey2 = new TestKey("World");
    History history = History.of(testKey1, testKey2);
    assertThat(history.top()).isSameAs(testKey2);
}
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