当前位置: 首页>>代码示例>>Java>>正文


Java TypeSafeDiagnosingMatcher类代码示例

本文整理汇总了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;
        }

    };
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:IncludeAccessorsPropertiesIT.java

示例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)");
    }
  };
}
 
开发者ID:bazelbuild,项目名称:bazel-integration-testing,代码行数:26,代码来源:BazelBaseTestCaseTest.java

示例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);
        }
    };
}
 
开发者ID:energizedwork,项目名称:swagger-http-validator,代码行数:24,代码来源:CustomMatchers.java

示例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 + "'");
        }
    };
}
 
开发者ID:palantir,项目名称:docker-compose-rule,代码行数:19,代码来源:IOMatchers.java

示例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);
		}
	};
}
 
开发者ID:SourcePond,项目名称:release-maven-plugin-parent,代码行数:26,代码来源:GitMatchers.java

示例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");
		}
	};
}
 
开发者ID:SourcePond,项目名称:release-maven-plugin-parent,代码行数:24,代码来源:GitMatchers.java

示例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;
        }

        ;
    };

}
 
开发者ID:mostlymagic,项目名称:hacking-java,代码行数:18,代码来源:AbstractCompilerTest.java

示例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;
        }

        ;
    };

}
 
开发者ID:mostlymagic,项目名称:hacking-java,代码行数:24,代码来源:AbstractCompilerTest.java

示例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);
		}
	};
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:22,代码来源:ConfigFileEnvironmentPostProcessorTests.java

示例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);
		}
	};
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:19,代码来源:ConfigFileEnvironmentPostProcessorTests.java

示例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);
        }
    };
}
 
开发者ID:danielflower,项目名称:multi-module-maven-release-plugin,代码行数:19,代码来源:GitMatchers.java

示例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");
        }
    };
}
 
开发者ID:danielflower,项目名称:multi-module-maven-release-plugin,代码行数:24,代码来源:GitMatchers.java

示例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));
        }
    };
}
 
开发者ID:pivotal,项目名称:executable-dist-plugin,代码行数:23,代码来源:MatcherUtils.java

示例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;
        }
    };
}
 
开发者ID:digipost,项目名称:digg,代码行数:20,代码来源:DiggMatchers.java

示例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;
            }
        }
    };
}
 
开发者ID:mwilliamson,项目名称:java-mammoth,代码行数:22,代码来源:DocumentMatchers.java


注:本文中的org.hamcrest.TypeSafeDiagnosingMatcher类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。