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

The following examples show how to use org.hamcrest.Matchers#containsInAnyOrder() . 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
public Matcher<Iterable<? extends TimeSeriesCollection>> build(GroupName group) {
    final int timeColumn = columns.indexOf("time");
    final List<TimeSeriesCollection> result = new ArrayList<>(values.size());

    for (List<Object> row : values) {
        ListIterator<String> columnIter = columns.listIterator();
        Iterator<Object> fieldIter = row.iterator();

        final long timestamp = ((Number) row.get(timeColumn)).longValue();
        Map<MetricName, MetricValue> valueMap = new HashMap<>();
        while (columnIter.hasNext()) {
            int columnIdx = columnIter.nextIndex();
            String column = columnIter.next();
            Number field = (Number) fieldIter.next();
            if (columnIdx == timeColumn) continue;
            valueMap.put(MetricName.valueOf(column.split(Pattern.quote("."))), MetricValue.fromNumberValue(field));
        }

        result.add(new SimpleTimeSeriesCollection(new DateTime(timestamp, DateTimeZone.UTC), Stream.of(new ImmutableTimeSeriesValue(group, valueMap))));
    }
    return Matchers.containsInAnyOrder(result.stream()
            .map(Matchers::equalTo)
            .collect(Collectors.toList()));
}
 
Example 2
Source Project: eclair   File: RelationResolverTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void reduceDescendants() {
    // given
    List<Class<?>> classes = asList(Number.class, BigDecimal.class, ArrayList.class, AbstractList.class);
    // when
    Set<Class<?>> reduced = RelationResolver.reduceDescendants(classes);
    // then
    assertThat(reduced, hasSize(2));
    @SuppressWarnings("unchecked")
    Matcher<Iterable<? extends Class<?>>> matcher = Matchers.containsInAnyOrder(Number.class, AbstractList.class);
    assertThat(reduced, matcher);
}
 
Example 3
Source Project: beam   File: ExecutableStageMatcher.java    License: Apache License 2.0 5 votes vote down vote up
public ExecutableStageMatcher withOutputs(Matcher<String>... pCollections) {
  return new ExecutableStageMatcher(
      inputPCollectionId,
      sideInputIds,
      Matchers.containsInAnyOrder(pCollections),
      fusedTransforms);
}
 
Example 4
Source Project: beam   File: ExecutableStageMatcher.java    License: Apache License 2.0 5 votes vote down vote up
public ExecutableStageMatcher withOutputs(String... pCollections) {
  return new ExecutableStageMatcher(
      inputPCollectionId,
      sideInputIds,
      Matchers.containsInAnyOrder(pCollections),
      fusedTransforms);
}
 
Example 5
public static Matcher<Index> hasFieldsInAnyOrder(String... index) {
    return new FeatureMatcher<Index, List<String>>(Matchers.containsInAnyOrder(index),
            "fields", "fields") {
        @Override
        protected List<String> featureValueOf(Index i) {
            ArrayList fields = new ArrayList<String>();
            for (FieldSort f : i.fieldNames) {
                fields.add(f.field);
            }
            return fields;
        }
    };
}
 
Example 6
@Override
protected boolean matchesSafely(TableAnswerElement item, Description mismatchDescription) {
  Iterator<Row> iterator = item.getRows().iterator();
  Iterable<Row> rows = () -> iterator;
  Matcher<Iterable<? extends Row>> matcher = Matchers.containsInAnyOrder(_rowMatchers);
  if (!matcher.matches(rows)) {
    matcher.describeMismatch(rows, mismatchDescription);
    return false;
  }
  return true;
}
 
Example 7
private Matcher<Map<String, Object>> ruleOutputToMatchers(RuleOutput ruleOutput) {
  Matcher<Map<? extends String, ? extends Object>> targetMatcher =
      Matchers.hasEntry("target", ruleOutput.target);
  Matcher<Map<? extends String, ? extends Object>> valMatcher =
      Matchers.hasEntry("val", ruleOutput.val);

  Matcher<Object> srcs = createEndOfPathMatcher(ruleOutput.srcs);
  Matcher<Object> deps =
      (Matcher<Object>)
          (Matcher<? extends Object>)
              Matchers.containsInAnyOrder(
                  Collections2.transform(
                      ruleOutput.deps,
                      d -> (Matcher<? super Object>) (Matcher<?>) ruleOutputToMatchers(d)));
  Matcher<Object> outputs = createEndOfPathMatcher(ruleOutput.outputs);

  Matcher<Map<? extends String, ? extends Object>> srcsMatcher =
      Matchers.hasEntry(Matchers.is("srcs"), srcs);
  Matcher<Map<? extends String, ? extends Object>> depMatcher =
      Matchers.hasEntry(Matchers.is("dep"), deps);
  Matcher<Map<? extends String, ? extends Object>> outputsMatcher =
      Matchers.hasEntry(Matchers.is("outputs"), outputs);

  Matcher<? extends Map<? extends String, ? extends Object>> matcher =
      Matchers.allOf(targetMatcher, valMatcher, srcsMatcher, depMatcher, outputsMatcher);
  return (Matcher<Map<String, Object>>) matcher;
}
 
Example 8
private static Matcher<Object> createEndOfPathMatcher(List<Path> toMatch) {
  return (Matcher<Object>)
      (Matcher<? extends Object>)
          Matchers.containsInAnyOrder(
              Collections2.transform(
                  toMatch,
                  path ->
                      (Matcher<? super Object>) (Matcher<?>) Matchers.endsWith(path.toString())));
}
 
Example 9
@SuppressWarnings({"unchecked", "rawtypes"})
@SafeVarargs
public static <W extends Window> Matcher<Iterable<W>> ofWindows(Matcher<W>... windows) {
	return (Matcher) Matchers.containsInAnyOrder(windows);
}
 
Example 10
Source Project: flink   File: StreamRecordMatchers.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
@SafeVarargs
public static <W extends Window> Matcher<Iterable<W>> ofWindows(Matcher<W>... windows) {
	return (Matcher) Matchers.containsInAnyOrder(windows);
}
 
Example 11
Source Project: beam   File: WindowMatchers.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
@SafeVarargs
public static final <W extends BoundedWindow> Matcher<Iterable<W>> ofWindows(
    Matcher<W>... windows) {
  return (Matcher) Matchers.containsInAnyOrder(windows);
}
 
Example 12
Source Project: flink   File: StreamRecordMatchers.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
@SafeVarargs
public static <W extends Window> Matcher<Iterable<W>> ofWindows(Matcher<W>... windows) {
	return (Matcher) Matchers.containsInAnyOrder(windows);
}
 
Example 13
Source Project: gcp-ingestion   File: Lines.java    License: Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Return a Hamcrest matcher that checks if a collection contains an expected set of lines.
 *
 * <p>This is a thin wrapper on {@link Matchers#containsInAnyOrder(Object[])} that expands
 * a list argument into an array. The Hamcrest method has a varargs parameter list, so passing
 * a list directly will compile, but treats it as a single entity rather than as a collection
 * of elements.
 */
public static Matcher<Iterable<? extends String>> matchesInAnyOrder(List<String> expected) {
  return Matchers.containsInAnyOrder(expected.toArray(new String[0]));
}