// Path: app/src/main/java/com/tobi/movies/MovieApplication.java
// public class MovieApplication extends Application {
// 
//     private PopularMoviesComponent popularMoviesComponent;
//     private MovieDetailsComponent movieDetailsComponent;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         ApplicationComponent applicationComponent = applicationComponent();
//         popularMoviesComponent = popularMoviesComponent(applicationComponent);
//         movieDetailsComponent = movieDetailsComponent(applicationComponent);
//     }
// 
//     protected ApplicationComponent applicationComponent() {
//         return DaggerApplicationComponent.create();
//     }
// 
//     protected MovieDetailsComponent movieDetailsComponent(ApplicationComponent applicationComponent) {
//         return DaggerMovieDetailsComponent.builder()
//                 .applicationComponent(applicationComponent)
//                 .build();
//     }
// 
//     protected PopularMoviesComponent popularMoviesComponent(ApplicationComponent applicationComponent) {
//         return DaggerPopularMoviesComponent.builder()
//                 .applicationComponent(applicationComponent)
//                 .build();
//     }
// 
//     public PopularMoviesComponent getPopularMoviesComponent() {
//         return popularMoviesComponent;
//     }
// 
//     public MovieDetailsComponent getMovieDetailsComponent() {
//         return movieDetailsComponent;
//     }
// }
// 
// Path: app/src/androidTest/java/com/tobi/movies/backend/ConfigurableBackend.java
// public class ConfigurableBackend implements Backend {
// 
//     private final Map<Long, ApiMovieDetails> movieDetails = new HashMap<>();
//     private final List<ApiMoviePoster> popularStream = Lists.newArrayList();
// 
//     public void addMovieDetails(ApiMovieDetails apiMovieDetails) {
//         movieDetails.put(apiMovieDetails.movieId, apiMovieDetails);
//     }
// 
//     public void addToPopularStream(ApiMoviePoster movieDetails) {
//         popularStream.add(movieDetails);
//     }
// 
//     @Override
//     public Observable<ApiPopularMoviesResponse> popularStream() {
//         return Observable.fromCallable(new Callable<ApiPopularMoviesResponse>() {
//             @Override
//             public ApiPopularMoviesResponse call() throws Exception {
//                 return new PublicApiPopularMoviesResponse(popularStream);
//             }
//         });
//     }
// 
//     @Override
//     public Observable<ApiMovieDetails> movieDetails(@Path("id") final long movieId) {
//         return Observable.fromCallable(new Callable<ApiMovieDetails>() {
//             @Override
//             public ApiMovieDetails call() throws Exception {
//                 return movieDetails.get(movieId);
//             }
//         });
//     }
// 
//     public void clear() {
//         movieDetails.clear();
//         popularStream.clear();
//     }
// }
// 
// Path: app/src/androidTest/java/com/tobi/movies/popularstream/TestPopularMoviesComponent.java
// @ActivityScope
// @Component(
//         modules = {
//                 ImageModule.class,
//                 TestStreamConverterModule.class,
//                 TestStreamApiModule.class,
//                 TestThreadingModule.class,
//         },
//         dependencies = TestApplicationComponent.class
// )
// public interface TestPopularMoviesComponent extends PopularMoviesComponent {
//     Backend backend();
// }
// 
// Path: app/src/androidTest/java/com/tobi/movies/utils/ActivityFinisher.java
// public class ActivityFinisher implements Runnable {
// 
//     public static void finishOpenActivities() {
//         new Handler(Looper.getMainLooper()).post(new ActivityFinisher());
//     }
// 
//     private final ActivityLifecycleMonitor activityLifecycleMonitor;
// 
//     private ActivityFinisher() {
//         this.activityLifecycleMonitor = ActivityLifecycleMonitorRegistry.getInstance();
//     }
// 
//     @Override
//     public void run() {
//         final List<Activity> activities = new ArrayList<>();
// 
//         for (final Stage stage : EnumSet.range(Stage.CREATED, Stage.STOPPED)) {
//             activities.addAll(activityLifecycleMonitor.getActivitiesInStage(stage));
//         }
// 
//         for (final Activity activity : activities) {
//             if (!activity.isFinishing()) {
//                 activity.finish();
//             }
//         }
//     }
// }


import android.support.test.InstrumentationRegistry;
import com.tobi.movies.MovieApplication;
import com.tobi.movies.backend.ConfigurableBackend;
import com.tobi.movies.popularstream.TestPopularMoviesComponent;
import com.tobi.movies.utils.ActivityFinisher;
import cucumber.api.java.After;
package com.tobi.movies.steps;




public class SetupSteps {

    @After
    public void tearDown() {
        clearBackend();
        ActivityFinisher.finishOpenActivities();
    }

