use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class ScopingGlobalScopeTest method globalServicesFactoryFailsIfBackstackIsAddedAsService.
@Test
public void globalServicesFactoryFailsIfBackstackIsAddedAsService() {
Backstack backstack = new Backstack();
backstack.setGlobalServices(new GlobalServices.Factory() {
@Nonnull
@Override
public GlobalServices create(@Nonnull Backstack backstack) {
return GlobalServices.builder().addService("backstack", backstack).build();
}
});
backstack.setup(History.of(new TestKey("hello!")));
try {
backstack.setStateChanger(new StateChanger() {
@Override
public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) {
completionCallback.stateChangeComplete();
}
});
StateBundle bundle = backstack.toBundle();
Assert.fail("This would fail on `toBundle()`");
} catch (IllegalArgumentException e) {
// OK!
}
}
use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class ScopingGlobalScopeTest method globalServiceStateIsRestored.
@Test
public void globalServiceStateIsRestored() {
class Service implements Bundleable {
int blah = 2;
@Nonnull
@Override
public StateBundle toBundle() {
StateBundle stateBundle = new StateBundle();
stateBundle.putInt("blah", 5);
return stateBundle;
}
@Override
public void fromBundle(@Nullable StateBundle bundle) {
if (bundle != null) {
blah = bundle.getInt("blah");
}
}
}
TestKey testKey = new TestKey("world");
final Service service = new Service();
final Backstack backstack = new Backstack();
backstack.setGlobalServices(GlobalServices.builder().addService("service", service).build());
StateChanger stateChanger = new StateChanger() {
@Override
public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) {
completionCallback.stateChangeComplete();
}
};
backstack.setup(History.of(testKey));
backstack.setStateChanger(stateChanger);
assertThat(backstack.canFindService("service")).isTrue();
StateBundle stateBundle = backstack.toBundle();
final Backstack backstack2 = new Backstack();
backstack2.setGlobalServices(GlobalServices.builder().addService("service", new Service()).build());
StateChanger stateChanger2 = new StateChanger() {
@Override
public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) {
completionCallback.stateChangeComplete();
}
};
backstack2.setup(History.of(testKey));
backstack2.fromBundle(stateBundle);
backstack2.setStateChanger(stateChanger2);
assertThat(backstack2.lookupService("service")).isNotSameAs(service);
assertThat(backstack.<Service>lookupService("service").blah).isEqualTo(2);
assertThat(backstack2.<Service>lookupService("service").blah).isEqualTo(5);
}
use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class HistoryTest method builderFromBackstackDelegate.
@Test
public void builderFromBackstackDelegate() throws Exception {
TestKey testKey1 = new TestKey("Hello");
TestKey testKey2 = new TestKey("World");
BackstackDelegate backstackDelegate = new BackstackDelegate();
backstackDelegate.onCreate(null, null, History.of(testKey1, testKey2));
backstackDelegate.setStateChanger(new StateChanger() {
@Override
public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) {
completionCallback.stateChangeComplete();
}
});
assertThat(History.builderFrom(backstackDelegate)).containsExactly(testKey1, testKey2);
}
use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class HistoryTest method fromList.
@Test
public void fromList() throws Exception {
TestKey testKey1 = new TestKey("Hello");
TestKey testKey2 = new TestKey("World");
List<TestKey> list = new ArrayList<>(2);
list.add(testKey1);
list.add(testKey2);
assertThat(History.from(list)).containsExactly(testKey1, testKey2);
}
use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class HistoryTest method clear.
@Test
public void clear() throws Exception {
TestKey testKey1 = new TestKey("Hello");
TestKey testKey2 = new TestKey("World");
History history = History.of(testKey1, testKey2);
try {
history.clear();
fail();
} catch (UnsupportedOperationException e) {
// OK!
}
}
Aggregations