Search in sources :

Example 6 with Matcher

use of org.hamcrest.Matcher in project material-components-android by material-components.

the class NavigationViewTest method verifyCheckedAppearance.

private void verifyCheckedAppearance(@IdRes int checkedItemId, @ColorInt int uncheckedItemForeground, @ColorInt int checkedItemForeground, @ColorInt int uncheckedItemBackground, @ColorInt int checkedItemBackground) {
    for (int i = 0; i < MENU_CONTENT_ITEM_IDS.length; i++) {
        final boolean expectedToBeChecked = (MENU_CONTENT_ITEM_IDS[i] == checkedItemId);
        @ColorInt final int expectedItemForeground = expectedToBeChecked ? checkedItemForeground : uncheckedItemForeground;
        @ColorInt final int expectedItemBackground = expectedToBeChecked ? checkedItemBackground : uncheckedItemBackground;
        // For the background fill check we need to select a view that has its background
        // set by the current implementation (see disclaimer in testBackground)
        Matcher menuItemMatcher = allOf(hasDescendant(withText(mMenuStringContent.get(MENU_CONTENT_ITEM_IDS[i]))), isChildOfA(isAssignableFrom(RecyclerView.class)), isDescendantOfA(withId(R.id.start_drawer)));
        onView(menuItemMatcher).check(matches(withBackgroundFill(expectedItemBackground)));
        // And for the foreground color check we need to select a view with the text content
        Matcher menuItemTextMatcher = allOf(withText(mMenuStringContent.get(MENU_CONTENT_ITEM_IDS[i])), isDescendantOfA(withId(R.id.start_drawer)));
        onView(menuItemTextMatcher).check(matches(withTextColor(expectedItemForeground)));
    }
}
Also used : ColorInt(android.support.annotation.ColorInt) Matcher(org.hamcrest.Matcher)

Example 7 with Matcher

use of org.hamcrest.Matcher in project material-components-android by material-components.

the class NavigationViewTest method testActionLayout.

@Test
public void testActionLayout() {
    // Open our drawer
    onView(withId(R.id.drawer_layout)).perform(openDrawer(GravityCompat.START));
    // There are four conditions to "find" the menu item with action layout (switch):
    // 1. Is in the NavigationView
    // 2. Is direct child of a class that extends RecyclerView
    // 3. Has a child with "people" text
    // 4. Has fully displayed child that extends SwitchCompat
    // Note that condition 2 makes a certain assumption about the internal implementation
    // details of the NavigationMenu, while conditions 3 and 4 aim to be as generic as
    // possible and to not rely on the internal details of the current layout implementation
    // of an individual menu item in NavigationMenu.
    Matcher menuItemMatcher = allOf(isDescendantOfA(withId(R.id.start_drawer)), isChildOfA(isAssignableFrom(RecyclerView.class)), hasDescendant(withText(mMenuStringContent.get(R.id.destination_people))), hasDescendant(allOf(isAssignableFrom(SwitchCompat.class), isCompletelyDisplayed())));
    // While we don't need to perform any action on our row, the invocation of perform()
    // makes our matcher actually run. If for some reason NavigationView fails to inflate and
    // display our SwitchCompat action layout, the next line will fail in the matcher pass.
    onView(menuItemMatcher).perform(click());
    // Check that the full custom view is displayed without title and icon.
    final Resources res = activityTestRule.getActivity().getResources();
    Matcher customItemMatcher = allOf(isDescendantOfA(withId(R.id.start_drawer)), isChildOfA(isAssignableFrom(RecyclerView.class)), hasDescendant(withText(res.getString(R.string.navigate_custom))), hasDescendant(allOf(isAssignableFrom(TextView.class), withEffectiveVisibility(Visibility.GONE))));
    onView(customItemMatcher).perform(click());
}
Also used : Matcher(org.hamcrest.Matcher) TextView(android.widget.TextView) Resources(android.content.res.Resources) SwitchCompat(android.support.v7.widget.SwitchCompat) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 8 with Matcher

use of org.hamcrest.Matcher in project material-components-android by material-components.

the class CoordinatorSnackbarWithFabTest method getSnackbarLocationOnScreen.

