package com.github.kubode.wiggle;

import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.view.WindowManager;

import com.github.kubode.wiggle.test.R;

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.scrollTo;
import static android.support.test.espresso.action.ViewActions.swipeDown;
import static android.support.test.espresso.action.ViewActions.swipeUp;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static com.github.kubode.wiggle.MyMatchers.withLastNon0TranslationY;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.lessThan;

@RunWith(AndroidJUnit4.class)
public class WiggleHelperTest {

    @Rule
    public ActivityTestRule<MockActivity> rule = new ActivityTestRule<>(MockActivity.class);

    @Before
    public void setUp() {
        rule.getActivity().runOnUiThread(new Runnable() {
            public void run() {
                rule.getActivity().getWindow().addFlags(
                        WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                                | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                                | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            }
        });
        onView(withId(R.id.view)).perform(scrollTo());
    }

    @Test
    public void lastNon0TranslationYGreaterThan0WhenSwipeUp() {
        onView(withId(R.id.scrollView)).perform(swipeUp());
        onView(withId(R.id.view)).check(matches(withLastNon0TranslationY(greaterThan(0f))));
    }

    @Test
    public void lastNon0TranslationYLessThan0WhenSwipeDown() {
        onView(withId(R.id.scrollView)).perform(swipeDown());
        onView(withId(R.id.view)).check(matches(withLastNon0TranslationY(lessThan(0f))));
    }
}

@@ -132,43 +132,8 @@
 it4;
-%0Aimport android.view.WindowManager;
 %0A%0Aim
@@ -634,16 +634,96 @@
 atches;%0A
+import static android.support.test.espresso.matcher.RootMatchers.withDecorView;%0A
 import s
@@ -912,16 +912,56 @@
 erThan;%0A
+import static org.hamcrest.Matchers.is;%0A
 import s
@@ -1208,418 +1208,8 @@
 ) %7B%0A
-        rule.getActivity().runOnUiThread(new Runnable() %7B%0A            public void run() %7B%0A                rule.getActivity().getWindow().addFlags(%0A                        WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON%0A                                %7C WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED%0A                                %7C WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);%0A            %7D%0A        %7D);%0A
     
@@ -1371,32 +1371,139 @@
 .id.scrollView))
+%0A                .inRoot(withDecorView(is(rule.getActivity().getWindow().getDecorView())))%0A                
 .perform(swipeUp
@@ -1715,24 +1715,131 @@
 scrollView))
+%0A                .inRoot(withDecorView(is(rule.getActivity().getWindow().getDecorView())))%0A                
 .perform(swi

Fix build.