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