/** Returns the location of our snackbar on the screen. */
private static int[] getSnackbarLocationOnScreen() {
    final int[] location = new int[2];
    onView(isAssignableFrom(Snackbar.SnackbarLayout.class)).perform(new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isEnabled();
        }

        @Override
        public String getDescription() {
            return "Snackbar matcher";
        }

        @Override
        public void perform(UiController uiController, View view) {
            view.getLocationOnScreen(location);
        }
    });
    return location;
}
Also used : ViewAction(android.support.test.espresso.ViewAction) Matcher(org.hamcrest.Matcher) UiController(android.support.test.espresso.UiController) AppCompatTextView(android.support.v7.widget.AppCompatTextView) Espresso.onView(android.support.test.espresso.Espresso.onView) View(android.view.View)

Example 9 with Matcher

use of org.hamcrest.Matcher in project gocd by gocd.

the class TestGoMessageListener method waitForMessage.

public void waitForMessage(Matcher matcher) {
    Matcher iterableMatcher = hasItem(matcher);
    long start = System.currentTimeMillis();
    while (!iterableMatcher.matches(received)) {
        if (System.currentTimeMillis() - start > TIMEOUT) {
            bomb("Timeout waiting for message : " + received);
        }
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
        }
    }
}
Also used : Matcher(org.hamcrest.Matcher)

Example 10 with Matcher

use of org.hamcrest.Matcher in project iosched by google.

the class MatchersHelper method getTextForViewGroupDescendant.

/**
     * This returns the text for the view that has an id of {@code idOfDescendantViewToGetTextFor}
     * and is a descendant of the nth child of {@code parentViewWithMultipleChildren}, where n
     * equals {@code indexOfDescendant}. The parent view is expected to be a {@link ViewGroup} and
     * the descendant view is expected to be a {@link TextView}. This is used when there is a
     * certain randomness in the elements shown in a collection view, even with mock data.
     *
     * @see com.google.samples.apps.iosched.videolibrary.VideoLibraryModel
     */
public static String getTextForViewGroupDescendant(final Matcher<View> parentViewWithMultipleChildren, final int indexOfDescendant, final int idOfDescendantViewToGetTextFor) {
    /**
         * We cannot use a String directly as we need to make it final to access it inside the
         * inner method but we cannot reassign a value to a final String.
         */
    final String[] stringHolder = { null };
    onView(parentViewWithMultipleChildren).perform(new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isAssignableFrom(ViewGroup.class);
        }

        @Override
        public String getDescription() {
            return "getting text from a TextView with a known id and that is a descendant of " + "the nth child of a viewgroup";
        }

        @Override
        public void perform(UiController uiController, View view) {
            ViewGroup vg = (ViewGroup) view;
            View nthDescendant = vg.getChildAt(indexOfDescendant);
            TextView matchedView = (TextView) nthDescendant.findViewById(idOfDescendantViewToGetTextFor);
            stringHolder[0] = matchedView.getText().toString();
        }
    });
    return stringHolder[0];
}
Also used : ViewAction(android.support.test.espresso.ViewAction) BaseMatcher(org.hamcrest.BaseMatcher) Matcher(org.hamcrest.Matcher) ViewGroup(android.view.ViewGroup) UiController(android.support.test.espresso.UiController) TextView(android.widget.TextView) TextView(android.widget.TextView) Espresso.onView(android.support.test.espresso.Espresso.onView) View(android.view.View)

Aggregations

Matcher (org.hamcrest.Matcher)28 Description (org.hamcrest.Description)7 View (android.view.View)6 Test (org.junit.Test)6 Espresso.onView (android.support.test.espresso.Espresso.onView)4 UiController (android.support.test.espresso.UiController)4 ViewAction (android.support.test.espresso.ViewAction)4 TextView (android.widget.TextView)4 MockedPulsarServiceBaseTest (com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest)4 NamespaceBundle (com.yahoo.pulsar.common.naming.NamespaceBundle)4 NamespaceName (com.yahoo.pulsar.common.naming.NamespaceName)4 URL (java.net.URL)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Test (org.testng.annotations.Test)4 RestException (com.yahoo.pulsar.broker.web.RestException)3 ArrayList (java.util.ArrayList)3 Resources (android.content.res.Resources)2 ColorInt (android.support.annotation.ColorInt)2 MediumTest (android.support.test.filters.MediumTest)2 ViewGroup (android.view.ViewGroup)2