org.fest.assertions
Class ObjectArrayAssert

java.lang.Object
  extended by org.fest.assertions.Assert
      extended by org.fest.assertions.GenericAssert<T>
          extended by org.fest.assertions.GroupAssert<T>
              extended by org.fest.assertions.ArrayAssert<Object[]>
                  extended by org.fest.assertions.ObjectArrayAssert

public class ObjectArrayAssert
extends ArrayAssert<Object[]>

Understands assertions for Object arrays. To create a new instance of this class use the method Assertions.assertThat(Object[]).

Author:
Yvonne Wang, Alex Ruiz

Field Summary
 
Fields inherited from class org.fest.assertions.GenericAssert
actual
 
Constructor Summary
protected ObjectArrayAssert(Object... actual)
          Creates a new ObjectArrayAssert.
 
Method Summary
 ObjectArrayAssert as(Description description)
          Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails.
 ObjectArrayAssert as(String description)
          Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails.
 ObjectArrayAssert contains(Object... objects)
          Verifies that the actual Object array contains the given objects.
 ObjectArrayAssert containsOnly(Object... objects)
          Verifies that the actual Object array contains the given objects only.
 ObjectArrayAssert describedAs(Description description)
          Alias for GenericAssert.as(Description), since "as" is a keyword in Groovy.
 ObjectArrayAssert describedAs(String description)
          Alias for GenericAssert.as(String), since "as" is a keyword in Groovy.
 ObjectArrayAssert doesNotHaveDuplicates()
          Verifies that the actual Object array does not have duplicates.
 ObjectArrayAssert doesNotSatisfy(Condition<Object[]> condition)
          Verifies that the actual Object array does not satisfy the given condition.
 ObjectArrayAssert excludes(Object... objects)
          Verifies that the actual Object array does not contain the given objects.
 ObjectArrayAssert hasAllElementsOfType(Class<?> type)
          Verifies that all the elements in the actual Object array belong to the specified type.
 ObjectArrayAssert hasAtLeastOneElementOfType(Class<?> type)
          Verifies that at least one element in the actual Object array belong to the specified type.
 ObjectArrayAssert hasSize(int expected)
          Verifies that the number of elements in the actual Object array is equal to the given one.
 ObjectArrayAssert is(Condition<Object[]> condition)
          Alias for satisfies(Condition).
 ObjectArrayAssert isEqualTo(Object[] expected)
          Verifies that the actual Object array is equal to the given array.
 ObjectArrayAssert isNot(Condition<Object[]> condition)
          Alias for doesNotSatisfy(Condition).
 ObjectArrayAssert isNotEmpty()
          Verifies that the actual Object array contains at least on element.
 ObjectArrayAssert isNotEqualTo(Object[] array)
          Verifies that the actual Object array is not equal to the given array.
 ObjectArrayAssert isNotNull()
          Verifies that the actual Object array is not null.
 ObjectArrayAssert isNotSameAs(Object[] expected)
          Verifies that the actual Object array is not the same as the given array.
 ObjectArrayAssert isSameAs(Object[] expected)
          Verifies that the actual Object array is the same as the given array.
 ObjectArrayAssert overridingErrorMessage(String message)
          Replaces the default message displayed in case of a failure with the given one.
 ObjectArrayAssert satisfies(Condition<Object[]> condition)
          Verifies that the actual Object array satisfies the given condition.
 
Methods inherited from class org.fest.assertions.ArrayAssert
actualGroupSize, actualInBrackets, assertContains, assertContainsOnly, assertExcludes, assertThatActualHasSize, assertThatActualIsNotEmpty, assertThatActualIsNotNull, isEmpty, isNullOrEmpty
 
Methods inherited from class org.fest.assertions.GenericAssert
assertDoesNotSatisfy, assertEqualTo, assertIs, assertIsNot, assertNotEqualTo, assertNotNull, assertNotSameAs, assertSameAs, assertSatisfies, isNull
 
