當前位置: 首頁>>代碼示例>>Java>>正文


Java Matcher.matches方法代碼示例

本文整理匯總了Java中org.hamcrest.Matcher.matches方法的典型用法代碼示例。如果您正苦於以下問題:Java Matcher.matches方法的具體用法?Java Matcher.matches怎麽用?Java Matcher.matches使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.hamcrest.Matcher的用法示例。


在下文中一共展示了Matcher.matches方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: childAtPosition

import org.hamcrest.Matcher; //導入方法依賴的package包/類
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));
        }
    };
}
 
開發者ID:charafau,項目名稱:TurboChat,代碼行數:19,代碼來源:ProfileActivityNavigationTest.java

示例2: hasHolderItem

import org.hamcrest.Matcher; //導入方法依賴的package包/類
@NonNull
public static ViewAssertion hasHolderItem(final Matcher<RecyclerView.ViewHolder> viewHolderMatcher) {
	return new ViewAssertion() {
		@Override public void check(View view, NoMatchingViewException e) {
			if (!(view instanceof RecyclerView)) {
				throw e;
			}

			boolean hasMatch = false;
			RecyclerView rv = (RecyclerView) view;
			for (int i = 0; i < rv.getChildCount(); i++) {
				RecyclerView.ViewHolder vh = rv.findViewHolderForAdapterPosition(i);
				hasMatch |= viewHolderMatcher.matches(vh);
			}
			Assert.assertTrue(hasMatch);
		}
	};
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:ConnectbotMatchers.java

示例3: withCollapsingToolbarTitle

import org.hamcrest.Matcher; //導入方法依賴的package包/類
private static Matcher<Object> withCollapsingToolbarTitle(
        final Matcher<CharSequence> textMatcher) {
    return new BoundedMatcher<Object, CollapsingToolbarLayout>(CollapsingToolbarLayout.class) {

        @Override
        public void describeTo(Description description) {
            description.appendText("with collapsing toolbar title: ");
            textMatcher.describeTo(description);
        }

        @Override
        protected boolean matchesSafely(CollapsingToolbarLayout collapsingToolbarLayout) {
            return textMatcher.matches(collapsingToolbarLayout.getTitle());
        }

    };
}
 
開發者ID:ecarrara-araujo,項目名稱:yabaking,代碼行數:18,代碼來源:ToolbarMatchers.java

示例4: childAtPosition

import org.hamcrest.Matcher; //導入方法依賴的package包/類
private static Matcher<View> childAtPosition(
        final Matcher<View> parentMatcher, @SuppressWarnings("SameParameterValue") 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));
        }
    };
}
 
開發者ID:orionlee,項目名稱:aDictOnCopy,代碼行數:19,代碼來源:MainActivityTest.java

示例5: isNthChildOf

import org.hamcrest.Matcher; //導入方法依賴的package包/類
/**
 * Returns a matcher that matches a {@link View} that is a child of the described parent
 * at the specified index.
 *
 * @param parentMatcher A matcher that describes the view's parent.
 * @param childIndex The index of the view at which it is a child of the described parent.
 */
private static Matcher<View> isNthChildOf(final Matcher<View> parentMatcher, final int childIndex) {
    return new TypeSafeMatcher<View>() {
        @Override
        public void describeTo(Description description) {
            description.appendText("is child at index "+childIndex+" of view matched by parentMatcher: ");
            parentMatcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(View view) {
            ViewGroup parent = (ViewGroup) view.getParent();
            return parentMatcher.matches(parent) && view.equals(parent.getChildAt(childIndex));
        }
    };
}
 
開發者ID:philliphsu,項目名稱:NumberPadTimePicker,代碼行數:23,代碼來源:NumberPadTimePickerDialogTest.java

示例6: withIndex

import org.hamcrest.Matcher; //導入方法依賴的package包/類
public static Matcher<View> withIndex(final Matcher<View> matcher, final int index) {
    return new TypeSafeMatcher<View>() {
        int currentIndex = 0;

        @Override
        public void describeTo(Description description) {
            description.appendText("with index: ");
            description.appendValue(index);
            matcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(View view) {
            return matcher.matches(view) && currentIndex++ == index;
        }
    };
}
 
開發者ID:cuplv,項目名稱:ChimpCheck,代碼行數:18,代碼來源:MatchWithIndex.java

示例7: hasMessage

import org.hamcrest.Matcher; //導入方法依賴的package包/類
@Factory
public static Matcher<Throwable> hasMessage(final Matcher<String> matcher) {
    return new BaseMatcher<Throwable>() {
        public boolean matches(Object o) {
            Throwable t = (Throwable) o;
            return matcher.matches(t.getMessage());
        }

        public void describeTo(Description description) {
            description.appendText("an exception with message that is ").appendDescriptionOf(matcher);
        }
    };
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:14,代碼來源:Matchers.java

示例8: waitForMatch

import org.hamcrest.Matcher; //導入方法依賴的package包/類
public static ViewAction waitForMatch(final Matcher<View> aViewMatcher, final long timeout) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return isRoot();
        }

        @Override
        public String getDescription() {
            return "Waiting for view matching " + aViewMatcher;
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();

            final long startTime = System.currentTimeMillis();
            final long endTime = startTime + timeout;

            do {
                for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
                    if (aViewMatcher.matches(child)) {
                        // found
                        return;
                    }
                }


                uiController.loopMainThreadForAtLeast(50);
            } while (System.currentTimeMillis() < endTime);

            //The action has timed out.
            throw new PerformException.Builder()
                    .withActionDescription(getDescription())
                    .withViewDescription("")
                    .withCause(new TimeoutException())
                    .build();
        }
    };
}
 
