org.fest.assertions.internal
Class ObjectArrays

java.lang.Object
  extended by org.fest.assertions.internal.ObjectArrays

public class ObjectArrays
extends Object

Reusable assertions for arrays of objects.

Author:
Alex Ruiz, Joel Costigliola, Nicolas François

Constructor Summary
ObjectArrays(org.fest.util.ComparisonStrategy comparisonStrategy)
           
 
Method Summary
<E> void
assertAre(AssertionInfo info, Object[] actual, Condition<E> condition)
          Assert that each element of given array satisfies the given condition.
<E> void
assertAreAtLeast(AssertionInfo info, Object[] actual, int n, Condition<E> condition)
          Assert that there is at least n array elements satisfying the given condition.
<E> void
assertAreAtMost(AssertionInfo info, Object[] actual, int n, Condition<E> condition)
          Assert that there is at most n array elements satisfying the given condition.
<E> void
assertAreExactly(AssertionInfo info, Object[] actual, int n, Condition<E> condition)
          Verifies that there is exactly n array elements satisfying the given condition.
<E> void
assertAreNot(AssertionInfo info, Object[] actual, Condition<E> condition)
          Assert that each element of given array not satisfies the given condition.
<E> void
assertAreNotAtLeast(AssertionInfo info, Object[] actual, int n, Condition<E> condition)
          Assert that there is at least n array elements not satisfying the given condition.
<E> void
assertAreNotAtMost(AssertionInfo info, Object[] actual, int n, Condition<E> condition)
          Verifies that there is at most n array elements not satisfying the given condition.
<E> void
assertAreNotExactly(AssertionInfo info, Object[] actual, int n, Condition<E> condition)
          Verifies that there is exactly n elements in the actual Iterable not satisfying the given condition.
 void assertContains(AssertionInfo info, Object[] actual, Object[] values)
          Asserts that the given array contains the given values, in any order.
 void assertContains(AssertionInfo info, Object[] actual, Object value, Index index)
          Verifies that the given array contains the given object at the given index.
 void assertContainsNull(AssertionInfo info, Object[] actual)
          Asserts that the given array contains at least a null element.
 void assertContainsOnly(AssertionInfo info, Object[] actual, Object[] values)
          Asserts that the given array contains only the given values and nothing else, in any order.
 void assertContainsSequence(AssertionInfo info, Object[] actual, Object[] sequence)
          Verifies that the given array contains the given sequence of objects, without any other objects between them.
 void assertDoesNotContain(AssertionInfo info, Object[] actual, Object[] values)
          Asserts that the given array does not contain the given values.
 void assertDoesNotContain(AssertionInfo info, Object[] actual, Object value, Index index)
          Verifies that the given array does not contain the given object at the given index.
 void assertDoesNotContainNull(AssertionInfo info, Object[] actual)
          Asserts that the given array does not contain null elements.
 void assertDoesNotHaveDuplicates(AssertionInfo info, Object[] actual)
          Asserts that the given array does not have duplicate values.
<E> void
assertDoNotHave(AssertionInfo info, Object[] actual, Condition<E> condition)
          Assert that each element of given array not satisfies the given condition.
<E> void
assertDoNotHaveAtLeast(AssertionInfo info, Object[] actual, int times, Condition<E> condition)
          An alias method of assertAreNotAtLeast(AssertionInfo, Object[], int, Condition) to provide a richer fluent api (same logic, only error message differs).
<E> void
assertDoNotHaveAtMost(AssertionInfo info, Object[] actual, int times, Condition<E> condition)
          An alias method of assertAreNotAtMost(AssertionInfo, Object[], int, Condition) to provide a richer fluent api (same logic, only error message differs).
