Search in sources :

Example 46 with TestKey

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

the class BackstackCoreTest method fromTopOnEmptyArrayThrows.

@Test
public void fromTopOnEmptyArrayThrows() {
    TestKey initial1 = new TestKey("hello1");
    Backstack backstack = new Backstack();
    backstack.setup(History.of(initial1));
    try {
        backstack.fromTop(0);
        Assert.fail();
    } catch (IllegalStateException e) {
    // OK!
    }
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) Test(org.junit.Test)

Example 47 with TestKey

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

the class BackstackCoreTest method goUpChainWithMultipleElementWhenAllExistsWithBefore.

@Test
public void goUpChainWithMultipleElementWhenAllExistsWithBefore() {
    TestKey initial1 = new TestKey("hello1");
    TestKey initial2 = new TestKey("hello2");
    TestKey initial3 = new TestKey("hello3");
    TestKey initial4 = new TestKey("hello4");
    Backstack backstack = new Backstack();
    backstack.setup(History.of(initial1, initial2, initial3, initial4));
    StateChanger stateChanger = new StateChanger() {

        @Override
        public void handleStateChange(@Nonnull StateChange _stateChange, @Nonnull Callback completionCallback) {
            stateChange = _stateChange;
            callback = completionCallback;
        }
    };
    backstack.setStateChanger(stateChanger);
    callback.stateChangeComplete();
    backstack.goUpChain(History.of(initial2, initial3));
    callback.stateChangeComplete();
    assertThat(backstack.getHistory()).containsExactly(initial1, initial2, initial3);
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) Nonnull(javax.annotation.Nonnull) Test(org.junit.Test)

Example 48 with TestKey

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

the class BackstackCoreTest method goBackShouldReturnFalseWithOneElement.

@Test
public void goBackShouldReturnFalseWithOneElement() {
    TestKey hi = new TestKey("hi");
    Backstack backstack = new Backstack();
    backstack.setup(History.of(hi));
    backstack.setStateChanger(new StateChanger() {

        @Override
        public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) {
            callback = completionCallback;
        }
    });
    callback.stateChangeComplete();
    assertThat(backstack.goBack()).isFalse();
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) Test(org.junit.Test)

Example 49 with TestKey

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

the class BackstackCoreTest method goUpReplacesTopForSingleElement.

@Test
public void goUpReplacesTopForSingleElement() {
    TestKey initial = new TestKey("hello");
    TestKey other = new TestKey("other");
    Backstack backstack = new Backstack();
    backstack.setup(History.of(initial));
    StateChanger stateChanger = new StateChanger() {

        @Override
        public void handleStateChange(@Nonnull StateChange _stateChange, @Nonnull Callback completionCallback) {
            stateChange = _stateChange;
            callback = completionCallback;
        }
    };
    backstack.setStateChanger(stateChanger);
    callback.stateChangeComplete();
    backstack.goUp(other);
    callback.stateChangeComplete();
    assertThat(backstack.getHistory()).containsExactly(other);
}
Also used : TestKey(com.zhuinden.simplestack.helpers.TestKey) Nonnull(javax.annotation.Nonnull) Test(org.junit.Test)

Example 50 with TestKey

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

the class BackstackCoreTest method forceClearShouldThrowIfStateChangeIsEnqueued.

@Test
public void forceClearShouldThrowIfStateChangeIsEnqueued() {
    TestKey initial = new TestKey("hello");
    Backstack backstack = new Backstack();
    backstack.setup(History.of(initial));
    StateChanger stateChanger = new StateChanger() {

        @Override
        public void handleStateChange(@Nonnull StateChange _stateChange, @Nonnull Callback completionCallback) {
            stateChange = _stateChange;
            callback = completionCallback;
        }
    };
    // initialize state change
    backstack.setStateChanger(stateChanger);
    try {
        backstack.forceClear();
        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