Search in sources :

Example 36 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project beam by apache.

the class CombineFnTesterTest method usesMatcher.

@Test
public void usesMatcher() {
    final AtomicBoolean matcherUsed = new AtomicBoolean();
    Matcher<Integer> matcher = new TypeSafeMatcher<Integer>() {

        @Override
        public void describeTo(Description description) {
        }

        @Override
        protected boolean matchesSafely(Integer item) {
            matcherUsed.set(true);
            return item == 30;
        }
    };
    CombineFnTester.testCombineFn(Sum.ofIntegers(), Arrays.asList(1, 1, 2, 2, 3, 3, 4, 4, 5, 5), matcher);
    assertThat(matcherUsed.get(), is(true));
    try {
        CombineFnTester.testCombineFn(Sum.ofIntegers(), Arrays.asList(1, 2, 3, 4, 5), Matchers.not(Matchers.equalTo(15)));
    } catch (AssertionError ignored) {
        // Success! Return to avoid the call to fail();
        return;
    }
    fail("The matcher should have failed, throwing an error");
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) Test(org.junit.Test)

Example 37 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project Team-Plant-Power by Alexander1994.

the class HistoricalHumidityTest method childAtPosition.

private static Matcher<View> childAtPosition(final Matcher<View> parentMatcher, final int position) {
    return new TypeSafeMatcher<View>() {

        @Override
        public void describeTo(Description description) {
            description.appendText("Child at position " + position + " in parent ");
            parentMatcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(View view) {
            ViewParent parent = view.getParent();
            return parent instanceof ViewGroup && parentMatcher.matches(parent) && view.equals(((ViewGroup) parent).getChildAt(position));
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ViewParent(android.view.ViewParent) ViewGroup(android.view.ViewGroup) Espresso.onView(android.support.test.espresso.Espresso.onView) View(android.view.View)

Example 38 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher 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 39 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project junit4 by junit-team.

the class EventCollector method hasSingleFailureWithMessage.

static Matcher<EventCollector> hasSingleFailureWithMessage(final Matcher<String> messageMatcher) {
    return new TypeSafeMatcher<EventCollector>() {

        @Override
        public boolean matchesSafely(EventCollector item) {
            return hasSingleFailure().matches(item) && messageMatcher.matches(item.fFailures.get(0).getMessage());
        }

        public void describeTo(org.hamcrest.Description description) {
            description.appendText("has single failure with message ");
            messageMatcher.describeTo(description);
        }

        @Override
        protected void describeMismatchSafely(EventCollector item, org.hamcrest.Description description) {
            description.appendText("was ");
            hasSingleFailure().describeMismatch(item, description);
            description.appendText(": ");
            boolean first = true;
            for (Failure f : item.fFailures) {
                if (!first) {
                    description.appendText(" ,");
                }
                description.appendText("'");
                description.appendText(f.getMessage());
                description.appendText("'");
                first = false;
            }
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.junit.runner.Description) Failure(org.junit.runner.notification.Failure)

Example 40 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project junit4 by junit-team.

the class EventCollector method failureIs.

static Matcher<EventCollector> failureIs(final Matcher<? super Throwable> exceptionMatcher) {
    return new TypeSafeMatcher<EventCollector>() {

        @Override
        public boolean matchesSafely(EventCollector item) {
            for (Failure f : item.fFailures) {
                return exceptionMatcher.matches(f.getException());
            }
            return false;
        }

        public void describeTo(org.hamcrest.Description description) {
            description.appendText("failure is ");
            exceptionMatcher.describeTo(description);
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.junit.runner.Description) Failure(org.junit.runner.notification.Failure)

Aggregations

TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)82 Description (org.hamcrest.Description)79 View (android.view.View)44 ViewParent (android.view.ViewParent)33 ViewGroup (android.view.ViewGroup)30 Espresso.onView (android.support.test.espresso.Espresso.onView)25 TextView (android.widget.TextView)9 Test (org.junit.Test)9 ViewMatchers.withContentDescription (android.support.test.espresso.matcher.ViewMatchers.withContentDescription)7 JsonNode (org.codehaus.jackson.JsonNode)6 JsonParseException (org.neo4j.server.rest.domain.JsonParseException)6 HTTP (org.neo4j.test.server.HTTP)6 Resources (android.content.res.Resources)5 StringDescription (org.hamcrest.StringDescription)5 AdapterView (android.widget.AdapterView)4 RecyclerView (android.support.v7.widget.RecyclerView)3 Adapter (android.widget.Adapter)3 Espresso.onView (com.google.android.apps.common.testing.ui.espresso.Espresso.onView)3 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3