FEST Fluent Assertions 1.2 API

This document is the API specification for the FEST "Flexible Assertions" Module.

See:
          Description

Packages
org.fest.assertions Assertion methods bound to the type they apply.

 

This document is the API specification for the FEST "Flexible Assertions" Module.

Currently, this module provides assertions that apply to the following data types:

  1. Object
  2. String
  3. Collection
  4. List
  5. Map
  6. Primitives (boolean, int, char, etc.)
  7. Object arrays
  8. Arrays of primitives
  9. BufferedImage
  10. Throwable
  11. File
  12. BigDecimal

Quick example:

int removed = employees.removeFired();
assertThat(removed).isZero();
 
List<Employee> newEmployees = employees.hired(TODAY);
assertThat(newEmployees).hasSize(6);

Assertions can also be extended by using custom Conditions. The following condition verifies that the characters in a String are in uppercase:

class UpperCaseCondition extends Condition<String> {
  public boolean matches(String value) {
    if(isEmpty(value)) return false;
    return value.equals(value.toUpperCase());
  }

  public static UpperCaseCondition isUpperCase() {
    return new UpperCaseCondition("Uppercase");
  }
}
This example shows how to use such condition:
assertThat("hello").as("Greeting").satisfies(isUppercase());
which will fail with the message "[Greeting] expected:Uppercase but was:<'hello'>"



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