org.fest.assertions
Class ByteArrayAssert

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.ItemGroupAssert<T>
                  extended by org.fest.assertions.ArrayAssert<byte[]>
                      extended by org.fest.assertions.ByteArrayAssert

public class ByteArrayAssert
extends ArrayAssert<byte[]>

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

Author:
Yvonne Wang, Alex Ruiz

Field Summary
 
Fields inherited from class org.fest.assertions.GenericAssert
actual
 
Constructor Summary
protected ByteArrayAssert(byte... actual)
          Creates a new ByteArrayAssert.
 
Method Summary
 ByteArrayAssert as(Description description)
          Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails.
 ByteArrayAssert as(String description)
          Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails.
 ByteArrayAssert contains(byte... values)
          Verifies that the actual byte array contains the given values.
 ByteArrayAssert containsOnly(byte... values)
          Verifies that the actual byte array contains the given values only.
 ByteArrayAssert describedAs(Description description)
          Alias for GenericAssert.as(Description), since "as" is a keyword in Groovy.
 ByteArrayAssert describedAs(String description)
          Alias for GenericAssert.as(String), since "as" is a keyword in Groovy.
 ByteArrayAssert doesNotSatisfy(Condition<byte[]> condition)
          Verifies that the actual byte array does not satisfy the given condition.
 ByteArrayAssert excludes(byte... values)
          Verifies that the actual byte array does not contain the given values.
 ByteArrayAssert hasSize(int expected)
          Verifies that the number of elements in the actual byte array is equal to the given one.
 ByteArrayAssert is(Condition<byte[]> condition)
          Alias for satisfies(Condition).
 ByteArrayAssert isEqualTo(byte[] expected)
          Verifies that the actual byte array is equal to the given array.
 ByteArrayAssert isNot(Condition<byte[]> condition)
          Alias for doesNotSatisfy(Condition).
 ByteArrayAssert isNotEmpty()
          Verifies that the actual byte array contains at least on element.
 ByteArrayAssert isNotEqualTo(byte[] array)
          Verifies that the actual byte array is not equal to the given array.
 ByteArrayAssert isNotNull()
          Verifies that the actual byte array is not null.
 ByteArrayAssert isNotSameAs(byte[] expected)
          Verifies that the actual byte array is not the same as the given array.
 ByteArrayAssert isSameAs(byte[] expected)
          Verifies that the actual byte array is the same as the given array.
 ByteArrayAssert overridingErrorMessage(String message)
          Replaces the default message displayed in case of a failure with the given one.
 ByteArrayAssert satisfies(Condition<byte[]> condition)
          Verifies that the actual byte array satisfies the given condition.
 
Methods inherited from class org.fest.assertions.ArrayAssert
actualAsList, actualAsSet, actualGroupSize
 
Methods inherited from class org.fest.assertions.ItemGroupAssert
assertContains, assertContainsOnly, assertDoesNotHaveDuplicates, assertExcludes, asSet, validateIsNotNull
 
Methods inherited from class org.fest.assertions.GroupAssert
assertHasSize, assertIsNotEmpty, 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

ByteArrayAssert

protected ByteArrayAssert(byte... actual)
Creates a new ByteArrayAssert.

Parameters:
actual - the target to verify.
Method Detail

as

public ByteArrayAssert 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 GroupAssert<byte[]>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

describedAs

public ByteArrayAssert 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 GroupAssert<byte[]>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

as

public ByteArrayAssert 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 GroupAssert<byte[]>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

describedAs

public ByteArrayAssert 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 GroupAssert<byte[]>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

contains

public ByteArrayAssert contains(byte... values)
Verifies that the actual byte array contains the given values.

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

containsOnly

public ByteArrayAssert containsOnly(byte... values)
Verifies that the actual byte array contains the given values only.

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

excludes

public ByteArrayAssert excludes(byte... values)
Verifies that the actual byte array does not contain the given values.

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

satisfies

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

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

doesNotSatisfy

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

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

is

public ByteArrayAssert is(Condition<byte[]> condition)
Alias for satisfies(Condition).

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

isNot

public ByteArrayAssert isNot(Condition<byte[]> condition)
Alias for doesNotSatisfy(Condition).

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

isNotNull

public ByteArrayAssert isNotNull()
Verifies that the actual byte array is not null.

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

isNotEmpty

public ByteArrayAssert isNotEmpty()
Verifies that the actual byte array contains at least on element.

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

isEqualTo

public ByteArrayAssert isEqualTo(byte[] expected)
Verifies that the actual byte array is equal to the given array. Array equality is checked by Arrays.equals(byte[], byte[]).

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

isNotEqualTo

public ByteArrayAssert isNotEqualTo(byte[] array)
Verifies that the actual byte array is not equal to the given array. Array equality is checked by Arrays.equals(byte[], byte[]).

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

hasSize

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

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

isSameAs

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

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

isNotSameAs

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

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

overridingErrorMessage

public ByteArrayAssert 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 GroupAssert<byte[]>
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.