下面列出了org.hamcrest.Description#appendValue ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static Matcher<View> withMinimalAdapterItemCount(final int minimalCount) {
return new TypeSafeMatcher<View>() {
@Override
protected boolean matchesSafely(View item) {
//noinspection SimplifiableIfStatement - for more readable code
if (!(item instanceof RecyclerView)) {
return false;
}
return ((RecyclerView) item).getAdapter().getItemCount() >= minimalCount;
}
@Override
public void describeTo(Description description) {
description.appendText("Adapter has minimal ");
description.appendValue(minimalCount);
description.appendText(" items (to access requested index ");
description.appendValue(minimalCount - 1);
description.appendText(")");
}
};
}
@Override
public void describeTo(Description description) {
description.appendText("with drawable from resource id: ");
description.appendValue(resourceId);
if (resourceName != null) {
description.appendText("[");
description.appendText(resourceName);
description.appendText("]");
}
}
/**
* @param floatLabelHint
* @return View Matcher for the child EditText
*/
public static Matcher<View> withFloatLabelHint(final String floatLabelHint) {
return new BoundedMatcher<View, EditText>(EditText.class) {
@Override
public void describeTo(Description description) {
description.appendText("has floatlabel hint ");
description.appendValue(floatLabelHint);
if (null != floatLabelHint) {
description.appendText("[");
description.appendText(floatLabelHint);
description.appendText("]");
}
if (null != floatLabelHint) {
description.appendText(" value: ");
description.appendText(floatLabelHint);
}
}
@Override
protected boolean matchesSafely(EditText editText) {
if (!(editText instanceof EditText)) {
return false;
}
String hint = ((EditText) editText).getHint().toString();
return floatLabelHint.equals(hint);
}
};
}
@Override
public void describeMismatch(Object item, Description description) {
description.appendText("was ");
if (!(item instanceof IgnoreFilePattern.PathNameMatchResult)) {
description.appendValue(item);
} else {
IgnoreFilePattern.PathNameMatchResult res = (IgnoreFilePattern.PathNameMatchResult) item;
description.appendText("isMatch? ").appendValue(res.isMatch)
.appendText(" requiresMore? ").appendValue(res.requiresMore)
.appendText(" isLast? ").appendValue(res.isLastElementMatch)
.appendText(" next ").appendValue(res.next);
}
}
private static Matcher<OLogEntryHeader> theSameMessageAs(OLogEntryHeader message) {
return new TypeSafeMatcher<OLogEntryHeader>() {
@Override
public boolean matchesSafely(OLogEntryHeader item) {
return message.getSeqNum() == item.getSeqNum()
&& message.getTerm() == item.getTerm()
&& message.getContentLength() == item.getContentLength();
}
@Override
public void describeTo(Description description) {
description.appendValue(message);
}
};
}
@Override
protected void describeMismatchSafely(Try<S> item, Description mismatchDescription) {
mismatchDescription.appendText(DESCRIPTION);
if (item.isSuccess()) {
mismatchDescription.appendValue(item.get());
} else {
mismatchDescription.appendText(" but was a Try failure");
}
}
@Override
public void describeMismatch(Object file, Description description) {
List<String> lines = readLinesSafely(file, description);
if (lines != null) {
lineMatchingDelegate.describeMismatch(lines, description);
description.appendText(" in file ");
description.appendValue(file);
description.appendText(" with lines ");
description.appendValue(readLinesSafely(file, Description.NONE));
}
}
private Matcher<InvoiceAttributesVM> viewModelFor(final InvoiceForLease invoice) {
return new TypeSafeMatcher<InvoiceAttributesVM>() {
@Override protected boolean matchesSafely(final InvoiceAttributesVM invoiceAttributesVM) {
return invoiceAttributesVM.getInvoice() == invoice;
}
@Override public void describeTo(final Description description) {
description.appendValue("is view model wrapping " + invoice);
}
};
}
@Override
public void describeTo(Description description) {
if (!someExpected) {
description.appendText("<Absent>");
} else if (expected.isPresent()) {
description.appendValue(expected);// "a Some with " +
// expected.some());
} else if (matcher.isPresent()) {
description.appendText("a present value matching ");
matcher.get().describeTo(description);
} else {
description.appendText("<Present>");
}
}
@Override
public void describeTo(final Description description) {
try {
Object expectedJsonAsPrettyJson = JSONParser.parseJSON(expectedJson);
description.appendValue(expectedJsonAsPrettyJson);
} catch (final JSONException e) {
throw new RuntimeException(String.format("Error parsing expected JSON string %s. Got Exception %s",
expectedJson, e.toString()));
}
}
@Override
protected boolean matchesSafely(TtlValue<T> item, Description mismatchDescription) {
mismatchDescription.appendText("TtlValue with value ");
mismatchDescription.appendValue(item.getUserValue());
mismatchDescription.appendText(" with timestamp ");
mismatchDescription.appendValue(item.getLastAccessTimestamp());
return valueMatcher.matches(item.getUserValue()) &&
timestampMatcher.matches(item.getLastAccessTimestamp());
}
@Override
public void describeTo(Description description) {
description.appendValue("serialized clone");
}
public void describeTo(Description description) {
description.appendText("has a symmetric equals(Object) method with ");
description.appendValue(other);
}
@Override
public void describeTo(Description description) {
description.appendValue(expected);
}
@Override
public void describeTo(Description description) {
description.appendValue(this.expectedJson);
}
public void describeTo(Description description) {
description.appendText("returns a future with exception ");
description.appendValue(exception);
}
public void describeTo(Description description) {
description.appendValue( expected );
}
public void describeTo(Description description) {
description.appendText("returns a future with value ");
description.appendValue(futureResult);
}
public void describeTo(Description description) {
description.appendText("follows the hashCode contract when compared to ");
description.appendValue(other);
}
@Override
public void describeTo(Description description) {
description.appendText("with MinSizeMatcher: ");
description.appendValue(expectedMinWith + "x" + expectedMinHeight);
}