org.fest.assertions.api
Class ShortArrayAssert

java.lang.Object
  extended by org.fest.assertions.api.AbstractAssert<ShortArrayAssert,short[]>
      extended by org.fest.assertions.api.ShortArrayAssert
All Implemented Interfaces:
ArraySortedAssert<ShortArrayAssert,Short>, Assert<ShortArrayAssert,short[]>, Descriptable<ShortArrayAssert>, EnumerableAssert<ShortArrayAssert>, ExtensionPoints<ShortArrayAssert,short[]>

public class ShortArrayAssert
extends AbstractAssert<ShortArrayAssert,short[]>
implements EnumerableAssert<ShortArrayAssert>, ArraySortedAssert<ShortArrayAssert,Short>

Assertion methods for arrays of shorts.

To create an instance of this class, invoke Assertions.assertThat(short[]).

Author:
Yvonne Wang, Alex Ruiz, Joel Costigliola

Field Summary
 
Fields inherited from class org.fest.assertions.api.AbstractAssert
actual, myself
 
Constructor Summary
protected ShortArrayAssert(short[] actual)
           
 
Method Summary
 ShortArrayAssert contains(short... values)
          Verifies that the actual array contains the given values, in any order.
 ShortArrayAssert contains(short value, Index index)
          Verifies that the actual array contains the given value at the given index.
 ShortArrayAssert containsOnly(short... values)
          Verifies that the actual array contains only the given values and nothing else, in any order.
 ShortArrayAssert containsSequence(short... sequence)
          Verifies that the actual array contains the given sequence, without any other values between them.
 ShortArrayAssert doesNotContain(short... values)
          Verifies that the actual array does not contain the given values.
 ShortArrayAssert doesNotContain(short value, Index index)
          Verifies that the actual array does not contain the given value at the given index.
 ShortArrayAssert doesNotHaveDuplicates()
          Verifies that the actual array does not contain duplicates.
 ShortArrayAssert endsWith(short... sequence)
          Verifies that the actual array ends with the given sequence of values, without any other values between them.
 ShortArrayAssert hasSize(int expected)
          Verifies that the number of values in the actual group is equal to the given one.
 void isEmpty()
          Verifies that the actual group of values is empty.
 ShortArrayAssert isNotEmpty()
          Verifies that the actual group of values is not empty.
 void isNullOrEmpty()
          Verifies that the actual group of values is null or empty.
 ShortArrayAssert isSorted()
          Verifies that the actual array is sorted into ascending order according to the natural ordering of its elements.
 ShortArrayAssert isSortedAccordingTo(Comparator<? extends Short> comparator)
          Verifies that the actual array is sorted according to the given comparator.
 ShortArrayAssert startsWith(short... sequence)
          Verifies that the actual array starts with the given sequence of values, without any other values between them.
 ShortArrayAssert usingComparator(Comparator<?> customComparator)
          Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
 ShortArrayAssert usingDefaultComparator()
          Revert to standard comparison for incoming assertion checks.
 
Methods inherited from class org.fest.assertions.api.AbstractAssert
as, as, describedAs, describedAs, descriptionText, doesNotHave, equals, has, hashCode, is, isEqualTo, isIn, isIn, isNot, isNotEqualTo, isNotIn, isNotIn, isNotNull, isNotSameAs, isNull, isSameAs
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShortArrayAssert

protected ShortArrayAssert(short[] actual)
Method Detail

isNullOrEmpty

public void isNullOrEmpty()
Verifies that the actual group of values is null or empty.

Specified by:
isNullOrEmpty in interface EnumerableAssert<ShortArrayAssert>

isEmpty

public void isEmpty()
Verifies that the actual group of values is empty.

Specified by:
isEmpty in interface EnumerableAssert<ShortArrayAssert>

isNotEmpty

public ShortArrayAssert isNotEmpty()
Verifies that the actual group of values is not empty.

Specified by:
isNotEmpty in interface EnumerableAssert<ShortArrayAssert>
Returns:
this assertion object.

hasSize

public ShortArrayAssert hasSize(int expected)
Verifies that the number of values in the actual group is equal to the given one.

Specified by:
hasSize in interface EnumerableAssert<ShortArrayAssert>
Parameters:
expected - the expected number of values in the actual group.
Returns:
this assertion object.

contains

public ShortArrayAssert contains(short... values)
Verifies that the actual array contains the given values, in any order.

Parameters:
values - the given values.
Returns:
this assertion object.
Throws:
NullPointerException - if the given argument is null.
IllegalArgumentException - if the given argument is an empty array.
AssertionError - if the actual array is null.
AssertionError - if the actual array does not contain the given values.

containsOnly

public ShortArrayAssert containsOnly(short... values)
Verifies that the actual array contains only the given values and nothing else, in any order.

Parameters:
values - the given values.
Returns:
this assertion object.
Throws:
NullPointerException - if the given argument is null.
IllegalArgumentException - if the given argument is an empty array.
AssertionError - if the actual array is null.
AssertionError - if the actual array does not contain the given values, i.e. the actual array contains some or none of the given values, or the actual array contains more values than the given ones.

containsSequence

public ShortArrayAssert containsSequence(short... sequence)
Verifies that the actual array contains the given sequence, without any other values between them.

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

contains

public ShortArrayAssert contains(short value,
                                 Index index)
