-
Notifications
You must be signed in to change notification settings - Fork 64
Creating specific assertions
joel-costigliola edited this page Apr 17, 2012
·
21 revisions
Creating its own assertions is simple : create a class inheriting from AbstractAssert and add your custom assertions method.
To be easy to use, you should also add a static method assertThat to provide an handy entry point to your new assertion class.
Let's see how to do that on an example !
The example is taken from fest-examples and more specifically TolkienCharacterAssert.java.
The class we want to make assertion on is TolkienCharacter :
// getter/setter not shown for brievety
public class TolkienCharacter {
private String name;
private Race race;
private int age;
}A TolkienCharacter has Race, which is a simple class having only a name and an immortal attribute :
public class Race {
private final String name;
private final boolean immortal;
}