use of com.zhuinden.simplestack.helpers.ServiceProvider in project simple-stack by Zhuinden.
the class ScopingTest method serviceBinderAddThrowsForNullService.
@Test
public void serviceBinderAddThrowsForNullService() {
final String serviceTag = "serviceTag";
final Object nullService = null;
TestKeyWithScope testKeyWithScope = new TestKeyWithScope("blah") {
@Override
public void bindServices(ServiceBinder serviceBinder) {
assertThat(serviceBinder.getScopeTag()).isEqualTo(getScopeTag());
serviceBinder.addService(serviceTag, null);
}
@Nonnull
@Override
public String getScopeTag() {
return "beep";
}
};
Backstack backstack = new Backstack();
backstack.setScopedServices(new ServiceProvider());
backstack.setup(History.of(testKeyWithScope));
try {
backstack.setStateChanger(stateChanger);
Assert.fail();
} catch (Exception e) {
assertThat(e.getMessage()).isEqualTo("service cannot be null!");
}
}
use of com.zhuinden.simplestack.helpers.ServiceProvider in project simple-stack by Zhuinden.
the class ScopingTest method serviceBinderAddThrowsForNullServiceTag.
@Test
public void serviceBinderAddThrowsForNullServiceTag() {
final String nullTag = null;
final Object service = new Service();
TestKeyWithScope testKeyWithScope = new TestKeyWithScope("blah") {
@Override
public void bindServices(ServiceBinder serviceBinder) {
assertThat(serviceBinder.getScopeTag()).isEqualTo(getScopeTag());
serviceBinder.addService(nullTag, service);
}
@Nonnull
@Override
public String getScopeTag() {
return "beep";
}
};
Backstack backstack = new Backstack();
backstack.setScopedServices(new ServiceProvider());
backstack.setup(History.of(testKeyWithScope));
try {
backstack.setStateChanger(stateChanger);
Assert.fail();
} catch (Exception e) {
assertThat(e.getMessage()).isEqualTo("serviceTag cannot be null!");
}
}
use of com.zhuinden.simplestack.helpers.ServiceProvider in project simple-stack by Zhuinden.
the class ScopingTest method serviceBinderMethodsWork.
@Test
public void serviceBinderMethodsWork() {
Backstack backstack = new Backstack();
backstack.setScopedServices(new ServiceProvider());
final Service service1 = new Service();
final Service service2 = new Service();
TestKeyWithScope beep = new TestKeyWithScope("beep") {
@Override
public void bindServices(ServiceBinder serviceBinder) {
assertThat(serviceBinder.getScopeTag()).isEqualTo(getScopeTag());
assertThat(serviceBinder.hasService("SERVICE1")).isFalse();
assertThat(serviceBinder.canFindService("SERVICE1")).isFalse();
serviceBinder.addService("SERVICE1", service1);
assertThat(serviceBinder.hasService("SERVICE1")).isTrue();
assertThat(serviceBinder.canFindService("SERVICE1")).isTrue();
assertThat(serviceBinder.lookupService("SERVICE1")).isSameAs(service1);
}
@Nonnull
@Override
public String getScopeTag() {
return "beep";
}
};
TestKeyWithScope boop = new TestKeyWithScope("boop") {
@Override
public void bindServices(ServiceBinder serviceBinder) {
assertThat(serviceBinder.getScopeTag()).isEqualTo(getScopeTag());
assertThat(serviceBinder.hasService("SERVICE1")).isFalse();
assertThat(serviceBinder.canFindService("SERVICE1")).isTrue();
assertThat(serviceBinder.hasService("SERVICE2")).isFalse();
serviceBinder.addService("SERVICE2", service2);
assertThat(serviceBinder.hasService("SERVICE2")).isTrue();
assertThat(serviceBinder.canFindService("SERVICE2")).isTrue();
assertThat(serviceBinder.hasService("SERVICE2")).isTrue();
assertThat(serviceBinder.lookupService("SERVICE1")).isSameAs(service1);
assertThat(serviceBinder.lookupService("SERVICE2")).isSameAs(service2);
}
@Nonnull
@Override
public String getScopeTag() {
return "boop";
}
};
backstack.setup(History.of(beep, boop));
backstack.setStateChanger(stateChanger);
}
use of com.zhuinden.simplestack.helpers.ServiceProvider in project simple-stack by Zhuinden.
the class BackstackTest method exitScopeToThrowsWhenBackstackIsEmpty.
@Test
public void exitScopeToThrowsWhenBackstackIsEmpty() {
Backstack backstack = new Backstack();
backstack.setScopedServices(new ServiceProvider());
Object key = new TestKeyWithScope("blah") {
@Override
public void bindServices(ServiceBinder serviceBinder) {
}
};
backstack.setup(History.of(key));
Object targetKey = new TestKey("target");
try {
backstack.exitScopeTo("blah", targetKey, StateChange.FORWARD);
Assert.fail();
} catch (IllegalStateException e) {
// OK!
}
}
use of com.zhuinden.simplestack.helpers.ServiceProvider in project simple-stack by Zhuinden.
the class BackstackTest method exitScopeExitsExplicitScopesCorrectly.
@Test
public void exitScopeExitsExplicitScopesCorrectly() {
Backstack backstack = new Backstack();
backstack.setScopedServices(new ServiceProvider());
Object firstKey = new TestKey("firstKey");
Object secondKey = new TestKey("secondKey");
Object lastKey = new TestKey("lastKey");
Object key1 = new TestKeyWithExplicitParent("key1") {
@Nonnull
@Override
public List<String> getParentScopes() {
return History.of("blah", "parentKey1");
}
@Override
protected void bindParentServices(ServiceBinder serviceBinder) {
}
@Override
protected void bindOwnServices(ServiceBinder serviceBinder) {
}
};
Object key2 = new TestKeyWithExplicitParent("key2") {
@Nonnull
@Override
public List<String> getParentScopes() {
return History.of("blah", "parentKey2");
}
@Override
protected void bindParentServices(ServiceBinder serviceBinder) {
}
@Override
protected void bindOwnServices(ServiceBinder serviceBinder) {
}
};
backstack.setup(History.of(firstKey, secondKey, key1, key2, lastKey));
backstack.setStateChanger(new StateChanger() {
@Override
public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) {
completionCallback.stateChangeComplete();
}
});
backstack.exitScope("blah");
assertThat(backstack.getHistory()).containsExactly(firstKey, secondKey);
}
Aggregations