Class DoubleArrayAssert


public class DoubleArrayAssert extends ArrayAssert<double[]>
Understands assertion methods for double arrays. To create a new instance of this class use the method Assertions.assertThat(double[]).
  • Constructor Details

    • DoubleArrayAssert

      protected DoubleArrayAssert(double... actual)
      Creates a new DoubleArrayAssert.
      Parameters:
      actual - the target to verify.
  • Method Details

    • as

      public DoubleArrayAssert 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<double[]>
      Parameters:
      description - the description of the actual value.
      Returns:
      this assertion object.
    • describedAs

      public DoubleArrayAssert 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<double[]>
      Parameters:
      description - the description of the actual value.
      Returns:
      this assertion object.
    • as

      public DoubleArrayAssert 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<double[]>
      Parameters:
      description - the description of the actual value.
      Returns:
      this assertion object.
    • describedAs

      public DoubleArrayAssert 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<double[]>
      Parameters:
      description - the description of the actual value.
      Returns:
      this assertion object.
    • contains

      public DoubleArrayAssert contains(double... values)
      Verifies that the actual double array contains the given values.
      Parameters:
      values - the values to look for.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual double array is null.
      NullPointerException - if the given double array is null.
      AssertionError - if the actual double array does not contain the given values.
    • containsOnly

      public DoubleArrayAssert containsOnly(double... values)
      Verifies that the actual double array contains the given values only.
      Parameters:
      values - the values to look for.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual double array is null.
      NullPointerException - if the given double array is null.
      AssertionError - if the actual double array does not contain the given objects, or if the actual double array contains elements other than the ones specified.
    • excludes

      public DoubleArrayAssert excludes(double... values)
      Verifies that the actual double array does not contain the given values.
      Parameters:
      values - the values the array should exclude.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual double array is null.
      NullPointerException - if the given double array is null.
      AssertionError - if the actual double array contains any of the given values.
    • satisfies

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

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

      public DoubleArrayAssert is(Condition<double[]> condition)
      Specified by:
      is in class GenericAssert<double[]>
      Parameters:
      condition - the given condition.
      Returns:
      this assertion object.
      Throws:
      NullPointerException - if the given condition is null.
      AssertionError - if the actual double array does not satisfy the given condition.
      Since:
      1.2
    • isNot

      public DoubleArrayAssert isNot(Condition<double[]> condition)
      Specified by:
      isNot in class GenericAssert<double[]>
      Parameters:
      condition - the given condition.
      Returns:
      this assertion object.
      Throws:
      NullPointerException - if the given condition is null.
      AssertionError - if the actual double array satisfies the given condition.
      Since:
      1.2
    • isNotNull

      public DoubleArrayAssert isNotNull()
      Verifies that the actual double array is not null.
      Specified by:
      isNotNull in class GenericAssert<double[]>
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual double array is null.
    • isNotEmpty

      public DoubleArrayAssert isNotEmpty()
      Verifies that the actual double array contains at least on element.
      Specified by:
      isNotEmpty in class GroupAssert<double[]>
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual double array is null.
      AssertionError - if the actual double array is empty.
    • isEqualTo

      public DoubleArrayAssert isEqualTo(double[] expected)
      Verifies that the actual double array is equal to the given array. Array equality is checked by Arrays.equals(double[], double[]).
      Specified by:
      isEqualTo in class GenericAssert<double[]>
      Parameters:
      expected - the given array to compare the actual array to.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual double array is not equal to the given one.
    • isEqualTo

      public DoubleArrayAssert isEqualTo(double[] expected, Delta delta)
      Verifies that the actual double array is equal to the given array, within a positive delta.
      Parameters:
      expected - the given array to compare the actual array to.
      delta - the given delta.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual double array is not equal to the given one.
      Since:
      1.1
    • failureWhenNotEqual

      private AssertionError failureWhenNotEqual(double[] expected, Delta delta)
    • equals

      private boolean equals(double e, double a, Delta delta)
    • isNotEqualTo

      public DoubleArrayAssert isNotEqualTo(double[] array)
      Verifies that the actual double array is not equal to the given array. Array equality is checked by Arrays.equals(double[], double[]).
      Specified by:
      isNotEqualTo in class GenericAssert<double[]>
      Parameters:
      array - the given array to compare the actual array to.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual double array is equal to the given one.
    • hasSize

      public DoubleArrayAssert hasSize(int expected)
      Verifies that the number of elements in the actual double array is equal to the given one.
      Specified by:
      hasSize in class GroupAssert<double[]>
      Parameters:
      expected - the expected number of elements in the actual double array.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual double array is null.
      AssertionError - if the number of elements in the actual double array is not equal to the given one.
    • isSameAs

      public DoubleArrayAssert isSameAs(double[] expected)
      Verifies that the actual double array is the same as the given array.
      Specified by:
      isSameAs in class GenericAssert<double[]>
      Parameters:
      expected - the given array to compare the actual array to.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual double array is not the same as the given one.
    • isNotSameAs

      public DoubleArrayAssert isNotSameAs(double[] expected)
      Verifies that the actual double array is not the same as the given array.
      Specified by:
      isNotSameAs in class GenericAssert<double[]>
      Parameters:
      expected - the given array to compare the actual array to.
      Returns:
      this assertion object.
      Throws:
      AssertionError - if the actual double array is the same as the given one.
    • overridingErrorMessage

      public DoubleArrayAssert 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<double[]>
      Parameters:
      message - the given error message, which will replace the default one.
      Returns:
      this assertion.