    private void clearBackend() {
// Path: app/src/main/java/com/tobi/movies/MovieApplication.java
// public class MovieApplication extends Application {
// 
//     private PopularMoviesComponent popularMoviesComponent;
//     private MovieDetailsComponent movieDetailsComponent;
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         ApplicationComponent applicationComponent = applicationComponent();
//         popularMoviesComponent = popularMoviesComponent(applicationComponent);
//         movieDetailsComponent = movieDetailsComponent(applicationComponent);
//     }
// 
//     protected ApplicationComponent applicationComponent() {
//         return DaggerApplicationComponent.create();
//     }
// 
//     protected MovieDetailsComponent movieDetailsComponent(ApplicationComponent applicationComponent) {
//         return DaggerMovieDetailsComponent.builder()
//                 .applicationComponent(applicationComponent)
//                 .build();
//     }
// 
//     protected PopularMoviesComponent popularMoviesComponent(ApplicationComponent applicationComponent) {
//         return DaggerPopularMoviesComponent.builder()
//                 .applicationComponent(applicationComponent)
//                 .build();
//     }
// 
//     public PopularMoviesComponent getPopularMoviesComponent() {
//         return popularMoviesComponent;
//     }
// 
//     public MovieDetailsComponent getMovieDetailsComponent() {
//         return movieDetailsComponent;
//     }
// }
// 
// Path: app/src/androidTest/java/com/tobi/movies/backend/ConfigurableBackend.java
// public class ConfigurableBackend implements Backend {
// 
//     private final Map<Long, ApiMovieDetails> movieDetails = new HashMap<>();
//     private final List<ApiMoviePoster> popularStream = Lists.newArrayList();
// 
//     public void addMovieDetails(ApiMovieDetails apiMovieDetails) {
//         movieDetails.put(apiMovieDetails.movieId, apiMovieDetails);
//     }
// 
//     public void addToPopularStream(ApiMoviePoster movieDetails) {
//         popularStream.add(movieDetails);
//     }
// 
//     @Override
//     public Observable<ApiPopularMoviesResponse> popularStream() {
//         return Observable.fromCallable(new Callable<ApiPopularMoviesResponse>() {
//             @Override
//             public ApiPopularMoviesResponse call() throws Exception {
//                 return new PublicApiPopularMoviesResponse(popularStream);
//             }
//         });
//     }
// 
//     @Override
//     public Observable<ApiMovieDetails> movieDetails(@Path("id") final long movieId) {
//         return Observable.fromCallable(new Callable<ApiMovieDetails>() {
//             @Override
//             public ApiMovieDetails call() throws Exception {
//                 return movieDetails.get(movieId);
//             }
//         });
//     }
// 
//     public void clear() {
//         movieDetails.clear();
//         popularStream.clear();
//     }
// }
// 
// Path: app/src/androidTest/java/com/tobi/movies/popularstream/TestPopularMoviesComponent.java
// @ActivityScope
// @Component(
//         modules = {
//                 ImageModule.class,
//                 TestStreamConverterModule.class,
//                 TestStreamApiModule.class,
//                 TestThreadingModule.class,
//         },
//         dependencies = TestApplicationComponent.class
// )
// public interface TestPopularMoviesComponent extends PopularMoviesComponent {
//     Backend backend();
// }
// 
// Path: app/src/androidTest/java/com/tobi/movies/utils/ActivityFinisher.java
// public class ActivityFinisher implements Runnable {
// 
//     public static void finishOpenActivities() {
//         new Handler(Looper.getMainLooper()).post(new ActivityFinisher());
//     }
// 
//     private final ActivityLifecycleMonitor activityLifecycleMonitor;
// 
//     private ActivityFinisher() {
//         this.activityLifecycleMonitor = ActivityLifecycleMonitorRegistry.getInstance();
//     }
// 
//     @Override
//     public void run() {
//         final List<Activity> activities = new ArrayList<>();
// 
//         for (final Stage stage : EnumSet.range(Stage.CREATED, Stage.STOPPED)) {
//             activities.addAll(activityLifecycleMonitor.getActivitiesInStage(stage));
//         }
// 
//         for (final Activity activity : activities) {
//             if (!activity.isFinishing()) {
//                 activity.finish();
//             }
//         }
//     }
// }


// Path: app/src/androidTest/java/com/tobi/movies/steps/SetupSteps.java
import android.support.test.InstrumentationRegistry;
import com.tobi.movies.MovieApplication;
import com.tobi.movies.backend.ConfigurableBackend;
import com.tobi.movies.popularstream.TestPopularMoviesComponent;
import com.tobi.movies.utils.ActivityFinisher;
import cucumber.api.java.After;

package com.tobi.movies.steps;




public class SetupSteps {

    @After
    public void tearDown() {
        clearBackend();
        ActivityFinisher.finishOpenActivities();
    }

    private void clearBackend() {
        MovieApplication movieApplication = (MovieApplication) InstrumentationRegistry.getTargetContext().getApplicationContext();