androidx.test.espresso.matcher.BoundedMatcher Java Examples
The following examples show how to use
androidx.test.espresso.matcher.BoundedMatcher.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Matchers.java From Kore with Apache License 2.0 | 6 votes |
public static Matcher<Object> withItemContent(final Matcher<String> textMatcher) { return new BoundedMatcher<Object, Cursor>(Cursor.class) { @Override protected boolean matchesSafely(Cursor item) { for (int i = 0; i < item.getColumnCount();i++) { switch (item.getType(i)) { case Cursor.FIELD_TYPE_STRING: if (CursorMatchers.withRowString(i, textMatcher).matches(item)) return true; break; } } return false; } @Override public void describeTo(Description description) { description.appendText("withItemContent: "); textMatcher.describeTo(description); } }; }
Example #2
Source File: HintMatcher.java From testing-samples with Apache License 2.0 | 6 votes |
static Matcher<View> withHint(final Matcher<String> stringMatcher) { checkNotNull(stringMatcher); return new BoundedMatcher<View, EditText>(EditText.class) { @Override public boolean matchesSafely(EditText view) { final CharSequence hint = view.getHint(); return hint != null && stringMatcher.matches(hint.toString()); } @Override public void describeTo(Description description) { description.appendText("with hint: "); stringMatcher.describeTo(description); } }; }
Example #3
Source File: HintMatcher.java From testing-samples with Apache License 2.0 | 6 votes |
static Matcher<View> withHint(final Matcher<String> stringMatcher) { checkNotNull(stringMatcher); return new BoundedMatcher<View, EditText>(EditText.class) { @Override public boolean matchesSafely(EditText view) { final CharSequence hint = view.getHint(); return hint != null && stringMatcher.matches(hint.toString()); } @Override public void describeTo(Description description) { description.appendText("with hint: "); stringMatcher.describeTo(description); } }; }
Example #4
Source File: LongListMatchers.java From android-test with Apache License 2.0 | 6 votes |
/** * Creates a matcher against the text stored in R.id.item_size. This text is the size of the text * printed in R.id.item_content. */ @SuppressWarnings("rawtypes") public static Matcher<Object> withItemSize(final Matcher<Integer> itemSizeMatcher) { // use preconditions to fail fast when a test is creating an invalid matcher. checkNotNull(itemSizeMatcher); return new BoundedMatcher<Object, Map>(Map.class) { @Override public boolean matchesSafely(Map map) { return hasEntry(equalTo("LEN"), itemSizeMatcher).matches(map); } @Override public void describeTo(Description description) { description.appendText("with item size: "); itemSizeMatcher.describeTo(description); } }; }
Example #5
Source File: LongListMatchers.java From android-test with Apache License 2.0 | 6 votes |
/** * Creates a matcher against the text stored in R.id.item_content. This text is roughly * "item: $row_number". */ @SuppressWarnings("rawtypes") public static Matcher<Object> withItemContent(final Matcher<String> itemTextMatcher) { // use preconditions to fail fast when a test is creating an invalid matcher. checkNotNull(itemTextMatcher); return new BoundedMatcher<Object, Map>(Map.class) { @Override public boolean matchesSafely(Map map) { return hasEntry(equalTo("STR"), itemTextMatcher).matches(map); } @Override public void describeTo(Description description) { description.appendText("with item content: "); itemTextMatcher.describeTo(description); } }; }
Example #6
Source File: TestUtilsMatchers.java From material-components-android with Apache License 2.0 | 6 votes |
/** 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; } }; }
Example #7
Source File: TestUtilsMatchers.java From material-components-android with Apache License 2.0 | 6 votes |
/** 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; } }; }
Example #8
Source File: SwipeOpenItemTouchHelperTest.java From SwipeOpenItemTouchHelper with Apache License 2.0 | 6 votes |
/** * 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 item.getTranslationX() > 0; } else { return item.getTranslationX() < 0; } } }; }
Example #9
Source File: TestUtilsMatchers.java From material-components-android with Apache License 2.0 | 6 votes |
/** 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; } }; }
Example #10
Source File: TestUtilsMatchers.java From material-components-android with Apache License 2.0 | 6 votes |
/** 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; } }; }
Example #11
Source File: Matchers.java From Kore with Apache License 2.0 | 5 votes |
public static Matcher<View> withProgressGreaterThanOrEqual(final String time) { return new BoundedMatcher<View, SeekBar>(SeekBar.class) { @Override protected boolean matchesSafely(SeekBar item) { return item.getProgress() >= UIUtils.timeToSeconds(time); } @Override public void describeTo(Description description) { description.appendText("expected progress greater than " + time); } }; }
Example #12
Source File: PFViewMatchers.java From PFLockScreen-Android with Apache License 2.0 | 5 votes |
public static Matcher<View> withCodeValue(final String expectedValue) { return new BoundedMatcher<View, PFCodeView>(PFCodeView.class) { @Override protected boolean matchesSafely(PFCodeView item) { return item.getCode().equals(expectedValue); } @Override public void describeTo(Description description) { description.appendText("Checking the matcher on received view: "); description.appendText("with expectedValue=" + expectedValue); } }; }
Example #13
Source File: ImageViewHasDrawableMatcher.java From testing-samples with Apache License 2.0 | 5 votes |
public static BoundedMatcher<View, ImageView> hasDrawable() { 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; } }; }
Example #14
Source File: DrawerMatchers.java From android-test with Apache License 2.0 | 5 votes |
/** * Returns a matcher that verifies that the drawer with the specified gravity is closed. Matches * only when the drawer is fully closed. Use {@link #isOpen(int)} instead of {@code * not(isClosed()))} when you wish to check that the drawer is fully open. */ public static Matcher<View> isClosed(final int gravity) { return new BoundedMatcher<View, DrawerLayout>(DrawerLayout.class) { @Override public void describeTo(Description description) { description.appendText("is drawer closed"); } @Override public boolean matchesSafely(DrawerLayout drawer) { return !drawer.isDrawerVisible(gravity); } }; }
Example #15
Source File: DrawerMatchers.java From android-test with Apache License 2.0 | 5 votes |
/** * Returns a matcher that verifies that the drawer with the specified gravity is open. Matches * only when the drawer is fully open. Use {@link #isClosed(int)} instead of {@code not(isOpen())} * when you wish to check that the drawer is fully closed. */ public static Matcher<View> isOpen(final int gravity) { return new BoundedMatcher<View, DrawerLayout>(DrawerLayout.class) { @Override public void describeTo(Description description) { description.appendText("is drawer open"); } @Override public boolean matchesSafely(DrawerLayout drawer) { return drawer.isDrawerOpen(gravity); } }; }
Example #16
Source File: WebViewActivityTest.java From android-test with Apache License 2.0 | 5 votes |
@SuppressWarnings("rawtypes") public static Matcher<Object> withItemContent(final Matcher<String> itemTextMatcher) { return new BoundedMatcher<Object, Map>(Map.class) { @Override public boolean matchesSafely(Map map) { return hasEntry(equalTo("title"), itemTextMatcher).matches(map); } @Override public void describeTo(Description description) { description.appendText("with item content: "); itemTextMatcher.describeTo(description); } }; }
Example #17
Source File: SwipeOpenItemTouchHelperTest.java From SwipeOpenItemTouchHelper with Apache License 2.0 | 5 votes |
/** * Checks for zero translation of a view * * @return a matcher that checks that all translation on a view is zero */ public static Matcher<View> checkZeroTranslation() { return new BoundedMatcher<View, View>(View.class) { @Override public void describeTo(Description description) { description.appendText("translation should be zero"); } @Override protected boolean matchesSafely(View item) { return item.getTranslationX() == 0; } }; }
Example #18
Source File: DraweeViewHasImageMatcher.java From fresco with MIT License | 5 votes |
static BoundedMatcher<View, SimpleDraweeView> hasImage() { return new BoundedMatcher<View, SimpleDraweeView>(SimpleDraweeView.class) { @Override public void describeTo(Description description) { description.appendText("has image"); } @Override public boolean matchesSafely(SimpleDraweeView draweeView) { return draweeView.getHierarchy().hasImage(); } }; }
Example #19
Source File: Matchers.java From Kore with Apache License 2.0 | 5 votes |
public static Matcher<View> withRepeatMode(final RepeatModeButton.MODE mode) { return new BoundedMatcher<View, RepeatModeButton>(RepeatModeButton.class) { @Override protected boolean matchesSafely(RepeatModeButton item) { return item.getMode() == mode; } @Override public void describeTo(Description description) { description.appendText("expected: " + mode.name()); } }; }
Example #20
Source File: Matchers.java From Kore with Apache License 2.0 | 5 votes |
public static Matcher<View> withHighlightState(final boolean highlight) { return new BoundedMatcher<View, HighlightButton>(HighlightButton.class) { @Override protected boolean matchesSafely(HighlightButton item) { return item.isHighlighted(); } @Override public void describeTo(Description description) { description.appendText("expected: " + highlight); } }; }
Example #21
Source File: Matchers.java From Kore with Apache License 2.0 | 5 votes |
public static Matcher<View> withProgressGreaterThan(final int progress) { return new BoundedMatcher<View, SeekBar>(SeekBar.class) { @Override protected boolean matchesSafely(SeekBar item) { return item.getProgress() > progress; } @Override public void describeTo(Description description) { description.appendText("expected progress greater than " + progress); } }; }
Example #22
Source File: Matchers.java From Kore with Apache License 2.0 | 5 votes |
public static Matcher<View> withProgress(final String progress) { return new BoundedMatcher<View, TextView>(TextView.class) { @Override protected boolean matchesSafely(TextView item) { return progress.contentEquals(item.getText()); } @Override public void describeTo(Description description) { description.appendText("expected: " + progress); } }; }
Example #23
Source File: Matchers.java From Kore with Apache License 2.0 | 5 votes |
public static Matcher<View> withProgress(final int progress) { return new BoundedMatcher<View, SeekBar>(SeekBar.class) { @Override protected boolean matchesSafely(SeekBar item) { return item.getProgress() == progress; } @Override public void describeTo(Description description) { description.appendText("expected: " + progress); } }; }
Example #24
Source File: PFViewMatchers.java From PFLockScreen-Android with Apache License 2.0 | 5 votes |
public static Matcher<View> withCodeLength(final int expectedLength) { return new BoundedMatcher<View, PFCodeView>(PFCodeView.class) { @Override protected boolean matchesSafely(PFCodeView item) { return item.getInputCodeLength() == expectedLength; } @Override public void describeTo(Description description) { description.appendText("Checking the matcher on received view: "); description.appendText("with expectedLength=" + expectedLength); } }; }
Example #25
Source File: AppBarLayoutMatchers.java From material-components-android with Apache License 2.0 | 5 votes |
/** Returns a matcher that matches AppBarLayouts which are collapsed. */ public static Matcher<View> isCollapsed() { return new BoundedMatcher<View, AppBarLayout>(AppBarLayout.class) { @Override public void describeTo(Description description) { description.appendText("AppBarLayout is collapsed"); } @Override protected boolean matchesSafely(AppBarLayout item) { return item.getBottom() == (item.getHeight() - item.getTotalScrollRange()); } }; }
Example #26
Source File: TestUtilsMatchers.java From material-components-android with Apache License 2.0 | 5 votes |
/** Returns a matcher that matches FloatingActionButtons with the specified content height */ public static Matcher<View> withCompoundDrawable(final int index, final Drawable expected) { 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) { if (!(view instanceof TextView)) { return false; } final TextView textView = (TextView) view; Drawable actual = TextViewCompat.getCompoundDrawablesRelative(textView)[index]; if (expected != TextViewCompat.getCompoundDrawablesRelative(textView)[index]) { failedCheckDescription = "Drawable " + actual + "at index " + index + " does not match expected " + expected; return false; } return true; } }; }
Example #27
Source File: TestUtilsMatchers.java From material-components-android with Apache License 2.0 | 5 votes |
/** Returns a matcher that matches FloatingActionButtons with the specified content height */ public static Matcher<View> withFabContentHeight(final int size) { 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) { if (!(view instanceof FloatingActionButton)) { return false; } final FloatingActionButton fab = (FloatingActionButton) view; final Rect area = new Rect(); fab.getContentRect(area); if (area.height() != size) { failedCheckDescription = "Content height " + area.height() + " is different than expected " + size; return false; } return true; } }; }
Example #28
Source File: TestUtilsMatchers.java From material-components-android with Apache License 2.0 | 5 votes |
/** Returns a matcher that matches FloatingActionButtons with the specified custom size. */ public static Matcher<View> withFabCustomSize(final int customSize) { 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) { if (!(view instanceof FloatingActionButton)) { return false; } final FloatingActionButton fab = (FloatingActionButton) view; if (Math.abs(fab.getCustomSize() - customSize) > 1.0f) { failedCheckDescription = "Custom size " + fab.getCustomSize() + " is different than expected " + customSize; return false; } return true; } }; }
Example #29
Source File: TestUtilsMatchers.java From material-components-android with Apache License 2.0 | 5 votes |
/** * Returns a matcher that matches TextViews whose start drawable is filled with the specified fill * color. */ public static Matcher<View> withStartDrawableFilledWith( final @ColorInt int fillColor, final int allowedComponentVariance) { 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 Drawable[] compoundDrawables = view.getCompoundDrawables(); final boolean isRtl = (ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_RTL); final Drawable startDrawable = isRtl ? compoundDrawables[2] : compoundDrawables[0]; if (startDrawable == null) { failedCheckDescription = "no start drawable"; return false; } try { final Rect bounds = startDrawable.getBounds(); TestUtils.assertAllPixelsOfColor( "", startDrawable, bounds.width(), bounds.height(), true, fillColor, allowedComponentVariance, true); } catch (Throwable t) { failedCheckDescription = t.getMessage(); return false; } return true; } }; }
Example #30
Source File: TestUtilsMatchers.java From material-components-android with Apache License 2.0 | 4 votes |
/** Returns a matcher that matches FloatingActionButtons with the specified gravity. */ public static Matcher<View> withFabContentAreaOnMargins(final int gravity) { 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) { if (!(view instanceof FloatingActionButton)) { return false; } final FloatingActionButton fab = (FloatingActionButton) view; final ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) fab.getLayoutParams(); final ViewGroup parent = (ViewGroup) view.getParent(); final Rect area = new Rect(); fab.getContentRect(area); final int absGravity = GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(view)); try { switch (absGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.TOP: assertEquals(lp.topMargin, fab.getTop() + area.top); break; case Gravity.BOTTOM: assertEquals(parent.getHeight() - lp.bottomMargin, fab.getTop() + area.bottom); break; } switch (absGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.LEFT: assertEquals(lp.leftMargin, fab.getLeft() + area.left); break; case Gravity.RIGHT: assertEquals(parent.getWidth() - lp.rightMargin, fab.getLeft() + area.right); break; } return true; } catch (Throwable t) { failedCheckDescription = t.getMessage(); return false; } } }; }