<E> void
assertDoNotHaveExactly(AssertionInfo info, Object[] actual, int times, Condition<E> condition)
          An alias method of assertAreNotExactly(AssertionInfo, Object[], int, Condition) to provide a richer fluent api (same logic, only error message differs).
 void assertEmpty(AssertionInfo info, Object[] actual)
          Asserts that the given array is empty.
 void assertEndsWith(AssertionInfo info, Object[] actual, Object[] sequence)
          Verifies that the given array ends with the given sequence of objects, without any other objects between them.
 void assertHasSize(AssertionInfo info, Object[] actual, int expectedSize)
          Asserts that the number of elements in the given array is equal to the expected one.
<E> void
assertHave(AssertionInfo info, Object[] actual, Condition<E> condition)
          Assert that each element of given array satisfies the given condition.
<E> void
assertHaveAtLeast(AssertionInfo info, Object[] actual, int times, Condition<E> condition)
          An alias method of assertAreAtLeast(AssertionInfo, Object[], int, Condition) to provide a richer fluent api (same logic, only error message differs).
<E> void
assertHaveAtMost(AssertionInfo info, Object[] actual, int times, Condition<E> condition)
          An alias method of assertAreAtMost(AssertionInfo, Object[], int, Condition) to provide a richer fluent api (same logic, only error message differs).
<E> void
assertHaveExactly(AssertionInfo info, Object[] actual, int times, Condition<E> condition)
          An alias method of assertAreExactly(AssertionInfo, Object[], int, Condition) to provide a richer fluent api (same logic, only error message differs).
 void assertIsSorted(AssertionInfo info, Object[] actual)
          Concrete implementation of ArraySortedAssert.isSorted().
 void assertIsSortedAccordingToComparator(AssertionInfo info, Object[] actual, Comparator<? extends Object> comparator)
          Concrete implementation of ArraySortedAssert.isSortedAccordingTo(Comparator).
 void assertNotEmpty(AssertionInfo info, Object[] actual)
          Asserts that the given array is not empty.
 void assertNullOrEmpty(AssertionInfo info, Object[] actual)
          Asserts that the given array is null or empty.
 void assertStartsWith(AssertionInfo info, Object[] actual, Object[] sequence)
          Verifies that the given array starts with the given sequence of objects, without any other objects between them.
 Comparator<?> getComparator()
           
static ObjectArrays instance()
          Returns the singleton instance of this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectArrays

public ObjectArrays(org.fest.util.ComparisonStrategy comparisonStrategy)
Method Detail

instance

public static ObjectArrays instance()
Returns the singleton instance of this class.

Returns:
the singleton instance of this class.

getComparator

public Comparator<?> getComparator()

assertNullOrEmpty

public void assertNullOrEmpty(AssertionInfo info,
                              Object[] actual)
Asserts that the given array is null or empty.

Parameters:
info - contains information about the assertion.
actual - the given array.
Throws:
AssertionError - if the given array is not null *and* contains one or more elements.

assertEmpty

public void assertEmpty(AssertionInfo info,
                        Object[] actual)
Asserts that the given array is empty.

Parameters:
info - contains information about the assertion.
actual - the given array.
Throws:
AssertionError - if the given array is null.
AssertionError - if the given array is not empty.

assertNotEmpty

public void assertNotEmpty(AssertionInfo info,
                           Object[] actual)
Asserts that the given array is not empty.

Parameters:
info - contains information about the assertion.
actual - the given array.
Throws:
AssertionError - if the given array is null.
AssertionError - if the given array is empty.

assertHasSize

public void assertHasSize(AssertionInfo info,
                          Object[] actual,
                          int expectedSize)
Asserts that the number of elements in the given array is equal to the expected one.

Parameters:
info - contains information about the assertion.
actual - the given array.
expectedSize - the expected size of actual.
Throws:
AssertionError - if the given array is null.
AssertionError - if the number of elements in the given array is different than the expected one.

assertContains

public void assertContains(AssertionInfo info,
                           Object[] actual,
                           Object[] values)
Asserts that the given array contains the given values, in any order.

