UiObjectMatcher { public UiObject getUiObject(UiDevice device) { return device.findObject(getUiSelector()); } UiObjectMatcher(UiSelector uiSelector, BySelector bySelector); static UiObjectMatcher withTextStartingWith(String text); static UiObjectMatcher withTextStartingWith(String text, Class klass); static UiObjectMatcher withTextContaining(String text); static UiObjectMatcher withTextContaining(String text, Class klass); static UiObjectMatcher withText(String text); static UiObjectMatcher withText(String text, Class klass); static UiObjectMatcher withContentDescription(String text); static UiObjectMatcher withContentDescription(String text, Class klass); static UiObjectMatcher withResourceId(String id); static UiObjectMatcher withResourceId(String id, Class klass); static UiObjectMatcher withClass(Class klass); UiObjectMatcher childMatcher(UiObjectMatcher childMatcher); UiObjectMatcher instance(int instance); UiSelector getUiSelector(); UiObject getUiObject(UiDevice device); BySelector getBySelector();  }
@Test public void getUiObject() { UiObject uiObject = mock(UiObject.class); UiDevice device = mock(UiDevice.class); when(device.findObject(any(UiSelector.class))).thenReturn(uiObject); UiObjectMatcher matcher = UiObjectMatcher.withClass(TextView.class); UiObject object = matcher.getUiObject(device); verify(device).findObject(matcher.getUiSelector()); assertEquals(uiObject, object); }