// Path: app/src/main/java/com/thoughtworks/startup/StartupApplication.java
// public class StartupApplication extends Application  {
// 
//     ApplicationComponent applicationComponent;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
// 
//         if (BuildConfig.DEBUG) {
//             Timber.plant(new Timber.DebugTree());
//         }
//     }
// 
//     public static StartupApplication get(Context context) {
//         return (StartupApplication) context.getApplicationContext();
//     }
// 
//     public ApplicationComponent getComponent() {
//         if (applicationComponent == null) {
//             applicationComponent = DaggerApplicationComponent.builder()
//                     .applicationModule(new ApplicationModule(this))
//                     .build();
//         }
//         return applicationComponent;
//     }
// 
//     // Needed to replace the component with a test specific one
//     public void setComponent(ApplicationComponent applicationComponent) {
//         this.applicationComponent = applicationComponent;
//     }
// }
// 
// Path: app/src/main/java/com/thoughtworks/startup/data/DataManager.java
// @Singleton
// public class DataManager {
// 
//     private final RibotsService ribotsService;
//     private final DatabaseHelper databaseHelper;
//     private final PreferencesHelper preferencesHelper;
//     private final EventPosterHelper eventPosterHelper;
// 
//     @Inject
//     public DataManager(RibotsService ribotsService, PreferencesHelper preferencesHelper,
//                        DatabaseHelper databaseHelper, EventPosterHelper eventPosterHelper) {
//         this.ribotsService = ribotsService;
//         this.preferencesHelper = preferencesHelper;
//         this.databaseHelper = databaseHelper;
//         this.eventPosterHelper = eventPosterHelper;
//     }
// 
//     public PreferencesHelper getPreferencesHelper() {
//         return preferencesHelper;
//     }
// 
//     public Observable<Ribot> syncRibots() {
//         return ribotsService.getRibots()
//                 .concatMap(new Func1<List<Ribot>, Observable<Ribot>>() {
//                     @Override
//                     public Observable<Ribot> call(List<Ribot> ribots) {
//                         return databaseHelper.setRibots(ribots);
//                     }
//                 });
//     }
// 
//     public Observable<List<Ribot>> getRibots() {
//         return databaseHelper.getRibots().distinct();
//     }
// 
// 
//     /// Helper method to post events from doOnCompleted.
//     private Action0 postEventAction(final Object event) {
//         return new Action0() {
//             @Override
//             public void call() {
//                 eventPosterHelper.postEventSafely(event);
//             }
//         };
//     }
// 
// }
// 
// Path: app/src/commonTest/java/com/thoughtworks/startup/injection/component/TestComponent.java
// @Singleton
// @Component(modules = {TestApplicationModule.class, TestAndroidServicesModule.class})
// public interface TestComponent extends ApplicationComponent {
// 
// }
// 
// Path: app/src/commonTest/java/com/thoughtworks/startup/injection/module/TestApplicationModule.java
// @Module
// public class TestApplicationModule {
// 
//     private final Application application;
// 
//     public TestApplicationModule(Application application) {
//         this.application = application;
//     }
// 
//     @Provides
//     Application provideApplication() {
//         return application;
//     }
// 
//     @Provides
//     @ApplicationContext
//     Context provideContext() {
//         return application;
//     }
// 
//     @Provides
//     @Singleton
//     Bus provideEventBus() {
//         return new Bus();
//     }
// 
//     /*************
//      * MOCKS
//      *************/
// 
//     @Provides
//     @Singleton
//     DataManager provideDataManager() {
//         return mock(DataManager.class);
//     }
// 
//     @Provides
//     @Singleton
//     RibotsService provideRibotsService() {
//         return mock(RibotsService.class);
//     }
// 
//     @Provides
//     @Singleton
//     SignInService provideSignInService() {
//         return mock(SignInService.class);
//     }
// 
//     @Provides
//     @Singleton
//     GitHubService provideGitHubService() {
//         return mock(GitHubService.class);
//     }
// 
// }
// 
// Path: app/src/commonTest/java/com/thoughtworks/startup/injection/module/TestAndroidServicesModule.java
// @Module
// public class TestAndroidServicesModule {
// 
//     @Provides
//     @Singleton
//     public InputMethodManager provideInputMethodManager(Context context) {
//         return mock(InputMethodManager.class);
//     }
// 
//     @Provides
//     @Singleton
//     PackageManager providePackageManager(Context context) {
//         return mock(PackageManager.class);
//     }
// 
//     @Provides
//     @Singleton
//     LocationManager provideLocationManager(Context context) {
//         return mock(LocationManager.class);
//     }
// 
//     @Provides
//     @Singleton
//     LocalBroadcastManager provideLocalBroadcastManager(Context context) {
//         return mock(LocalBroadcastManager.class);
//     }
// 
// }


