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!
}
}
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);
}
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();
}
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);
}
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!
}
}
Aggregations