private Matcher<? super List<HttpHeaderValue>> containsWithValue(final String value) { return new CustomTypeSafeMatcher<List<HttpHeaderValue>>("contains with value:" + value) { @Override protected boolean matchesSafely(List<HttpHeaderValue> list) { return any(list, new Predicate<HttpHeaderValue>() { @Override public boolean apply(@Nullable HttpHeaderValue httpHeaderValue) { return httpHeaderValue.getValue().equals(value); } }); } }; }
private RelativeMatcher(Matcher<View> target, DoublePredicate<View> predicate, String description, Type type) { mTarget = target; mTargetPredicate = new Predicate<View>() { @Override public boolean apply(@Nullable View view) { return mTarget.matches(view); } }; mPredicate = predicate; mDescription = description; mType = type; }
@Override public boolean matchesSafely(final View testView) { if (!mTargetPredicate.apply(testView)) return false; Predicate<View> pred = new Predicate<View>() { @Override public boolean apply(@Nullable View targetView) { return mPredicate.apply(testView, targetView); } }; Iterable<View> traversal = Iterables.filter(breadthFirstViewTraversal(testView.getRootView()), new Predicate<View>() { @Override public boolean apply(@Nullable View input) { return input != testView && mTargetPredicate.apply(input); } }); if (Iterables.isEmpty(traversal)) { throw new NoMatchingViewException.Builder().withViewMatcher(mTarget).build(); // TODO: build an actual err msg } switch (mType) { case ANY: return Iterables.any(traversal, pred); case ALL: return Iterables.all(traversal, pred); case NONE: return !Iterables.any(traversal, pred); default: throw new IllegalStateException("impossible mType"); } }