Search in sources :

Example 1 with ViewAssertion

use of androidx.test.espresso.ViewAssertion in project DiscreteScrollView by yarolegovich.

the class CustomAssertions method doesNotHaveChildren.

public static ViewAssertion doesNotHaveChildren() {
    return new ViewAssertion() {

        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            ensureViewFound(noViewFoundException);
            assertThat(view, isAssignableFrom(ViewGroup.class));
            ViewGroup viewGroup = (ViewGroup) view;
            assertThat(viewGroup.getChildCount(), is(equalTo(0)));
        }
    };
}
Also used : ViewAssertion(androidx.test.espresso.ViewAssertion) ViewGroup(android.view.ViewGroup) NoMatchingViewException(androidx.test.espresso.NoMatchingViewException) DiscreteScrollView(com.yarolegovich.discretescrollview.DiscreteScrollView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 2 with ViewAssertion

use of androidx.test.espresso.ViewAssertion in project mobile-center-sdk-android by Microsoft.

the class EspressoUtils method waitFor.

public static ViewInteraction waitFor(final ViewInteraction viewInteraction, final long millis) throws InterruptedException {
    final long startTime = System.currentTimeMillis();
    final long endTime = startTime + millis;
    final View[] found = new View[] { null };
    while (System.currentTimeMillis() < endTime) {
        try {
            viewInteraction.check(new ViewAssertion() {

                @Override
                public void check(View view, NoMatchingViewException noViewFoundException) {
                    found[0] = view;
                }
            });
        } catch (NoMatchingRootException ignored) {
        }
        if (found[0] != null)
            return viewInteraction;
        Thread.sleep(CHECK_DELAY);
    }
    Assert.fail();
    return viewInteraction;
}
Also used : ViewAssertion(androidx.test.espresso.ViewAssertion) NoMatchingRootException(androidx.test.espresso.NoMatchingRootException) NoMatchingViewException(androidx.test.espresso.NoMatchingViewException) Espresso.onView(androidx.test.espresso.Espresso.onView) RootMatchers.withDecorView(androidx.test.espresso.matcher.RootMatchers.withDecorView) TextView(android.widget.TextView) View(android.view.View)

Example 3 with ViewAssertion

use of androidx.test.espresso.ViewAssertion in project DiscreteScrollView by yarolegovich.

the class CustomAssertions method currentPositionIs.

public static ViewAssertion currentPositionIs(final int expectedPosition) {
    return new ViewAssertion() {

        @Override
        public void check(View view, NoMatchingViewException noViewFoundException) {
            ensureViewFound(noViewFoundException);
            assertThat(view, isAssignableFrom(DiscreteScrollView.class));
            DiscreteScrollView dsv = (DiscreteScrollView) view;
            assertThat(dsv.getCurrentItem(), is(equalTo(expectedPosition)));
            View midChild = findCenteredChildIn(dsv);
            assertThat(midChild, is(notNullValue()));
            RecyclerView.ViewHolder holder = dsv.getChildViewHolder(midChild);
            assertThat(holder.getAdapterPosition(), is(equalTo(expectedPosition)));
        }
    };
}
Also used : ViewAssertion(androidx.test.espresso.ViewAssertion) NoMatchingViewException(androidx.test.espresso.NoMatchingViewException) DiscreteScrollView(com.yarolegovich.discretescrollview.DiscreteScrollView) RecyclerView(androidx.recyclerview.widget.RecyclerView) DiscreteScrollView(com.yarolegovich.discretescrollview.DiscreteScrollView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Aggregations

View (android.view.View)3 NoMatchingViewException (androidx.test.espresso.NoMatchingViewException)3 ViewAssertion (androidx.test.espresso.ViewAssertion)3 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 DiscreteScrollView (com.yarolegovich.discretescrollview.DiscreteScrollView)2 ViewGroup (android.view.ViewGroup)1 TextView (android.widget.TextView)1 Espresso.onView (androidx.test.espresso.Espresso.onView)1 NoMatchingRootException (androidx.test.espresso.NoMatchingRootException)1 RootMatchers.withDecorView (androidx.test.espresso.matcher.RootMatchers.withDecorView)1