本文整理匯總了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);
}