// Path: app/src/androidTest/java/com/starter/util/RxIdlingResource.java
// public class RxIdlingResource implements IdlingResource {
// 
//     private final AtomicInteger activeSubscriptionsCount = new AtomicInteger(0);
//     private ResourceCallback resourceCallback;
// 
//     @Override
//     public String getName() {
//         return getClass().getSimpleName();
//     }
// 
//     @Override
//     public void registerIdleTransitionCallback(ResourceCallback callback) {
//         resourceCallback = callback;
//     }
// 
//     public void incrementActiveSubscriptionsCount() {
//         int count = activeSubscriptionsCount.incrementAndGet();
//         Timber.i("Active subscriptions count increased to %d", count);
//     }
// 
//     public void decrementActiveSubscriptionsCount() {
//         int count = activeSubscriptionsCount.decrementAndGet();
//         Timber.i("Active subscriptions count decreased to %d", count);
//         if (isIdleNow()) {
//             Timber.i("There is no active subscriptions, transitioning to Idle");
//             resourceCallback.onTransitionToIdle();
//         }
//     }
// 
//     @Override
//     public boolean isIdleNow() {
//         return activeSubscriptionsCount.get() == 0;
//     }
// }


import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import android.support.test.espresso.Espresso;
import android.support.test.runner.AndroidJUnitRunner;
import com.starter.util.RxIdlingResource;
import io.appflate.restmock.RESTMockServerStarter;
import io.appflate.restmock.android.AndroidAssetsFileParser;
import io.appflate.restmock.android.AndroidLogger;
import rx.plugins.RxJavaHooks;
package com.starter;


public class StarterTestRunner extends AndroidJUnitRunner {
    @Override
    public Application newApplication(ClassLoader cl, String className, Context context)
        throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        String testApplicationClassName = TestApplication.class.getCanonicalName();

        return super.newApplication(cl, testApplicationClassName, context);
    }

    @Override
    public void onCreate(Bundle arguments) {
        super.onCreate(arguments);

        RESTMockServerStarter.startSync(new AndroidAssetsFileParser(this.getContext()),
            new AndroidLogger());

        registerRxJavaIdlingResources();
    }

    private void registerRxJavaIdlingResources() {
// Path: app/src/androidTest/java/com/starter/util/RxIdlingResource.java
// public class RxIdlingResource implements IdlingResource {
// 
//     private final AtomicInteger activeSubscriptionsCount = new AtomicInteger(0);
//     private ResourceCallback resourceCallback;
// 
//     @Override
//     public String getName() {
//         return getClass().getSimpleName();
//     }
// 
//     @Override
//     public void registerIdleTransitionCallback(ResourceCallback callback) {
//         resourceCallback = callback;
//     }
// 
//     public void incrementActiveSubscriptionsCount() {
//         int count = activeSubscriptionsCount.incrementAndGet();
//         Timber.i("Active subscriptions count increased to %d", count);
//     }
// 
//     public void decrementActiveSubscriptionsCount() {
//         int count = activeSubscriptionsCount.decrementAndGet();
//         Timber.i("Active subscriptions count decreased to %d", count);
//         if (isIdleNow()) {
//             Timber.i("There is no active subscriptions, transitioning to Idle");
//             resourceCallback.onTransitionToIdle();
//         }
//     }
// 
//     @Override
//     public boolean isIdleNow() {
//         return activeSubscriptionsCount.get() == 0;
//     }
// }


// Path: app/src/androidTest/java/com/starter/StarterTestRunner.java
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import android.support.test.espresso.Espresso;
import android.support.test.runner.AndroidJUnitRunner;
import com.starter.util.RxIdlingResource;
import io.appflate.restmock.RESTMockServerStarter;
import io.appflate.restmock.android.AndroidAssetsFileParser;
import io.appflate.restmock.android.AndroidLogger;
import rx.plugins.RxJavaHooks;

package com.starter;


public class StarterTestRunner extends AndroidJUnitRunner {
    @Override
    public Application newApplication(ClassLoader cl, String className, Context context)
        throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        String testApplicationClassName = TestApplication.class.getCanonicalName();

        return super.newApplication(cl, testApplicationClassName, context);
    }

    @Override
    public void onCreate(Bundle arguments) {
        super.onCreate(arguments);

        RESTMockServerStarter.startSync(new AndroidAssetsFileParser(this.getContext()),
            new AndroidLogger());

        registerRxJavaIdlingResources();
    }

    private void registerRxJavaIdlingResources() {
        RxIdlingResource rxIdlingResource = new RxIdlingResource();