use of com.zhuinden.simplestack.helpers.ServiceProvider in project simple-stack by Zhuinden.
the class ScopingTest method scopeServicesArePersistedToStateBundleDelayedScopedServicesCall.
@Test
public void scopeServicesArePersistedToStateBundleDelayedScopedServicesCall() {
final Backstack backstack = new Backstack();
final Service service = new Service();
TestKeyWithScope testKeyWithScope = new TestKeyWithScope("blah") {
@Override
public void bindServices(ServiceBinder serviceBinder) {
assertThat(serviceBinder.getScopeTag()).isEqualTo(getScopeTag());
serviceBinder.addService(SERVICE_TAG, service);
}
@Nonnull
@Override
public String getScopeTag() {
return "beep";
}
};
backstack.setup(History.of(testKeyWithScope));
// !
backstack.setScopedServices(new ServiceProvider());
backstack.setStateChanger(new StateChanger() {
@Override
public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) {
completionCallback.stateChangeComplete();
}
});
assertThat(backstack.hasService(testKeyWithScope.getScopeTag(), SERVICE_TAG)).isTrue();
StateBundle stateBundle = backstack.toBundle();
// noinspection ConstantConditions
// backstack.getScopesTag() is internal
assertThat(stateBundle.getBundle(Backstack.getScopesTag()).getBundle(testKeyWithScope.getScopeTag()).getBundle(SERVICE_TAG).getInt("blah")).isEqualTo(5);
}
use of com.zhuinden.simplestack.helpers.ServiceProvider in project simple-stack by Zhuinden.
the class ScopingTest method canFindServiceNoOverlapsWorks.
@Test
public void canFindServiceNoOverlapsWorks() {
Backstack backstack = new Backstack();
backstack.setScopedServices(new ServiceProvider());
final Service service = new Service();
TestKeyWithScope beep = new TestKeyWithScope("beep") {
@Override
public void bindServices(ServiceBinder serviceBinder) {
assertThat(serviceBinder.getScopeTag()).isEqualTo(getScopeTag());
serviceBinder.addService(SERVICE_TAG, service);
}
@Nonnull
@Override
public String getScopeTag() {
return "beep";
}
};
TestKeyWithScope boop = new TestKeyWithScope("boop") {
@Override
public void bindServices(ServiceBinder serviceBinder) {
}
@Nonnull
@Override
public String getScopeTag() {
return "boop";
}
};
backstack.setup(History.of(beep, boop));
assertThat(backstack.hasService("beep", SERVICE_TAG)).isFalse();
backstack.setStateChanger(stateChanger);
assertThat(backstack.hasService("beep", SERVICE_TAG)).isTrue();
assertThat(backstack.hasService("boop", SERVICE_TAG)).isFalse();
assertThat(backstack.<Object>canFindService(SERVICE_TAG)).isTrue();
backstack.goBack();
assertThat(backstack.hasService("beep", SERVICE_TAG)).isTrue();
assertThat(backstack.<Object>canFindService(SERVICE_TAG)).isTrue();
backstack.setHistory(History.single(testKey1), StateChange.REPLACE);
assertThat(backstack.hasService("beep", SERVICE_TAG)).isFalse();
assertThat(backstack.canFindService(SERVICE_TAG)).isFalse();
}
Aggregations