Java 类android.support.test.espresso.matcher.BoundedMatcher 实例源码

项目:smart-lens    文件:CustomMatchers.java   
/**
 * Returns a matcher that matches {@link TextView}s based on text property value.
 *
 * @param stringMatcher {@link Matcher} of {@link String} with text to match
 */
@NonNull
public static Matcher<View> withPasswordText(final Matcher<String> stringMatcher) {

    return new BoundedMatcher<View, TextView>(TextView.class) {

        @Override
        public void describeTo(final Description description) {
            description.appendText("with error text: ");
            stringMatcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(final TextView textView) {
            return stringMatcher.matches(textView.getText().toString());
        }
    };
}
项目:yabaking    文件:ToolbarMatchers.java   
private static Matcher<Object> withCollapsingToolbarTitle(
        final Matcher<CharSequence> textMatcher) {
    return new BoundedMatcher<Object, CollapsingToolbarLayout>(CollapsingToolbarLayout.class) {

        @Override
        public void describeTo(Description description) {
            description.appendText("with collapsing toolbar title: ");
            textMatcher.describeTo(description);
        }

        @Override
        protected boolean matchesSafely(CollapsingToolbarLayout collapsingToolbarLayout) {
            return textMatcher.matches(collapsingToolbarLayout.getTitle());
        }

    };
}
项目:lacomida    文件:EspressoCustomActions.java   
public static Matcher<View> atPosition(final int position, final Matcher<View> itemMatcher) {
    return new BoundedMatcher<View, RecyclerView>(RecyclerView.class) {
        @Override
        public void describeTo(Description description) {
            description.appendText("has item at position " + position + ": ");
            itemMatcher.describeTo(description);
        }

        @Override
        protected boolean matchesSafely(final RecyclerView view) {
            RecyclerView.ViewHolder viewHolder = view.findViewHolderForAdapterPosition(position);
            if (viewHolder == null) {
                return false;
            }
            return itemMatcher.matches(viewHolder.itemView);
        }
    };
}
项目:smart-lens    文件:CustomMatchers.java   
/**
 * Returns a matcher that matches {@link TextView}s based on text property value.
 *
 * @param stringMatcher {@link Matcher} of {@link String} with text to match
 */
@NonNull
public static Matcher<View> withErrorText(final Matcher<String> stringMatcher) {

    return new BoundedMatcher<View, TextView>(TextView.class) {

        @Override
        public void describeTo(final Description description) {
            description.appendText("with error text: ");
            stringMatcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(final TextView textView) {
            return stringMatcher.matches(textView.getError().toString());
        }
    };
}
项目:smart-lens    文件:CustomMatchers.java   
/**
 * Returns a matcher that matches {@link TextView}s based on text property value.
 */
@NonNull
public static Matcher<View> hasError() {

    return new BoundedMatcher<View, TextView>(TextView.class) {

        @Override
        public void describeTo(final Description description) {
            description.appendText("Has error case failed.");
        }

        @Override
        public boolean matchesSafely(final TextView textView) {
            return textView.getError() != null;
        }
    };
}
项目:smart-lens    文件:CustomMatchers.java   
/**
 * Returns a matcher that matches {@link TextView}s based on text property value.
 */
@NonNull
public static Matcher<View> checkTextLength(final int length) {

    return new BoundedMatcher<View, TextView>(TextView.class) {

        @Override
        public void describeTo(final Description description) {
            description.appendText("Text length is : " + description);
        }

        @Override
        public boolean matchesSafely(final TextView textView) {
            return textView.getText().length() == length;
        }
    };
}
项目:smart-lens    文件:CustomMatchers.java   
/**
 * Returns a matcher that matches {@link TextView}s based on text property value.
 */
@NonNull
public static Matcher<View> hasText() {

    return new BoundedMatcher<View, TextView>(TextView.class) {

        @Override
        public void describeTo(final Description description) {
            description.appendText("Text length is : " + description);
        }

        @Override
        public boolean matchesSafely(final TextView textView) {
            return textView.getText().length() > 0;
        }
    };
}
项目:ChipsLayoutManager    文件:RecyclerViewEspressoFactory.java   
public static Matcher<View> atPosition(final int position, @NonNull final Matcher<View> itemMatcher) {
    checkNotNull(itemMatcher);
    return new BoundedMatcher<View, RecyclerView>(RecyclerView.class) {
        @Override
        public void describeTo(Description description) {
            description.appendText("has item at position " + position + ":\n");
            itemMatcher.describeTo(description);
        }

        @Override
        protected boolean matchesSafely(final RecyclerView view) {
            RecyclerView.ViewHolder viewHolder = view.findViewHolderForAdapterPosition(position);
            return viewHolder != null && itemMatcher.matches(viewHolder.itemView);
        }
    };
}
项目:ChipsLayoutManager    文件:RecyclerViewEspressoFactory.java   
public static <T extends RecyclerView.ViewHolder> Matcher<View> atPosition(final int position, @NonNull final ViewHolderMatcher<T> itemMatcher) {
    checkNotNull(itemMatcher);
    return new BoundedMatcher<View, RecyclerView>(RecyclerView.class) {
        @Override
        public void describeTo(Description description) {
            description.appendText("has item at position " + position + ":\n");
            itemMatcher.describeTo(description);
        }

        @Override
        protected boolean matchesSafely(final RecyclerView view) {
            RecyclerView.ViewHolder viewHolder = view.findViewHolderForAdapterPosition(position);
            return viewHolder != null && itemMatcher.matches(viewHolder);
        }
    };
}
项目:espresso-doppio    文件:DoppioMatchers.java   
/**
 * Matches fragment with specific tag
 *
 * @param tag fragment tag
 * @return BaseMatcher<Fragment>
 */
public static Matcher<Fragment> withTag(final String tag) {
    return new BoundedMatcher<Fragment, Fragment>(Fragment.class) {

        @Override
        public void describeTo(Description description) {
            description.appendText("Matches fragment tag");
        }

        @Override
        protected boolean matchesSafely(Fragment item) {
            String fragTag = item.getTag();
            return fragTag != null && fragTag.equals(tag);
        }
    };
}
项目:BrainPhaser    文件:TestUtils.java   
public static Matcher<View> atPosition(final int position, @NonNull final Matcher<View> itemMatcher) {
    checkNotNull(itemMatcher);
    return new BoundedMatcher<View, RecyclerView>(RecyclerView.class) {
        @Override
        public void describeTo(Description description) {
            description.appendText("has item at position " + position + ": ");
            itemMatcher.describeTo(description);
        }

        @Override
        protected boolean matchesSafely(final RecyclerView view) {
            RecyclerView.ViewHolder viewHolder = view.findViewHolderForAdapterPosition(position);
            return viewHolder != null && itemMatcher.matches(viewHolder.itemView);
        }
    };
}
项目:SwipeOpenItemTouchHelper    文件:SwipeOpenItemTouchHelperTest.java   
/**
 * Matcher for finding the SwipeView for a SwipeOpenViewHolders in a RecyclerView
 * @param position the position of the view holder
 * @param itemMatcher matcher to compare the SwipeView to
 * @return a Matcher that compares a SwipeOpenViewHolder at a position with a passed in matcher
 */
public static Matcher<View> atPosition(final int position, @NonNull final Matcher<View> itemMatcher) {
  checkNotNull(itemMatcher);
  return new BoundedMatcher<View, RecyclerView>(RecyclerView.class) {
    @Override protected boolean matchesSafely(RecyclerView view) {
      RecyclerView.ViewHolder viewHolder = view.findViewHolderForAdapterPosition(position);
      if (viewHolder == null || !(viewHolder instanceof SwipeOpenViewHolder)) {
        // has no item on such position
        return false;
      }
      return itemMatcher.matches(((SwipeOpenViewHolder) viewHolder).getSwipeView());
    }

    @Override
    public void describeTo(Description description) {
      description.appendText("has item at position " + position + ": ");
      itemMatcher.describeTo(description);
    }

  };
}
项目:SwipeOpenItemTouchHelper    文件:SwipeOpenItemTouchHelperTest.java   
/**
 * Checks for a positive or negative translationX in a View
 * @param positive true if positive translation, false if negative
 * @return matcher for checking positive/negative translationX
 */
public static Matcher<View> checkTranslationX(final boolean positive) {
  return new BoundedMatcher<View, View>(View.class) {

    @Override public void describeTo(Description description) {
      description.appendText("translationX should be non-zero");
    }

    @Override protected boolean matchesSafely(View item) {
      if (positive) {
        return ViewCompat.getTranslationX(item) > 0;
      } else {
        return ViewCompat.getTranslationX(item) < 0;
      }
    }
  };
}
项目:px-android    文件:CustomMatchers.java   
public static Matcher<View> atPosition(final int position, @NonNull final Matcher<View> itemMatcher) {
    checkNotNull(itemMatcher);
    return new BoundedMatcher<View, RecyclerView>(RecyclerView.class) {
        @Override
        public void describeTo(Description description) {
            description.appendText("has item at position " + position + ": ");
            itemMatcher.describeTo(description);
        }

        @Override
        protected boolean matchesSafely(final RecyclerView view) {
            RecyclerView.ViewHolder viewHolder = view.findViewHolderForAdapterPosition(position);
            if (viewHolder == null) {
                // has no item on such position
                return false;
            }
            return itemMatcher.matches(viewHolder.itemView);
        }
    };
}
项目:Red-Calorie    文件:MenuItemMatchers.java   
public static Matcher<View> onMenuItems(final Matcher<Iterable<MenuItem>> matcher) {
    return new BoundedMatcher<View, NavigationView>(NavigationView.class) {
        @Override
        protected boolean matchesSafely(NavigationView item) {
            try {
                viewResources = item.getResources();
                return matcher.matches(new IterableMenu(item.getMenu()));
            } finally {
                viewResources = null;
            }
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("from navigation menu items ");
            description.appendDescriptionOf(matcher);
        }
    };
}
项目:bigbang    文件:RecyclerViewAssertions.java   
public static Matcher<View> atPosition(final int position, @NonNull final Matcher<View> itemMatcher) {
  checkNotNull(itemMatcher);
  return new BoundedMatcher<View, RecyclerView>(RecyclerView.class) {
    @Override
    public void describeTo(Description description) {
      description.appendText("has item at position " + position + ": ");
      itemMatcher.describeTo(description);
    }

    @Override
    protected boolean matchesSafely(final RecyclerView view) {
      RecyclerView.ViewHolder viewHolder = view.findViewHolderForAdapterPosition(position);
      return viewHolder != null && itemMatcher.matches(viewHolder.itemView);
    }
  };
}
项目:bigbang    文件:RecyclerViewAssertions.java   
public static Matcher<View> atPosition(final int position, @NonNull final Matcher<View> itemMatcher) {
  checkNotNull(itemMatcher);
  return new BoundedMatcher<View, RecyclerView>(RecyclerView.class) {
    @Override
    public void describeTo(Description description) {
      description.appendText("has item at position " + position + ": ");
      itemMatcher.describeTo(description);
    }

    @Override
    protected boolean matchesSafely(final RecyclerView view) {
      RecyclerView.ViewHolder viewHolder = view.findViewHolderForAdapterPosition(position);
      return viewHolder != null && itemMatcher.matches(viewHolder.itemView);
    }
  };
}
项目:ProgressButton    文件:Utils.java   
public static Matcher<View> withCompoundDrawable(final int resourceId) {
    return new BoundedMatcher<View, Button>(Button.class) {
        @Override
        public void describeTo(Description description) {
            description.appendText("has compound drawable resource " + resourceId);
        }

        @Override
        public boolean matchesSafely(Button textView) {
            for (Drawable drawable : textView.getCompoundDrawables()) {
                if (sameBitmap(textView.getContext(), drawable, resourceId)) {
                    return true;
                }
            }
            return false;
        }
    };
}
项目:commitstrip-reader    文件:RecyclerViewUtil.java   
public static Matcher<View> atPosition(final int position, @NonNull final Matcher<View> itemMatcher) {
  checkNotNull(itemMatcher);
  return new BoundedMatcher<View, RecyclerView>(RecyclerView.class) {

    @Override
    public void describeTo(Description description) {
      description.appendText("has item at position " + position + ": ");
      itemMatcher.describeTo(description);
    }

    @Override
    protected boolean matchesSafely(final RecyclerView view) {
      RecyclerView.ViewHolder viewHolder = view.findViewHolderForAdapterPosition(position);
      if (viewHolder == null) {
        // has no item on such position
        return false;
      }

      return itemMatcher.matches(viewHolder.itemView);
    }
  };
}
项目:AndroidBaseApplication    文件:CountriesActivityTest.java   
private Matcher<? super View> withToolbarBackGroundColor ()
{
    return new BoundedMatcher<View, View>( View.class )
    {
        @Override
        public boolean matchesSafely (View view)
        {
            final ColorDrawable backgroundColor = ( ColorDrawable ) view.getBackground( );

            return ContextCompat
                    .getColor( activityTestRule.getActivity( ), R.color.colorPrimary ) ==
                    backgroundColor.getColor( );
        }

        @Override
        public void describeTo (Description description)
        {
        }
    };
}
项目:Expander    文件:TestUtils.java   
public static Matcher<View> atPosition(final int position, @NonNull final Matcher<View> itemMatcher) {
    checkNotNull(itemMatcher);
    return new BoundedMatcher<View, RecyclerView>(RecyclerView.class) {
        @Override
        public void describeTo(Description description) {
            description.appendText("has item at position " + position + ": ");
            itemMatcher.describeTo(description);
        }

        @Override
        protected boolean matchesSafely(final RecyclerView view) {
            RecyclerView.ViewHolder viewHolder = view.findViewHolderForAdapterPosition(position);
            if (viewHolder == null) {
                // has no item on such position
                return false;
            }
            return itemMatcher.matches(viewHolder.itemView);
        }
    };
}
项目:Expander    文件:TestUtils.java   
public static Matcher<View> hasErrorText(final String expectedError) {
    return new BoundedMatcher<View, View>(View.class) {

        @Override
        public void describeTo(Description description) {
            description.appendText("with error: " + expectedError);
        }

        @Override
        protected boolean matchesSafely(View view) {

            if (!(view instanceof EditText)) {
                return false;
            }

            EditText editText = (EditText) view;

            return expectedError.equals(editText.getError());
        }
    };
}
项目:material-components-android    文件:TestUtilsMatchers.java   
/** Returns a matcher that matches Views that are not narrower than specified width in pixels. */
public static Matcher<View> isNotNarrowerThan(final int minWidth) {
  return new BoundedMatcher<View, View>(View.class) {
    private String failedCheckDescription;

    @Override
    public void describeTo(final Description description) {
      description.appendText(failedCheckDescription);
    }

    @Override
    public boolean matchesSafely(final View view) {
      final int viewWidth = view.getWidth();
      if (viewWidth < minWidth) {
        failedCheckDescription = "width " + viewWidth + " is less than minimum " + minWidth;
        return false;
      }
      return true;
    }
  };
}
项目:material-components-android    文件:TestUtilsMatchers.java   
/** Returns a matcher that matches Views that are not wider than specified width in pixels. */
public static Matcher<View> isNotWiderThan(final int maxWidth) {
  return new BoundedMatcher<View, View>(View.class) {
    private String failedCheckDescription;

    @Override
    public void describeTo(final Description description) {
      description.appendText(failedCheckDescription);
    }

    @Override
    public boolean matchesSafely(final View view) {
      final int viewWidth = view.getWidth();
      if (viewWidth > maxWidth) {
        failedCheckDescription = "width " + viewWidth + " is more than maximum " + maxWidth;
        return false;
      }
      return true;
    }
  };
}
项目:material-components-android    文件:TestUtilsMatchers.java   
/** Returns a matcher that matches TextViews with the specified text size. */
public static Matcher<View> withTextSize(final float textSize) {
  return new BoundedMatcher<View, TextView>(TextView.class) {
    private String failedCheckDescription;

    @Override
    public void describeTo(final Description description) {
      description.appendText(failedCheckDescription);
    }

    @Override
    public boolean matchesSafely(final TextView view) {
      final float ourTextSize = view.getTextSize();
      if (Math.abs(textSize - ourTextSize) > 1.0f) {
        failedCheckDescription =
            "text size " + ourTextSize + " is different than expected " + textSize;
        return false;
      }
      return true;
    }
  };
}
项目:material-components-android    文件:TestUtilsMatchers.java   
/** Returns a matcher that matches Views with the specified background fill color. */
public static Matcher<View> withBackgroundFill(final @ColorInt int fillColor) {
  return new BoundedMatcher<View, View>(View.class) {
    private String failedCheckDescription;

    @Override
    public void describeTo(final Description description) {
      description.appendText(failedCheckDescription);
    }

    @Override
    public boolean matchesSafely(final View view) {
      Drawable background = view.getBackground();
      try {
        TestUtils.assertAllPixelsOfColor(
            "", background, view.getWidth(), view.getHeight(), true, fillColor, 0, true);
      } catch (Throwable t) {
        failedCheckDescription = t.getMessage();
        return false;
      }
      return true;
    }
  };
}
项目:testing-workshop    文件:MainActivityEspressoTest.java   
@Test
public void testWrongCredentialsValidation() {
    Espresso.onView(withId(R.id.usernameEditText)).perform(typeText("Akshay"));
    Espresso.onView(withId(R.id.validateButton)).perform(click());
    Espresso.onView(withId(R.id.resultTextView)).check(matches(withText(R.string.failure_message)));

    Espresso.onView(withId(R.id.resultTextView)).check(matches(new BoundedMatcher<View, TextView>(TextView.class) {
        @Override
        public void describeTo(Description description) {
            // do nothing
        }

        @Override
        protected boolean matchesSafely(TextView textView) {
            int color = textView.getTextColors().getDefaultColor();
            int colorToMatch = ContextCompat.getColor(textView.getContext(), R.color.colorAccent);
            return color == colorToMatch;
        }
    }));
}
项目:testing-workshop    文件:MainActivityEspressoTest.java   
@Test
public void testValidCredentialsValidation() {
    Espresso.onView(withId(R.id.usernameEditText)).perform(typeText("vipul"));
    Espresso.onView(withId(R.id.validateButton)).perform(click());
    Espresso.onView(withId(R.id.resultTextView)).check(matches(withText(R.string.success_message)));
    Espresso.onView(withId(R.id.resultTextView)).check(matches(new BoundedMatcher<View, TextView>(TextView.class) {
        @Override
        public void describeTo(Description description) {
            // do nothing
        }

        @Override
        protected boolean matchesSafely(TextView textView) {
            int color = textView.getTextColors().getDefaultColor();
            int colorToMatch = ContextCompat.getColor(textView.getContext(), R.color.colorPrimary);
            return color == colorToMatch;
        }
    }));
}
项目:testing-workshop    文件:MainActivityEspressoTest.java   
@Test
public void testSpinnerBackgroundColor() {
    Espresso.onView(withId(R.id.colorSpinner)).perform(click());
    Espresso.onData(allOf(is(instanceOf(String.class)), is("Color 1"))).perform(click());
    Espresso.onView(withId(R.id.container)).check(matches(new BoundedMatcher<View, ViewGroup>(ViewGroup.class) {
        @Override
        public void describeTo(Description description) {

        }

        @Override
        protected boolean matchesSafely(ViewGroup viewGroup) {
            int color = ((ColorDrawable) viewGroup.getBackground()).getColor();
            return color == ContextCompat.getColor(viewGroup.getContext(), R.color.color1);
        }
    }));
}
项目:bluesnap-android-int    文件:TestUtils.java   
/**
 * Returns a matcher that matches {@link TextView}s based on text property value. Note: View's
 * text property is never null. If you setText(null) it will still be "". Do not use null
 * matcher.
 *
 * @param integerMatcher {@link Matcher} of {@link String} with text to match
 */
public static Matcher<View> withCurrentTextColor(final Matcher<Integer> integerMatcher) {
    checkNotNull(integerMatcher);
    return new BoundedMatcher<View, TextView>(TextView.class) {
        @Override
        public void describeTo(Description description) {
            description.appendText("with text color: ");
            integerMatcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(TextView textView) {
            return integerMatcher.matches(textView.getCurrentTextColor());
        }
    };
}
项目:AndroidSnippets    文件:CustomMatchers.java   
public static Matcher<Object> hasInputType(final int inputType) {
    return new BoundedMatcher<Object, EditText>(EditText.class) {
        int v;

        @Override
        protected boolean matchesSafely(EditText editText) {
            v = editText.getInputType();
            return v == inputType;
        }

        @Override
        public void describeTo(org.hamcrest.Description description) {
            description.appendText("has inputyType:" + inputType + ", but has " + v);
        }
    };
}
项目:BreadcrumbsView    文件:Helpers.java   
private static Matcher<View> breadcrumbsMatcher(final Func func, final Matcher<Integer> expectedCount,
    final String msgDescription) {
  return new BoundedMatcher<View, BreadcrumbsView>(BreadcrumbsView.class) {
    @Override protected boolean matchesSafely(BreadcrumbsView view) {
      int nDots = 0;
      for (int i = 0; i < view.getChildCount(); i++) {
        View viewChild = view.getChildAt(i);
        if (viewChild.getTag() != null) {
          if (func.call((ViewGroup) viewChild)) nDots++;
        }
      }
      return expectedCount.matches(nDots);
    }

    @Override public void describeTo(Description description) {
      description.appendText(msgDescription);
      expectedCount.describeTo(description);
    }
  };
}
项目:green-coffee    文件:ActionableObject.java   
public BoundedMatcher<View, ImageView> hasDrawableImageView()
{
    return new BoundedMatcher<View, ImageView>(ImageView.class)
    {
        @Override
        public void describeTo(Description description)
        {
            description.appendText("has drawable");
        }

        @Override
        public boolean matchesSafely(ImageView imageView)
        {
            return (imageView.getDrawable() != null);
        }
    };
}
项目:TimeMachine    文件:RecyclerMatchers.java   
public static Matcher<View> atPosition(
    final int position, @NonNull final Matcher<View> itemMatcher) {
    checkNotNull(itemMatcher);
    return new BoundedMatcher<View, RecyclerView>(RecyclerView.class) {
        @Override
        public void describeTo(Description description) {
            description.appendText("has item at position " + position + ": ");
            itemMatcher.describeTo(description);
        }


        @Override
        protected boolean matchesSafely(final RecyclerView view) {
            RecyclerView.ViewHolder viewHolder =
                view.findViewHolderForAdapterPosition(position);
            if (viewHolder == null) {
                return false;
            }
            return itemMatcher.matches(viewHolder.itemView);
        }
    };
}
项目:zulip-android    文件:Matchers.java   
public static Matcher<RecyclerView.ViewHolder> withMessageHolder(final String text, final int textViewId) {
    return new BoundedMatcher<RecyclerView.ViewHolder, MessageHolder>(MessageHolder.class) {
        private boolean found = false;

        @Override
        public void describeTo(Description description) {
            description.appendText("No ViewHolder found with text: ");
        }

        @Override
        protected boolean matchesSafely(MessageHolder item) {
            if (found) return false;
            found = ((TextView) item.itemView.findViewById(textViewId)).getText().toString().matches(text);
            return found;
        }
    };
}
项目:zulip-android    文件:Matchers.java   
public static Matcher<RecyclerView.ViewHolder> withMessageHeaderHolder(final MessageType messageType) {
    return new BoundedMatcher<RecyclerView.ViewHolder, MessageHeaderParent.MessageHeaderHolder>(MessageHeaderParent.MessageHeaderHolder.class) {
        private boolean found = false;

        @Override
        public void describeTo(Description description) {
            description.appendText("No ViewHolder found with text: " + messageType.toString());
        }

        @Override
        protected boolean matchesSafely(MessageHeaderParent.MessageHeaderHolder item) {
            if (found) return false;
            MessageHeaderParent messageHeaderParent = item.onItemClickListener.getMessageHeaderParentAtPosition(item.getLayoutPosition());
            found = (messageType == messageHeaderParent.getMessageType());
            return found;
        }
    };
}
项目:zulip-android    文件:LoginDevAuthTest.java   
private Matcher<View> emailFilter() {

        return new BoundedMatcher<View, Button>(Button.class) {
            @Override
            public void describeTo(Description description) {
                description.appendText("ERROR");
            }

            @Override
            protected boolean matchesSafely(Button item) {
                if (!matchedBefore && item.getText().toString().contains("@")) {
                    EMAIL_TEST = item.getText().toString();
                    matchedBefore = true;
                    return true;
                }
                return false;
            }
        };
    }
项目:MicroPinner    文件:Matches.java   
/**
 * This matcher checks if a TextView displays its text in
 * a specific color.
 *
 * @param color The color to verify.
 * @return Corresponding matcher.
 */
@NonNull
public static Matcher<View> withTextColor(@ColorInt final int color) {
    Checks.checkNotNull(color);
    return new BoundedMatcher<View, TextView>(TextView.class) {
        @Override
        public boolean matchesSafely(TextView warning) {
            return color == warning.getCurrentTextColor();
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("with text color: ");
        }
    };
}
项目:MicroPinner    文件:Matches.java   
/**
 * This matcher checks if a View displays its background in
 * a specific color.
 *
 * @param color The color to verify.
 * @return Corresponding matcher.
 */
@NonNull
public static Matcher<View> withBackgroundColor(@ColorInt final int color) {
    Checks.checkNotNull(color);

    return new BoundedMatcher<View, View>(View.class) {
        @Override
        public boolean matchesSafely(View warning) {
            return color == ((ColorDrawable) warning.getBackground()).getColor();
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("with text color: ");
        }
    };
}
项目:espresso-errortext-matcher    文件:ErrorTextMatchers.java   
/**
 * Returns a matcher that matches {@link android.widget.TextView}s based on text property value.
 *
 * @param stringMatcher {@link Matcher} of {@link String} with text to match
 */
@NonNull
public static Matcher<View> withErrorText(final Matcher<String> stringMatcher) {

  return new BoundedMatcher<View, TextView>(TextView.class) {

    @Override
    public void describeTo(final Description description) {
      description.appendText("with error text: ");
      stringMatcher.describeTo(description);
    }

    @Override
    public boolean matchesSafely(final TextView textView) {
      return stringMatcher.matches(textView.getError().toString());
    }
  };
}