use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class HistoryTest method buildUpon.
@Test
public void buildUpon() throws Exception {
TestKey testKey1 = new TestKey("Hello");
TestKey testKey2 = new TestKey("World");
TestKey testKey3 = new TestKey("Kappa");
History history = History.of(testKey1, testKey2);
assertThat(history.buildUpon().add(testKey3).build()).containsExactly(testKey1, testKey2, testKey3);
}
use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class HistoryTest method builderFromObjects.
@Test
public void builderFromObjects() throws Exception {
TestKey testKey1 = new TestKey("Hello");
TestKey testKey2 = new TestKey("World");
assertThat(History.builderOf(testKey1, testKey2).build()).containsExactly(testKey1, testKey2);
}
use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class HistoryTest method builderFromList.
@Test
public void builderFromList() throws Exception {
TestKey testKey1 = new TestKey("Hello");
TestKey testKey2 = new TestKey("World");
TestKey testKey3 = new TestKey("Kappa");
List<TestKey> list = new ArrayList<>(3);
list.add(testKey1);
list.add(testKey2);
list.add(testKey3);
assertThat(History.builderFrom(list)).containsExactly(testKey1, testKey2, testKey3);
}
use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class HistoryTest method contains.
@Test
public void contains() throws Exception {
TestKey testKey1 = new TestKey("Hello");
TestKey testKey2 = new TestKey("World");
TestKey testKey3 = new TestKey("Kappa");
History history = History.of(testKey1, testKey2);
assertThat(history.contains(testKey2)).isTrue();
assertThat(history.contains(testKey3)).isFalse();
}
use of com.zhuinden.simplestack.helpers.TestKey in project simple-stack by Zhuinden.
the class ScopeLookupModeTest method findScopesForKeyWorks.
@Test
public void findScopesForKeyWorks() {
final Backstack backstack = new Backstack();
backstack.setScopedServices(new ServiceProvider());
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", "parent3");
}
}
Object key1 = new Key1("beep");
Object key2 = new Key2("boop");
backstack.setup(History.of(key1, key2));
assertThat(backstack.findScopesForKey(key1, ScopeLookupMode.EXPLICIT)).isEmpty();
assertThat(backstack.findScopesForKey(key2, ScopeLookupMode.EXPLICIT)).isEmpty();
assertThat(backstack.findScopesForKey(key1, ScopeLookupMode.ALL)).isEmpty();
assertThat(backstack.findScopesForKey(key2, ScopeLookupMode.ALL)).isEmpty();
backstack.setStateChanger(new StateChanger() {
@Override
public void handleStateChange(@Nonnull StateChange stateChange, @Nonnull Callback completionCallback) {
completionCallback.stateChangeComplete();
}
});
assertThat(backstack.findScopesForKey(key1, ScopeLookupMode.EXPLICIT)).containsExactly("beep", "parent1");
assertThat(backstack.findScopesForKey(key2, ScopeLookupMode.EXPLICIT)).containsExactly("boop", "parent3", "parent2");
assertThat(backstack.findScopesForKey(key1, ScopeLookupMode.ALL)).containsExactly("beep", "parent1");
assertThat(backstack.findScopesForKey(key2, ScopeLookupMode.ALL)).containsExactly("boop", "parent3", "parent2", "beep", "parent1");
backstack.moveToTop(key1);
assertThat(backstack.findScopesForKey(key1, ScopeLookupMode.EXPLICIT)).containsExactly("beep", "parent1");
assertThat(backstack.findScopesForKey(key2, ScopeLookupMode.EXPLICIT)).containsExactly("boop", "parent3", "parent2");
assertThat(backstack.findScopesForKey(key1, ScopeLookupMode.ALL)).containsExactly("beep", "parent1", "boop", "parent3", "parent2");
assertThat(backstack.findScopesForKey(key2, ScopeLookupMode.ALL)).containsExactly("boop", "parent3", "parent2");
backstack.moveToTop(key2);
assertThat(backstack.findScopesForKey(key1, ScopeLookupMode.EXPLICIT)).containsExactly("beep", "parent1");
assertThat(backstack.findScopesForKey(key2, ScopeLookupMode.EXPLICIT)).containsExactly("boop", "parent3", "parent2");
assertThat(backstack.findScopesForKey(key1, ScopeLookupMode.ALL)).containsExactly("beep", "parent1");
assertThat(backstack.findScopesForKey(key2, ScopeLookupMode.ALL)).containsExactly("boop", "parent3", "parent2", "beep", "parent1");
}
Aggregations