android.support.test.espresso.matcher.BoundedMatcher Java Examples

The following examples show how to use android.support.test.espresso.matcher.BoundedMatcher. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: android-espresso-revealed   Author: Apress   File: RecyclerViewMatchers.java    License: Apache License 2.0 6 votes vote down vote up
public static Matcher<RecyclerView.ViewHolder> withTitle(final String taskTitle) {
    Checks.checkNotNull(taskTitle);

    return new BoundedMatcher<RecyclerView.ViewHolder, TasksFragment.TasksAdapter.ViewHolder>(
            TasksAdapter.ViewHolder.class) {
        @Override
        protected boolean matchesSafely(TasksAdapter.ViewHolder holder) {
            final String holderTaskTitle = holder.getHolderTask().getTitle();
            return taskTitle.equals(holderTaskTitle);
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("with task title: " + taskTitle);
        }
    };
}
 
Example #2
Source Project: android-espresso-revealed   Author: Apress   File: RecyclerViewMatchers.java    License: Apache License 2.0 6 votes vote down vote up
public static Matcher<RecyclerView.ViewHolder> withTask(final TodoItem taskItem) {
    Checks.checkNotNull(taskItem);

    return new BoundedMatcher<RecyclerView.ViewHolder, TasksFragment.TasksAdapter.ViewHolder>(
            TasksAdapter.ViewHolder.class) {
        @Override
        protected boolean matchesSafely(TasksAdapter.ViewHolder holder) {
            final String holderTaskTitle = holder.getHolderTask().getTitle();
            final String holderTaskDesc = holder.getHolderTask().getDescription();
            return taskItem.getTitle().equals(holderTaskTitle)
                    && taskItem.getDescription().equals(holderTaskDesc);
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("task with title: " + taskItem.getTitle()
                    + " and description: " + taskItem.getDescription());
        }
    };
}
 
Example #3
Source Project: android-espresso-revealed   Author: Apress   File: RecyclerViewMatchers.java    License: Apache License 2.0 6 votes vote down vote up
public static Matcher<RecyclerView.ViewHolder> withTaskTitleFromTextView(final String taskTitle) {
    Checks.checkNotNull(taskTitle);

    return new BoundedMatcher<RecyclerView.ViewHolder, TasksFragment.TasksAdapter.ViewHolder>(
            TasksAdapter.ViewHolder.class) {
        @Override
        protected boolean matchesSafely(TasksAdapter.ViewHolder holder) {
            final TextView titleTextView = (TextView) holder.itemView.findViewById(R.id.title);
            return taskTitle.equals(titleTextView.getText().toString());
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("with task title: " + taskTitle);
        }
    };
}
 
Example #4
Source Project: BrainPhaser   Author: Kamshak   File: TestUtils.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static Matcher<View> atPosition(final int position, @NonNull final Matcher<View> itemMatcher) {
    checkNotNull(itemMatcher);
    return new BoundedMatcher<View, RecyclerView>(RecyclerView.class) {
        @Override
        public void describeTo(Description description) {
            description.appendText("has item at position " + position + ": ");
            itemMatcher.describeTo(description);
        }

        @Override
        protected boolean matchesSafely(final RecyclerView view) {
            RecyclerView.ViewHolder viewHolder = view.findViewHolderForAdapterPosition(position);
            return viewHolder != null && itemMatcher.matches(viewHolder.itemView);
        }
    };
}
 
Example #5
Source Project: ProgressButton   Author: nihasKalam07   File: Utils.java    License: Apache License 2.0 6 votes vote down vote up
public static Matcher<View> withCompoundDrawable(final int resourceId) {
    return new BoundedMatcher<View, Button>(Button.class) {
        @Override
        public void describeTo(Description description) {
            description.appendText("has compound drawable resource " + resourceId);
        }

        @Override
        public boolean matchesSafely(Button textView) {
            for (Drawable drawable : textView.getCompoundDrawables()) {
                if (sameBitmap(textView.getContext(), drawable, resourceId)) {
                    return true;
                }
            }
            return false;
        }
    };
}
 
