package com.basgeekball.awesomevalidation.demo;

import android.app.Activity;
import android.support.test.espresso.ViewInteraction;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.view.WindowManager;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
import static android.support.test.espresso.action.ViewActions.swipeUp;
import static android.support.test.espresso.action.ViewActions.typeText;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;

@RunWith(AndroidJUnit4.class)
public class DemoActivityTest {

    @Rule
    public ActivityTestRule<DemoActivity> mActivityRule = new ActivityTestRule<>(DemoActivity.class);

    @Before
    public void unlockScreen() {
        final Activity activity = mActivityRule.getActivity();
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
                        WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
                        WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
                        WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
            }
        });
    }

    @Test
    public void testValidatePass() {
        enterText(R.id.edt_userid, "Flash");
        enterText(R.id.edt_password, "FatherPrime#3");
        enterText(R.id.edt_password_confirmation, "FatherPrime#3");
        enterText(R.id.edt_firstname, "Dwyane");
        enterText(R.id.edt_lastname, "Wade");
        enterText(R.id.edt_email, "D-Wade@nba.com");
        enterText(R.id.edt_ip, "184.154.83.119");
        enterText(R.id.edt_tel, "312-455-4000");
        enterText(R.id.edt_zipcode, "53201");
        enterText(R.id.edt_year, "1982");
        enterText(R.id.edt_height, "1.93");
        clickButton(R.id.btn_done);
        scrollToTheBottom();
        assertViewIsDisplayed(R.id.container_success);
    }

    private ViewInteraction findView(int viewId) {
        return onView(withId(viewId));
    }

    private void enterText(int viewId, String text) {
        findView(viewId).perform(typeText(text), closeSoftKeyboard());
    }

    private void clickButton(int viewId) {
        findView(viewId).perform(click());
    }

    private void assertViewIsDisplayed(int viewId) {
        findView(viewId).check(matches(isDisplayed()));
    }

    private void scrollToTheBottom() {
        findView(R.id.scroll_view).perform(swipeUp());
    }

}

@@ -46,37 +46,8 @@
 o;%0A%0A
-import android.app.Activity;%0A
 impo
@@ -201,68 +201,8 @@
 t4;%0A
-import android.view.WindowManager;%0A%0Aimport org.junit.Before;
 %0Aimp
@@ -1046,569 +1046,8 @@
 );%0A%0A
-    @Before%0A    public void unlockScreen() %7B%0A        final Activity activity = mActivityRule.getActivity();%0A        activity.runOnUiThread(new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A                activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED %7C%0A                        WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON %7C%0A                        WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON %7C%0A                        WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);%0A            %7D%0A        %7D);%0A    %7D%0A%0A
     

Remove unnecessary unlockScreen from UI test