|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.fest.assertions.Assertions
public class Assertions
Entry point for assertion methods for different data types. Each method in this class is a static factory for the type-specific assertion objects. The purpose of this class is to make test code more readable.
For example:
int removed = employees.removeFired();assertThat(removed).isZero(); List<Employee> newEmployees = employees.hired(TODAY);assertThat(newEmployees).hasSize(6);
| Constructor Summary | |
|---|---|
protected |
Assertions()
This constructor is protected to make it possible to subclass this class. |
| Method Summary | ||
|---|---|---|
static BigDecimalAssert |
assertThat(BigDecimal actual)
Creates a new instance of . |
|
static BooleanAssert |
assertThat(boolean actual)
Creates a new instance of . |
|
static BooleanAssert |
assertThat(Boolean actual)
Creates a new instance of . |
|
static BooleanArrayAssert |
assertThat(boolean[] actual)
Creates a new instance of . |
|
static ImageAssert |
assertThat(BufferedImage actual)
Creates a new instance of . |
|
static ByteAssert |
assertThat(byte actual)
Creates a new instance of . |
|
static ByteAssert |
assertThat(Byte actual)
Creates a new instance of . |
|
static ByteArrayAssert |
assertThat(byte[] actual)
Creates a new instance of . |
|
static CharAssert |
assertThat(char actual)
Creates a new instance of . |
|
static CharArrayAssert |
assertThat(char[] actual)
Creates a new instance of . |
|
static CharAssert |
assertThat(Character actual)
Creates a new instance of . |
|
static CollectionAssert |
assertThat(Collection<?> actual)
Creates a new instance of . |
|
static DoubleAssert |
assertThat(double actual)
Creates a new instance of . |
|
static DoubleAssert |
assertThat(Double actual)
Creates a new instance of . |
|
static DoubleArrayAssert |
assertThat(double[] actual)
Creates a new instance of . |
|
static FileAssert |
assertThat(File actual)
Creates a new instance of . |
|
static FloatAssert |
assertThat(float actual)
Creates a new instance of . |
|
static FloatAssert |
assertThat(Float actual)
Creates a new instance of . |
|
static FloatArrayAssert |
assertThat(float[] actual)
Creates a new instance of . |
|
static IntAssert |
assertThat(int actual)
Creates a new instance of . |
|
static IntArrayAssert |
assertThat(int[] actual)
Creates a new instance of . |
|
static IntAssert |
assertThat(Integer actual)
Creates a new instance of . |
|
static IteratorAssert |
assertThat(Iterable<?> actual)
Creates a new instance of . |
|
static IteratorAssert |
assertThat(Iterator<?> actual)
Creates a new instance of . |
|
static ListAssert |
assertThat(List<?> actual)
Creates a new instance of . |
|
static LongAssert |
assertThat(long actual)
Creates a new instance of . |
|
static LongAssert |
assertThat(Long actual)
Creates a new instance of . |
|
static LongArrayAssert |
assertThat(long[] actual)
Creates a new instance of . |
|
static MapAssert |
assertThat(Map<?,?> actual)
Creates a new instance of . |
|
static ObjectAssert |
assertThat(Object actual)
Creates a new instance of . |
|
static ObjectArrayAssert |
assertThat(Object[] actual)
Creates a new instance of . |
|
static ShortAssert |
assertThat(short actual)
Creates a new instance of . |
|
static ShortAssert |
assertThat(Short actual)
Creates a new instance of . |
|
static ShortArrayAssert |
assertThat(short[] actual)
Creates a new instance of . |
|
static StringAssert |
assertThat(String actual)
Creates a new instance of . |
|
static
|
assertThat(T assertion)
Returns the given assertion. |
|
static ThrowableAssert |
assertThat(Throwable actual)
Creates a new instance of . |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
protected Assertions()
| Method Detail |
|---|
public static BigDecimalAssert assertThat(BigDecimal actual)
BigDecimalAssert.
actual - the value to be the target of the assertions methods.
public static BooleanAssert assertThat(boolean actual)
BooleanAssert.
actual - the value to be the target of the assertions methods.
public static BooleanAssert assertThat(Boolean actual)
BooleanAssert.
actual - the value to be the target of the assertions methods.
public static BooleanArrayAssert assertThat(boolean[] actual)
BooleanArrayAssert.
actual - the value to be the target of the assertions methods.
public static ImageAssert assertThat(BufferedImage actual)
ImageAssert.
actual - the value to be the target of the assertions methods.
public static ByteAssert assertThat(byte actual)
ByteAssert.
actual - the value to be the target of the assertions methods.
public static ByteAssert assertThat(Byte actual)
ByteAssert.
actual - the value to be the target of the assertions methods.
public static ByteArrayAssert assertThat(byte[] actual)
ByteArrayAssert.
actual - the value to be the target of the assertions methods.
public static CharAssert assertThat(char actual)
CharAssert.
actual - the value to be the target of the assertions methods.
public static CharAssert assertThat(Character actual)
CharAssert.
actual - the value to be the target of the assertions methods.
public static CharArrayAssert assertThat(char[] actual)
CharArrayAssert.
actual - the value to be the target of the assertions methods.
public static CollectionAssert assertThat(Collection<?> actual)
CollectionAssert.
actual - the value to be the target of the assertions methods.
public static ListAssert assertThat(List<?> actual)
ListAssert.
actual - the value to be the target of the assertions methods.
public static DoubleAssert assertThat(double actual)
DoubleAssert.
actual - the value to be the target of the assertions methods.
public static DoubleAssert assertThat(Double actual)
DoubleAssert.
actual - the value to be the target of the assertions methods.
public static DoubleArrayAssert assertThat(double[] actual)
DoubleArrayAssert.
actual - the value to be the target of the assertions methods.
public static FileAssert assertThat(File actual)
FileAssert.
actual - the value to be the target of the assertions methods.
public static FloatAssert assertThat(float actual)
FloatAssert.
actual - the value to be the target of the assertions methods.
public static FloatAssert assertThat(Float actual)
FloatAssert.
actual - the value to be the target of the assertions methods.
public static FloatArrayAssert assertThat(float[] actual)
FloatArrayAssert.
actual - the value to be the target of the assertions methods.
public static IntAssert assertThat(int actual)
IntAssert.
actual - the value to be the target of the assertions methods.
public static IntAssert assertThat(Integer actual)
IntAssert.
actual - the value to be the target of the assertions methods.
public static IntArrayAssert assertThat(int[] actual)
IntArrayAssert.
actual - the value to be the target of the assertions methods.
public static IteratorAssert assertThat(Iterable<?> actual)
IteratorAssert.
actual - an Iterable whose contents will be added to a new Collection.
public static IteratorAssert assertThat(Iterator<?> actual)
IteratorAssert.
actual - an Iterator whose contents will be added to a new Collection.
public static LongAssert assertThat(long actual)
LongAssert.
actual - the value to be the target of the assertions methods.
public static LongAssert assertThat(Long actual)
LongAssert.
actual - the value to be the target of the assertions methods.
public static LongArrayAssert assertThat(long[] actual)
LongArrayAssert.
actual - the value to be the target of the assertions methods.
public static MapAssert assertThat(Map<?,?> actual)
MapAssert.
actual - the value to be the target of the assertions methods.
public static ObjectAssert assertThat(Object actual)
ObjectAssert.
actual - the value to be the target of the assertions methods.
public static ObjectArrayAssert assertThat(Object[] actual)
ObjectArrayAssert.
actual - the value to be the target of the assertions methods.
public static ShortAssert assertThat(short actual)
ShortAssert.
actual - the value to be the target of the assertions methods.
public static ShortAssert assertThat(Short actual)
ShortAssert.
actual - the value to be the target of the assertions methods.
public static ShortArrayAssert assertThat(short[] actual)
ShortArrayAssert.
actual - the value to be the target of the assertions methods.
public static StringAssert assertThat(String actual)
StringAssert.
actual - the value to be the target of the assertions methods.
public static <T extends AssertExtension> T assertThat(T assertion)
assertThat".
For example, let's assume we have the following custom assertion class:
public class ServerSocketAssertion implements AssertExtension {
private final ServerSocket socket;
public ServerSocketAssertion(ServerSocket socket) {
this.socket = socket;
}
public ServerSocketAssert isConnectedTo(int port) {
assertThat(socket.isBound()).isTrue();
assertThat(socket.getLocalPort()).isEqualTo(port);
assertThat(socket.isClosed()).isFalse();
return this;
}
}
We can wrap that assertion with "assertThat" to improve test code readability.
ServerSocketAssertion socket = new ServerSocketAssertion(server.getSocket()); assertThat(socket).isConnectedTo(2000);
T - the generic type of the user-defined assertion.assertion - the assertion to return.
public static ThrowableAssert assertThat(Throwable actual)
ThrowableAssert.
actual - the value to be the target of the assertions methods.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||