use of com.zhuinden.simplestack.helpers.TestKeyWithScope 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.TestKeyWithScope in project simple-stack by Zhuinden.
the class BackstackTest method exitScopeToExitsImplicitScopeCorrectlyAndGoesBackIfFound.
@Test
public void exitScopeToExitsImplicitScopeCorrectlyAndGoesBackIfFound() {
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) {
}
};
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", secondKey, StateChange.BACKWARD);
assertThat(backstack.getHistory()).containsExactly(firstKey, secondKey);
}
use of com.zhuinden.simplestack.helpers.TestKeyWithScope in project simple-stack by Zhuinden.
the class BackstackTest method exitScopeDefaultsToJumpToRootIfRootHasScope.
@Test
public void exitScopeDefaultsToJumpToRootIfRootHasScope() {
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.exitScope("blah");
assertThat(backstack.getHistory()).containsExactly(key);
}
use of com.zhuinden.simplestack.helpers.TestKeyWithScope in project simple-stack by Zhuinden.
the class BackstackTest method exitScopeThrowsWhenBackstackIsEmpty.
@Test
public void exitScopeThrowsWhenBackstackIsEmpty() {
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("blah");
Assert.fail();
} catch (IllegalStateException e) {
// OK!
}
}
use of com.zhuinden.simplestack.helpers.TestKeyWithScope in project simple-stack by Zhuinden.
the class BackstackTest method exitScopeToWorks.
@Test
public void exitScopeToWorks() {
Backstack backstack = new Backstack();
backstack.setScopedServices(new ServiceProvider());
Object key = new TestKeyWithScope("blah") {
@Override
public void bindServices(ServiceBinder serviceBinder) {
}
};
Object targetKey = new TestKey("targetKey");
backstack.setup(History.of(key));
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(targetKey);
}
Aggregations