Methods inherited from class org.fest.assertions.Assert
customErrorMessage, description, description, description, equals, fail, fail, failIfCustomMessageIsSet, failIfCustomMessageIsSet, failure, formattedErrorMessage, hashCode, rawDescription, replaceDefaultErrorMessagesWith
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectArrayAssert

protected ObjectArrayAssert(Object... actual)
Creates a new ObjectArrayAssert.

Parameters:
actual - the target to verify.
Method Detail

as

public ObjectArrayAssert as(String description)
Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.

For example:

 assertThat(val).as("name").isEqualTo("Frodo");
 

Specified by:
as in class GenericAssert<Object[]>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

describedAs

public ObjectArrayAssert describedAs(String description)
Alias for GenericAssert.as(String), since "as" is a keyword in Groovy. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.

For example:

 assertThat(val).describedAs("name").isEqualTo("Frodo");
 

Specified by:
describedAs in class GenericAssert<Object[]>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

as

public ObjectArrayAssert as(Description description)
Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.

For example:

 assertThat(val).as(new BasicDescription("name")).isEqualTo("Frodo");
 

Specified by:
as in class GenericAssert<Object[]>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

describedAs

public ObjectArrayAssert describedAs(Description description)
Alias for GenericAssert.as(Description), since "as" is a keyword in Groovy. This method should be called before any assertion method, otherwise any assertion failure will not show the provided description.

For example:

 assertThat(val).describedAs(new BasicDescription("name")).isEqualTo("Frodo");
 

Specified by:
describedAs in class GenericAssert<Object[]>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

hasAllElementsOfType

public ObjectArrayAssert hasAllElementsOfType(Class<?> type)
Verifies that all the elements in the actual Object array belong to the specified type. Matching includes subclasses of the given type.

For example, consider the following code listing:

 Number[] numbers = { 2, 6 ,8 };
 assertThat(numbers).hasComponentType(Integer.class);
 
The assertion hasAllElementsOfType will be successful.

Parameters:
type - the expected type.
Returns:
this assertion object.
Throws:
NullPointerException - if the given type is null.
AssertionError - if the component type of the actual Object array is not the same as the specified one.

hasAtLeastOneElementOfType

public ObjectArrayAssert hasAtLeastOneElementOfType(Class<?> type)
Verifies that at least one element in the actual Object array belong to the specified type. Matching includes subclasses of the given type.

Parameters:
type - the expected type.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Object does not have any elements of the given type.

contains

public ObjectArrayAssert contains(Object... objects)
Verifies that the actual Object array contains the given objects.

Parameters:
objects - the objects to look for.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Object array is null.
NullPointerException - if the given Object array is null.
AssertionError - if the actual Object array does not contain the given objects.

containsOnly

public ObjectArrayAssert containsOnly(Object... objects)
Verifies that the actual Object array contains the given objects only.

Parameters:
objects - the objects to look for.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Object array is null.
NullPointerException - if the given Object array is null.
AssertionError - if the actual Object array does not contain the given objects, or if the actual Object array contains elements other than the ones specified.

excludes

public ObjectArrayAssert excludes(Object... objects)
Verifies that the actual Object array does not contain the given objects.

Parameters:
objects - the objects the array should exclude.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Object array is null.
NullPointerException - if the given Object array is null.
AssertionError - if the actual Object array contains any of the given objects.

doesNotHaveDuplicates

public ObjectArrayAssert doesNotHaveDuplicates()
Verifies that the actual Object array does not have duplicates.

Returns:
this assertion object.
Throws:
AssertionError - if the actual Object array is null.
AssertionError - if the actual Object array has duplicates.

satisfies

public ObjectArrayAssert satisfies(Condition<Object[]> condition)
Verifies that the actual Object array satisfies the given condition.

Specified by:
satisfies in class GenericAssert<Object[]>
Parameters:
condition - the given condition.
Returns:
this assertion object.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if the actual Object array does not satisfy the given condition.
See Also:
is(Condition)

doesNotSatisfy

