use of org.hamcrest.StringDescription in project freud by LMAX-Exchange.
the class AnalysisListenerStub method assertOutcome.
@SuppressWarnings("unchecked")
private void assertOutcome(Matcher matcher, final Deque<Object> deque, String eventDescription) {
for (Object analysedObject : deque) {
if (matcher.matches(analysedObject)) {
return;
}
}
StringDescription description = new StringDescription();
matcher.describeTo(description);
Assert.fail(eventDescription + ": " + description.toString());
}
use of org.hamcrest.StringDescription in project querydsl by querydsl.
the class PathMatcherTest method describe.
@Test
public void describe() {
Description description = new StringDescription();
hasValue($.horsePower, equalTo(321)).describeTo(description);
assertEquals("valueOf(\"car.horsePower\", <321>)", description.toString());
}
use of org.hamcrest.StringDescription in project neo4j by neo4j.
the class Assert method assertEventually.
public static <T, E extends Exception> void assertEventually(String reason, ThrowingSupplier<T, E> actual, Matcher<? super T> matcher, long timeout, TimeUnit timeUnit) throws E, InterruptedException {
long endTimeMillis = System.currentTimeMillis() + timeUnit.toMillis(timeout);
T last;
boolean matched;
do {
long sampleTime = System.currentTimeMillis();
last = actual.get();
matched = matcher.matches(last);
if (matched || sampleTime > endTimeMillis) {
break;
}
Thread.sleep(100);
} while (true);
if (!matched) {
Description description = new StringDescription();
description.appendText(reason).appendText("\nExpected: ").appendDescriptionOf(matcher).appendText("\n but: ");
matcher.describeMismatch(last, description);
throw new AssertionError("Timeout hit (" + timeout + " " + timeUnit.toString().toLowerCase() + ") while waiting for condition to match: " + description.toString());
}
}
use of org.hamcrest.StringDescription in project neo4j by neo4j.
the class AssertableLogProvider method assertContainsLogCallsMatching.
@SafeVarargs
public final void assertContainsLogCallsMatching(int logSkipCount, Matcher<String>... matchers) {
synchronized (logCalls) {
assertEquals(logCalls.size(), logSkipCount + matchers.length);
for (int i = 0; i < matchers.length; i++) {
LogCall logCall = logCalls.get(logSkipCount + i);
Matcher<String> matcher = matchers[i];
if (!matcher.matches(logCall.message)) {
StringDescription description = new StringDescription();
description.appendDescriptionOf(matcher);
fail(format("Expected log statement with message as %s, but none found. Actual log call was:\n%s", description.toString(), logCall.toString()));
}
}
}
}
use of org.hamcrest.StringDescription in project double-espresso by JakeWharton.
the class AmbiguousViewMatcherExceptionTest method testExceptionContainsMatcherDescription.
public void testExceptionContainsMatcherDescription() {
StringBuilder matcherDescription = new StringBuilder();
alwaysTrueMatcher.describeTo(new StringDescription(matcherDescription));
assertThat(createException().getMessage(), containsString(matcherDescription.toString()));
}
Aggregations