Parameters:
info - contains information about the assertion.
actual - the given array.
values - the values that are expected to be in the given array.
Throws:
NullPointerException - if the array of values is null.
IllegalArgumentException - if the array of values is empty.
AssertionError - if the given array is null.
AssertionError - if the given array does not contain the given values.

assertContains

public void assertContains(AssertionInfo info,
                           Object[] actual,
                           Object value,
                           Index index)
Verifies that the given array contains the given object at the given index.

Parameters:
info - contains information about the assertion.
actual - the given array.
value - the object to look for.
index - the index where the object should be stored in the given array.
Throws:
AssertionError - if the given array is null or empty.
NullPointerException - if the given Index is null.
IndexOutOfBoundsException - if the value of the given Index is equal to or greater than the size of the given array.
AssertionError - if the given array does not contain the given object at the given index.

assertDoesNotContain

public void assertDoesNotContain(AssertionInfo info,
                                 Object[] actual,
                                 Object value,
                                 Index index)
Verifies that the given array does not contain the given object at the given index.

Parameters:
info - contains information about the assertion.
actual - the given array.
value - the object to look for.
index - the index where the object should be stored in the given array.
Throws:
AssertionError - if the given array is null.
NullPointerException - if the given Index is null.
AssertionError - if the given array contains the given object at the given index.

assertContainsOnly

public void assertContainsOnly(AssertionInfo info,
                               Object[] actual,
                               Object[] values)
Asserts that the given array contains only the given values and nothing else, in any order.

Parameters:
info - contains information about the assertion.
actual - the given array.
values - the values that are expected to be in the given array.
Throws:
NullPointerException - if the array of values is null.
IllegalArgumentException - if the array of values is empty.
AssertionError - if the given array is null.
AssertionError - if the given array does not contain the given values or if the given array contains values that are not in the given array.

assertContainsSequence

public void assertContainsSequence(AssertionInfo info,
                                   Object[] actual,
                                   Object[] sequence)
Verifies that the given array contains the given sequence of objects, without any other objects between them.

Parameters:
info - contains information about the assertion.
actual - the given array.
sequence - the sequence of objects to look for.
Throws:
AssertionError - if the given array is null.
NullPointerException - if the given sequence is null.
IllegalArgumentException - if the given sequence is empty.
AssertionError - if the given array does not contain the given sequence of objects.

assertDoesNotContain

public void assertDoesNotContain(AssertionInfo info,
                                 Object[] actual,
                                 Object[] values)
Asserts that the given array does not contain the given values.

Parameters:
info - contains information about the assertion.
actual - the given array.
values - the values that are expected not to be in the given array.
Throws:
NullPointerException - if the array of values is null.
IllegalArgumentException - if the array of values is empty.
AssertionError - if the given array is null.
AssertionError - if the given array contains any of given values.

assertDoesNotHaveDuplicates

public void assertDoesNotHaveDuplicates(AssertionInfo info,
                                        Object[] actual)
Asserts that the given array does not have duplicate values.

Parameters:
info - contains information about the assertion.
actual - the given array.
Throws:
NullPointerException - if the array of values is null.
IllegalArgumentException - if the array of values is empty.
AssertionError - if the given array is null.
AssertionError - if the given array contains duplicate values.

assertStartsWith

public void assertStartsWith(AssertionInfo info,
                             Object[] actual,
                             Object[] sequence)
Verifies that the given array starts with the given sequence of objects, without any other objects between them. Similar to assertContainsSequence(AssertionInfo, Object[], Object[]), but it also verifies that the first element in the sequence is also the first element of the given array.

Parameters:
info - contains information about the assertion.
actual - the given array.
sequence - the sequence of objects to look for.
Throws:
NullPointerException - if the given argument is null.
IllegalArgumentException - if the given argument is an empty array.
AssertionError - if the given array is null.
AssertionError - if the given array does not start with the given sequence of objects.

assertEndsWith

public void assertEndsWith(AssertionInfo info,
                           Object[] actual,
                           Object[] sequence)
