Search in sources :

Example 31 with TypeSafeMatcher

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);
        }
    };
}
Also used : InputConnection(android.view.inputmethod.InputConnection) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) EditorInfo(android.view.inputmethod.EditorInfo) TextView(android.widget.TextView) View(android.view.View)

Example 32 with TypeSafeMatcher

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);
        }
    };
}
Also used : Rect(android.graphics.Rect) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) TextView(android.widget.TextView) View(android.view.View)

Example 33 with TypeSafeMatcher

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));
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ViewMatchers.withContentDescription(android.support.test.espresso.matcher.ViewMatchers.withContentDescription) ViewParent(android.view.ViewParent) ViewGroup(android.view.ViewGroup) Espresso.onView(android.support.test.espresso.Espresso.onView) View(android.view.View)

Example 34 with TypeSafeMatcher

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));
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ViewMatchers.withContentDescription(android.support.test.espresso.matcher.ViewMatchers.withContentDescription) ViewParent(android.view.ViewParent) ViewGroup(android.view.ViewGroup) View(android.view.View) Espresso.onView(android.support.test.espresso.Espresso.onView)

Example 35 with TypeSafeMatcher

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;
        }
    }));
}
Also used : ParallelInstruction(com.google.api.services.dataflow.model.ParallelInstruction) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) WorkItemStatus(com.google.api.services.dataflow.model.WorkItemStatus) MapTask(com.google.api.services.dataflow.model.MapTask) WorkItem(com.google.api.services.dataflow.model.WorkItem) Test(org.junit.Test)

Aggregations

TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)82 Description (org.hamcrest.Description)79 View (android.view.View)44 ViewParent (android.view.ViewParent)33 ViewGroup (android.view.ViewGroup)30 Espresso.onView (android.support.test.espresso.Espresso.onView)25 TextView (android.widget.TextView)9 Test (org.junit.Test)9 ViewMatchers.withContentDescription (android.support.test.espresso.matcher.ViewMatchers.withContentDescription)7 JsonNode (org.codehaus.jackson.JsonNode)6 JsonParseException (org.neo4j.server.rest.domain.JsonParseException)6 HTTP (org.neo4j.test.server.HTTP)6 Resources (android.content.res.Resources)5 StringDescription (org.hamcrest.StringDescription)5 AdapterView (android.widget.AdapterView)4 RecyclerView (android.support.v7.widget.RecyclerView)3 Adapter (android.widget.Adapter)3 Espresso.onView (com.google.android.apps.common.testing.ui.espresso.Espresso.onView)3 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3