// Path: app/src/androidTest/java/com/autonomousapps/reactivestopwatch/test/AbstractAnimationDisablingTest.java
// public abstract class AbstractAnimationDisablingTest {
// 
//     @BeforeClass
//     public static void disableAnimations() {
//         SystemAnimations.disableAll(InstrumentationRegistry.getTargetContext());
//     }
// 
//     @AfterClass
//     public static void enableAnimations() {
//         SystemAnimations.enableAll(InstrumentationRegistry.getTargetContext());
//     }
// }
// 
// Path: app/src/androidTest/java/com/autonomousapps/reactivestopwatch/test/Timer.java
// public class Timer {
// 
//     private final long start;
// 
//     public Timer() {
//         start = System.currentTimeMillis();
//     }
// 
//     public long elapsedTime() {
//         return System.currentTimeMillis() - start;
//     }
// }


import com.autonomousapps.reactivestopwatch.test.AbstractAnimationDisablingTest;
import com.autonomousapps.reactivestopwatch.test.Timer;
import com.autonomousapps.reactivestopwatch.test.annotations.AcceptanceStage;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.support.annotation.NonNull;
import android.support.test.InstrumentationRegistry;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.BySelector;
import android.support.test.uiautomator.Configurator;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.Until;
import java.util.Collection;
import java.util.LinkedList;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.Matchers.equalToIgnoringCase;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertThat;

    @Before
    public void setup() throws Exception {
        device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
        pressHome();
        launchApp();

        // UI thread is *never* idle because of the nature of the app, so set idle timeout to 0
        setIdleTimeout(IDLE_TIMEOUT_0);

        checkPreconditions();
    }

    private void checkPreconditions() throws Exception {
        assertThat(device, notNullValue());
        verifyUi();
    }

    private void verifyUi() throws Exception {
        stopwatch = getStopwatchView();
        startStopBtn = getStartPauseButton();
        resetLapBtn = getResetButton();

        assertThat(stopwatch, notNullValue());
        assertThat(startStopBtn, notNullValue());
        assertThat(resetLapBtn, notNullValue());
    }

    @After
    public void teardown() throws Exception {
// Path: app/src/androidTest/java/com/autonomousapps/reactivestopwatch/test/AbstractAnimationDisablingTest.java
// public abstract class AbstractAnimationDisablingTest {
// 
//     @BeforeClass
//     public static void disableAnimations() {
//         SystemAnimations.disableAll(InstrumentationRegistry.getTargetContext());
//     }
// 
//     @AfterClass
//     public static void enableAnimations() {
//         SystemAnimations.enableAll(InstrumentationRegistry.getTargetContext());
//     }
// }
// 
// Path: app/src/androidTest/java/com/autonomousapps/reactivestopwatch/test/Timer.java
// public class Timer {
// 
//     private final long start;
// 
//     public Timer() {
//         start = System.currentTimeMillis();
//     }
// 
//     public long elapsedTime() {
//         return System.currentTimeMillis() - start;
//     }
// }


// Path: app/src/androidTest/java/com/autonomousapps/reactivestopwatch/ui/StopwatchAcceptanceTest.java
import com.autonomousapps.reactivestopwatch.test.AbstractAnimationDisablingTest;
import com.autonomousapps.reactivestopwatch.test.Timer;
import com.autonomousapps.reactivestopwatch.test.annotations.AcceptanceStage;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.support.annotation.NonNull;
import android.support.test.InstrumentationRegistry;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.BySelector;
import android.support.test.uiautomator.Configurator;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.Until;
import java.util.Collection;
import java.util.LinkedList;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.Matchers.equalToIgnoringCase;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertThat;


    @Before
    public void setup() throws Exception {
        device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
        pressHome();
        launchApp();

        // UI thread is *never* idle because of the nature of the app, so set idle timeout to 0
        setIdleTimeout(IDLE_TIMEOUT_0);

        checkPreconditions();
    }

    private void checkPreconditions() throws Exception {
        assertThat(device, notNullValue());
        verifyUi();
    }

    private void verifyUi() throws Exception {
        stopwatch = getStopwatchView();
        startStopBtn = getStartPauseButton();
        resetLapBtn = getResetButton();

        assertThat(stopwatch, notNullValue());
        assertThat(startStopBtn, notNullValue());
        assertThat(resetLapBtn, notNullValue());
    }

    @After
    public void teardown() throws Exception {
        resetTestState();