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) {
}
};
}
use of org.hamcrest.TypeSafeMatcher in project neo4j by neo4j.
the class TransportTestUtil method eventuallyReceives.
public static Matcher<TransportConnection> eventuallyReceives(final Matcher<ResponseMessage>... messages) {
return new TypeSafeMatcher<TransportConnection>() {
@Override
protected boolean matchesSafely(TransportConnection conn) {
try {
for (Matcher<ResponseMessage> matchesMessage : messages) {
final ResponseMessage message = receiveOneResponseMessage(conn);
assertThat(message, matchesMessage);
}
return true;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public void describeTo(Description description) {
description.appendValueList("Messages[", ",", "]", messages);
}
};
}
Aggregations