Verifies that the given array ends with the given sequence of objects, without any other objects between them. Similar to assertContainsSequence(AssertionInfo, Object[], Object[]), but it also verifies that the last element in the sequence is also the last element of the given array.

Parameters:
info - contains information about the assertion.
actual - the given array.
sequence - the sequence of objects to look for.
Throws:
NullPointerException - if the given argument is null.
IllegalArgumentException - if the given argument is an empty array.
AssertionError - if the given array is null.
AssertionError - if the given array does not end with the given sequence of objects.

assertContainsNull

public void assertContainsNull(AssertionInfo info,
                               Object[] actual)
Asserts that the given array contains at least a null element.

Parameters:
info - contains information about the assertion.
actual - the given array.
Throws:
AssertionError - if the given array is null.
AssertionError - if the given array does not contain a null element.

assertDoesNotContainNull

public void assertDoesNotContainNull(AssertionInfo info,
                                     Object[] actual)
Asserts that the given array does not contain null elements.

Parameters:
info - contains information about the assertion.
actual - the given array.
Throws:
AssertionError - if the given array is null.
AssertionError - if the given array contains a null element.

assertAre

public <E> void assertAre(AssertionInfo info,
                          Object[] actual,
                          Condition<E> condition)
Assert that each element of given array satisfies the given condition.

Parameters:
info - contains information about the assertion.
actual - the given array.
condition - the given Condition.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if a element cannot be cast to E.
AssertionError - if one or more element not satisfy the given condition.

assertAreNot

public <E> void assertAreNot(AssertionInfo info,
                             Object[] actual,
                             Condition<E> condition)
Assert that each element of given array not satisfies the given condition.

Parameters:
info - contains information about the assertion.
actual - the given array.
condition - the given Condition.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if a element cannot be cast to E.
AssertionError - if one or more element satisfy the given condition.

assertHave

public <E> void assertHave(AssertionInfo info,
                           Object[] actual,
                           Condition<E> condition)
Assert that each element of given array satisfies the given condition.

Parameters:
info - contains information about the assertion.
actual - the given array.
condition - the given Condition.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if a element cannot be cast to E.
AssertionError - if one or more element not satisfy the given condition.

assertDoNotHave

public <E> void assertDoNotHave(AssertionInfo info,
                                Object[] actual,
                                Condition<E> condition)
Assert that each element of given array not satisfies the given condition.

Parameters:
info - contains information about the assertion.
actual - the given array.
condition - the given Condition.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if a element cannot be cast to E.
AssertionError - if one or more element satisfy the given condition.

assertAreAtLeast

public <E> void assertAreAtLeast(AssertionInfo info,
                                 Object[] actual,
                                 int n,
                                 Condition<E> condition)
Assert that there is at least n array elements satisfying the given condition.

Parameters:
info - contains information about the assertion.
actual - the given array.
n - the minimum number of times the condition should be verified.
condition - the given Condition.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if a element cannot be cast to E.
AssertionError - if the number of elements satisfying the given condition is < n.

assertAreNotAtLeast

public <E> void assertAreNotAtLeast(AssertionInfo info,
                                    Object[] actual,
                                    int n,
                                    Condition<E> condition)
Assert that there is at least n array elements not satisfying the given condition.

Parameters:
info - contains information about the assertion.
actual - the given array.
n - the number of times the condition should not be verified at least.
condition - the given Condition.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if a element cannot be cast to E.
AssertionError - if the number of elements not satisfying the given condition is < n.

assertAreAtMost

public <E> void assertAreAtMost(AssertionInfo info,
                                Object[] actual,
                                int n,
                                Condition<E> condition)
Assert that there is at most n array elements satisfying the given condition.

Parameters:
info - contains information about the assertion.
actual - the given array.
n - the number of times the condition should be at most verified.
condition - the given Condition.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if a element cannot be cast to E.
AssertionError - if the number of elements satisfying the given condition is > n.

assertAreNotAtMost

