org.fest.assertions
Class DoubleAssert

java.lang.Object
  extended by org.fest.assertions.Assert
      extended by org.fest.assertions.GenericAssert<Double>
          extended by org.fest.assertions.DoubleAssert
All Implemented Interfaces:
NumberAssert

public class DoubleAssert
extends GenericAssert<Double>
implements NumberAssert

Understands Assertion methods for Doubles and doubles. To create a new instance of this class call Assertions.assertThat(Double) or Assertions.assertThat(double).

Author:
Yvonne Wang, David DIDIER, Alex Ruiz, Ansgar Konermann

Nested Class Summary
static class DoubleAssert.Delta
          Deprecated. use top-level class Delta instead. This class will be removed in version 2.0.
 
Field Summary
 
Fields inherited from class org.fest.assertions.GenericAssert
actual
 
Constructor Summary
protected DoubleAssert(double actual)
          Creates a new DoubleAssert.
protected DoubleAssert(Double actual)
          Creates a new DoubleAssert.
 
Method Summary
 DoubleAssert as(Description description)
          Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails.
 DoubleAssert as(String description)
          Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails.
static DoubleAssert.Delta delta(double d)
          Deprecated. use method Delta.delta(double) instead. This method will be removed in version 2.0.
 DoubleAssert describedAs(Description description)
          Alias for GenericAssert.as(Description), since "as" is a keyword in Groovy.
 DoubleAssert describedAs(String description)
          Alias for GenericAssert.as(String), since "as" is a keyword in Groovy.
 DoubleAssert doesNotSatisfy(Condition<Double> condition)
          Verifies that the actual Double does not satisfy the given condition.
 DoubleAssert is(Condition<Double> condition)
          Alias for satisfies(Condition).
 DoubleAssert isEqualTo(double expected)
          Verifies that the actual Double is equal to the given one.
 DoubleAssert isEqualTo(Double expected)
          Verifies that the actual Double is equal to the given one.
 DoubleAssert isEqualTo(double expected, Delta delta)
          Verifies that the actual Double is equal to the given one, within a positive delta.
 DoubleAssert isEqualTo(Double expected, Delta delta)
          Verifies that the actual Double is equal to the given one, within a positive delta.
 DoubleAssert isEqualTo(double expected, DoubleAssert.Delta delta)
          Deprecated. use method isEqualTo(double, org.fest.assertions.Delta) instead. This method will be removed in version 2.0.
 DoubleAssert isGreaterThan(double other)
          Verifies that the actual Double is greater than the given one.
 DoubleAssert isGreaterThanOrEqualTo(double other)
          Verifies that the actual Double is greater or equal to the given one.
 DoubleAssert isLessThan(double other)
          Verifies that the actual Double is less than the given one.
 DoubleAssert isLessThanOrEqualTo(double other)
          Verifies that the actual Double is less or equal to the given one.
 DoubleAssert isNaN()
          Verifies that the actual Double is equal to Double.NaN.
 DoubleAssert isNegative()
          Verifies that the actual Double is negative.
 DoubleAssert isNot(Condition<Double> condition)
          Alias for doesNotSatisfy(Condition).
 DoubleAssert isNotEqualTo(double other)
          Verifies that the actual Double is not equal to the given one.
 DoubleAssert isNotEqualTo(Double other)
          Verifies that the actual Double is not equal to the given one.
 DoubleAssert isNotNull()
          Verifies that the actual Double is not null.
 DoubleAssert isNotSameAs(Double other)
          Verifies that the actual Double is not the same object as the given one.
 DoubleAssert isPositive()
          Verifies that the actual Double is positive.
 DoubleAssert isSameAs(Double expected)
          Verifies that the actual Double is the same object as the given one.
 DoubleAssert isZero()
          Verifies that the actual Double is equal to zero.
 DoubleAssert overridingErrorMessage(String message)
          Replaces the default message displayed in case of a failure with the given one.
 DoubleAssert satisfies(Condition<Double> condition)
          Verifies that the actual Double satisfies the given condition.
 
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

DoubleAssert

protected DoubleAssert(double actual)
Creates a new DoubleAssert.

Parameters:
actual - the actual value to verify.

DoubleAssert

protected DoubleAssert(Double actual)
Creates a new DoubleAssert.

Parameters:
actual - the actual value to verify.
Method Detail

as

public DoubleAssert 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<Double>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

describedAs

public DoubleAssert 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<Double>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

as

public DoubleAssert 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<Double>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

describedAs

public DoubleAssert 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<Double>
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

isEqualTo

public DoubleAssert isEqualTo(double expected)
Verifies that the actual Double is equal to the given one.

Parameters:
expected - the value to compare the actual one to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Double is not equal to the given one.

isEqualTo

public DoubleAssert isEqualTo(Double expected)
Verifies that the actual Double is equal to the given one.

Specified by:
isEqualTo in class GenericAssert<Double>
Parameters:
expected - the given value to compare the actual Double to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Double is not equal to the given one.
Since:
1.3

