Esempio n. 1
0
 /**
  * Verifies that all the elements in the actual <code>Object</code> array belong to the specified
  * type. Matching includes subclasses of the given type.
  *
  * <p>For example, consider the following code listing:
  *
  * <pre>
  * Number[] numbers = { 2, 6 ,8 };
  * assertThat(numbers).hasComponentType(Integer.class);
  * </pre>
  *
  * The assertion <code>hasAllElementsOfType</code> will be successful.
  *
  * @param type the expected type.
  * @return this assertion object.
  * @throws NullPointerException if the given type is <code>null</code>.
  * @throws AssertionError if the component type of the actual <code>Object</code> array is not the
  *     same as the specified one.
  */
 public ObjectArrayAssert hasAllElementsOfType(Class<?> type) {
   validateIsNotNull(type);
   isNotNull();
   for (Object o : actual) {
     if (type.isInstance(o)) continue;
     failIfCustomMessageIsSet();
     fail(
         concat(
             "not all elements in array:",
             inBrackets(actual),
             " belong to the type:",
             inBrackets(type)));
   }
   return this;
 }
Esempio n. 2
0
 /**
  * Verifies that at least one element in the actual <code>Object</code> array belong to the
  * specified type. Matching includes subclasses of the given type.
  *
  * @param type the expected type.
  * @return this assertion object.
  * @throws AssertionError if the actual <code>Object</code> does not have any elements of the
  *     given type.
  */
 public ObjectArrayAssert hasAtLeastOneElementOfType(Class<?> type) {
   validateIsNotNull(type);
   isNotNull();
   boolean found = false;
   for (Object o : actual) {
     if (!type.isInstance(o)) continue;
     found = true;
     break;
   }
   if (found) return this;
   failIfCustomMessageIsSet();
   throw failure(
       concat(
           "array:",
           inBrackets(actual),
           " does not have any elements of type:",
           inBrackets(type)));
 }