import android.content.Context;
import com.thoughtworks.startup.StartupApplication;
import com.thoughtworks.startup.data.DataManager;
import com.thoughtworks.startup.injection.component.DaggerTestComponent;
import com.thoughtworks.startup.injection.component.TestComponent;
import com.thoughtworks.startup.injection.module.TestApplicationModule;
import com.thoughtworks.startup.injection.module.TestAndroidServicesModule;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
package com.thoughtworks.startup.rules;




/**
 * Test rule that creates and sets a Dagger TestComponent into the application overriding the
 * existing application component.
 * Use this rule in your test case in order for the app to use mock dependencies.
 * It also exposes some of the dependencies so they can be easily accessed from the tests, e.g. to
 * stub mocks etc.
 */
public class TestComponentRule implements TestRule {

    private final TestComponent testComponent;
    private final Context context;

    public TestComponentRule(Context context) {
        this.context = context;
        StartupApplication application = StartupApplication.get(context);
        testComponent = DaggerTestComponent.builder()
                .testApplicationModule(new TestApplicationModule(application))
                .testAndroidServicesModule(new TestAndroidServicesModule())
                .build();
    }

    public Context getContext() {
        return context;
    }

    public DataManager getMockDataManager() {
        return testComponent.dataManager();
    }

    @Override
    public Statement apply(final Statement base, Description description) {
        return new Statement() {
            @Override
            public void evaluate() throws Throwable {
// Path: app/src/main/java/com/thoughtworks/startup/StartupApplication.java
// public class StartupApplication extends Application  {
// 
//     ApplicationComponent applicationComponent;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
// 
//         if (BuildConfig.DEBUG) {
//             Timber.plant(new Timber.DebugTree());
//         }
//     }
// 
//     public static StartupApplication get(Context context) {
//         return (StartupApplication) context.getApplicationContext();
//     }
// 
//     public ApplicationComponent getComponent() {
//         if (applicationComponent == null) {
//             applicationComponent = DaggerApplicationComponent.builder()
//                     .applicationModule(new ApplicationModule(this))
//                     .build();
//         }
//         return applicationComponent;
//     }
// 
//     // Needed to replace the component with a test specific one
//     public void setComponent(ApplicationComponent applicationComponent) {
//         this.applicationComponent = applicationComponent;
//     }
// }
// 
// Path: app/src/main/java/com/thoughtworks/startup/data/DataManager.java
// @Singleton
// public class DataManager {
// 
//     private final RibotsService ribotsService;
//     private final DatabaseHelper databaseHelper;
//     private final PreferencesHelper preferencesHelper;
//     private final EventPosterHelper eventPosterHelper;
// 
//     @Inject
//     public DataManager(RibotsService ribotsService, PreferencesHelper preferencesHelper,
//                        DatabaseHelper databaseHelper, EventPosterHelper eventPosterHelper) {
//         this.ribotsService = ribotsService;
//         this.preferencesHelper = preferencesHelper;
//         this.databaseHelper = databaseHelper;
//         this.eventPosterHelper = eventPosterHelper;
//     }
// 
//     public PreferencesHelper getPreferencesHelper() {
//         return preferencesHelper;
//     }
// 
//     public Observable<Ribot> syncRibots() {
//         return ribotsService.getRibots()
//                 .concatMap(new Func1<List<Ribot>, Observable<Ribot>>() {
//                     @Override
//                     public Observable<Ribot> call(List<Ribot> ribots) {
//                         return databaseHelper.setRibots(ribots);
//                     }
//                 });
//     }
// 
//     public Observable<List<Ribot>> getRibots() {
//         return databaseHelper.getRibots().distinct();
//     }
// 
// 
//     /// Helper method to post events from doOnCompleted.
//     private Action0 postEventAction(final Object event) {
//         return new Action0() {
//             @Override
//             public void call() {
//                 eventPosterHelper.postEventSafely(event);
//             }
//         };
//     }
// 
// }
// 
// Path: app/src/commonTest/java/com/thoughtworks/startup/injection/component/TestComponent.java
// @Singleton
// @Component(modules = {TestApplicationModule.class, TestAndroidServicesModule.class})
// public interface TestComponent extends ApplicationComponent {
// 
// }
// 
// Path: app/src/commonTest/java/com/thoughtworks/startup/injection/module/TestApplicationModule.java
// @Module
// public class TestApplicationModule {
// 
//     private final Application application;
// 
//     public TestApplicationModule(Application application) {
//         this.application = application;
//     }
// 
//     @Provides
//     Application provideApplication() {
//         return application;
//     }
// 
//     @Provides
//     @ApplicationContext
//     Context provideContext() {
//         return application;
//     }
// 
//     @Provides
//     @Singleton
//     Bus provideEventBus() {
//         return new Bus();
//     }
// 
//     /*************
//      * MOCKS
//      *************/
// 
//     @Provides
//     @Singleton
//     DataManager provideDataManager() {
//         return mock(DataManager.class);
//     }
// 
//     @Provides
//     @Singleton
//     RibotsService provideRibotsService() {
//         return mock(RibotsService.class);
//     }
// 
//     @Provides
//     @Singleton
//     SignInService provideSignInService() {
//         return mock(SignInService.class);
//     }
// 
//     @Provides
//     @Singleton
//     GitHubService provideGitHubService() {
//         return mock(GitHubService.class);
//     }
// 
// }
// 
// Path: app/src/commonTest/java/com/thoughtworks/startup/injection/module/TestAndroidServicesModule.java
// @Module
// public class TestAndroidServicesModule {
// 
//     @Provides
//     @Singleton
//     public InputMethodManager provideInputMethodManager(Context context) {
//         return mock(InputMethodManager.class);
//     }
// 
//     @Provides
//     @Singleton
//     PackageManager providePackageManager(Context context) {
//         return mock(PackageManager.class);
//     }
// 
//     @Provides
//     @Singleton
//     LocationManager provideLocationManager(Context context) {
//         return mock(LocationManager.class);
//     }
// 
//     @Provides
//     @Singleton
//     LocalBroadcastManager provideLocalBroadcastManager(Context context) {
//         return mock(LocalBroadcastManager.class);
//     }
// 
// }


// Path: app/src/commonTest/java/com/thoughtworks/startup/rules/TestComponentRule.java
import android.content.Context;
import com.thoughtworks.startup.StartupApplication;
import com.thoughtworks.startup.data.DataManager;
import com.thoughtworks.startup.injection.component.DaggerTestComponent;
import com.thoughtworks.startup.injection.component.TestComponent;
import com.thoughtworks.startup.injection.module.TestApplicationModule;
import com.thoughtworks.startup.injection.module.TestAndroidServicesModule;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

package com.thoughtworks.startup.rules;




/**
 * Test rule that creates and sets a Dagger TestComponent into the application overriding the
 * existing application component.
 * Use this rule in your test case in order for the app to use mock dependencies.
 * It also exposes some of the dependencies so they can be easily accessed from the tests, e.g. to
 * stub mocks etc.
 */
public class TestComponentRule implements TestRule {

    private final TestComponent testComponent;
    private final Context context;

    public TestComponentRule(Context context) {
        this.context = context;
        StartupApplication application = StartupApplication.get(context);
        testComponent = DaggerTestComponent.builder()
                .testApplicationModule(new TestApplicationModule(application))
                .testAndroidServicesModule(new TestAndroidServicesModule())
                .build();
    }

    public Context getContext() {
        return context;
    }

    public DataManager getMockDataManager() {
        return testComponent.dataManager();
    }

    @Override
    public Statement apply(final Statement base, Description description) {
        return new Statement() {
            @Override
            public void evaluate() throws Throwable {
                StartupApplication application = StartupApplication.get(context);