本文整理汇总了Java中org.hamcrest.Description.toString方法的典型用法代码示例。如果您正苦于以下问题:Java Description.toString方法的具体用法?Java Description.toString怎么用?Java Description.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hamcrest.Description
的用法示例。
在下文中一共展示了Description.toString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assertThatClassIsImmutable
import org.hamcrest.Description; //导入方法依赖的package包/类
/**
* Assert that the given class adheres to the immutable class rules.
*
* @param clazz the class to check
*
* @throws java.lang.AssertionError if the class is not an
* immutable class
*/
public static void assertThatClassIsImmutable(Class<?> clazz) {
final ImmutableClassChecker checker = new ImmutableClassChecker();
if (!checker.isImmutableClass(clazz, false)) {
final Description toDescription = new StringDescription();
final Description mismatchDescription = new StringDescription();
checker.describeTo(toDescription);
checker.describeMismatch(mismatchDescription);
final String reason =
"\n" +
"Expected: is \"" + toDescription.toString() + "\"\n" +
" but : was \"" + mismatchDescription.toString() + "\"";
throw new AssertionError(reason);
}
}
示例2: assertThatClassIsImmutableBaseClass
import org.hamcrest.Description; //导入方法依赖的package包/类
/**
* Assert that the given class adheres to the immutable class rules, but
* is not declared final. Classes that need to be inherited from cannot be
* declared final.
*
* @param clazz the class to check
*
* @throws java.lang.AssertionError if the class is not an
* immutable class
*/
public static void assertThatClassIsImmutableBaseClass(Class<?> clazz) {
final ImmutableClassChecker checker = new ImmutableClassChecker();
if (!checker.isImmutableClass(clazz, true)) {
final Description toDescription = new StringDescription();
final Description mismatchDescription = new StringDescription();
checker.describeTo(toDescription);
checker.describeMismatch(mismatchDescription);
final String reason =
"\n" +
"Expected: is \"" + toDescription.toString() + "\"\n" +
" but : was \"" + mismatchDescription.toString() + "\"";
throw new AssertionError(reason);
}
}
示例3: assertThatClassIsUtility
import org.hamcrest.Description; //导入方法依赖的package包/类
/**
* Assert that the given class adheres to the utility class rules.
*
* @param clazz the class to check
*
* @throws java.lang.AssertionError if the class is not a valid
* utility class
*/
public static void assertThatClassIsUtility(Class<?> clazz) {
final UtilityClassChecker checker = new UtilityClassChecker();
if (!checker.isProperlyDefinedUtilityClass(clazz)) {
final Description toDescription = new StringDescription();
final Description mismatchDescription = new StringDescription();
checker.describeTo(toDescription);
checker.describeMismatch(mismatchDescription);
final String reason =
"\n" +
"Expected: is \"" + toDescription.toString() + "\"\n" +
" but : was \"" + mismatchDescription.toString() + "\"";
throw new AssertionError(reason);
}
}
示例4: fail
import org.hamcrest.Description; //导入方法依赖的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;
}
示例5: assertThat
import org.hamcrest.Description; //导入方法依赖的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());
}
}