use of org.hamcrest.Description in project ChipsLayoutManager by BelooS.
the class RecyclerViewEspressoFactory method orderMatcher.
///////////////////////////////////////////////////////////////////////////
// Matcher
///////////////////////////////////////////////////////////////////////////
private static Matcher<View> orderMatcher() {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("with correct position order");
}
@Override
public boolean matchesSafely(View v) {
RecyclerView view = (RecyclerView) v;
if (view.getLayoutManager() == null)
return false;
ChildViewsIterable childViews = new ChildViewsIterable(view.getLayoutManager());
int pos = view.getChildAdapterPosition(childViews.iterator().next());
for (View child : childViews) {
if (pos != view.getChildAdapterPosition(child)) {
return false;
}
pos++;
}
return true;
}
};
}
use of org.hamcrest.Description in project graylog2-server by Graylog2.
the class RestAssuredSetupRule method before.
@Override
protected void before() throws Throwable {
final URI uri = IntegrationTestsConfig.getGlServerURL();
RestAssured.baseURI = uri.getScheme() + "://" + uri.getHost();
RestAssured.port = uri.getPort();
String[] userInfo = uri.getUserInfo().split(":");
authenticationScheme = preemptive().basic(userInfo[0], userInfo[1]);
// we want all the details for failed tests
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
// we want to be able to describe mismatches in a custom way.
final MatcherConfig matcherConfig = RestAssured.config().getMatcherConfig().errorDescriptionType(MatcherConfig.ErrorDescriptionType.HAMCREST);
RestAssured.config = RestAssured.config().matcherConfig(matcherConfig);
// we usually send and receive JSON, so we preconfigure for that.
RestAssured.requestSpecification = new RequestSpecBuilder().build().accept(JSON).contentType(JSON);
// immediately query the server for its version number, we need it to be able to process the RequireVersion annotations.
given().when().authentication().preemptive().basic(userInfo[0], userInfo[1]).get("/system").then().body("version", new BaseMatcher<Object>() {
@Override
public boolean matches(Object item) {
if (item instanceof String) {
String str = (String) item;
try {
// clean our slightly non-semver version number
str = str.replaceAll("\\(.*?\\)", "").trim();
serverUnderTestVersion = Version.valueOf(str);
return true;
} catch (RuntimeException e) {
return false;
}
}
return false;
}
@Override
public void describeTo(Description description) {
description.appendText("parse the system under test's version number");
}
});
}
use of org.hamcrest.Description in project wire-android by wireapp.
the class CustomMatchers method otrSwitchWithId.
public static Matcher<View> otrSwitchWithId(final int id) {
return new TypeSafeMatcher<View>() {
Resources resources = null;
@Override
public void describeTo(Description description) {
String idDescription = Integer.toString(id);
if (resources != null) {
try {
idDescription = resources.getResourceName(id);
} catch (Resources.NotFoundException e) {
// No big deal, will just use the int value.
idDescription = String.format("%s (resource name not found)", id);
}
}
description.appendText("with id: " + idDescription);
}
@Override
public boolean matchesSafely(View view) {
resources = view.getResources();
ViewParent parent = view.getParent();
return parent != null && parent instanceof OtrSwitch && id == ((OtrSwitch) parent).getId() && view instanceof SwitchCompat;
}
};
}
use of org.hamcrest.Description in project freud by LMAX-Exchange.
the class AnnotatedElementDeclarationMatchers method hasDeclaredAnnotation.
public FreudExtendedMatcher<T> hasDeclaredAnnotation(final String annotationName, final Matcher<String> defaultValueMatcher) {
return new FreudExtendedMatcher<T>() {
@Override
protected boolean matchesSafely(final AnnotatedElementDeclaration toBeAnalysed) {
for (Annotation declaredAnnotation : toBeAnalysed.getDeclaredAnnotations()) {
if (annotationName.equals(declaredAnnotation.getName())) {
return defaultValueMatcher.matches(declaredAnnotation.getDefaultParameter());
}
}
return false;
}
@Override
public String toString() {
Description description = new StringDescription();
description.appendText("HasDeclaredAnnotation(").appendText(annotationName);
defaultValueMatcher.describeTo(description);
description.appendText(")");
return description.toString();
}
@Override
public void describeTo(Description description) {
description.appendText(toString());
}
};
}
use of org.hamcrest.Description in project Rosie by Karumi.
the class AncestorMatcher method withAncestor.
public static Matcher<Object> withAncestor(final Matcher<View> viewMatcher) {
return new BoundedMatcher<Object, View>(View.class) {
@Override
public boolean matchesSafely(View view) {
boolean found = false;
ViewParent parent = view.getParent();
while (!found && parent != null) {
found = viewMatcher.matches(parent);
parent = parent.getParent();
}
return found;
}
@Override
public void describeTo(Description description) {
description.appendText("with view ancestor: ");
viewMatcher.describeTo(description);
}
};
}
Aggregations