開發者ID:IrrilevantHappyLlamas,項目名稱:Runnest,代碼行數:41,代碼來源:EspressoTest.java

示例9: propertyMatches

import org.hamcrest.Matcher; //導入方法依賴的package包/類
protected boolean propertyMatches(String propertyName, T propertyValue, Matcher<? super T> matcher, Description description) {
  if (matcher == null) {
    return true;
  }
  if (matcher.matches(propertyValue)) {
    return true;
  }
  newline(description).appendText(propertyName).appendText(": ");
  indent();
  matcher.describeMismatch(propertyValue, description);
  outdent();
  return false;
}
 
開發者ID:poetix,項目名稱:fluvius,代碼行數:14,代碼來源:BasePropertyMatcher.java

示例10: testValidJsonBooleanValidates

import org.hamcrest.Matcher; //導入方法依賴的package包/類
@Test
public void testValidJsonBooleanValidates() {
	Matcher<JsonElement> matcher = aJsonBoolean(true);

	JsonPrimitive jsonPrimitive = new JsonPrimitive(true);

	boolean matches = matcher.matches(jsonPrimitive);

	assertThat(matches, is(true));
}
 
開發者ID:liferay,項目名稱:com-liferay-apio-architect,代碼行數:11,代碼來源:IsJsonBooleanMatcherTest.java

示例11: testValidJsonTextValidates

import org.hamcrest.Matcher; //導入方法依賴的package包/類
@Test
public void testValidJsonTextValidates() {
	Matcher<JsonElement> matcher = aJsonString(equalTo("Live long"));

	JsonPrimitive jsonPrimitive = new JsonPrimitive("Live long");

	boolean matches = matcher.matches(jsonPrimitive);

	assertThat(matches, is(true));
}
 
開發者ID:liferay,項目名稱:com-liferay-apio-architect,代碼行數:11,代碼來源:IsJsonStringMatcherTest.java

示例12: testValidJsonLongValidates

import org.hamcrest.Matcher; //導入方法依賴的package包/類
@Test
public void testValidJsonLongValidates() {
	Matcher<JsonElement> matcher = aJsonLong(equalTo(42L));

	JsonPrimitive jsonPrimitive = new JsonPrimitive(42L);

	boolean matches = matcher.matches(jsonPrimitive);

	assertThat(matches, is(true));
}
 
開發者ID:liferay,項目名稱:com-liferay-apio-architect,代碼行數:11,代碼來源:IsJsonLongMatcherTest.java

示例13: no

import org.hamcrest.Matcher; //導入方法依賴的package包/類
/**
 * Require `actual` **NOT** satisfied the condition specified by `matcher`. Otherwise
 * an {@link AssertionError} is thrown with the reason string and information
 * about the matcher and failing value. Example:
 *
 * ```
 * int n = 0;
 * no(n, is(1)) // passes
 * no(n, is(0), "Help! Integers don't work"); // fails:
 * // failure message:
 * // Help! Integers don't work
 * // expected: not is <0>
 * // got value: <0>
 * ```
 * @param actual the computed value being compared
 * @param matcher an expression, built of {@link Matcher}s, specifying disallowed values
 * @param message
 *              additional information about the error
 * @param messageArgs
 *              message arguments
 * @param <T>
 *              the static type accepted by the matcher (this can flag obvious
 *              compile-time problems such as `no(1, is("a"))`
 *
 * @see org.hamcrest.CoreMatchers
 * @see org.junit.matchers.JUnitMatchers
 */
public static <T> void no(T actual, Matcher<T> matcher, String message, Object... messageArgs) {
    if (matcher.matches(actual)) {
        assertThat(fmt(message, messageArgs), actual, not(matcher));
    }
}
 
開發者ID:osglworks,項目名稱:java-unit,代碼行數:33,代碼來源:TestBase.java


注:本文中的org.hamcrest.Matcher.matches方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。