public <E> void assertAreNotAtMost(AssertionInfo info,
                                   Object[] actual,
                                   int n,
                                   Condition<E> condition)
Verifies that there is at most n array elements not satisfying the given condition.

Parameters:
info - contains information about the assertion.
actual - the given array.
n - the number of times the condition should not be verified at most.
condition - the given Condition.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if a element cannot be cast to E.
AssertionError - if the number of elements not satisfying the given condition is > n.

assertAreExactly

public <E> void assertAreExactly(AssertionInfo info,
                                 Object[] actual,
                                 int n,
                                 Condition<E> condition)
Verifies that there is exactly n array elements satisfying the given condition.

Parameters:
info - contains information about the assertion.
actual - the given array.
n - the exact number of times the condition should be verified.
condition - the given Condition.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if a element cannot be cast to E.
AssertionError - if the number of elements satisfying the given condition is ≠ n.

assertAreNotExactly

public <E> void assertAreNotExactly(AssertionInfo info,
                                    Object[] actual,
                                    int n,
                                    Condition<E> condition)
Verifies that there is exactly n elements in the actual Iterable not satisfying the given condition.

Parameters:
info - contains information about the assertion.
actual - the given array.
n - most times the condition should not be verify.
condition - the given Condition.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if a element cannot be cast to E.
AssertionError - if the number of elements not satisfying the given condition is ≠ n.

assertHaveAtLeast

public <E> void assertHaveAtLeast(AssertionInfo info,
                                  Object[] actual,
                                  int times,
                                  Condition<E> condition)
An alias method of assertAreAtLeast(AssertionInfo, Object[], int, Condition) to provide a richer fluent api (same logic, only error message differs).


assertDoNotHaveAtLeast

public <E> void assertDoNotHaveAtLeast(AssertionInfo info,
                                       Object[] actual,
                                       int times,
                                       Condition<E> condition)
An alias method of assertAreNotAtLeast(AssertionInfo, Object[], int, Condition) to provide a richer fluent api (same logic, only error message differs).


assertHaveAtMost

public <E> void assertHaveAtMost(AssertionInfo info,
                                 Object[] actual,
                                 int times,
                                 Condition<E> condition)
An alias method of assertAreAtMost(AssertionInfo, Object[], int, Condition) to provide a richer fluent api (same logic, only error message differs).


assertDoNotHaveAtMost

public <E> void assertDoNotHaveAtMost(AssertionInfo info,
                                      Object[] actual,
                                      int times,
                                      Condition<E> condition)
An alias method of assertAreNotAtMost(AssertionInfo, Object[], int, Condition) to provide a richer fluent api (same logic, only error message differs).


assertHaveExactly

public <E> void assertHaveExactly(AssertionInfo info,
                                  Object[] actual,
                                  int times,
                                  Condition<E> condition)
An alias method of assertAreExactly(AssertionInfo, Object[], int, Condition) to provide a richer fluent api (same logic, only error message differs).


assertDoNotHaveExactly

public <E> void assertDoNotHaveExactly(AssertionInfo info,
                                       Object[] actual,
                                       int times,
                                       Condition<E> condition)
An alias method of assertAreNotExactly(AssertionInfo, Object[], int, Condition) to provide a richer fluent api (same logic, only error message differs).


assertIsSorted

public void assertIsSorted(AssertionInfo info,
                           Object[] actual)
Concrete implementation of ArraySortedAssert.isSorted().

Parameters:
info - contains information about the assertion.
actual - the given array.

assertIsSortedAccordingToComparator

public void assertIsSortedAccordingToComparator(AssertionInfo info,
                                                Object[] actual,
                                                Comparator<? extends Object> comparator)
Concrete implementation of ArraySortedAssert.isSortedAccordingTo(Comparator).

Parameters:
info - contains information about the assertion.
actual - the given array.
comparator - the Comparator used to compare array elements


Copyright © 2007-2012 FEST (Fixtures for Easy Software Testing). All Rights Reserved.