Package org.fest.assertions.api
Class DoubleArrayAssert
- java.lang.Object
-
- org.fest.assertions.api.AbstractAssert<DoubleArrayAssert,double[]>
-
- org.fest.assertions.api.DoubleArrayAssert
-
- All Implemented Interfaces:
ArraySortedAssert<DoubleArrayAssert,java.lang.Double>
,Assert<DoubleArrayAssert,double[]>
,Descriptable<DoubleArrayAssert>
,EnumerableAssert<DoubleArrayAssert,java.lang.Double>
,ExtensionPoints<DoubleArrayAssert,double[]>
public class DoubleArrayAssert extends AbstractAssert<DoubleArrayAssert,double[]> implements EnumerableAssert<DoubleArrayAssert,java.lang.Double>, ArraySortedAssert<DoubleArrayAssert,java.lang.Double>
Assertion methods for arrays ofdouble
s.To create an instance of this class, invoke
.Assertions.assertThat(double[])
- Author:
- Yvonne Wang, Alex Ruiz, Joel Costigliola, Mikhail Mazursky, Nicolas François
-
-
Field Summary
-
Fields inherited from class org.fest.assertions.api.AbstractAssert
actual, myself
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
DoubleArrayAssert(double[] actual)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DoubleArrayAssert
contains(double... values)
Verifies that the actual array contains the given values, in any order.DoubleArrayAssert
contains(double value, Index index)
Verifies that the actual array contains the given value at the given index.DoubleArrayAssert
containsOnly(double... values)
Verifies that the actual array contains only the given values and nothing else, in any order.DoubleArrayAssert
containsSequence(double... sequence)
Verifies that the actual array contains the given sequence, without any other values between them.DoubleArrayAssert
doesNotContain(double... values)
Verifies that the actual array does not contain the given values.DoubleArrayAssert
doesNotContain(double value, Index index)
Verifies that the actual array does not contain the given value at the given index.DoubleArrayAssert
doesNotHaveDuplicates()
Verifies that the actual array does not contain duplicates.DoubleArrayAssert
endsWith(double... sequence)
Verifies that the actual array ends with the given sequence of values, without any other values between them.DoubleArrayAssert
hasSameSizeAs(java.lang.Iterable<?> other)
Verifies that the actual group has the same size as givenIterable
.DoubleArrayAssert
hasSameSizeAs(java.lang.Object[] other)
Verifies that the actual group has the same size as given array.DoubleArrayAssert
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.DoubleArrayAssert
isNotEmpty()
Verifies that the actual group of values is not empty.void
isNullOrEmpty()
Verifies that the actual group of values isnull
or empty.DoubleArrayAssert
isSorted()
Verifies that the actual array is sorted into ascending order according to the natural ordering of its elements.DoubleArrayAssert
isSortedAccordingTo(java.util.Comparator<? super java.lang.Double> 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.DoubleArrayAssert
startsWith(double... sequence)
Verifies that the actual array starts with the given sequence of values, without any other values between them.DoubleArrayAssert
usingDefaultElementComparator()
Revert to standard comparison for incoming assertion group element checks.DoubleArrayAssert
usingElementComparator(java.util.Comparator<? super java.lang.Double> customComparator)
Use given custom comparator instead of relying on actual type Aequals
method to compare group elements for incoming assertion checks.-
Methods inherited from class org.fest.assertions.api.AbstractAssert
as, as, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, getWritableAssertionInfo, has, hashCode, hasSameClassAs, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, overridingErrorMessage, usingComparator, usingDefaultComparator
-
-
-
-
Method Detail
-
isNullOrEmpty
public void isNullOrEmpty()
Verifies that the actual group of values isnull
or empty.- Specified by:
isNullOrEmpty
in interfaceEnumerableAssert<DoubleArrayAssert,java.lang.Double>
-
isEmpty
public void isEmpty()
Verifies that the actual group of values is empty.- Specified by:
isEmpty
in interfaceEnumerableAssert<DoubleArrayAssert,java.lang.Double>
-
isNotEmpty
public DoubleArrayAssert isNotEmpty()
Verifies that the actual group of values is not empty.- Specified by:
isNotEmpty
in interfaceEnumerableAssert<DoubleArrayAssert,java.lang.Double>
- Returns:
this
assertion object.
-
hasSize
public DoubleArrayAssert hasSize(int expected)
Verifies that the number of values in the actual group is equal to the given one.- Specified by:
hasSize
in interfaceEnumerableAssert<DoubleArrayAssert,java.lang.Double>
- Parameters:
expected
- the expected number of values in the actual group.- Returns:
this
assertion object.
-
hasSameSizeAs
public DoubleArrayAssert hasSameSizeAs(java.lang.Object[] other)
Verifies that the actual group has the same size as given array.- Specified by:
hasSameSizeAs
in interfaceEnumerableAssert<DoubleArrayAssert,java.lang.Double>
- Parameters:
other
- the array to compare size with actual group.- Returns:
this
assertion object.
-
hasSameSizeAs
public DoubleArrayAssert hasSameSizeAs(java.lang.Iterable<?> other)
Verifies that the actual group has the same size as givenIterable
.- Specified by:
hasSameSizeAs
in interfaceEnumerableAssert<DoubleArrayAssert,java.lang.Double>
- Parameters:
other
- theIterable
to compare size with actual group.- Returns:
this
assertion object.
-
contains
public DoubleArrayAssert contains(double... values)
Verifies that the actual array contains the given values, in any order.- Parameters:
values
- the given values.- Returns:
this
assertion object.- Throws:
java.lang.NullPointerException
- if the given argument isnull
.java.lang.IllegalArgumentException
- if the given argument is an empty array.java.lang.AssertionError
- if the actual array isnull
.java.lang.AssertionError
- if the actual array does not contain the given values.
-
containsOnly
public DoubleArrayAssert containsOnly(double... 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:
java.lang.NullPointerException
- if the given argument isnull
.java.lang.IllegalArgumentException
- if the given argument is an empty array.java.lang.AssertionError
- if the actual array isnull
.java.lang.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 DoubleArrayAssert containsSequence(double... 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:
java.lang.AssertionError
- if the actual array isnull
.java.lang.AssertionError
- if the given array isnull
.java.lang.AssertionError
- if the actual array does not contain the given sequence.
-
contains
public DoubleArrayAssert contains(double 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:
java.lang.AssertionError
- if the actual array isnull
or empty.java.lang.NullPointerException
- if the givenIndex
isnull
.java.lang.IndexOutOfBoundsException
- if the value of the givenIndex
is equal to or greater than the size of the actual array.java.lang.AssertionError
- if the actual array does not contain the given value at the given index.
-
doesNotContain
public DoubleArrayAssert doesNotContain(double... values)
Verifies that the actual array does not contain the given values.- Parameters:
values
- the given values.- Returns:
this
assertion object.- Throws:
java.lang.NullPointerException
- if the given argument isnull
.java.lang.IllegalArgumentException
- if the given argument is an empty array.java.lang.AssertionError
- if the actual array isnull
.java.lang.AssertionError
- if the actual array contains any of the given values.
-
doesNotContain
public DoubleArrayAssert doesNotContain(double 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:
java.lang.AssertionError
- if the actual array isnull
.java.lang.NullPointerException
- if the givenIndex
isnull
.java.lang.AssertionError
- if the actual array contains the given value at the given index.
-
doesNotHaveDuplicates
public DoubleArrayAssert doesNotHaveDuplicates()
Verifies that the actual array does not contain duplicates.- Returns:
this
assertion object.- Throws:
java.lang.AssertionError
- if the actual array isnull
.java.lang.AssertionError
- if the actual array contains duplicates.
-
startsWith
public DoubleArrayAssert startsWith(double... sequence)
Verifies that the actual array starts with the given sequence of values, without any other values between them. Similar to
, but it also verifies that the first element in the sequence is also first element of the actual array.containsSequence(double...)
- Parameters:
sequence
- the sequence of values to look for.- Returns:
- this assertion object.
- Throws:
java.lang.NullPointerException
- if the given argument isnull
.java.lang.IllegalArgumentException
- if the given argument is an empty array.java.lang.AssertionError
- if the actual array isnull
.java.lang.AssertionError
- if the actual array does not start with the given sequence.
-
endsWith
public DoubleArrayAssert endsWith(double... sequence)
Verifies that the actual array ends with the given sequence of values, without any other values between them. Similar to
, but it also verifies that the last element in the sequence is also last element of the actual array.containsSequence(double...)
- Parameters:
sequence
- the sequence of values to look for.- Returns:
- this assertion object.
- Throws:
java.lang.NullPointerException
- if the given argument isnull
.java.lang.IllegalArgumentException
- if the given argument is an empty array.java.lang.AssertionError
- if the actual array isnull
.java.lang.AssertionError
- if the actual array does not end with the given sequence.
-
isSorted
public DoubleArrayAssert 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 :- a array composed of {2, 4, 6} is ok because the element type is a primitive type.
- a array composed of {"a1", "a2", "a3"} is ok because the element type (String) is Comparable
- a array composed of Rectangle {r1, r2, r3} is NOT ok because Rectangle is not Comparable
- a array composed of {True, "abc", False} is NOT ok because elements are not mutually comparable (even though each element type implements Comparable)
- Specified by:
isSorted
in interfaceArraySortedAssert<DoubleArrayAssert,java.lang.Double>
- Returns:
this
assertion object.
-
isSortedAccordingTo
public DoubleArrayAssert isSortedAccordingTo(java.util.Comparator<? super java.lang.Double> 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 interfaceArraySortedAssert<DoubleArrayAssert,java.lang.Double>
- Parameters:
comparator
- theComparator
used to compare array elements- Returns:
this
assertion object.
-
usingElementComparator
public DoubleArrayAssert usingElementComparator(java.util.Comparator<? super java.lang.Double> customComparator)
Use given custom comparator instead of relying on actual type Aequals
method to compare group elements 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.
Examples :
// 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 falls back to standard comparison strategy // based on Invoice's equal method to compare invoiceList elements to lowestInvoice. assertThat(invoiceList).contains(lowestInvoice). // standard comparison : the fellowshipOfTheRing includes Gandalf but not Sauron (believe me) ... assertThat(fellowshipOfTheRing).contains(gandalf) .doesNotContain(sauron); // ... but if we compare only races, Sauron is in fellowshipOfTheRing because he's a Maia like Gandalf. assertThat(fellowshipOfTheRing).usingElementComparator(raceComparator) .contains(sauron);
- Specified by:
usingElementComparator
in interfaceEnumerableAssert<DoubleArrayAssert,java.lang.Double>
- Parameters:
customComparator
- the comparator to use for incoming assertion checks.- Returns:
this
assertion object.
-
usingDefaultElementComparator
public DoubleArrayAssert usingDefaultElementComparator()
Revert to standard comparison for incoming assertion group element checks.This method should be used to disable a custom comparison strategy set by calling
EnumerableAssert.usingElementComparator(Comparator)
.- Specified by:
usingDefaultElementComparator
in interfaceEnumerableAssert<DoubleArrayAssert,java.lang.Double>
- Returns:
this
assertion object.
-
-