Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. package com.example.app;
  2.  
  3. import android.support.test.espresso.matcher.BoundedMatcher;
  4. import android.view.View;
  5. import android.widget.TextView;
  6.  
  7. import org.hamcrest.Description;
  8. import org.hamcrest.Matcher;
  9.  
  10. import static com.google.common.base.Preconditions.checkNotNull;
  11. import static org.hamcrest.Matchers.is;
  12.  
  13. public class IgnoreCaseTextMatcher {
  14. /**
  15. * Returns a matcher that matches {@link TextView} based on its text property value BUT IGNORES CASE.
  16. * Note: View's Sugar for withText(is("string")).
  17. *
  18. * @param text {@link String} with the text to match
  19. */
  20. public static Matcher<View> withText(String text) {
  21. return withText(is(text.toLowerCase()));
  22. }
  23.  
  24. private static Matcher<View> withText(final Matcher<String> stringMatcher) {
  25. checkNotNull(stringMatcher);
  26. return new BoundedMatcher<View, TextView>(TextView.class) {
  27. @Override
  28. public void describeTo(Description description) {
  29. description.appendText("with text (ignoring case): ");
  30. stringMatcher.describeTo(description);
  31. }
  32.  
  33. @Override
  34. public boolean matchesSafely(TextView textView) {
  35.  
  36. return stringMatcher.matches(textView.getText().toString().toLowerCase());
  37. }
  38. };
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement