All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.devonfw.cobigen.test.matchers.CustomHamcrestMatchers Maven / Gradle / Ivy

The newest version!
package com.devonfw.cobigen.test.matchers;

import static org.hamcrest.core.AllOf.allOf;

import java.util.ArrayList;
import java.util.List;

import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.core.IsCollectionContaining;

/**
 * These functions have been ported from hamcrest, whereas the signature has been customized
 */
public class CustomHamcrestMatchers {

  /**
   * Creates a matcher for {@link List}s that matches when consecutive passes over the examined {@link List} yield at
   * least one item that is matched by the corresponding matcher from the specified itemMatchers. Whilst
   * matching, each traversal of the examined {@link List} will stop as soon as a matching item is found.
   * 

* For example: * *

   * assertThat(Arrays.asList("foo", "bar", "baz"), hasItems(endsWith("z"), endsWith("o")))
   * 
* * @param Type of items to be matched * * @param itemMatchers the matchers to apply to items provided by the examined {@link List} * @return the matcher instance */ @Factory @SuppressWarnings("unchecked") public static Matcher> hasItemsInList(Matcher... itemMatchers) { List>> all = new ArrayList<>(itemMatchers.length); for (Matcher elementMatcher : itemMatchers) { // Doesn't forward to hasItem() method so compiler can sort out generics. all.add(new IsCollectionContaining<>(elementMatcher)); } return allOf(all); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy