下面列出了org.hamcrest.Matchers#contains ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static Matcher<Iterable<? extends TimeSeriesCollection>> computeDataMatcher(Collection<KeyedQuery> queries, boolean reverse) {
final List<Matcher<? super TimeSeriesCollection>> result = computeData(queries)
.map(Matchers::equalTo)
.collect(Collectors.toList());
if (reverse) Collections.reverse(result);
return Matchers.contains(result);
}
public static <T> Matcher<WindowedValue<? extends T>> isSingleWindowedValue(
Matcher<? super T> valueMatcher,
Matcher<? super Instant> timestampMatcher,
Matcher<? super BoundedWindow> windowMatcher) {
return new WindowedValueMatcher<>(
valueMatcher, timestampMatcher, Matchers.contains(windowMatcher), Matchers.anything());
}
public static <T> Matcher<WindowedValue<? extends T>> isSingleWindowedValue(
Matcher<? super T> valueMatcher,
Matcher<? super Instant> timestampMatcher,
Matcher<? super BoundedWindow> windowMatcher,
Matcher<? super PaneInfo> paneInfoMatcher) {
return new WindowedValueMatcher<>(
valueMatcher, timestampMatcher, Matchers.contains(windowMatcher), paneInfoMatcher);
}
/** Traverse visits every element of an input value without coercing to the output type. */
@Test
public void traverseShouldVisitEveryObject() throws NoSuchFieldException {
Type type = TestFields.class.getField("stringMapOfLists").getGenericType();
@SuppressWarnings("unchecked")
TypeCoercer<Object, ImmutableMap<String, ImmutableList<String>>> coercer =
(TypeCoercer<Object, ImmutableMap<String, ImmutableList<String>>>)
typeCoercerFactory.typeCoercerForType(TypeToken.of(type));
ImmutableMap<String, ImmutableList<String>> input =
ImmutableMap.of(
"foo", ImmutableList.of("//foo:bar", "//foo:baz"),
"bar", ImmutableList.of(":bar", "//foo:foo"));
TestTraversal traversal = new TestTraversal();
coercer.traverse(cellNameResolver, input, traversal);
Matcher<Iterable<?>> matcher =
Matchers.contains(
ImmutableList.of(
sameInstance((Object) input),
is((Object) "foo"),
sameInstance((Object) input.get("foo")),
is((Object) "//foo:bar"),
is((Object) "//foo:baz"),
is((Object) "bar"),
sameInstance((Object) input.get("bar")),
is((Object) ":bar"),
is((Object) "//foo:foo")));
assertThat(traversal.getObjects(), matcher);
}
public static <T, R> Matcher<Iterable<? extends R>> containsUsingCustomMatcher(List<T> items, MatcherFunction<T, R> matcherFunction) {
return Matchers.contains(createMatchers(items, matcherFunction));
}
public static <T, R> Matcher<Iterable<? extends R>> containsUsingCustomMatcher(List<T> items, MatcherFunction<T, R> matcherFunction) {
return Matchers.contains(createMatchers(items, matcherFunction));
}