Search in sources :

Example 26 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project mule by mulesoft.

the class MessageProcessingFlowTraceManagerTestCase method hasExecutedProcessors.

private Matcher<ProcessorsTrace> hasExecutedProcessors(final String... expectedProcessors) {
    return new TypeSafeMatcher<ProcessorsTrace>() {

        private List<Matcher> failed = new ArrayList<>();

        @Override
        protected boolean matchesSafely(ProcessorsTrace processorsTrace) {
            Matcher<Collection<? extends Object>> sizeMatcher = hasSize(expectedProcessors.length);
            if (!sizeMatcher.matches(processorsTrace.getExecutedProcessors())) {
                failed.add(sizeMatcher);
            }
            int i = 0;
            for (String expectedProcessor : expectedProcessors) {
                Matcher processorItemMatcher = is(expectedProcessor);
                if (!processorItemMatcher.matches(processorsTrace.getExecutedProcessors().get(i))) {
                    failed.add(processorItemMatcher);
                }
                ++i;
            }
            return failed.isEmpty();
        }

        @Override
        public void describeTo(Description description) {
            description.appendValue(Arrays.asList(expectedProcessors));
        }

        @Override
        protected void describeMismatchSafely(ProcessorsTrace item, Description description) {
            description.appendText("was ").appendValue(item.getExecutedProcessors());
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Matcher(org.hamcrest.Matcher) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) ProcessorsTrace(org.mule.runtime.core.api.context.notification.ProcessorsTrace)

Example 27 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project openScale by oliexdev.

the class UserAddTest 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) View(android.view.View) Espresso.onView(android.support.test.espresso.Espresso.onView)

Example 28 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project linkki by linkki-framework.

the class OkCancelDialogTest method displayingMessage.

private Matcher<OkCancelDialog> displayingMessage(String text) {
    return new TypeSafeMatcher<OkCancelDialog>() {

        @SuppressWarnings("null")
        @Override
        public void describeTo(Description description) {
            description.appendText("an OkCancelDialog displaying a message with the text '");
            description.appendText(text);
            description.appendText("'");
        }

        @SuppressWarnings("null")
        @Override
        protected boolean matchesSafely(OkCancelDialog dialog) {
            VerticalLayout layout = (VerticalLayout) dialog.getContent();
            VerticalLayout nestedLayout = (VerticalLayout) layout.getComponent(0);
            return components(nestedLayout).filter(MessageRow.class::isInstance).findFirst().map(c -> ((MessageRow) c).getText().equals(text)).orElse(false);
        }
    };
}
Also used : Description(org.hamcrest.Description) ErrorLevel(com.vaadin.server.ErrorMessage.ErrorLevel) VerticalLayout(com.vaadin.ui.VerticalLayout) Matchers.not(org.hamcrest.Matchers.not) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Assert.assertThat(org.junit.Assert.assertThat) Button(com.vaadin.ui.Button) Stream(java.util.stream.Stream) Matchers.contains(org.hamcrest.Matchers.contains) ValidationMarker(org.linkki.util.validation.ValidationMarker) HorizontalLayout(com.vaadin.ui.HorizontalLayout) MessageRow(org.linkki.framework.ui.component.MessageRow) Matcher(org.hamcrest.Matcher) ValidationService(org.linkki.core.binding.validation.ValidationService) Label(com.vaadin.ui.Label) MessageList(org.linkki.core.message.MessageList) Matchers.is(org.hamcrest.Matchers.is) StreamSupport(java.util.stream.StreamSupport) Message(org.linkki.core.message.Message) ValidationDisplayState(org.linkki.core.binding.validation.ValidationDisplayState) Component(com.vaadin.ui.Component) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) VerticalLayout(com.vaadin.ui.VerticalLayout)

Example 29 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project kiwix-android by kiwix.

the class ContentTest 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) ViewMatchers.withContentDescription(android.support.test.espresso.matcher.ViewMatchers.withContentDescription) ViewParent(android.view.ViewParent) ViewGroup(android.view.ViewGroup) View(android.view.View) Espresso.onView(android.support.test.espresso.Espresso.onView)

Example 30 with TypeSafeMatcher

use of org.hamcrest.TypeSafeMatcher in project double-espresso by JakeWharton.

the class AdapterViewTest method withAdaptedData.

private static Matcher<View> withAdaptedData(final Matcher<Object> dataMatcher) {
    return new TypeSafeMatcher<View>() {

        @Override
        public void describeTo(Description description) {
            description.appendText("with class name: ");
            dataMatcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(View view) {
            if (!(view instanceof AdapterView)) {
                return false;
            }
            @SuppressWarnings("rawtypes") Adapter adapter = ((AdapterView) view).getAdapter();
            for (int i = 0; i < adapter.getCount(); i++) {
                if (dataMatcher.matches(adapter.getItem(i))) {
                    return true;
                }
            }
            return false;
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) AdapterView(android.widget.AdapterView) Adapter(android.widget.Adapter) Espresso.onView(com.google.android.apps.common.testing.ui.espresso.Espresso.onView) View(android.view.View) AdapterView(android.widget.AdapterView)

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