use of org.hamcrest.Description in project dobby-android by InceptAi.
the class WifiExpertUITests method childAtPosition.
private static Matcher<View> childAtPosition(final Matcher<View> parentMatcher, final int position) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("Child at position " + position + " in parent ");
parentMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent) && view.equals(((ViewGroup) parent).getChildAt(position));
}
};
}
use of org.hamcrest.Description in project double-espresso by JakeWharton.
the class ViewMatchers method hasImeAction.
/**
* Returns a matcher that matches views that support input methods (e.g. EditText) and have the
* specified IME action set in its {@link EditorInfo}.
*
* @param imeActionMatcher a matcher for the IME action
*/
public static Matcher<View> hasImeAction(final Matcher<Integer> imeActionMatcher) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("has ime action: ");
imeActionMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
EditorInfo editorInfo = new EditorInfo();
InputConnection inputConnection = view.onCreateInputConnection(editorInfo);
if (inputConnection == null) {
return false;
}
int actionId = editorInfo.actionId != 0 ? editorInfo.actionId : editorInfo.imeOptions & EditorInfo.IME_MASK_ACTION;
return imeActionMatcher.matches(actionId);
}
};
}
use of org.hamcrest.Description in project double-espresso by JakeWharton.
the class ViewMatchers method isDisplayingAtLeast.
/**
* Returns a matcher which accepts a view so long as a given percentage of that view's area is
* not obscured by any other view and is thus visible to the user.
*
* @param areaPercentage an integer ranging from (0, 100] indicating how much percent of the
* surface area of the view must be shown to the user to be accepted.
*/
public static Matcher<View> isDisplayingAtLeast(final int areaPercentage) {
checkState(areaPercentage <= 100, "Cannot have over 100 percent: %s", areaPercentage);
checkState(areaPercentage > 0, "Must have a positive, non-zero value: %s", areaPercentage);
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText(String.format("at least %s percent of the view's area is displayed to the user.", areaPercentage));
}
@Override
public boolean matchesSafely(View view) {
Rect visibleParts = new Rect();
boolean visibleAtAll = view.getGlobalVisibleRect(visibleParts);
if (!visibleAtAll) {
return false;
}
double maxArea = view.getHeight() * view.getWidth();
double visibleArea = visibleParts.height() * visibleParts.width();
int displayedPercentage = (int) ((visibleArea / maxArea) * 100);
return displayedPercentage >= areaPercentage && withEffectiveVisibility(Visibility.VISIBLE).matches(view);
}
};
}
use of org.hamcrest.Description in project double-espresso by JakeWharton.
the class ViewMatchers method assertThat.
/**
* A replacement for MatcherAssert.assertThat that renders View objects nicely.
*
* @param message the message to display.
* @param actual the actual value.
* @param matcher a matcher that accepts or rejects actual.
*/
public static <T> void assertThat(String message, T actual, Matcher<T> matcher) {
if (!matcher.matches(actual)) {
Description description = new StringDescription();
description.appendText(message).appendText("\nExpected: ").appendDescriptionOf(matcher).appendText("\n Got: ");
if (actual instanceof View) {
description.appendValue(HumanReadables.describe((View) actual));
} else {
description.appendValue(actual);
}
description.appendText("\n");
throw new AssertionFailedError(description.toString());
}
}
use of org.hamcrest.Description in project protoman by spotify.
the class MatcherHelperBase method matchesSafely.
@Override
protected boolean matchesSafely(final T item, final Description mismatchDescription) {
boolean ret = true;
mismatchDescription.appendText(className).appendText(" {\n");
for (final Matcher<T> matcher : matchers) {
if (!matcher.matches(item)) {
mismatchDescription.appendText(" ");
Description innerDescription = new StringDescription();
matcher.describeMismatch(item, innerDescription);
indentDescription(mismatchDescription, innerDescription);
ret = false;
}
}
mismatchDescription.appendText("}");
return ret;
}
Aggregations