isEqualTo

@Deprecated
public DoubleAssert isEqualTo(double expected,
                                         DoubleAssert.Delta delta)
Deprecated. use method isEqualTo(double, org.fest.assertions.Delta) instead. This method will be removed in version 2.0.

Verifies that the actual Double is equal to the given one, within a positive delta.

Parameters:
expected - the value to compare the actual one to.
delta - the given delta.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Double is not equal to the given one.

isEqualTo

public DoubleAssert isEqualTo(double expected,
                              Delta delta)
Verifies that the actual Double is equal to the given one, within a positive delta.

Parameters:
expected - the value to compare the actual one to.
delta - the given delta.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Double is not equal to the given one.
Since:
1.1

isEqualTo

public DoubleAssert isEqualTo(Double expected,
                              Delta delta)
Verifies that the actual Double is equal to the given one, within a positive delta.

Parameters:
expected - the value to compare the actual one to.
delta - the given delta.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Double is not equal to the given one.
Since:
1.3

isNotEqualTo

public DoubleAssert isNotEqualTo(double other)
Verifies that the actual Double is not equal to the given one.

Parameters:
other - the given value.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Double is equal to the given one.

isGreaterThan

public DoubleAssert isGreaterThan(double other)
Verifies that the actual Double is greater than the given one.

Parameters:
other - the given value.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Double is not greater than the given one.

isLessThan

public DoubleAssert isLessThan(double other)
Verifies that the actual Double is less than the given one.

Parameters:
other - the given value.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Double is not less than the given one.

isGreaterThanOrEqualTo

public DoubleAssert isGreaterThanOrEqualTo(double other)
Verifies that the actual Double is greater or equal to the given one.

Parameters:
other - the given value.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Double is not greater than or equal to the given one.

isLessThanOrEqualTo

public DoubleAssert isLessThanOrEqualTo(double other)
Verifies that the actual Double is less or equal to the given one.

Parameters:
other - the given value.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Double is not less than or equal to the given one.

isZero

public DoubleAssert isZero()
Verifies that the actual Double is equal to zero.

Specified by:
isZero in interface NumberAssert
Returns:
this assertion object.
Throws:
AssertionError - if the actual Double is not equal to zero.

isPositive

public DoubleAssert isPositive()
Verifies that the actual Double is positive.

Specified by:
isPositive in interface NumberAssert
Returns:
this assertion object.
Throws:
AssertionError - if the actual Double is not positive.

isNegative

public DoubleAssert isNegative()
Verifies that the actual Double is negative.

Specified by:
isNegative in interface NumberAssert
Returns:
this assertion object.
Throws:
AssertionError - if the actual Double is not negative.

isNaN

public DoubleAssert isNaN()
Verifies that the actual Double is equal to Double.NaN.

Returns:
this assertion object.
Throws:
AssertionError - if the actual Double is not equal to NAN.

delta

@Deprecated
public static DoubleAssert.Delta delta(double d)
Deprecated. use method Delta.delta(double) instead. This method will be removed in version 2.0.

Creates a new holder for a delta value to be used in isEqualTo(double, org.fest.assertions.DoubleAssert.Delta).

Parameters:
d - the delta value.
Returns:
a new delta value holder.

overridingErrorMessage

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

satisfies

public DoubleAssert satisfies(Condition<Double> condition)
Verifies that the actual Double 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 does not satisfy the given condition.
Since:
1.3
See Also:
is(Condition)

doesNotSatisfy

public DoubleAssert doesNotSatisfy(Condition<Double> condition)
Verifies that the actual Double 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 value does satisfies the given condition.
Since:
1.3
See Also:
isNot(Condition)

is

public DoubleAssert is(Condition<Double> condition)
Alias for satisfies(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 does not satisfy the given condition.
Since:
1.3

isNot

public DoubleAssert isNot(Condition<Double> condition)
Alias for doesNotSatisfy(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 does not satisfy the given condition.
Since:
1.3

isNotEqualTo

public DoubleAssert isNotEqualTo(Double other)
Verifies that the actual Double is not equal to the given one.

Specified by:
isNotEqualTo in class GenericAssert<Double>
Parameters:
other - the given Double to compare the actual Double to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Double is equal to the given one.
Since:
1.3

isNotNull

public DoubleAssert isNotNull()
Verifies that the actual Double is not null.

Specified by:
isNotNull in class GenericAssert<Double>
Returns:
this assertion object.
Throws:
AssertionError - if the actual Double is null.
Since:
1.3

isSameAs

public DoubleAssert isSameAs(Double expected)
Verifies that the actual Double is the same object as the given one.

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

isNotSameAs

public DoubleAssert isNotSameAs(Double other)
Verifies that the actual Double is not the same object as the given one.

Specified by:
isNotSameAs in class GenericAssert<Double>
Parameters:
other - the given Double to compare the actual BigDecimal to.
Returns:
this assertion object.
Throws:
AssertionError - if the actual Double is the same as the given one.
Since:
1.3


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