本文整理汇总了Java中org.hamcrest.Matcher类的典型用法代码示例。如果您正苦于以下问题:Java Matcher类的具体用法?Java Matcher怎么用?Java Matcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Matcher类属于org.hamcrest包,在下文中一共展示了Matcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clickNoConstraints
import org.hamcrest.Matcher; //导入依赖的package包/类
static ViewAction clickNoConstraints() {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isEnabled(); // No constraints, isEnabled and isClickable are checked
}
@Override
public String getDescription() {
return "Click a view with no constraints.";
}
@Override
public void perform(UiController uiController, View view) {
view.performClick();
}
};
}
示例2: testInvokingAddConsumerCreatesAValidJsonArray
import org.hamcrest.Matcher; //导入依赖的package包/类
@Test
public void testInvokingAddConsumerCreatesAValidJsonArray() {
_jsonObjectBuilder.field(
"array"
).arrayValue(
).add(
jsonObjectBuilder -> jsonObjectBuilder.field(
"solution"
).numberValue(
42
)
);
@SuppressWarnings("unchecked")
Matcher<JsonElement> isAJsonArrayWithElements = is(
aJsonArrayThat(contains(_aJsonObjectWithTheSolution)));
Matcher<JsonElement> isAJsonObjectWithAnArray = is(
aJsonObjectWhere("array", isAJsonArrayWithElements));
assertThat(getJsonObject(), isAJsonObjectWithAnArray);
}
示例3: withIndex
import org.hamcrest.Matcher; //导入依赖的package包/类
private 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;
}
};
}
示例4: showControls
import org.hamcrest.Matcher; //导入依赖的package包/类
private static ViewAction showControls() {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isAssignableFrom(MovieView.class);
}
@Override
public String getDescription() {
return "Show controls of MovieView";
}
@Override
public void perform(UiController uiController, View view) {
uiController.loopMainThreadUntilIdle();
((MovieView) view).showControls();
uiController.loopMainThreadUntilIdle();
}
};
}
示例5: hasContent
import org.hamcrest.Matcher; //导入依赖的package包/类
public static Matcher<? super HttpResponse> hasContent(final String content, final String charset) {
return new BaseMatcher<HttpResponse>() {
public boolean matches(Object o) {
try {
HttpResponse response = (HttpResponse) o;
Reader reader = new InputStreamReader(response.getEntity().getContent(), charset);
int intValueOfChar;
String targetString = "";
while ((intValueOfChar = reader.read()) != -1) {
targetString += (char) intValueOfChar;
}
reader.close();
return targetString.equals(content);
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
public void describeTo(Description description) {
description.appendText(content);
}
};
}
示例6: 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));
}
};
}
示例7: withBackgroundColor
import org.hamcrest.Matcher; //导入依赖的package包/类
/**
* A customized {@link Matcher} for testing that
* if one color match the background color of current view.
* @param backgroundColor A color int value.
*
* @return Match or not.
*/
public static Matcher<View> withBackgroundColor(final int backgroundColor) {
return new TypeSafeMatcher<View>() {
@Override
public boolean matchesSafely(View view) {
int color = ((ColorDrawable) view.getBackground().getCurrent()).getColor();
return color == backgroundColor;
}
@Override
public void describeTo(Description description) {
description.appendText("with background color value: " + backgroundColor);
}
};
}
示例8: testGoToManual
import org.hamcrest.Matcher; //导入依赖的package包/类
/**
* Test if the manual input activity opens.
*/
@Test
public void testGoToManual() {
onView(withId(R.id.manual_input_button)).check(matches(allOf( isEnabled(), isClickable()))).perform(
new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isEnabled(); // no constraints, they are checked above
}
@Override
public String getDescription() {
return "click manual input button";
}
@Override
public void perform(UiController uiController, View view) {
view.performClick();
}
}
);
intended(hasComponent(ManualInputActivity.class.getName()));
}
示例9: hasBackgroundSpanOn
import org.hamcrest.Matcher; //导入依赖的package包/类
public static Matcher<View> hasBackgroundSpanOn(final String text, @ColorRes final int colorResource) {
return new CustomTypeSafeMatcher<View>("") {
@Override
protected boolean matchesSafely(View view) {
if (view == null || !(view instanceof TextView))
return false;
SpannableString spannableString = (SpannableString) ((TextView) view).getText();
BackgroundColorSpan[] spans = spannableString.getSpans(0, spannableString.length(), BackgroundColorSpan.class);
for (BackgroundColorSpan span : spans) {
int start = spannableString.getSpanStart(span);
int end = spannableString.getSpanEnd(span);
CharSequence highlightedString = spannableString.subSequence(start, end);
if (text.equals(highlightedString.toString())) {
return span.getBackgroundColor() == view.getContext().getResources().getColor(colorResource);
}
}
return false;
}
};
}
示例10: withinSecondsAfter
import org.hamcrest.Matcher; //导入依赖的package包/类
public static Matcher<String> withinSecondsAfter(Seconds seconds, DateTime after) {
return new TypeSafeMatcher<String>() {
@Override
public void describeTo(Description description) {
description.appendText(String.format(
"a date time within %s seconds after %s",
seconds.getSeconds(), after.toString()));
}
@Override
protected boolean matchesSafely(String textRepresentation) {
//response representation might vary from request representation
DateTime actual = DateTime.parse(textRepresentation);
return actual.isAfter(after) &&
Seconds.secondsBetween(after, actual).isLessThan(seconds);
}
};
}
示例11: childAtPosition
import org.hamcrest.Matcher; //导入依赖的package包/类
public 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));
}
};
}
示例12: used
import org.hamcrest.Matcher; //导入依赖的package包/类
private static Matcher<UsedJourneys> used(Journey journey) {
return new TypeSafeMatcher<UsedJourneys>() {
@Override
public void describeTo(Description description) {
description.appendText("used");
description.appendValue(journey);
}
@Override
protected boolean matchesSafely(UsedJourneys journeys) {
return journeys.used(journey);
}
@Override
protected void describeMismatchSafely(UsedJourneys item, Description mismatchDescription) {
mismatchDescription.appendText("not used");
mismatchDescription.appendValue(journey);
}
};
}
示例13: atPosition
import org.hamcrest.Matcher; //导入依赖的package包/类
public static Matcher<View> atPosition(final int position, final Matcher<View> itemMatcher) {
return new BoundedMatcher<View, RecyclerView>(RecyclerView.class) {
@Override
public void describeTo(Description description) {
description.appendText("has item at position " + position + ": ");
itemMatcher.describeTo(description);
}
@Override
protected boolean matchesSafely(final RecyclerView view) {
RecyclerView.ViewHolder viewHolder = view.findViewHolderForAdapterPosition(position);
if (viewHolder == null) {
return false;
}
return itemMatcher.matches(viewHolder.itemView);
}
};
}
示例14: isSameAs
import org.hamcrest.Matcher; //导入依赖的package包/类
public static Matcher<List<AuditLogEntry>> isSameAs(
final List<AuditLog> auditLogs) {
return new BaseMatcher<List<AuditLogEntry>>() {
private int errorPosition;
@Override
public boolean matches(Object object) {
List<AuditLogEntry> auditLogEntries = (List<AuditLogEntry>) object;
assertEquals(auditLogEntries.size(), auditLogs.size());
for (int i = 0; i < auditLogEntries.size(); i++) {
errorPosition = i;
compareAuditLogEntry(auditLogEntries.get(i),
auditLogs.get(i));
}
return true;
}
@Override
public void describeTo(Description description) {
description
.appendText("AuditLogEntry is not equal with AuditLog at position "
+ errorPosition);
}
};
}
示例15: view_withCondition_thenAnd_thenNot_doesNotImplementMatcher_implementsMatching
import org.hamcrest.Matcher; //导入依赖的package包/类
@Order(5)
@Test
public void view_withCondition_thenAnd_thenNot_doesNotImplementMatcher_implementsMatching() {
final Negated.Unfinished.And.Matcher matcher = Cortado.view().withText("test").and().not();
assertThat(matcher).isNotInstanceOf(org.hamcrest.Matcher.class);
assertThat(matcher).isInstanceOf(Matching.class);
}