use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class BackstackDelegateTest method onCreateRestoresBackstackKeys.
@Test
public void onCreateRestoresBackstackKeys() {
BackstackDelegate backstackDelegate = new BackstackDelegate();
TestKey testKey = new TestKey("hello");
final TestKey restoredKey = new TestKey("world");
ArrayList<Parcelable> restoredKeys = new ArrayList<Parcelable>() {
{
add(restoredKey);
}
};
StateBundle stateBundle = new StateBundle();
stateBundle.putParcelableArrayList(Backstack.getHistoryTag(), restoredKeys);
Mockito.when(savedInstanceState.getParcelable(backstackDelegate.getHistoryTag())).thenReturn(stateBundle);
backstackDelegate.onCreate(savedInstanceState, null, History.single(testKey));
assertThat(backstackDelegate.getBackstack()).isNotNull();
backstackDelegate.setStateChanger(stateChanger);
assertThat(backstackDelegate.getBackstack().getHistory()).containsExactly(restoredKey);
}
use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class BackstackDelegateTest method globalServicesWorks.
@Test
public void globalServicesWorks() {
BackstackDelegate backstackDelegate = new BackstackDelegate();
final Object service = new Object();
backstackDelegate.setGlobalServices(null, GlobalServices.builder().addService("service", service).addAlias("alias", service).build());
TestKey testKey = new TestKey("hello");
backstackDelegate.onCreate(null, null, History.of(testKey));
backstackDelegate.setStateChanger(new StateChanger() {
@Override
public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) {
completionCallback.stateChangeComplete();
}
});
assertThat(backstackDelegate.canFindService("service")).isTrue();
assertThat(backstackDelegate.lookupService("service")).isSameAs(service);
assertThat(backstackDelegate.canFindService("alias")).isTrue();
assertThat(backstackDelegate.lookupService("alias")).isSameAs(service);
}
use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class BackstackDelegateTest method onPauseRemovesStateChanger.
@Test
public void onPauseRemovesStateChanger() {
BackstackDelegate backstackDelegate = new BackstackDelegate();
TestKey key = new TestKey("hello");
backstackDelegate.onCreate(null, null, History.single(key));
backstackDelegate.setStateChanger(stateChanger);
backstackDelegate.onPause();
assertThat(backstackDelegate.getBackstack().hasStateChanger()).isFalse();
}
use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class BackstackDelegateTest method onCreateInvalidNonConfigurationThrowsException.
@Test
public void onCreateInvalidNonConfigurationThrowsException() {
BackstackDelegate backstackDelegate = new BackstackDelegate();
try {
backstackDelegate.onCreate(null, new TestKey("crashpls"), History.single(new TestKey("hello")));
Assert.fail();
} catch (IllegalArgumentException e) {
// OK
}
}
use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class BackstackDelegateTest method addStateChangeListenerAfterOnCreateThrows.
@Test
public void addStateChangeListenerAfterOnCreateThrows() {
TestKey testKey = new TestKey("hello");
Backstack.CompletionListener completionListener = new Backstack.CompletionListener() {
@Override
public void stateChangeCompleted(@Nonnull StateChange stateChange) {
// do nothing
}
};
BackstackDelegate backstackDelegate = new BackstackDelegate();
backstackDelegate.onCreate(null, null, History.single(testKey));
try {
backstackDelegate.addStateChangeCompletionListener(completionListener);
Assert.fail();
} catch (IllegalStateException e) {
// OK
}
}
Aggregations