Example #6
Source Project: ChipsLayoutManager   Author: BelooS   File: RecyclerViewEspressoFactory.java    License: Apache License 2.0 6 votes vote down vote up
public static Matcher<View> atPosition(final int position, @NonNull final Matcher<View> itemMatcher) {
    checkNotNull(itemMatcher);
    return new BoundedMatcher<View, RecyclerView>(RecyclerView.class) {
        @Override
        public void describeTo(Description description) {
            description.appendText("has item at position " + position + ":\n");
            itemMatcher.describeTo(description);
        }

        @Override
        protected boolean matchesSafely(final RecyclerView view) {
            RecyclerView.ViewHolder viewHolder = view.findViewHolderForAdapterPosition(position);
            return viewHolder != null && itemMatcher.matches(viewHolder.itemView);
        }
    };
}
 
Example #7
Source Project: ChipsLayoutManager   Author: BelooS   File: RecyclerViewEspressoFactory.java    License: Apache License 2.0 6 votes vote down vote up
public static <T extends RecyclerView.ViewHolder> Matcher<View> atPosition(final int position, @NonNull final ViewHolderMatcher<T> itemMatcher) {
    checkNotNull(itemMatcher);
    return new BoundedMatcher<View, RecyclerView>(RecyclerView.class) {
        @Override
        public void describeTo(Description description) {
            description.appendText("has item at position " + position + ":\n");
            itemMatcher.describeTo(description);
        }

        @Override
        protected boolean matchesSafely(final RecyclerView view) {
            RecyclerView.ViewHolder viewHolder = view.findViewHolderForAdapterPosition(position);
            return viewHolder != null && itemMatcher.matches(viewHolder);
        }
    };
}
 
Example #8
Source Project: BreadcrumbsView   Author: VictorAlbertos   File: Helpers.java    License: Apache License 2.0 6 votes vote down vote up
private static Matcher<View> breadcrumbsMatcher(final Func func, final Matcher<Integer> expectedCount,
    final String msgDescription) {
  return new BoundedMatcher<View, BreadcrumbsView>(BreadcrumbsView.class) {
    @Override protected boolean matchesSafely(BreadcrumbsView view) {
      int nDots = 0;
      for (int i = 0; i < view.getChildCount(); i++) {
        View viewChild = view.getChildAt(i);
        if (viewChild.getTag() != null) {
          if (func.call((ViewGroup) viewChild)) nDots++;
        }
      }
      return expectedCount.matches(nDots);
    }

    @Override public void describeTo(Description description) {
      description.appendText(msgDescription);
      expectedCount.describeTo(description);
    }
  };
}
 
Example #9
Source Project: zulip-android   Author: zulip   File: Matchers.java    License: Apache License 2.0 6 votes vote down vote up
public static Matcher<RecyclerView.ViewHolder> withMessageHolder(final String text, final int textViewId) {
    return new BoundedMatcher<RecyclerView.ViewHolder, MessageHolder>(MessageHolder.class) {
        private boolean found = false;

        @Override
        public void describeTo(Description description) {
            description.appendText("No ViewHolder found with text: ");
        }

        @Override
        protected boolean matchesSafely(MessageHolder item) {
            if (found) return false;
            found = ((TextView) item.itemView.findViewById(textViewId)).getText().toString().matches(text);
            return found;
        }
    };
}
 
Example #10
Source Project: zulip-android   Author: zulip   File: Matchers.java    License: Apache License 2.0 6 votes vote down vote up
public static Matcher<RecyclerView.ViewHolder> withMessageHeaderHolder(final MessageType messageType) {
    return new BoundedMatcher<RecyclerView.ViewHolder, MessageHeaderParent.MessageHeaderHolder>(MessageHeaderParent.MessageHeaderHolder.class) {
        private boolean found = false;

        @Override
        public void describeTo(Description description) {
            description.appendText("No ViewHolder found with text: " + messageType.toString());
        }

        @Override
        protected boolean matchesSafely(MessageHeaderParent.MessageHeaderHolder item) {
            if (found) return false;
            MessageHeaderParent messageHeaderParent = item.onItemClickListener.getMessageHeaderParentAtPosition(item.getLayoutPosition());
            found = (messageType == messageHeaderParent.getMessageType());
            return found;
        }
    };
}
 
