Search in sources :

Example 6 with StringDescription

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

Example 7 with StringDescription

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

Example 8 with StringDescription

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());
        }
    };
}
Also used : Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) AnnotatedElementDeclaration(org.freud.analysed.javasource.AnnotatedElementDeclaration) StringDescription(org.hamcrest.StringDescription) FreudExtendedMatcher(org.freud.java.matcher.FreudExtendedMatcher) Annotation(org.freud.analysed.javasource.Annotation)

Example 9 with StringDescription

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

Example 10 with StringDescription

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()));
}
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