本文整理汇总了Java中org.hamcrest.TypeSafeDiagnosingMatcher类的典型用法代码示例。如果您正苦于以下问题:Java TypeSafeDiagnosingMatcher类的具体用法?Java TypeSafeDiagnosingMatcher怎么用?Java TypeSafeDiagnosingMatcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TypeSafeDiagnosingMatcher类属于org.hamcrest包,在下文中一共展示了TypeSafeDiagnosingMatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: everyItemInArray
import org.hamcrest.TypeSafeDiagnosingMatcher; //导入依赖的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: successfulExitCode
import org.hamcrest.TypeSafeDiagnosingMatcher; //导入依赖的package包/类
private TypeSafeDiagnosingMatcher<Integer> successfulExitCode(
final Command cmd, final File workspace) {
return new TypeSafeDiagnosingMatcher<Integer>() {
@Override
protected boolean matchesSafely(
final Integer exitCode, final Description mismatchDescription) {
if (exitCode != 0) {
mismatchDescription
.appendText(" exit code was ")
.appendValue(exitCode)
.appendText("\n")
.appendText("Workspace contents: \n")
.appendValueList("", "\n", "\n", contents(workspace.toPath()))
.appendDescriptionOf(commandDescription(cmd));
return false;
}
return true;
}
@Override
public void describeTo(final Description description) {
description.appendText("successful exit code (0)");
}
};
}
示例3: validationError
import org.hamcrest.TypeSafeDiagnosingMatcher; //导入依赖的package包/类
public static Matcher<ValidationError> validationError(final String propertyPath, final String message) {
return new TypeSafeDiagnosingMatcher<ValidationError>() {
@Override
protected boolean matchesSafely(ValidationError item, Description mismatchDescription) {
if (!item.getErrorMessage().equals(message)) {
mismatchDescription.appendText("message was " + item.getErrorMessage());
return false;
}
if (!item.getFieldPath().equals(propertyPath)) {
mismatchDescription.appendText("field path was " + item.getFieldPath());
return false;
}
return true;
}
@Override
public void describeTo(Description description) {
description.appendText("a validation error for field " + propertyPath + " with message " + message);
}
};
}
示例4: matchingPattern
import org.hamcrest.TypeSafeDiagnosingMatcher; //导入依赖的package包/类
public static Matcher<String> matchingPattern(String patternStr) {
return new TypeSafeDiagnosingMatcher<String>() {
@Override
protected boolean matchesSafely(String text, Description mismatchDescription) {
Pattern pattern = Pattern.compile(patternStr, Pattern.DOTALL);
boolean matches = pattern.matcher(text).matches();
if (!matches) {
mismatchDescription.appendText(text);
}
return matches;
}
@Override
public void describeTo(Description description) {
description.appendText("matching '" + patternStr + "'");
}
};
}
示例5: hasTag
import org.hamcrest.TypeSafeDiagnosingMatcher; //导入依赖的package包/类
public static Matcher<Git> hasTag(final String tag) {
return new TypeSafeDiagnosingMatcher<Git>() {
@Override
protected boolean matchesSafely(final Git repo, final Description mismatchDescription) {
try {
mismatchDescription.appendValueList("a git repo with tags: ", ", ", "",
repo.getRepository().getTags().keySet());
for (final Ref ref : repo.tagList().call()) {
final String currentTag = ref.getName().replace(REFS_TAGS, "");
if (tag.equals(currentTag)) {
return true;
}
}
return false;
} catch (final GitAPIException e) {
throw new RuntimeException("Couldn't access repo", e);
}
}
@Override
public void describeTo(final Description description) {
description.appendText("a git repo with the tag " + tag);
}
};
}
示例6: hasCleanWorkingDirectory
import org.hamcrest.TypeSafeDiagnosingMatcher; //导入依赖的package包/类
public static Matcher<Git> hasCleanWorkingDirectory() {
return new TypeSafeDiagnosingMatcher<Git>() {
@Override
protected boolean matchesSafely(final Git git, final Description mismatchDescription) {
try {
final Status status = git.status().call();
if (!status.isClean()) {
final String start = "Uncommitted changes in ";
final String end = " at " + git.getRepository().getWorkTree().getAbsolutePath();
mismatchDescription.appendValueList(start, ", ", end, status.getUncommittedChanges());
}
return status.isClean();
} catch (final GitAPIException e) {
throw new RuntimeException("Error checking git status", e);
}
}
@Override
public void describeTo(final Description description) {
description.appendText("A git directory with no staged or unstaged changes");
}
};
}
示例7: isSuccess
import org.hamcrest.TypeSafeDiagnosingMatcher; //导入依赖的package包/类
protected Matcher<CompilationResult> isSuccess() {
return new TypeSafeDiagnosingMatcher<CompilationResult>() {
@Override public void describeTo(final Description description) {
description.appendText("Successful compilation");
}
@Override protected boolean matchesSafely(final CompilationResult item,
final Description mismatchDescription) {
final boolean success = item.isSuccess();
if (!success) mismatchDescription.appendText(Joiner.on('\n').join(item.getErrors()));
return success;
}
;
};
}
示例8: isFailureWithExpectedMessage
import org.hamcrest.TypeSafeDiagnosingMatcher; //导入依赖的package包/类
protected Matcher<CompilationResult> isFailureWithExpectedMessage(String message) {
return new TypeSafeDiagnosingMatcher<CompilationResult>() {
@Override public void describeTo(final Description description) {
description.appendText("Compilation Failure");
}
@Override protected boolean matchesSafely(final CompilationResult item,
final Description mismatchDescription) {
boolean falseSuccess = item.isSuccess();
final String errorMessagesAsBlock = Joiner.on('\n').join(item.getErrors());
if (!errorMessagesAsBlock.contains(message)) {
falseSuccess = true;
mismatchDescription.appendText("expected error message: ").appendText(message)
.appendText(" but got ");
}
mismatchDescription.appendText(errorMessagesAsBlock);
return !falseSuccess;
}
;
};
}
示例9: containsPropertySource
import org.hamcrest.TypeSafeDiagnosingMatcher; //导入依赖的package包/类
private static Matcher<? super ConfigurableEnvironment> containsPropertySource(
final String sourceName) {
return new TypeSafeDiagnosingMatcher<ConfigurableEnvironment>() {
@Override
public void describeTo(Description description) {
description.appendText("environment containing property source ")
.appendValue(sourceName);
}
@Override
protected boolean matchesSafely(ConfigurableEnvironment item,
Description mismatchDescription) {
MutablePropertySources sources = new MutablePropertySources(
item.getPropertySources());
ConfigurationPropertySources.finishAndRelocate(sources);
mismatchDescription.appendText("Not matched against: ")
.appendValue(sources);
return sources.contains(sourceName);
}
};
}
示例10: acceptsProfiles
import org.hamcrest.TypeSafeDiagnosingMatcher; //导入依赖的package包/类
private static Matcher<? super ConfigurableEnvironment> acceptsProfiles(
final String... profiles) {
return new TypeSafeDiagnosingMatcher<ConfigurableEnvironment>() {
@Override
public void describeTo(Description description) {
description.appendText("environment accepting profiles ")
.appendValue(profiles);
}
@Override
protected boolean matchesSafely(ConfigurableEnvironment item,
Description mismatchDescription) {
mismatchDescription.appendText("Not matched against: ")
.appendValue(item.getActiveProfiles());
return item.acceptsProfiles(profiles);
}
};
}
示例11: hasTag
import org.hamcrest.TypeSafeDiagnosingMatcher; //导入依赖的package包/类
public static Matcher<Git> hasTag(final String tag) {
return new TypeSafeDiagnosingMatcher<Git>() {
@Override
protected boolean matchesSafely(Git repo, Description mismatchDescription) {
try {
mismatchDescription.appendValueList("a git repo with tags: ", ", ", "", repo.getRepository().getTags().keySet());
return GitHelper.hasLocalTag(repo, tag);
} catch (GitAPIException e) {
throw new RuntimeException("Couldn't access repo", e);
}
}
@Override
public void describeTo(Description description) {
description.appendText("a git repo with the tag " + tag);
}
};
}
示例12: hasCleanWorkingDirectory
import org.hamcrest.TypeSafeDiagnosingMatcher; //导入依赖的package包/类
public static Matcher<Git> hasCleanWorkingDirectory() {
return new TypeSafeDiagnosingMatcher<Git>() {
@Override
protected boolean matchesSafely(Git git, Description mismatchDescription) {
try {
Status status = git.status().call();
if (!status.isClean()) {
String start = "Uncommitted changes in ";
String end = " at " + git.getRepository().getWorkTree().getAbsolutePath();
mismatchDescription.appendValueList(start, ", ", end, status.getUncommittedChanges());
}
return status.isClean();
} catch (GitAPIException e) {
throw new RuntimeException("Error checking git status", e);
}
}
@Override
public void describeTo(Description description) {
description.appendText("A git directory with no staged or unstaged changes");
}
};
}
示例13: allOf
import org.hamcrest.TypeSafeDiagnosingMatcher; //导入依赖的package包/类
@SafeVarargs
public static <T> Matcher<T> allOf(Matcher<? super T>... matchers) {
return new TypeSafeDiagnosingMatcher<T>() {
@Override
protected boolean matchesSafely(T item, Description mismatchDescription) {
boolean matches = true;
for (Matcher<? super T> matcher : matchers) {
if (!matcher.matches(item)) {
if (!matches) mismatchDescription.appendText(", ");
matcher.describeMismatch(item, mismatchDescription);
matches = false;
}
}
return matches;
}
@Override
public void describeTo(Description description) {
description.appendList("(", " " + "and" + " ", ")", Arrays.asList(matchers));
}
};
}
示例14: hasCause
import org.hamcrest.TypeSafeDiagnosingMatcher; //导入依赖的package包/类
public static Matcher<Exception> hasCause(Matcher<? extends Throwable> causeMatcher) {
return new TypeSafeDiagnosingMatcher<Exception>() {
@Override
public void describeTo(Description description) {
description.appendText("cause should ").appendDescriptionOf(causeMatcher);
}
@Override
protected boolean matchesSafely(Exception e, Description mismatchDescription) {
Throwable cause = e.getCause();
boolean matches = causeMatcher.matches(cause);
if (!matches) {
mismatchDescription.appendValue(e).appendText(" had cause ").appendValue(cause);
}
return matches;
}
};
}
示例15: cast
import org.hamcrest.TypeSafeDiagnosingMatcher; //导入依赖的package包/类
private static <T, U> Matcher<U> cast(Class<T> clazz, Matcher<? super T> downcastMatcher) {
return new TypeSafeDiagnosingMatcher<U>() {
@Override
public void describeTo(Description description) {
downcastMatcher.describeTo(description);
}
@Override
protected boolean matchesSafely(Object item, Description mismatchDescription) {
if (!clazz.isInstance(item)) {
mismatchDescription.appendText("was a " + item.getClass().getSimpleName());
return false;
} if (downcastMatcher.matches(item)) {
return true;
} else {
downcastMatcher.describeMismatch(item, mismatchDescription);
return false;
}
}
};
}