Verifies that the actual array contains the given value at the given index.

Parameters:
value - the value to look for.
index - the index where the value should be stored in the actual array.
Returns:
this assertion object.
Throws:
AssertionError - if the actual 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 actual array.
AssertionError - if the actual array does not contain the given value at the given index.

doesNotContain

public ShortArrayAssert doesNotContain(short... values)
Verifies that the actual array does not contain the given values.

Parameters:
values - the given values.
Returns:
this assertion object.
Throws:
NullPointerException - if the given argument is null.
IllegalArgumentException - if the given argument is an empty array.
AssertionError - if the actual array is null.
AssertionError - if the actual array contains any of the given values.

doesNotContain

public ShortArrayAssert doesNotContain(short value,
                                       Index index)
Verifies that the actual array does not contain the given value at the given index.

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

doesNotHaveDuplicates

public ShortArrayAssert doesNotHaveDuplicates()
Verifies that the actual array does not contain duplicates.

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

startsWith

public ShortArrayAssert startsWith(short... sequence)
Verifies that the actual array starts with the given sequence of values, without any other values between them. Similar to containsSequence(short...), but it also verifies that the first element in the sequence is also first element of the actual array.

Parameters:
sequence - the sequence of values to look for.
Returns:
this assertion object.
Throws:
NullPointerException - if the given argument is null.
IllegalArgumentException - if the given argument is an empty array.
AssertionError - if the actual array is null.
AssertionError - if the actual array does not start with the given sequence.

endsWith

public ShortArrayAssert endsWith(short... sequence)
Verifies that the actual array ends with the given sequence of values, without any other values between them. Similar to containsSequence(short...), but it also verifies that the last element in the sequence is also last element of the actual array.

Parameters:
sequence - the sequence of values to look for.
Returns:
this assertion object.
Throws:
NullPointerException - if the given argument is null.
IllegalArgumentException - if the given argument is an empty array.
AssertionError - if the actual array is null.
AssertionError - if the actual array does not end with the given sequence.

isSorted

public ShortArrayAssert isSorted()
Verifies that the actual array is sorted into ascending order according to the natural ordering of its elements.

All array elements must be primitive or implement the Comparable interface and must be mutually comparable (that is, e1.compareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the array), examples :

Empty or one element arrays are considered sorted (unless the array element type is not Comparable).

Specified by:
isSorted in interface ArraySortedAssert<ShortArrayAssert,Short>
Returns:
this assertion object.

isSortedAccordingTo

public ShortArrayAssert isSortedAccordingTo(Comparator<? extends Short> comparator)
Verifies that the actual array is sorted according to the given comparator.
Empty arrays are considered sorted whatever the comparator is.
One element arrays are considered sorted if element is compatible with comparator, otherwise an AssertionError is thrown.

Specified by:
isSortedAccordingTo in interface ArraySortedAssert<ShortArrayAssert,Short>
Parameters:
comparator - the Comparator used to compare array elements
Returns:
this assertion object.

usingComparator

public ShortArrayAssert usingComparator(Comparator<?> customComparator)
Description copied from class: AbstractAssert
Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
Custom comparator is bound to assertion instance, meaning that if a new assertion is created, it will use default comparison strategy.

Example :
 // compares invoices by payee 
 assertThat(invoiceList).usingComparator(invoicePayeeComparator).isEqualTo(expectedInvoiceList).
 
 // compares invoices by date, doesNotHaveDuplicates and contains both use the given invoice date comparator
 assertThat(invoiceList).usingComparator(invoiceDateComparator).doesNotHaveDuplicates().contains(may2010Invoice)
 
 // as assertThat(invoiceList) creates a new assertion, it uses standard comparison strategy (Invoice's equal method) to compare invoiceList elements to lowestInvoice.                                                      
 assertThat(invoiceList).contains(lowestInvoice).
 
Custom comparator is not parameterized with actual type A (ie. Comparator<A>) because if it was, we could not write the following code :
 // frodo and sam are instances of Character (a Character having a Race)
 // raceComparator implements Comparator<Character> 
 // assertThat(frodo) returns an ObjectAssert and not a custom CharacterAssert implementing Assert<CharacterAssert, Character>  
 assertThat(frodo).usingComparator(raceComparator).isEqualTo(sam); // won't compile !
 
 The code does not compile because assertThat(frodo) returns an ObjectAssert, thus usingComparator expects a Comparator<Object> 
 and Comparator<Character> is not a Comparator<Object> as generics are not reified.
 
 Note that, it would have worked if assertThat(frodo) returned a CharacterAssert implementing Assert<CharacterAssert, Character>. 
 

Specified by:
usingComparator in interface Assert<ShortArrayAssert,short[]>
Overrides:
usingComparator in class AbstractAssert<ShortArrayAssert,short[]>
Parameters:
customComparator - the comparator to use for incoming assertion checks.
Returns:
this assertion object.

usingDefaultComparator

public ShortArrayAssert usingDefaultComparator()
Description copied from class: AbstractAssert
Revert to standard comparison for incoming assertion checks.
This method should be used to disable a custom comparison strategy set by calling Assert.usingComparator(Comparator).

Specified by:
usingDefaultComparator in interface Assert<ShortArrayAssert,short[]>
Overrides:
usingDefaultComparator in class AbstractAssert<ShortArrayAssert,short[]>
Returns:
this assertion object.


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