use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class BackstackDelegateTest method addStateChangeListenerAddsCompletionListener.
@Test
public void addStateChangeListenerAddsCompletionListener() {
TestKey testKey = new TestKey("hello");
final List<StateChange> called = new LinkedList<>();
Backstack.CompletionListener completionListener = new Backstack.CompletionListener() {
@Override
public void stateChangeCompleted(@Nonnull StateChange stateChange) {
called.add(stateChange);
}
};
BackstackDelegate backstackDelegate = new BackstackDelegate();
backstackDelegate.addStateChangeCompletionListener(completionListener);
backstackDelegate.onCreate(null, null, History.single(testKey));
backstackDelegate.setStateChanger(stateChanger);
assertThat(called.get(0).topNewKey()).isSameAs(testKey);
}
use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class BackstackDelegateTest method getSavedStateForNullThrowsException.
@Test
public void getSavedStateForNullThrowsException() {
BackstackDelegate backstackDelegate = new BackstackDelegate();
TestKey testKey = new TestKey("hello");
backstackDelegate.onCreate(null, null, History.single(testKey));
try {
backstackDelegate.getSavedState(null);
Assert.fail();
} catch (IllegalArgumentException e) {
// OK
}
}
use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class BackstackDelegateTest method getBackstackReturnsBackstack.
@Test
public void getBackstackReturnsBackstack() {
TestKey testKey = new TestKey("Hello");
BackstackDelegate backstackDelegate = new BackstackDelegate();
backstackDelegate.onCreate(null, null, History.single(testKey));
assertThat(backstackDelegate.getBackstack()).isNotNull();
}
use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class BackstackDelegateTest method onPostResumeThrowsExceptionIfStateChangerNotSet.
@Test
public void onPostResumeThrowsExceptionIfStateChangerNotSet() {
BackstackDelegate backstackDelegate = new BackstackDelegate();
TestKey key = new TestKey("hello");
backstackDelegate.onCreate(null, null, History.single(key));
// no state changer set
try {
backstackDelegate.onPostResume();
Assert.fail();
} catch (IllegalStateException e) {
// OK
}
}
use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class FlowTest method replaceTopDoesNotAlterHistoryLength.
@Test
public void replaceTopDoesNotAlterHistoryLength() {
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.replaceTop(delta, StateChange.REPLACE);
assertThat(lastStack.top()).isEqualTo(new TestKey("Delta"));
assertThat(lastStack.top() == delta).isTrue();
assertThat(lastStack.top()).isSameAs(delta);
assertThat(lastStack.size()).isEqualTo(3);
assertThat(lastDirection).isEqualTo(StateChange.REPLACE);
}
Aggregations