public ObjectArrayAssert doesNotSatisfy(Condition<Object[]> condition)
Verifies that the actual Object array does not satisfy the given condition.

Specified by:
doesNotSatisfy in class GenericAssert<Object[]>
Parameters:
condition - the given condition.
Returns:
this assertion object.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if the actual Object array satisfies the given condition.
See Also:
isNot(Condition)

is

public ObjectArrayAssert is(Condition<Object[]> condition)
Alias for satisfies(Condition).

Specified by:
is in class GenericAssert<Object[]>
Parameters:
condition - the given condition.
Returns:
this assertion object.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if the actual Object array does not satisfy the given condition.
Since:
1.2

isNot

public ObjectArrayAssert isNot(Condition<Object[]> condition)
Alias for doesNotSatisfy(Condition).

Specified by:
isNot in class GenericAssert<Object[]>
Parameters:
condition - the given condition.
Returns:
this assertion object.
Throws:
NullPointerException - if the given condition is null.
AssertionError - if the actual Object array satisfies the given condition.
Since:
1.2

isNotNull

public ObjectArrayAssert isNotNull()
Verifies that the actual Object array is not null.

Specified by:
isNotNull in class GenericAssert<Object[]>
Returns:
this assertion object.
Throws:
AssertionError - if the actual Object array is null.

isNotEmpty

public ObjectArrayAssert isNotEmpty()
Verifies that the actual Object array contains at least on element.

Specified by:
isNotEmpty in class GroupAssert<Object[]>
Returns:
this assertion object.
Throws:
AssertionError - if the actual Object array is null.
AssertionError - if the actual Object array is empty.

isEqualTo

public ObjectArrayAssert isEqualTo(Object[] expected)
Verifies that the actual Object array is equal to the given array. Array equality is checked by Arrays.deepEquals(Object[], Object[]).

Specified by:
isEqualTo in class GenericAssert<Object[]>
Parameters:
expected - the given array to compare the actual array to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Object array is not equal to the given one.

isNotEqualTo

public ObjectArrayAssert isNotEqualTo(Object[] array)
Verifies that the actual Object array is not equal to the given array. Array equality is checked by Arrays.deepEquals(Object[], Object[]).

Specified by:
isNotEqualTo in class GenericAssert<Object[]>
Parameters:
array - the given array to compare the actual array to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Object array is equal to the given one.

hasSize

public ObjectArrayAssert hasSize(int expected)
Verifies that the number of elements in the actual Object array is equal to the given one.

Specified by:
hasSize in class GroupAssert<Object[]>
Parameters:
expected - the expected number of elements in the actual Object array.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Object array is null.
AssertionError - if the number of elements in the actual Object array is not equal to the given one.

isSameAs

public ObjectArrayAssert isSameAs(Object[] expected)
Verifies that the actual Object array is the same as the given array.

Specified by:
isSameAs in class GenericAssert<Object[]>
Parameters:
expected - the given array to compare the actual array to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Object array is not the same as the given one.

isNotSameAs

public ObjectArrayAssert isNotSameAs(Object[] expected)
Verifies that the actual Object array is not the same as the given array.

Specified by:
isNotSameAs in class GenericAssert<Object[]>
Parameters:
expected - the given array to compare the actual array to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Object array is the same as the given one.

overridingErrorMessage

public ObjectArrayAssert overridingErrorMessage(String message)
Replaces the default message displayed in case of a failure with the given one.

For example, the following assertion:

 assertThat("Hello").isEqualTo("Bye");
 
will fail with the default message "expected:<'[Bye]'> but was:<'[Hello]'>."

We can replace this message with our own:

 assertThat("Hello").overridingErrorMessage("'Hello' should be equal to 'Bye'").isEqualTo("Bye");
 
in this case, the assertion will fail showing the message "'Hello' should be equal to 'Bye'".

Specified by:
overridingErrorMessage in class GenericAssert<Object[]>
Parameters:
message - the given error message, which will replace the default one.
Returns:
this assertion.


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