本文整理汇总了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));
}
};
}
示例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);
}
};
}
示例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());
}
};
}
示例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));
}
};
}
示例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));
}
};
}
示例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;
}
};
}
示例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);
}
};
}
示例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();
}
};
}
示例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;
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
}