org.fest.assertions
Class BooleanAssert

java.lang.Object
  extended by org.fest.assertions.Assert
      extended by org.fest.assertions.PrimitiveAssert
          extended by org.fest.assertions.BooleanAssert

public class BooleanAssert
extends PrimitiveAssert

Understands assertion methods for boolean values. To create a new instance of this class use the method Assertions.assertThat(boolean).

Author:
Alex Ruiz, Yvonne Wang, David DIDIER

Constructor Summary
protected BooleanAssert(boolean actual)
          Creates a new BooleanAssert.
 
Method Summary
 BooleanAssert as(Description description)
          Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails.
 BooleanAssert as(String description)
          Sets the description of the actual value, to be used in as message of any AssertionError thrown when an assertion fails.
 BooleanAssert describedAs(Description description)
          Alias for as(Description), since "as" is a keyword in Groovy.
 BooleanAssert describedAs(String description)
          Alias for as(String), since "as" is a keyword in Groovy.
 BooleanAssert isEqualTo(boolean expected)
          Verifies that the actual boolean is equal to the given one.
 void isFalse()
          Verifies that the actual boolean value is false.
 BooleanAssert isNotEqualTo(boolean other)
          Verifies that the actual boolean is not equal to the given one.
 void isTrue()
          Verifies that the actual boolean value is true.
 BooleanAssert overridingErrorMessage(String message)
          Replaces the default message displayed in case of a failure with the given one.
 
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

BooleanAssert

protected BooleanAssert(boolean actual)
Creates a new BooleanAssert.

Parameters:
actual - the target to verify.
Method Detail

as

public BooleanAssert 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(value).as("Some value").isEqualTo(otherValue);
 

Specified by:
as in class PrimitiveAssert
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

describedAs

public BooleanAssert describedAs(String description)
Alias for 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(value).describedAs("Some value").isEqualTo(otherValue);
 

Specified by:
describedAs in class PrimitiveAssert
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

as

public BooleanAssert 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(value).as(new BasicDescription("Some value")).isEqualTo(otherValue);
 

Specified by:
as in class PrimitiveAssert
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

describedAs

public BooleanAssert describedAs(Description description)
Alias for 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(value).describedAs(new BasicDescription("Some value")).isEqualTo(otherValue);
 

Specified by:
describedAs in class PrimitiveAssert
Parameters:
description - the description of the actual value.
Returns:
this assertion object.

isTrue

public void isTrue()
Verifies that the actual boolean value is true.

Throws:
AssertionError - if the actual boolean value is false.

isFalse

public void isFalse()
Verifies that the actual boolean value is false.

Throws:
AssertionError - if the actual boolean value is true.

isEqualTo

public BooleanAssert isEqualTo(boolean expected)
Verifies that the actual boolean is equal to the given one.

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

isNotEqualTo

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

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

overridingErrorMessage

public BooleanAssert 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 PrimitiveAssert
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.