Class IsIn<T>

java.lang.Object
org.hamcrest.BaseMatcher<T>
org.hamcrest.collection.IsIn<T>
Type Parameters:
T - the type of the objects in the collection
All Implemented Interfaces:
Matcher<T>, SelfDescribing

public class IsIn<T> extends BaseMatcher<T>
Tests if a collection contains a matching object.
  • Constructor Details

    • IsIn

      public IsIn(Collection<T> collection)
      Constructor, best called from in(Collection).
      Parameters:
      collection - the expected element matchers
    • IsIn

      public IsIn(T[] elements)
      Constructor, best called from in(Object[]).
      Parameters:
      elements - the expected elements
  • Method Details

    • matches

      public boolean matches(Object o)
      Description copied from interface: Matcher
      Evaluates the matcher for argument item. This method matches against Object, instead of the generic type T. This is because the caller of the Matcher does not know at runtime what the type is (because of type erasure with Java generics). It is down to the implementations to check the correct type.
      Parameters:
      o - the object against which the matcher is evaluated.
      Returns:
      true if item matches, otherwise false.
      See Also:
    • describeTo

      public void describeTo(Description buffer)
      Description copied from interface: SelfDescribing
      Generates a description of the object. The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
      Parameters:
      buffer - The description to be built or appended to.
    • isIn

      @Deprecated public static <T> Matcher<T> isIn(Collection<T> collection)
      Deprecated.
      use is(in(...)) instead
      Creates a matcher that matches when the examined object is found within the specified collection. For example:
      assertThat("foo", isIn(Arrays.asList("bar", "foo")))
      Type Parameters:
      T - the matcher type.
      Parameters:
      collection - the collection in which matching items must be found
      Returns:
      The matcher.
    • in

      public static <T> Matcher<T> in(Collection<T> collection)
      Creates a matcher that matches when the examined object is found within the specified collection. For example:
      assertThat("foo", is(in(Arrays.asList("bar", "foo"))))
      Type Parameters:
      T - the matcher type.
      Parameters:
      collection - the collection in which matching items must be found
      Returns:
      The matcher.
    • isIn

      @Deprecated public static <T> Matcher<T> isIn(T[] elements)
      Deprecated.
      use is(in(...)) instead
      Creates a matcher that matches when the examined object is found within the specified array. For example:
      assertThat("foo", isIn(new String[]{"bar", "foo"}))
      Type Parameters:
      T - the matcher type.
      Parameters:
      elements - the array in which matching items must be found
      Returns:
      The matcher.
    • in

      public static <T> Matcher<T> in(T[] elements)
      Creates a matcher that matches when the examined object is found within the specified array. For example:
      assertThat("foo", is(in(new String[]{"bar", "foo"})))
      Type Parameters:
      T - the matcher type.
      Parameters:
      elements - the array in which matching items must be found
      Returns:
      The matcher.
    • isOneOf

      @SafeVarargs @Deprecated public static <T> Matcher<T> isOneOf(T... elements)
      Deprecated.
      use is(oneOf(...)) instead
      Creates a matcher that matches when the examined object is equal to one of the specified elements. For example:
      assertThat("foo", isOneOf("bar", "foo"))
      Type Parameters:
      T - the matcher type.
      Parameters:
      elements - the elements amongst which matching items will be found
      Returns:
      The matcher.
    • oneOf

      @SafeVarargs public static <T> Matcher<T> oneOf(T... elements)
      Creates a matcher that matches when the examined object is equal to one of the specified elements. For example:
      assertThat("foo", is(oneOf("bar", "foo")))
      Type Parameters:
      T - the matcher type.
      Parameters:
      elements - the elements amongst which matching items will be found
      Returns:
      The matcher.