Search in sources :

Example 26 with StringDescription

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());
}
Also used : StringDescription(org.hamcrest.StringDescription)

Example 27 with StringDescription

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());
}
Also used : Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) StringDescription(org.hamcrest.StringDescription) Test(org.junit.Test)

Example 28 with StringDescription

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());
    }
}
Also used : Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) StringDescription(org.hamcrest.StringDescription)

Example 29 with StringDescription

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()));
            }
        }
    }
}
Also used : StringDescription(org.hamcrest.StringDescription)

Example 30 with StringDescription

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()));
}
Also used : StringDescription(org.hamcrest.StringDescription)

Aggregations

StringDescription (org.hamcrest.StringDescription)32 Description (org.hamcrest.Description)22 Test (org.junit.Test)15 JsonPathMatchers.isJsonFile (com.jayway.jsonpath.matchers.JsonPathMatchers.isJsonFile)3 JsonPathMatchers.isJsonString (com.jayway.jsonpath.matchers.JsonPathMatchers.isJsonString)3 ResourceHelpers.resourceAsFile (com.jayway.jsonpath.matchers.helpers.ResourceHelpers.resourceAsFile)3 File (java.io.File)3 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 Adapter (android.widget.Adapter)1 TextView (android.widget.TextView)1 ViewAssertion (com.google.android.apps.common.testing.ui.espresso.ViewAssertion)1 ScrollToAction (com.google.android.apps.common.testing.ui.espresso.action.ScrollToAction)1 Optional (com.google.common.base.Optional)1 AssertionFailedError (junit.framework.AssertionFailedError)1 AnnotatedElementDeclaration (org.freud.analysed.javasource.AnnotatedElementDeclaration)1 Annotation (org.freud.analysed.javasource.Annotation)1 FreudExtendedMatcher (org.freud.java.matcher.FreudExtendedMatcher)1