Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

FEST Assertions Module has moved to Github !

Check this page :https://github.com/alexruiz/fest-assert-2.x/wiki

The documentation below is for Fest 1.x which is no more maintained, we are focusing our effort to the 2.x version !

...

Assertions classes provided by FEST-Assert can be extended by using custom conditions (instances of org.fest.assertions.Condition.)

For example, the following condition verifies that the characters in a String are in uppercase:

Code Block
java
java

// package org.fest.assert.sample;

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:

Code Block
java
java

// import static org.fest.assert.sample.UpperCaseCondition.isUpperCase;
assertThat("hello").as("Greeting").satisfies(isUppercase());

which will fail with the message:

No Format

[Greeting] actual value:<'hello'> should satisfy condition:<Uppercase>

...

In our previous example, we can change the name of the static factory method isUppercase to simply uppercase:

Code Block
java
java

public static UpperCaseCondition upperCase() {
  return new UpperCaseCondition("Uppercase");
}

and use the alias is:

Code Block
java
java

// import static org.fest.assert.sample.UpperCaseCondition.upperCase;
assertThat("hello").as("Greeting").is(uppercase());

...