当前位置: 首页>>代码示例>>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;未经允许,请勿转载。