Search in sources :

Example 31 with Description

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;
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) ChildViewsIterable(com.beloo.widget.chipslayoutmanager.ChildViewsIterable)

Example 32 with Description

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");
        }
    });
}
Also used : Description(org.hamcrest.Description) MatcherConfig(com.jayway.restassured.config.MatcherConfig) RequestSpecBuilder(com.jayway.restassured.builder.RequestSpecBuilder) URI(java.net.URI)

Example 33 with Description

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;
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ViewParent(android.view.ViewParent) Resources(android.content.res.Resources) OtrSwitch(com.waz.zclient.ui.views.e2ee.OtrSwitch) View(android.view.View) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 34 with Description

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

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);
        }
    };
}
Also used : Description(org.hamcrest.Description) ViewParent(android.view.ViewParent) BoundedMatcher(android.support.test.espresso.matcher.BoundedMatcher) View(android.view.View)

Aggregations

Description (org.hamcrest.Description)122 Test (org.junit.Test)38 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)35 StringDescription (org.hamcrest.StringDescription)29 BaseMatcher (org.hamcrest.BaseMatcher)27 View (android.view.View)22 ViewParent (android.view.ViewParent)11 TextView (android.widget.TextView)11 ViewGroup (android.view.ViewGroup)8 Expectations (org.jmock.Expectations)8 URL (java.net.URL)7 Matcher (org.hamcrest.Matcher)7 Invocation (org.jmock.api.Invocation)7 BoundedMatcher (android.support.test.espresso.matcher.BoundedMatcher)6 ImageView (android.widget.ImageView)6 File (java.io.File)6 IOException (java.io.IOException)6 URI (java.net.URI)6 List (java.util.List)6 JsonNode (org.codehaus.jackson.JsonNode)6