本文整理汇总了Java中org.hamcrest.Matcher.describeMismatch方法的典型用法代码示例。如果您正苦于以下问题:Java Matcher.describeMismatch方法的具体用法?Java Matcher.describeMismatch怎么用?Java Matcher.describeMismatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hamcrest.Matcher
的用法示例。
在下文中一共展示了Matcher.describeMismatch方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: everyItemInArray
import org.hamcrest.Matcher; //导入方法依赖的package包/类
private static <T> Matcher<T[]> everyItemInArray(final Matcher<T> itemMatcher) {
return new TypeSafeDiagnosingMatcher<T[]>() {
@Override
public void describeTo(Description description) {
description.appendText("every item in array is ").appendDescriptionOf(itemMatcher);
}
@Override
protected boolean matchesSafely(T[] items, Description mismatchDescription) {
for (T item : items) {
if (!itemMatcher.matches(item)) {
mismatchDescription.appendText("an item ");
itemMatcher.describeMismatch(item, mismatchDescription);
return false;
}
}
return true;
}
};
}
示例2: check
import org.hamcrest.Matcher; //导入方法依赖的package包/类
public <T> PropertyMismatchDescriber check(String propertyName, T propertyValue, Matcher<? super T> matcher) {
if (matcher == null) {
return this;
}
if (matcher.matches(propertyValue)) {
return this;
}
matches = false;
newline(description).appendText(propertyName).appendText(": ");
indent();
matcher.describeMismatch(propertyValue, description);
outdent();
return this;
}
示例3: matchesSafely
import org.hamcrest.Matcher; //导入方法依赖的package包/类
@Override
protected boolean matchesSafely(List<FlowEvent<T>> flowEvents, Description description) {
if (flowEvents.size() != matchers.size()) {
description.appendText("history contained ").appendText(Integer.toString(flowEvents.size())).appendText(" events");
return false;
}
boolean matched = true;
for (int i = 0; i < matchers.size(); i++) {
Matcher<FlowEvent<T>> matcher = matchers.get(i);
FlowEvent<T> flowEvent = flowEvents.get(i);
if (!matcher.matches(flowEvent)) {
matched = false;
IndentationControl.newline(description)
.appendText(Integer.toString(i))
.appendText(": ");
indent();
matcher.describeMismatch(flowEvent, description);
outdent();
}
}
return matched;
}
示例4: testInvalidJsonObjectWithMultiConditionUpdatesDescription
import org.hamcrest.Matcher; //导入方法依赖的package包/类
@Test
public void testInvalidJsonObjectWithMultiConditionUpdatesDescription() {
Conditions conditions = _builder.where(
"apio", is(aJsonString(equalTo("Live long and prosper")))
).where(
"geek", is(aJsonBoolean(true))
).build();
Matcher<String> stringMatcher = aJsonObjectStringWith(conditions);
Description description = new StringDescription();
stringMatcher.describeMismatch("{}", description);
String expected =
"was a JSON object {\n apio: was null\n geek: was null\n}";
assertThat(description.toString(), is(expected));
}
示例5: fail
import org.hamcrest.Matcher; //导入方法依赖的package包/类
static void fail(@Nullable Object actualValue, Matcher<?> matcher) {
Description description =
new StringDescription()
.appendText("\nExpected: ")
.appendDescriptionOf(matcher)
.appendText("\n but: ");
matcher.describeMismatch(actualValue, description);
AssertionError assertionError = new AssertionError(description.toString());
assertionError.setStackTrace(ObjectChecker.trimStackTrace(assertionError.getStackTrace()));
throw assertionError;
}
示例6: assertThat
import org.hamcrest.Matcher; //导入方法依赖的package包/类
@Step("Matching Actual - {1} and Expected {2}")
public static <T> void assertThat(String reason, T actual, Matcher<? super T> matcher) {
if (!matcher.matches(actual)) {
Description description = new StringDescription();
description.appendText(reason)
.appendText("\nExpected: ")
.appendDescriptionOf(matcher)
.appendText("\n but: ");
matcher.describeMismatch(actual, description);
ScreenShotUtil.takeScreenShot();
throw new AssertionError(description.toString());
}
}
示例7: 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;
}
示例8: testInvalidFunctionalListUpdatesDescription
import org.hamcrest.Matcher; //导入方法依赖的package包/类
@Test
public void testInvalidFunctionalListUpdatesDescription() {
FunctionalList<Integer> functionalList = new FunctionalList<>(null, 1);
Description description = new StringDescription();
Matcher<FunctionalList<Integer>> functionalListMatcher =
aFunctionalListThat(contains(2));
functionalListMatcher.describeMismatch(functionalList, description);
String expected = "was a functional list whose item 0: was <1>";
assertThat(description.toString(), is(expected));
}
示例9: testInvalidJsonLongUpdatesValidDescription
import org.hamcrest.Matcher; //导入方法依赖的package包/类
@Test
public void testInvalidJsonLongUpdatesValidDescription() {
JsonPrimitive jsonPrimitive = new JsonPrimitive(42L);
Matcher<JsonElement> matcher = aJsonLong(equalTo(23L));
Description description = new StringDescription();
matcher.describeMismatch(jsonPrimitive, description);
String expected = "was a number element with a value that was <42L>";
assertThat(description.toString(), is(expected));
}
示例10: testInvalidJsonObjectUpdatesValidDescription
import org.hamcrest.Matcher; //导入方法依赖的package包/类
@Test
public void testInvalidJsonObjectUpdatesValidDescription() {
Conditions conditions = _builder.build();
Matcher<String> stringMatcher = aJsonObjectStringWith(conditions);
Description description = new StringDescription();
stringMatcher.describeMismatch("{", description);
assertThat(description.toString(), is("was not a JSON object"));
}
示例11: testInvalidJsonBooleanUpdatesValidDescription
import org.hamcrest.Matcher; //导入方法依赖的package包/类
@Test
public void testInvalidJsonBooleanUpdatesValidDescription() {
JsonPrimitive jsonPrimitive = new JsonPrimitive(true);
Matcher<JsonElement> matcher = aJsonBoolean(false);
Description description = new StringDescription();
matcher.describeMismatch(jsonPrimitive, description);
String expected = "was a boolean element with a value that was <true>";
assertThat(description.toString(), is(expected));
}
示例12: testInvalidJsonIntUpdatesValidDescription
import org.hamcrest.Matcher; //导入方法依赖的package包/类
@Test
public void testInvalidJsonIntUpdatesValidDescription() {
JsonPrimitive jsonPrimitive = new JsonPrimitive(42);
Matcher<JsonElement> matcher = aJsonInt(equalTo(23));
Description description = new StringDescription();
matcher.describeMismatch(jsonPrimitive, description);
String expected = "was a number element with a value that was <42>";
assertThat(description.toString(), is(expected));
}
示例13: testInvalidJsonTextUpdatesValidDescription
import org.hamcrest.Matcher; //导入方法依赖的package包/类
@Test
public void testInvalidJsonTextUpdatesValidDescription() {
JsonPrimitive jsonPrimitive = new JsonPrimitive("Live long");
Matcher<JsonElement> matcher = aJsonString(equalTo("and prosper"));
Description description = new StringDescription();
matcher.describeMismatch(jsonPrimitive, description);
String expected =
"was a string element with a value that was \"Live long\"";
assertThat(description.toString(), is(expected));
}