// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java
// public interface HasServices
//         extends ScopeKey {
//     void bindServices(ServiceBinder serviceBinder);
// }
// 
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java
// public class ServiceProvider
//         implements ScopedServices {
//     @Override
//     public void bindServices(@Nonnull ServiceBinder serviceBinder) {
//         Object key = serviceBinder.getKey();
//         if(key instanceof HasServices) {
//             ((HasServices) key).bindServices(serviceBinder);
//             return;
//         }
//         if(key instanceof HasParentServices) {
//             ((HasParentServices) key).bindServices(serviceBinder);
//             //noinspection UnnecessaryReturnStatement
//             return;
//         }
//     }
// }
// 
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java
// public class TestKey
//         implements Parcelable {
//     public final String name;
// 
//     public TestKey(String name) {
//         this.name = name;
//     }
// 
//     protected TestKey(Parcel in) {
//         name = in.readString();
//     }
// 
//     public static final Creator<TestKey> CREATOR = new Creator<TestKey>() {
//         @Override
//         public TestKey createFromParcel(Parcel in) {
//             return new TestKey(in);
//         }
// 
//         @Override
//         public TestKey[] newArray(int size) {
//             return new TestKey[size];
//         }
//     };
// 
//     @Override
//     public boolean equals(Object o) {
//         if(this == o) {
//             return true;
//         }
//         if(o == null || getClass() != o.getClass()) {
//             return false;
//         }
//         TestKey key = (TestKey) o;
//         return name.equals(key.name);
//     }
// 
//     @Override
//     public int hashCode() {
//         return name.hashCode();
//     }
// 
//     @Override
//     public String toString() {
//         return String.format("%s{%h}", name, this);
//     }
// 
//     @Override
//     public int describeContents() {
//         return 0;
//     }
// 
//     @Override
//     public void writeToParcel(Parcel dest, int flags) {
//         dest.writeString(name);
//     }
// }
// 
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java
// public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices {
//     private final List<String> parentScopes;
// 
//     public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) {
//         super(name);
//         this.parentScopes = parentScopes;
//     }
// 
//     @Nonnull
//     @Override
//     public List<String> getParentScopes() {
//         return parentScopes;
//     }
// }


import android.app.Activity;
import android.os.Parcel;
import com.zhuinden.simplestack.helpers.HasServices;
import com.zhuinden.simplestack.helpers.ServiceProvider;
import com.zhuinden.simplestack.helpers.TestKey;
import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices;
import com.zhuinden.statebundle.StateBundle;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static org.assertj.core.api.Assertions.assertThat;
        assertThat(backstack.hasService("beep", SERVICE_TAG)).isTrue();
        assertThat(backstack.hasService("boop", SERVICE_TAG)).isTrue();
        assertThat(backstack.<Object>canFindService(SERVICE_TAG)).isTrue();
        backstack.goBack();
        assertThat(backstack.hasService("beep", SERVICE_TAG)).isTrue();
        assertThat(backstack.hasService("boop", SERVICE_TAG)).isFalse();
        assertThat(backstack.<Object>canFindService(SERVICE_TAG)).isTrue();
        backstack.setHistory(History.single(testKey1), StateChange.REPLACE);
        assertThat(backstack.hasService("beep", SERVICE_TAG)).isFalse();
        assertThat(backstack.hasService("boop", SERVICE_TAG)).isFalse();
        assertThat(backstack.canFindService(SERVICE_TAG)).isFalse();
    }

    @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();

// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/HasServices.java
// public interface HasServices
//         extends ScopeKey {
//     void bindServices(ServiceBinder serviceBinder);
// }
// 
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/ServiceProvider.java
// public class ServiceProvider
//         implements ScopedServices {
//     @Override
//     public void bindServices(@Nonnull ServiceBinder serviceBinder) {
//         Object key = serviceBinder.getKey();
//         if(key instanceof HasServices) {
//             ((HasServices) key).bindServices(serviceBinder);
//             return;
//         }
//         if(key instanceof HasParentServices) {
//             ((HasParentServices) key).bindServices(serviceBinder);
//             //noinspection UnnecessaryReturnStatement
//             return;
//         }
//     }
// }
// 
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKey.java
// public class TestKey
//         implements Parcelable {
//     public final String name;
// 
//     public TestKey(String name) {
//         this.name = name;
//     }
// 
//     protected TestKey(Parcel in) {
//         name = in.readString();
//     }
// 
//     public static final Creator<TestKey> CREATOR = new Creator<TestKey>() {
//         @Override
//         public TestKey createFromParcel(Parcel in) {
//             return new TestKey(in);
//         }
// 
//         @Override
//         public TestKey[] newArray(int size) {
//             return new TestKey[size];
//         }
//     };
// 
//     @Override
//     public boolean equals(Object o) {
//         if(this == o) {
//             return true;
//         }
//         if(o == null || getClass() != o.getClass()) {
//             return false;
//         }
//         TestKey key = (TestKey) o;
//         return name.equals(key.name);
//     }
// 
//     @Override
//     public int hashCode() {
//         return name.hashCode();
//     }
// 
//     @Override
//     public String toString() {
//         return String.format("%s{%h}", name, this);
//     }
// 
//     @Override
//     public int describeContents() {
//         return 0;
//     }
// 
//     @Override
//     public void writeToParcel(Parcel dest, int flags) {
//         dest.writeString(name);
//     }
// }
// 
// Path: simple-stack/src/test/java/com/zhuinden/simplestack/helpers/TestKeyWithOnlyParentServices.java
// public abstract class TestKeyWithOnlyParentServices extends TestKey implements HasParentServices {
//     private final List<String> parentScopes;
// 
//     public TestKeyWithOnlyParentServices(String name, List<String> parentScopes) {
//         super(name);
//         this.parentScopes = parentScopes;
//     }
// 
//     @Nonnull
//     @Override
//     public List<String> getParentScopes() {
//         return parentScopes;
//     }
// }


// Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopingTest.java
import android.app.Activity;
import android.os.Parcel;
import com.zhuinden.simplestack.helpers.HasServices;
import com.zhuinden.simplestack.helpers.ServiceProvider;
import com.zhuinden.simplestack.helpers.TestKey;
import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices;
import com.zhuinden.statebundle.StateBundle;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static org.assertj.core.api.Assertions.assertThat;

        assertThat(backstack.hasService("beep", SERVICE_TAG)).isTrue();
        assertThat(backstack.hasService("boop", SERVICE_TAG)).isTrue();
        assertThat(backstack.<Object>canFindService(SERVICE_TAG)).isTrue();
        backstack.goBack();
        assertThat(backstack.hasService("beep", SERVICE_TAG)).isTrue();
        assertThat(backstack.hasService("boop", SERVICE_TAG)).isFalse();
        assertThat(backstack.<Object>canFindService(SERVICE_TAG)).isTrue();
        backstack.setHistory(History.single(testKey1), StateChange.REPLACE);
        assertThat(backstack.hasService("beep", SERVICE_TAG)).isFalse();
        assertThat(backstack.hasService("boop", SERVICE_TAG)).isFalse();
        assertThat(backstack.canFindService(SERVICE_TAG)).isFalse();
    }

    @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);