Example #11
Source Project: zulip-android   Author: zulip   File: LoginDevAuthTest.java    License: Apache License 2.0 6 votes vote down vote up
private Matcher<View> emailFilter() {

        return new BoundedMatcher<View, Button>(Button.class) {
            @Override
            public void describeTo(Description description) {
                description.appendText("ERROR");
            }

            @Override
            protected boolean matchesSafely(Button item) {
                if (!matchedBefore && item.getText().toString().contains("@")) {
                    EMAIL_TEST = item.getText().toString();
                    matchedBefore = true;
                    return true;
                }
                return false;
            }
        };
    }
 
Example #12
Source Project: aws-device-farm-sample-app-for-android   Author: aws-samples   File: RegularExpressionMatcher.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Matches a string to a specific pattern
 *
 * @param pattern regular expression
 * @return the matcher result
 */
public static Matcher<View> matchesPattern(final String pattern){
    checkNotNull(pattern);
    return new BoundedMatcher<View, TextView>(TextView.class) {
        @Override
        public void describeTo(final Description description) {
            description.appendText("The textview does not conform to the pattern: ")
                    .appendText(pattern);
        }

        @Override
        protected boolean matchesSafely(TextView textView) {
            return textView.getText().toString().matches(pattern);
        }
    };
}
 
Example #13
Source Project: friendspell   Author: chiuki   File: CustomMatchers.java    License: Apache License 2.0 6 votes vote down vote up
public static Matcher<View> withColors(final int... colors) {
  return new BoundedMatcher<View, TextView>(TextView.class) {
    @Override public boolean matchesSafely(TextView textView) {
      SpannedString text = (SpannedString) textView.getText();
      ForegroundColorSpan[] spans = text.getSpans(0, text.length(), ForegroundColorSpan.class);
      if (spans.length != colors.length) {
        return false;
      }
      for (int i = 0; i < colors.length; ++i) {
        if (spans[i].getForegroundColor() != colors[i]) {
          return false;
        }
      }
      return true;
    }
    @Override public void describeTo(Description description) {
      description.appendText("has colors:");
      for (int color : colors) {
        description.appendText(" " + getHexColor(color));
      }
    }
  };
}
 
Example #14
Source Project: testing-cin   Author: damorim   File: HintMatcher.java    License: MIT License 6 votes vote down vote up
static Matcher<View> withHint(final Matcher<String> stringMatcher) {
    checkNotNull(stringMatcher);
    return new BoundedMatcher<View, EditText>(EditText.class) {

        @Override
        public boolean matchesSafely(EditText view) {
            final CharSequence hint = view.getHint();
            return hint != null && stringMatcher.matches(hint.toString());
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("with hint: ");
            stringMatcher.describeTo(description);
        }
    };
}
 
Example #15
Source Project: android-espresso-revealed   Author: Apress   File: CustomViewMatchers.java    License: Apache License 2.0 5 votes vote down vote up
public static Matcher<View> todoWithTitle(final String expectedTitle) {
    return new BoundedMatcher<View, LinearLayout>(LinearLayout.class) {

        @Override
        protected boolean matchesSafely(LinearLayout linearLayout) {
            TextView textView = linearLayout.findViewById(R.id.todo_title);
            return expectedTitle.equals(textView.getText().toString());
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("with TO-DO title: " + expectedTitle);
        }
    };
}
 
Example #16
Source Project: android-espresso-revealed   Author: Apress   File: CustomViewMatchers.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Matches EditText hint by specific text color.
 * @param expectedColor - expected color code
 * @return {@link Matcher<View>}
 */
public static Matcher<View> withHintColor(final int expectedColor) {
    return new BoundedMatcher<View, EditText>(EditText.class) {

        @Override
        protected boolean matchesSafely(EditText editText) {
            return expectedColor == editText.getCurrentHintTextColor();
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("expected with hint color: " + expectedColor);
        }
    };
}
 
Example #17
Source Project: BrainPhaser   Author: Kamshak   File: CategorySelectionTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Matches a view Holder whose title is catName
 *
 * @param catName category name that should be the viewHolders title.
 * @return created matcher
 */
public static Matcher<RecyclerView.ViewHolder> categoryVH(final String catName) {
    return new BoundedMatcher<RecyclerView.ViewHolder, CategoryViewHolder>(CategoryViewHolder.class) {
        @Override
        public void describeTo(Description description) {
            description.appendText("category title is " + catName);
        }

        @Override
        protected boolean matchesSafely(CategoryViewHolder item) {
            return item.getTitle().getText().equals(catName);
        }
    };
}
 
