Java Code Examples for org.hamcrest.Matchers#contains()

The following examples show how to use org.hamcrest.Matchers#contains() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
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);
}
 
Example 2
Source Project: beam   File: WindowMatchers.java    License: Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 3
Source Project: beam   File: WindowMatchers.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 4
Source Project: buck   File: TypeCoercerTest.java    License: Apache License 2.0 5 votes vote down vote up
/** 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);
}
 
Example 5
public static <T, R> Matcher<Iterable<? extends R>> containsUsingCustomMatcher(List<T> items, MatcherFunction<T, R> matcherFunction) {
    return Matchers.contains(createMatchers(items, matcherFunction));
}
 
Example 6
public static <T, R> Matcher<Iterable<? extends R>> containsUsingCustomMatcher(List<T> items, MatcherFunction<T, R> matcherFunction) {
    return Matchers.contains(createMatchers(items, matcherFunction));
}