use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class BackstackTest method exitScopeToExitsExplicitScopesCorrectly.
@Test
public void exitScopeToExitsExplicitScopesCorrectly() {
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();
}
});
Object targetKey = new TestKeyWithScope("blah") {
@Override
public void bindServices(ServiceBinder serviceBinder) {
}
};
backstack.exitScopeTo("blah", targetKey, StateChange.FORWARD);
assertThat(backstack.getHistory()).containsExactly(firstKey, secondKey, targetKey);
}
use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class BackstackTest method exitScopeToThrowsWhenScopeIsNotFound.
@Test
public void exitScopeToThrowsWhenScopeIsNotFound() {
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.TestKey in project simple-stack by Zhuinden.
the class BackstackTest method exitScopeToExitsExplicitScopeCorrectlyAndGoesBackIfFound.
@Test
public void exitScopeToExitsExplicitScopeCorrectlyAndGoesBackIfFound() {
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) {
}
};
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.TestKey in project simple-stack by Zhuinden.
the class BackstackTest method stateChangeCompletionListenerIsCalledInCorrectOrder.
@Test
public void stateChangeCompletionListenerIsCalledInCorrectOrder() {
final TestKey initial = new TestKey("initial");
final TestKey other = new TestKey("other");
final List<TestKey> integers = new ArrayList<>();
Backstack backstack = new Backstack();
backstack.setup(History.single(initial));
Backstack.CompletionListener stateChangeCompletionListener = new Backstack.CompletionListener() {
@Override
public void stateChangeCompleted(@Nonnull StateChange stateChange) {
integers.add(stateChange.<TestKey>topNewKey());
}
};
backstack.addStateChangeCompletionListener(stateChangeCompletionListener);
backstack.setStateChanger(stateChanger);
backstack.detachStateChanger();
backstack.goTo(other);
backstack.setHistory(History.single(initial), StateChange.REPLACE);
backstack.setHistory(History.single(other), StateChange.REPLACE);
backstack.setHistory(History.single(initial), StateChange.REPLACE);
backstack.setHistory(History.single(initial), StateChange.REPLACE);
backstack.goTo(other);
backstack.reattachStateChanger();
assertThat(integers).containsExactly(initial, other, initial, other, initial, initial, other);
}
use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class HistoryBuilderTest method removeUntilThrowsIfKeyNotFound.
@Test
public void removeUntilThrowsIfKeyNotFound() {
try {
History.Builder builder = History.newBuilder().add(new TestKey("hello"));
builder.removeUntil(new TestKey("bye"));
Assert.fail();
} catch (IllegalArgumentException e) {
// Good!
}
}
Aggregations