Example #18
Source Project: Villains-and-Heroes   Author: andremion   File: CustomMatchers.java    License: Apache License 2.0 5 votes vote down vote up
public static Matcher<View> withToolbarLayoutTitle(final Matcher<String> textMatcher) {
    return new BoundedMatcher<View, CollapsingToolbarLayout>(CollapsingToolbarLayout.class) {
        @Override
        public void describeTo(Description description) {
            description.appendText("with toolbar layout title: ");
            textMatcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(CollapsingToolbarLayout toolbarLayout) {
            //noinspection ConstantConditions
            return textMatcher.matches(toolbarLayout.getTitle());
        }
    };
}
 
Example #19
Source Project: redux-android-sample   Author: Catbag   File: Matchers.java    License: Apache License 2.0 5 votes vote down vote up
public static Matcher<View> withBGColor(final int color) {
    Checks.checkNotNull(color);
    return new BoundedMatcher<View, View>(View.class) {
        @Override
        public boolean matchesSafely(View view) {
            int currentColor = ((ColorDrawable) view.getBackground()).getColor();
            return color == currentColor;
        }
        @Override
        public void describeTo(Description description) {
            description.appendText("with background color: " + color);
        }
    };
}
 
Example #20
Source Project: redux-android-sample   Author: Catbag   File: Matchers.java    License: Apache License 2.0 5 votes vote down vote up
public static Matcher<View> withPlayingGifDrawable() {
    return new BoundedMatcher<View, View>(View.class) {
        @Override
        public boolean matchesSafely(View view) {
            GifImageView gifImageView = (GifImageView) view.findViewById(R.id.gif_image);
            return ((GifDrawable) gifImageView.getDrawable()).isPlaying();
        }
        @Override
        public void describeTo(Description description) {
            description.appendText("with gif image view playing");
        }
    };
}
 
Example #21
Source Project: redux-android-sample   Author: Catbag   File: Matchers.java    License: Apache License 2.0 5 votes vote down vote up
public static Matcher<View> withEqualsGifUuid(final String uuid) {
    return new BoundedMatcher<View, View>(View.class) {
        @Override
        public boolean matchesSafely(View view) {
            GifView gifView = (GifView) ((FrameLayout) view).getChildAt(0);
            return gifView.getGif().getUuid().equals(uuid);
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("with equals Gif UUID");
        }
    };
}
 
Example #22
Source Project: redux-android-sample   Author: Catbag   File: Matchers.java    License: Apache License 2.0 5 votes vote down vote up
public static Matcher<View> withGifDrawable() {
    return new BoundedMatcher<View, View>(View.class) {
        @Override
        public boolean matchesSafely(View view) {
            GifImageView gifImageView = (GifImageView) view.findViewById(R.id.gif_image);
            return gifImageView.getDrawable() != null;
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("with a not null drawable");
        }
    };
}
 
Example #23
Source Project: KataSuperHeroesAndroid   Author: Karumi   File: ToolbarMatcher.java    License: Apache License 2.0 5 votes vote down vote up
private static Matcher<Object> withToolbarTitle(final Matcher<CharSequence> textMatcher) {
  return new BoundedMatcher<Object, Toolbar>(Toolbar.class) {
    @Override public boolean matchesSafely(Toolbar toolbar) {
      return textMatcher.matches(toolbar.getTitle());
    }

    @Override public void describeTo(Description description) {
      description.appendText("with toolbar title: ");
      textMatcher.describeTo(description);
    }
  };
}
 
Example #24
Source Project: Game-of-Thrones   Author: tonilopezmr   File: ImageViewHasDrawableMatcher.java    License: Apache License 2.0 5 votes vote down vote up
public static BoundedMatcher<View, ImageView> hasDrawable() {
  return new BoundedMatcher<View, ImageView>(ImageView.class) {
    @Override
    public void describeTo(Description description) {
      description.appendText("has drawable");
    }

    @Override
    public boolean matchesSafely(ImageView imageView) {
      return imageView.getDrawable() != null;
    }
  };
}
 
Example #25
Source Project: Scoops   Author: 52inc   File: TestUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static Matcher<View> withTextColor(final int color) {
    Checks.checkNotNull(color);
    return new BoundedMatcher<View, TextView>(TextView.class) {
        @Override
        public boolean matchesSafely(TextView warning) {
            return color == warning.getCurrentTextColor();
        }
        @Override
        public void describeTo(Description description) {
            description.appendText("with text color: ");
        }
    };
}
 
Example #26
Source Project: daggerless-di-testing   Author: chiuki   File: CustomViewMatchers.java    License: Apache License 2.0 5 votes vote down vote up
public static Matcher<View> withTextColor(@ColorInt final int color) {
  return new BoundedMatcher<View, TextView>(TextView.class) {
    @Override public void describeTo(Description description) {
      description.appendText("has text color " + String.format("#%06X", (0xFFFFFF & color)));
    }
    @Override public boolean matchesSafely(TextView textView) {
      Log.e("chiuki", String.format("#%06X", (0xFFFFFF & textView.getCurrentTextColor())));
      return textView.getCurrentTextColor() == color;
    }
  };
}
 
Example #27
Source Project: Wiggle   Author: kubode   File: MyMatchers.java    License: Apache License 2.0 5 votes vote down vote up
public static Matcher<View> withLastNon0TranslationY(final Matcher<Float> lastNon0TranslationYMatcher) {
    return new BoundedMatcher<View, MockView>(MockView.class) {
        @Override
        public void describeTo(Description description) {
            description.appendText("with lastTranslationY: ");
            lastNon0TranslationYMatcher.describeTo(description);
        }

        @Override
        protected boolean matchesSafely(MockView view) {
            return lastNon0TranslationYMatcher.matches(view.getLastNon0TranslationY());
        }
    };
}
 
Example #28
Source Project: zulip-android   Author: zulip   File: Matchers.java    License: Apache License 2.0 5 votes vote down vote up
public static Matcher<RecyclerView.ViewHolder> withMessageHolderAndClick(final MessageType messageType, final int id) {
    return new BoundedMatcher<RecyclerView.ViewHolder, MessageHolder>(MessageHolder.class) {
        private boolean found = false;

        @Override
        public void describeTo(Description description) {
            description.appendText("No ViewHolder found with text: " + messageType.toString());
        }

        @Override
        protected boolean matchesSafely(MessageHolder item) {
            if (found) return false;
            if (item.getLayoutPosition() < 0) return false;
            Message message = item.onItemClickListener.getMessageAtPosition(item.getLayoutPosition());
            if (message == null) return false;
            if (messageType == message.getType()) {
                if (id == R.id.contentView) {
                    item.onItemClickListener.onItemClick(R.id.contentView, item.getLayoutPosition());
                }
                found = true;
                return true;
            } else {
                return false;
            }
        }
    };
}
 
Example #29
Source Project: twitter-kit-android   Author: twitter-archive   File: TweetAsserts.java    License: Apache License 2.0 5 votes vote down vote up
public static Matcher<View> hasCompoundDrawable(final int start, final int top,
                                                     final int end, final int bottom) {
    return new BoundedMatcher<View, TextView>(TextView.class){
        @Override
        public void describeTo(Description description) {
            final String formatted =
                    String.format(Locale.getDefault(),
                            "has Compound Drawable: start=%d, top=%d, end=%d, bottom=%d",
                            start, top, end, bottom);
            description.appendText(formatted);
        }

        @Override
        public boolean matchesSafely(TextView view) {
            // We cannot verify the actual drawable, but we can verify one has been set.
            final Drawable [] drawables = view.getCompoundDrawables();
            if (drawables[0] != null && start == 0) {
                return false;
            }
            if (drawables[1] != null && top == 0) {
                return false;
            }
            if (drawables[2] != null && end == 0) {
                return false;
            }
            if (drawables[3] != null && bottom == 0) {
                return false;
            }

            return true;
        }
    };
}
 
Example #30
Source Project: espresso-cucumber   Author: sebaslogen   File: NavInputFieldMatchers.java    License: Apache License 2.0 5 votes vote down vote up
public static Matcher<View> withNormalState() {
    return new BoundedMatcher<View, StockInputField>(StockInputField.class) {
        @Override
        public boolean matchesSafely(final StockInputField inputField) {
            final InputFieldMode inputMode = inputField.getModel().getEnum(Attributes.INPUT_MODE);

            return InputFieldMode.NORMAL.equals(inputMode);
        }

        @Override
        public void describeTo(final Description description) {
            description.appendText("with normal state");
        }
    };
}