use of org.hamcrest.TypeSafeMatcher in project double-espresso by JakeWharton.
the class ViewMatchers method hasImeAction.
/**
* Returns a matcher that matches views that support input methods (e.g. EditText) and have the
* specified IME action set in its {@link EditorInfo}.
*
* @param imeActionMatcher a matcher for the IME action
*/
public static Matcher<View> hasImeAction(final Matcher<Integer> imeActionMatcher) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("has ime action: ");
imeActionMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
EditorInfo editorInfo = new EditorInfo();
InputConnection inputConnection = view.onCreateInputConnection(editorInfo);
if (inputConnection == null) {
return false;
}
int actionId = editorInfo.actionId != 0 ? editorInfo.actionId : editorInfo.imeOptions & EditorInfo.IME_MASK_ACTION;
return imeActionMatcher.matches(actionId);
}
};
}
use of org.hamcrest.TypeSafeMatcher in project double-espresso by JakeWharton.
the class ViewMatchers method isDisplayingAtLeast.
/**
* Returns a matcher which accepts a view so long as a given percentage of that view's area is
* not obscured by any other view and is thus visible to the user.
*
* @param areaPercentage an integer ranging from (0, 100] indicating how much percent of the
* surface area of the view must be shown to the user to be accepted.
*/
public static Matcher<View> isDisplayingAtLeast(final int areaPercentage) {
checkState(areaPercentage <= 100, "Cannot have over 100 percent: %s", areaPercentage);
checkState(areaPercentage > 0, "Must have a positive, non-zero value: %s", areaPercentage);
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText(String.format("at least %s percent of the view's area is displayed to the user.", areaPercentage));
}
@Override
public boolean matchesSafely(View view) {
Rect visibleParts = new Rect();
boolean visibleAtAll = view.getGlobalVisibleRect(visibleParts);
if (!visibleAtAll) {
return false;
}
double maxArea = view.getHeight() * view.getWidth();
double visibleArea = visibleParts.height() * visibleParts.width();
int displayedPercentage = (int) ((visibleArea / maxArea) * 100);
return displayedPercentage >= areaPercentage && withEffectiveVisibility(Visibility.VISIBLE).matches(view);
}
};
}
use of org.hamcrest.TypeSafeMatcher in project chefly_android by chef-ly.
the class FavoriteNavgationTest method childAtPosition.
private static Matcher<View> childAtPosition(final Matcher<View> parentMatcher, final int position) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("Child at position " + position + " in parent ");
parentMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent) && view.equals(((ViewGroup) parent).getChildAt(position));
}
};
}
use of org.hamcrest.TypeSafeMatcher in project chefly_android by chef-ly.
the class ShoppinListTest method childAtPosition.
private static Matcher<View> childAtPosition(final Matcher<View> parentMatcher, final int position) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("Child at position " + position + " in parent ");
parentMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent) && view.equals(((ViewGroup) parent).getChildAt(position));
}
};
}
use of org.hamcrest.TypeSafeMatcher in project beam by apache.
the class BatchDataflowWorkerTest method testWhenNoWorkIsReturnedThatWeImmediatelyRetry.
@Test
public void testWhenNoWorkIsReturnedThatWeImmediatelyRetry() throws Exception {
final String workItemId = "14";
BatchDataflowWorker worker = new BatchDataflowWorker(null, /* pipeline */
SdkHarnessRegistries.emptySdkHarnessRegistry(), mockWorkUnitClient, IntrinsicMapTaskExecutorFactory.defaultFactory(), options);
WorkItem workItem = new WorkItem();
workItem.setId(Long.parseLong(workItemId));
workItem.setJobId("SuccessfulEmptyMapTask");
workItem.setInitialReportIndex(12L);
workItem.setMapTask(new MapTask().setInstructions(new ArrayList<ParallelInstruction>()).setStageName("testStage"));
workItem.setLeaseExpireTime(TimeUtil.toCloudTime(Instant.now()));
workItem.setReportStatusInterval(TimeUtil.toCloudDuration(Duration.standardMinutes(1)));
when(mockWorkUnitClient.getWorkItem()).thenReturn(Optional.<WorkItem>absent()).thenReturn(Optional.of(workItem));
assertTrue(worker.getAndPerformWork());
verify(mockWorkUnitClient).reportWorkItemStatus(MockitoHamcrest.argThat(new TypeSafeMatcher<WorkItemStatus>() {
@Override
public void describeTo(Description description) {
}
@Override
protected boolean matchesSafely(WorkItemStatus item) {
assertTrue(item.getCompleted());
assertEquals(workItemId, item.getWorkItemId());
return true;
}
}));
}
Aggregations