// 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/TestKeyWithExplicitParent.java
// public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices {
//     public TestKeyWithExplicitParent(String name) {
//         super(name);
//     }
// 
//     protected TestKeyWithExplicitParent(Parcel in) {
//         super(in);
//     }
// 
//     @Override
//     public final void bindServices(ServiceBinder serviceBinder) {
//         if(name.equals(serviceBinder.getScopeTag())) {
//             bindOwnServices(serviceBinder);
//         } else {
//             bindParentServices(serviceBinder);
//         }
//     }
// 
//     protected abstract void bindParentServices(ServiceBinder serviceBinder);
// 
//     protected abstract void bindOwnServices(ServiceBinder serviceBinder);
// }
// 
// 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/helpers/TestKeyWithScope.java
// public abstract class TestKeyWithScope
//         extends TestKey
//         implements HasServices {
//     public TestKeyWithScope(String name) {
//         super(name);
//     }
// 
//     protected TestKeyWithScope(Parcel in) {
//         super(in);
//     }
// 
//     @Nonnull
//     @Override
//     public String getScopeTag() {
//         return name;
//     }
// }


import com.zhuinden.simplestack.helpers.ServiceProvider;
import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent;
import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices;
import com.zhuinden.simplestack.helpers.TestKeyWithScope;
import org.junit.Test;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.Nonnull;
import static org.assertj.core.api.Assertions.assertThat;
package com.zhuinden.simplestack;






public class ScopingBackEventDispatchTest {
    private class HandlesBackOnce implements ScopedServices.HandlesBack {
        private boolean handledBackOnce = false;

        @Override
        public boolean onBackEvent() {
            if(!handledBackOnce) {
                this.handledBackOnce = true;
                return true;
            }
            return false;
        }
    }

    @Test
    public void onBackStackGoBackDispatchesBackToActiveScope() {
        final HandlesBackOnce service1 = new HandlesBackOnce();
        final HandlesBackOnce service2 = new HandlesBackOnce();

// 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/TestKeyWithExplicitParent.java
// public abstract class TestKeyWithExplicitParent extends TestKeyWithScope implements HasParentServices {
//     public TestKeyWithExplicitParent(String name) {
//         super(name);
//     }
// 
//     protected TestKeyWithExplicitParent(Parcel in) {
//         super(in);
//     }
// 
//     @Override
//     public final void bindServices(ServiceBinder serviceBinder) {
//         if(name.equals(serviceBinder.getScopeTag())) {
//             bindOwnServices(serviceBinder);
//         } else {
//             bindParentServices(serviceBinder);
//         }
//     }
// 
//     protected abstract void bindParentServices(ServiceBinder serviceBinder);
// 
//     protected abstract void bindOwnServices(ServiceBinder serviceBinder);
// }
// 
// 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/helpers/TestKeyWithScope.java
// public abstract class TestKeyWithScope
//         extends TestKey
//         implements HasServices {
//     public TestKeyWithScope(String name) {
//         super(name);
//     }
// 
//     protected TestKeyWithScope(Parcel in) {
//         super(in);
//     }
// 
//     @Nonnull
//     @Override
//     public String getScopeTag() {
//         return name;
//     }
// }


// Path: simple-stack/src/test/java/com/zhuinden/simplestack/ScopingBackEventDispatchTest.java
import com.zhuinden.simplestack.helpers.ServiceProvider;
import com.zhuinden.simplestack.helpers.TestKeyWithExplicitParent;
import com.zhuinden.simplestack.helpers.TestKeyWithOnlyParentServices;
import com.zhuinden.simplestack.helpers.TestKeyWithScope;
import org.junit.Test;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.Nonnull;
import static org.assertj.core.api.Assertions.assertThat;

package com.zhuinden.simplestack;






public class ScopingBackEventDispatchTest {
    private class HandlesBackOnce implements ScopedServices.HandlesBack {
        private boolean handledBackOnce = false;

        @Override
        public boolean onBackEvent() {
            if(!handledBackOnce) {
                this.handledBackOnce = true;
                return true;
            }
            return false;
        }
    }

    @Test
    public void onBackStackGoBackDispatchesBackToActiveScope() {
        final HandlesBackOnce service1 = new HandlesBackOnce();
        final HandlesBackOnce service2 = new HandlesBackOnce();

        Object key1 = new TestKeyWithScope("key1") {