use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class BackstackCoreTest method forceClearShouldClearStackIfStateChangeIsComplete.
@Test
public void forceClearShouldClearStackIfStateChangeIsComplete() {
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.goTo(other);
callback.stateChangeComplete();
backstack.forceClear();
assertThat(backstack.getHistory()).isEmpty();
backstack.setStateChanger(stateChanger);
callback.stateChangeComplete();
assertThat(backstack.getHistory()).containsExactly(initial);
}
use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class BackstackCoreTest method goUpWithMoreElementsFoundParentGoesToParent.
@Test
public void goUpWithMoreElementsFoundParentGoesToParent() {
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.goTo(other);
callback.stateChangeComplete();
backstack.goUp(initial);
callback.stateChangeComplete();
;
assertThat(backstack.getHistory()).containsExactly(initial);
}
use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class BackstackCoreTest method replaceTopReentrantShouldWorkAsIntended.
@Test
public void replaceTopReentrantShouldWorkAsIntended() {
TestKey initial = new TestKey("hello");
TestKey other = new TestKey("other");
TestKey another = new TestKey("another");
TestKey yetAnother = new TestKey("yetAnother");
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.goTo(other);
callback.stateChangeComplete();
assertThat(backstack.getHistory()).containsExactly(initial, other);
backstack.replaceTop(another, StateChange.BACKWARD);
// replaceTop is terminal, so this is ignored
backstack.replaceTop(yetAnother, StateChange.REPLACE);
assertThat(stateChange.getDirection()).isEqualTo(StateChange.BACKWARD);
assertThat(stateChange.getNewKeys()).containsExactly(initial, another);
callback.stateChangeComplete();
assertThat(backstack.getHistory()).containsExactly(initial, another);
try {
callback.stateChangeComplete();
Assert.fail();
} catch (IllegalStateException e) {
// OK
}
assertThat(backstack.getHistory()).containsExactly(initial, another);
}
use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class BackstackCoreTest method rootWorks.
@Test
public void rootWorks() {
TestKey initial1 = new TestKey("hello1");
TestKey initial2 = new TestKey("hello2");
TestKey initial3 = new TestKey("hello3");
Backstack backstack = new Backstack();
backstack.setup(History.of(initial1));
try {
backstack.root();
org.junit.Assert.fail();
} catch (IllegalStateException e) {
// OK!
}
StateChanger stateChanger = new StateChanger() {
@Override
public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) {
if (stateChange.getPreviousKeys().isEmpty()) {
assertThat(stateChange.getBackstack().root()).isSameAs(stateChange.getNewKeys().get(0));
} else {
assertThat(stateChange.getBackstack().root()).isSameAs(stateChange.getPreviousKeys().get(0));
}
completionCallback.stateChangeComplete();
}
};
backstack.setStateChanger(stateChanger);
assertThat(backstack.root()).isSameAs(initial1);
backstack.setHistory(History.of(initial2, initial3), StateChange.REPLACE);
assertThat(backstack.root()).isSameAs(initial2);
backstack.removeStateChanger();
backstack.setStateChanger(stateChanger);
}
use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class BackstackCoreTest method goUpWithMoreElementsNotFoundParentReplacesCurrentTop.
@Test
public void goUpWithMoreElementsNotFoundParentReplacesCurrentTop() {
TestKey initial = new TestKey("hello");
TestKey other = new TestKey("other");
TestKey another = new TestKey("another");
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.goTo(other);
callback.stateChangeComplete();
backstack.goUp(another);
callback.stateChangeComplete();
assertThat(backstack.getHistory()).containsExactly(initial, another);
}
Aggregations