use of org.hamcrest.StringDescription in project querydsl by querydsl.
the class PathMatcherTest method mismatch.
@Test
public void mismatch() {
Car car = new Car();
car.setHorsePower(123);
Description mismatchDescription = new StringDescription();
hasValue($.horsePower, equalTo(321)).describeMismatch(car, mismatchDescription);
assertEquals("value \"car.horsePower\" was <123>", mismatchDescription.toString());
}
use of org.hamcrest.StringDescription in project spring-boot by spring-projects.
the class Matched method matches.
@Override
public boolean matches(final T value) {
if (this.matcher.matches(value)) {
return true;
}
StringDescription description = new StringDescription();
this.matcher.describeTo(description);
describedAs(description.toString());
return false;
}
use of org.hamcrest.StringDescription 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.StringDescription in project beam by apache.
the class DisplayDataMatchersTest method testHasDisplayItemDescription.
@Test
public void testHasDisplayItemDescription() {
Matcher<DisplayData> matcher = hasDisplayItem();
Description desc = new StringDescription();
Description mismatchDesc = new StringDescription();
matcher.describeTo(desc);
matcher.describeMismatch(DisplayData.none(), mismatchDesc);
assertEquals("DisplayData not an empty collection", desc.toString());
assertEquals("DisplayData was <[]>", mismatchDesc.toString());
}
use of org.hamcrest.StringDescription in project double-espresso by JakeWharton.
the class NoMatchingViewExceptionTest method testExceptionContainsMatcherDescription.
public void testExceptionContainsMatcherDescription() {
StringBuilder matcherDescription = new StringBuilder();
alwaysFailingMatcher.describeTo(new StringDescription(matcherDescription));
assertThat(createException().getMessage(), containsString(matcherDescription.toString()));
}
Aggregations