org.assertj.core.api
Class Condition<T>

java.lang.Object
  extended by org.assertj.core.api.Condition<T>
Type Parameters:
T - the type of object this condition accepts.
All Implemented Interfaces:
Descriptable<Condition<T>>
Direct Known Subclasses:
Join, Negative

public abstract class Condition<T>
extends Object
implements Descriptable<Condition<T>>

A condition to be met by an object.

Author:
Yvonne Wang, Alex Ruiz

Constructor Summary
Condition()
          Creates a new Condition.
Condition(Description description)
          Creates a new Condition.
Condition(String description)
          Creates a new Condition.
 
Method Summary
 Condition<T> as(Description newDescription)
          Sets the description of this object.
 Condition<T> as(String newDescription, Object... args)
          Sets the description of this object supporting String.format(String, Object...) syntax.
 Condition<T> describedAs(Description newDescription)
          Alias for Descriptable.as(String, Object...) since "as" is a keyword in Groovy.
 Condition<T> describedAs(String newDescription, Object... args)
          Alias for Descriptable.as(String, Object...) since "as" is a keyword in Groovy.
 Description description()
          Returns the description of this condition.
abstract  boolean matches(T value)
          Verifies that the given value satisfies this condition.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Condition

public Condition()
Creates a new Condition. The default description of this condition will the simple name of the condition's class.


Condition

public Condition(String description)
Creates a new Condition.

Parameters:
description - the description of this condition.
Throws:
NullPointerException - if the given description is null.

Condition

public Condition(Description description)
Creates a new Condition.

Parameters:
description - the description of this condition.
Throws:
NullPointerException - if the given description is null.
Method Detail

describedAs

public Condition<T> describedAs(String newDescription,
                                Object... args)
Alias for Descriptable.as(String, Object...) since "as" is a keyword in Groovy.

Specified by:
describedAs in interface Descriptable<Condition<T>>
Parameters:
newDescription - the new description to set.
Returns:
this object.

as

public Condition<T> as(String newDescription,
                       Object... args)
Sets the description of this object supporting String.format(String, Object...) syntax.

Example :

 try {
   // set a bad age to Mr Frodo which is really 33 years old.
   frodo.setAge(50);
   // you can specify a test description with as() method or describedAs(), it supports String format args
   assertThat(frodo.getAge()).as("check %s's age", frodo.getName()).isEqualTo(33);
 } catch (AssertionError e) {
   assertThat(e).hasMessage("[check Frodo's age] expected:<[33]> but was:<[50]>");
 }
 
 

Specified by:
as in interface Descriptable<Condition<T>>
Parameters:
newDescription - the new description to set.
args - optional parameter if description is a format String.
Returns:
this object.
See Also:
Descriptable.describedAs(String, Object...)

describedAs

public Condition<T> describedAs(Description newDescription)
Alias for Descriptable.as(String, Object...) since "as" is a keyword in Groovy. To remove or clear the description, pass a EmptyTextDescription as argument.

This overloaded version of "describedAs" offers more flexibility than the one taking a String by allowing users to pass their own implementation of a description. For example, a description that creates its value lazily, only when an assertion failure occurs.

Specified by:
describedAs in interface Descriptable<Condition<T>>
Parameters:
newDescription - the new description to set.
Returns:
this object.

as

public Condition<T> as(Description newDescription)
Sets the description of this object. To remove or clear the description, pass a EmptyTextDescription as argument.

This overloaded version of "describedAs" offers more flexibility than the one taking a String by allowing users to pass their own implementation of a description. For example, a description that creates its value lazily, only when an assertion failure occurs.

Specified by:
as in interface Descriptable<Condition<T>>
Parameters:
newDescription - the new description to set.
Returns:
this object.
See Also:
Descriptable.describedAs(Description)

description

public Description description()
Returns the description of this condition.

Returns:
the description of this condition.

matches

public abstract boolean matches(T value)
Verifies that the given value satisfies this condition.

Parameters:
value - the value to verify.
Returns:
true if the given value satisfies this condition; false otherwise.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2013–2015 AssertJ. All rights reserved.