use of com.google.android.apps.common.testing.ui.espresso.NoMatchingViewException in project double-espresso by JakeWharton.
the class ViewFinderImplTest method testGetView_missing.
@UiThreadTest
public void testGetView_missing() {
ViewFinder finder = new ViewFinderImpl(Matchers.<View>nullValue(), testViewProvider);
try {
finder.getView();
fail("No children should pass that matcher!");
} catch (NoMatchingViewException expected) {
}
}
use of com.google.android.apps.common.testing.ui.espresso.NoMatchingViewException in project double-espresso by JakeWharton.
the class DefaultFailureHandlerTest method testCustomAssertionError.
public void testCustomAssertionError() {
try {
onView(isRoot()).check(new ViewAssertion() {
@Override
public void check(Optional<View> view, Optional<NoMatchingViewException> noViewFoundException) {
assertFalse(true);
}
});
fail("Previous call expected to fail");
} catch (AssertionFailedError e) {
assertFailureStackContainsThisClass(e);
}
}
use of com.google.android.apps.common.testing.ui.espresso.NoMatchingViewException in project double-espresso by JakeWharton.
the class ViewFinderImpl method getView.
@Override
public View getView() throws AmbiguousViewMatcherException, NoMatchingViewException {
checkMainThread();
final Predicate<View> matcherPredicate = new MatcherPredicateAdapter<View>(checkNotNull(viewMatcher));
View root = rootViewProvider.get();
Iterator<View> matchedViewIterator = Iterables.filter(breadthFirstViewTraversal(root), matcherPredicate).iterator();
View matchedView = null;
while (matchedViewIterator.hasNext()) {
if (matchedView != null) {
// Ambiguous!
throw new AmbiguousViewMatcherException.Builder().withViewMatcher(viewMatcher).withRootView(root).withView1(matchedView).withView2(matchedViewIterator.next()).withOtherAmbiguousViews(Iterators.toArray(matchedViewIterator, View.class)).build();
} else {
matchedView = matchedViewIterator.next();
}
}
if (null == matchedView) {
final Predicate<View> adapterViewPredicate = new MatcherPredicateAdapter<View>(ViewMatchers.isAssignableFrom(AdapterView.class));
List<View> adapterViews = Lists.newArrayList(Iterables.filter(breadthFirstViewTraversal(root), adapterViewPredicate).iterator());
if (adapterViews.isEmpty()) {
throw new NoMatchingViewException.Builder().withViewMatcher(viewMatcher).withRootView(root).build();
}
String warning = String.format("\nIf the target view is not part of the view hierarchy, you " + "may need to use Espresso.onData to load it from one of the following AdapterViews:%s", Joiner.on("\n- ").join(adapterViews));
throw new NoMatchingViewException.Builder().withViewMatcher(viewMatcher).withRootView(root).withAdapterViews(adapterViews).withAdapterViewWarning(Optional.of(warning)).build();
} else {
return matchedView;
}
}
Aggregations