下面列出了org.hamcrest.Description#appendDescriptionOf ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static Matcher<Uri> hasSchemeSpecificPart(
final Matcher<String> schemeMatcher, final Matcher<String> schemeSpecificPartMatcher) {
checkNotNull(schemeMatcher);
checkNotNull(schemeSpecificPartMatcher);
return new TypeSafeMatcher<Uri>() {
@Override
public boolean matchesSafely(Uri uri) {
return schemeMatcher.matches(uri.getScheme())
&& schemeSpecificPartMatcher.matches(uri.getSchemeSpecificPart());
}
@Override
public void describeTo(Description description) {
description.appendText("has scheme specific part: scheme: ");
description.appendDescriptionOf(schemeMatcher);
description.appendText(" scheme specific part: ");
description.appendDescriptionOf(schemeSpecificPartMatcher);
}
};
}
public static Matcher<Intent> hasAction(final Matcher<String> actionMatcher) {
checkNotNull(actionMatcher);
return new TypeSafeMatcher<Intent>() {
@Override
public void describeTo(Description description) {
description.appendText("has action: ");
description.appendDescriptionOf(actionMatcher);
}
@Override
public boolean matchesSafely(Intent intent) {
return actionMatcher.matches(intent.getAction());
}
};
}
/**
* Can match an intent by class name, package name or short class name.
*
* @param componentMatcher can be the value of {@link ComponentNameMatchers#hasClassName}, {@link
* ComponentNameMatchers#hasPackageName} or {@link ComponentNameMatchers#hasShortClassName}
*/
public static Matcher<Intent> hasComponent(final Matcher<ComponentName> componentMatcher) {
checkNotNull(componentMatcher);
return new TypeSafeMatcher<Intent>() {
@Override
public void describeTo(Description description) {
description.appendText("has component: ");
description.appendDescriptionOf(componentMatcher);
}
@Override
public boolean matchesSafely(Intent intent) {
return componentMatcher.matches(intent.getComponent());
}
};
}
public static Matcher<Intent> hasExtras(final Matcher<Bundle> bundleMatcher) {
checkNotNull(bundleMatcher);
return new TypeSafeMatcher<Intent>() {
@Override
public void describeTo(Description description) {
description.appendText("has extras: ");
description.appendDescriptionOf(bundleMatcher);
}
@Override
public boolean matchesSafely(Intent intent) {
return bundleMatcher.matches(intent.getExtras());
}
};
}
public static Matcher<Intent> hasType(final Matcher<String> typeMatcher) {
checkNotNull(typeMatcher);
return new TypeSafeMatcher<Intent>() {
@Override
public void describeTo(Description description) {
description.appendText("has type: ");
description.appendDescriptionOf(typeMatcher);
}
@Override
public boolean matchesSafely(Intent intent) {
return typeMatcher.matches(intent.getType());
}
};
}
public static Matcher<Intent> hasPackage(final Matcher<String> packageMatcher) {
checkNotNull(packageMatcher);
return new TypeSafeMatcher<Intent>() {
@Override
public void describeTo(Description description) {
description.appendText("has pkg: ");
description.appendDescriptionOf(packageMatcher);
}
@Override
public boolean matchesSafely(Intent intent) {
return packageMatcher.matches(intent.getPackage());
}
};
}
public static Matcher<Uri> hasHost(final Matcher<String> hostMatcher) {
checkNotNull(hostMatcher);
return new TypeSafeMatcher<Uri>() {
@Override
public boolean matchesSafely(Uri uri) {
return hostMatcher.matches(uri.getHost());
}
@Override
public void describeTo(Description description) {
description.appendText("has host: ");
description.appendDescriptionOf(hostMatcher);
}
};
}
public static Matcher<Uri> hasParamWithName(final Matcher<String> paramName) {
checkNotNull(paramName);
return new TypeSafeMatcher<Uri>() {
@Override
public boolean matchesSafely(Uri uri) {
return hasItem(paramName).matches(getQueryParameterNames(uri));
}
@Override
public void describeTo(Description description) {
description.appendText("has param with name: ");
description.appendDescriptionOf(paramName);
}
};
}
public static Matcher<Uri> hasParamWithValue(
final Matcher<String> paramName, final Matcher<String> paramVal) {
checkNotNull(paramName);
checkNotNull(paramVal);
final Matcher<QueryParamEntry> qpe = queryParamEntry(paramName, paramVal);
final Matcher<Iterable<? super QueryParamEntry>> matcherImpl = hasItem(qpe);
return new TypeSafeMatcher<Uri>() {
@Override
public boolean matchesSafely(Uri uri) {
List<QueryParamEntry> qpes = new ArrayList<>();
for (String name : getQueryParameterNames(uri)) {
qpes.add(new QueryParamEntry(name, uri.getQueryParameters(name)));
}
return matcherImpl.matches(qpes);
}
@Override
public void describeTo(Description description) {
description.appendText("has param with: name: ");
description.appendDescriptionOf(paramName);
description.appendText(" value: ");
description.appendDescriptionOf(paramVal);
}
};
}
@Override
public void describeTo(final Description description) {
for (int i = 0; i < extractors.size(); i++) {
if (i > 0) {
description.appendText(" AND ");
}
description.appendDescriptionOf(is(extractors.get(i).apply(expected)));
}
}
@Override
public void describeTo(Description description) {
description.appendText("has component with: class name: ");
description.appendDescriptionOf(classNameMatcher);
description.appendText(" package name: ");
description.appendDescriptionOf(packageNameMatcher);
description.appendText(" short class name: ");
description.appendDescriptionOf(shortClassNameMatcher);
}
public void describeTo(Description description) {
description.appendText("EqualsVariableMap: {");
for (Map.Entry<String, Matcher<?>> matcher : matchers.entrySet()) {
description.appendText(matcher.getKey() + " => ");
description.appendDescriptionOf(matcher.getValue());
}
description.appendText("}");
}
@Override
public void describeTo(Description description) {
description.appendText("PRMSAndQuery: ");
for (TypeSafeMatcher<PRMSQuery> clause: clauses) {
description.appendDescriptionOf(clause);
}
}
@Override
public void describeTo(Description description) {
description.appendText("after waiting up to 3 minutes ");
description.appendDescriptionOf(matcher);
if (neverMatches != null) {
description.appendText(" and not ");
description.appendDescriptionOf(neverMatches);
}
}
@Override
public void describeMismatch(Object item, Description description) {
if (errorMatches(item)) {
description.appendText("did match ");
description.appendDescriptionOf(neverMatches);
neverMatches.describeMismatch(item, description);
} else {
matcher.describeMismatch(item, description);
}
}
@Override
public void describeTo(Description description) {
description.appendDescriptionOf(mStringUriMatcher);
}
public void describeTo(Description description) {
description.appendText("exception with cause of cause ");
description.appendDescriptionOf(fMatcher);
}
public void describeTo(Description description) {
description.appendText("exception with message ");
description.appendDescriptionOf(messageMatcher);
}
@Override
public void describeTo(Description description) {
description.appendDescriptionOf(matchers);
}
@Override
public void describeTo(Description description) {
description.appendDescriptionOf(_subMatcher);
}