use of com.zhuinden.simplestack.helpers.ServiceProvider in project simple-stack by Zhuinden.
the class BackstackTest method exitScopeToDefaultsToJumpToRootIfRootHasScope.
@Test
public void exitScopeToDefaultsToJumpToRootIfRootHasScope() {
Backstack backstack = new Backstack();
backstack.setScopedServices(new ServiceProvider());
Object key = new TestKeyWithScope("blah") {
@Override
public void bindServices(ServiceBinder serviceBinder) {
}
};
backstack.setup(History.of(key));
backstack.setStateChanger(new StateChanger() {
@Override
public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) {
completionCallback.stateChangeComplete();
}
});
backstack.exitScopeTo("blah", key, StateChange.BACKWARD);
assertThat(backstack.getHistory()).containsExactly(key);
}
use of com.zhuinden.simplestack.helpers.ServiceProvider in project simple-stack by Zhuinden.
the class BackstackTest method exitScopeToExitsImplicitScopeCorrectlyAndAppendsIfNotFound.
@Test
public void exitScopeToExitsImplicitScopeCorrectlyAndAppendsIfNotFound() {
Backstack backstack = new Backstack();
backstack.setScopedServices(new ServiceProvider());
Object firstKey = new TestKey("firstKey");
Object secondKey = new TestKey("secondKey");
Object thirdKey = new TestKey("thirdKey");
Object lastKey = new TestKey("lastKey");
Object key = new TestKeyWithScope("blah") {
@Override
public void bindServices(ServiceBinder serviceBinder) {
}
};
Object targetKey = new TestKey("targetKey");
backstack.setup(History.of(firstKey, secondKey, thirdKey, key, lastKey));
backstack.setStateChanger(new StateChanger() {
@Override
public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) {
completionCallback.stateChangeComplete();
}
});
backstack.exitScopeTo("blah", targetKey, StateChange.FORWARD);
assertThat(backstack.getHistory()).containsExactly(firstKey, secondKey, thirdKey, targetKey);
}
use of com.zhuinden.simplestack.helpers.ServiceProvider in project simple-stack by Zhuinden.
the class BackstackTest method exitScopeToExitsExplicitScopeCorrectlyAndAppendsIfNotFound.
@Test
public void exitScopeToExitsExplicitScopeCorrectlyAndAppendsIfNotFound() {
Backstack backstack = new Backstack();
backstack.setScopedServices(new ServiceProvider());
Object firstKey = new TestKey("firstKey");
Object secondKey = new TestKey("secondKey");
Object thirdKey = new TestKey("thirdKey");
Object lastKey = new TestKey("lastKey");
Object key = new TestKeyWithOnlyParentServices("key", History.of("blah")) {
@Override
public void bindServices(ServiceBinder serviceBinder) {
}
};
Object targetKey = new TestKey("targetKey");
backstack.setup(History.of(firstKey, secondKey, thirdKey, key, lastKey));
backstack.setStateChanger(new StateChanger() {
@Override
public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) {
completionCallback.stateChangeComplete();
}
});
backstack.exitScopeTo("blah", targetKey, StateChange.FORWARD);
assertThat(backstack.getHistory()).containsExactly(firstKey, secondKey, thirdKey, targetKey);
}
use of com.zhuinden.simplestack.helpers.ServiceProvider in project simple-stack by Zhuinden.
the class BackstackTest method exitScopeThrowsWhenScopeIsNotFound.
@Test
public void exitScopeThrowsWhenScopeIsNotFound() {
Backstack backstack = new Backstack();
backstack.setScopedServices(new ServiceProvider());
Object key = new TestKeyWithScope("blah") {
@Override
public void bindServices(ServiceBinder serviceBinder) {
}
};
backstack.setup(History.of(key));
try {
backstack.exitScope("blahhhh");
Assert.fail();
} catch (IllegalStateException e) {
// OK!
}
}
use of com.zhuinden.simplestack.helpers.ServiceProvider in project simple-stack by Zhuinden.
the class ScopeLookupModeTest method findScopesForKeyIncludesGlobalScopeIfAvailable.
@Test
public void findScopesForKeyIncludesGlobalScopeIfAvailable() {
final Backstack backstack = new Backstack();
backstack.setScopedServices(new ServiceProvider());
Object globalService = new Object();
backstack.setGlobalServices(GlobalServices.builder().addService("globalService", globalService).build());
final Object parentService1 = new Object();
final Object parentService2 = new Object();
final Object service1 = new Object();
final Object service2 = new Object();
class Key1 extends TestKey implements HasServices, HasParentServices {
Key1(String name) {
super(name);
}
protected Key1(Parcel in) {
super(in);
}
@Override
public void bindServices(ServiceBinder serviceBinder) {
if ("parent1".equals(serviceBinder.getScopeTag())) {
serviceBinder.addService("parentService1", parentService1);
} else if (name.equals(serviceBinder.getScopeTag())) {
serviceBinder.addService("service1", service1);
}
}
@Nonnull
@Override
public String getScopeTag() {
return name;
}
@Nonnull
@Override
public List<String> getParentScopes() {
return History.of("parent1");
}
}
class Key2 extends TestKey implements HasServices, HasParentServices {
Key2(String name) {
super(name);
}
protected Key2(Parcel in) {
super(in);
}
@Override
public void bindServices(ServiceBinder serviceBinder) {
if ("parent2".equals(serviceBinder.getScopeTag())) {
serviceBinder.addService("parentService2", parentService2);
} else if (name.equals(serviceBinder.getScopeTag())) {
serviceBinder.addService("service2", service2);
}
}
@Nonnull
@Override
public String getScopeTag() {
return name;
}
@Nonnull
@Override
public List<String> getParentScopes() {
return History.of("parent2");
}
}
backstack.setup(History.of(new Key1("beep"), new Key2("boop")));
assertThat(backstack.findScopesForKey(new Key1("beep"), ScopeLookupMode.EXPLICIT)).isEmpty();
assertThat(backstack.findScopesForKey(new Key2("boop"), ScopeLookupMode.EXPLICIT)).isEmpty();
assertThat(backstack.findScopesForKey(new Key1("beep"), ScopeLookupMode.ALL)).isEmpty();
assertThat(backstack.findScopesForKey(new Key2("boop"), ScopeLookupMode.ALL)).isEmpty();
backstack.setStateChanger(new StateChanger() {
@Override
public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) {
completionCallback.stateChangeComplete();
}
});
assertThat(backstack.findScopesForKey(new Key1("beep"), ScopeLookupMode.EXPLICIT)).containsExactly("beep", "parent1", GlobalServices.SCOPE_TAG);
assertThat(backstack.findScopesForKey(new Key2("boop"), ScopeLookupMode.EXPLICIT)).containsExactly("boop", "parent2", GlobalServices.SCOPE_TAG);
assertThat(backstack.findScopesForKey(new Key1("beep"), ScopeLookupMode.ALL)).containsExactly("beep", "parent1", GlobalServices.SCOPE_TAG);
assertThat(backstack.findScopesForKey(new Key2("boop"), ScopeLookupMode.ALL)).containsExactly("boop", "parent2", "beep", "parent1", GlobalServices.SCOPE_TAG);
}
Aggregations