use of org.hamcrest.TypeSafeMatcher in project MultiType by drakeet.
the class RecyclerViewMatcher method atPositionOnView.
public Matcher<View> atPositionOnView(final int position, final int targetViewId) {
return new TypeSafeMatcher<View>() {
Resources resources = null;
View childView;
public void describeTo(Description description) {
String idDescription = Integer.toString(recyclerViewId);
if (this.resources != null) {
try {
idDescription = this.resources.getResourceName(recyclerViewId);
} catch (Resources.NotFoundException var4) {
idDescription = String.format("%s (resource name not found)", recyclerViewId);
}
}
description.appendText("with id: " + idDescription);
}
public boolean matchesSafely(View view) {
this.resources = view.getResources();
if (childView == null) {
RecyclerView recyclerView = view.getRootView().findViewById(recyclerViewId);
if (recyclerView != null && recyclerView.getId() == recyclerViewId) {
childView = recyclerView.findViewHolderForAdapterPosition(position).itemView;
} else {
return false;
}
}
if (targetViewId == -1) {
return view == childView;
} else {
View targetView = childView.findViewById(targetViewId);
return view == targetView;
}
}
};
}
use of org.hamcrest.TypeSafeMatcher in project kickmaterial by byoutline.
the class CustomMatchers method withErrorSet.
public static Matcher<View> withErrorSet(@NonNull final String expected) {
if (expected == null) {
throw new AssertionError("Null string passed");
}
return new TypeSafeMatcher<View>() {
@Override
public boolean matchesSafely(View view) {
if (!(view instanceof EditText)) {
return false;
}
EditText editText = (EditText) view;
CharSequence error = editText.getError();
if (error == null) {
return false;
}
return expected.equals(error.toString());
}
@Override
public void describeTo(Description description) {
description.appendText("view should have error: ").appendValue(expected).appendText(" set");
}
};
}
use of org.hamcrest.TypeSafeMatcher in project material-components-android by material-components.
the class TestUtilsMatchers method isActionViewOf.
/**
* Returns a matcher that matches the action view of the specified menu item.
*
* @param menu The menu
* @param id The ID of the menu item
*/
public static Matcher<View> isActionViewOf(@NonNull final Menu menu, @IdRes final int id) {
return new TypeSafeMatcher<View>() {
private Resources resources;
@Override
protected boolean matchesSafely(View view) {
resources = view.getResources();
MenuItemImpl item = (MenuItemImpl) menu.findItem(id);
return item != null && item.getActionView() == view;
}
@Override
public void describeTo(Description description) {
String name;
if (resources != null) {
name = resources.getResourceName(id);
} else {
name = Integer.toString(id);
}
description.appendText("is action view of menu item " + name);
}
};
}
use of org.hamcrest.TypeSafeMatcher in project material-components-android by material-components.
the class TestUtilsMatchers method isChildOfA.
/**
* Returns a matcher that matches {@link View}s based on the given parent type.
*
* @param parentMatcher the type of the parent to match on
*/
public static Matcher<View> isChildOfA(final Matcher<View> parentMatcher) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("is child of a: ");
parentMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
final ViewParent viewParent = view.getParent();
if (!(viewParent instanceof View)) {
return false;
}
if (parentMatcher.matches(viewParent)) {
return true;
}
return false;
}
};
}
use of org.hamcrest.TypeSafeMatcher in project neo4j by neo4j.
the class QueryResultsSerializationTest method restContainsNestedDeleted.
/**
* This matcher is hardcoded to check for a list containing one deleted node and one map with a deleted node mapped to the key `someKey`.
*/
public static Matcher<? super Response> restContainsNestedDeleted() {
return new TypeSafeMatcher<Response>() {
@Override
protected boolean matchesSafely(HTTP.Response response) {
try {
JsonNode list = TransactionMatchers.getJsonNodeWithName(response, "rest").iterator().next();
assertThat(list.get(0).get("metadata").get("deleted").asBoolean(), equalTo(Boolean.TRUE));
assertThat(list.get(1).get("someKey").get("metadata").get("deleted").asBoolean(), equalTo(Boolean.TRUE));
return true;
} catch (JsonParseException e) {
return false;
}
}
@Override
public void describeTo(Description description) {
}
};
}
Aggregations