Package org.fest.assertions
Class Assertions
java.lang.Object
org.fest.assertions.Assertions
Understands an 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
ConstructorsModifierConstructorDescriptionprotectedThis constructor is protected to make it possible to subclass this class. -
Method Summary
Modifier and TypeMethodDescriptionprivate static <T> Collection<T>asCollection(Iterator<T> iterator) static BooleanAssertassertThat(boolean actual) Creates a new instance of.BooleanAssertstatic BooleanArrayAssertassertThat(boolean[] actual) Creates a new instance of.BooleanArrayAssertstatic ByteAssertassertThat(byte actual) Creates a new instance of.ByteAssertstatic ByteArrayAssertassertThat(byte[] actual) Creates a new instance of.ByteArrayAssertstatic CharAssertassertThat(char actual) Creates a new instance of.CharAssertstatic CharArrayAssertassertThat(char[] actual) Creates a new instance of.CharArrayAssertstatic DoubleAssertassertThat(double actual) Creates a new instance of.DoubleAssertstatic DoubleArrayAssertassertThat(double[] actual) Creates a new instance of.DoubleArrayAssertstatic FloatAssertassertThat(float actual) Creates a new instance of.FloatAssertstatic FloatArrayAssertassertThat(float[] actual) Creates a new instance of.FloatArrayAssertstatic IntAssertassertThat(int actual) Creates a new instance of.IntAssertstatic IntArrayAssertassertThat(int[] actual) Creates a new instance of.IntArrayAssertstatic LongAssertassertThat(long actual) Creates a new instance of.LongAssertstatic LongArrayAssertassertThat(long[] actual) Creates a new instance of.LongArrayAssertstatic ShortAssertassertThat(short actual) Creates a new instance of.ShortAssertstatic ShortArrayAssertassertThat(short[] actual) Creates a new instance of.ShortArrayAssertstatic ImageAssertassertThat(BufferedImage actual) Creates a new instance of.ImageAssertstatic FileAssertassertThat(File actual) Creates a new instance of.FileAssertstatic BooleanAssertassertThat(Boolean actual) Creates a new instance of.BooleanAssertstatic ByteAssertassertThat(Byte actual) Creates a new instance of.ByteAssertstatic CharAssertassertThat(Character actual) Creates a new instance of.CharAssertstatic DoubleAssertassertThat(Double actual) Creates a new instance of.DoubleAssertstatic FloatAssertassertThat(Float actual) Creates a new instance of.FloatAssertstatic IntAssertassertThat(Integer actual) Creates a new instance of.IntAssertstatic CollectionAssertassertThat(Iterable<?> actual) Creates a new instance of.CollectionAssertstatic LongAssertassertThat(Long actual) Creates a new instance of.LongAssertstatic ObjectAssertassertThat(Object actual) Creates a new instance of.ObjectAssertstatic ObjectArrayAssertassertThat(Object[] actual) Creates a new instance of.ObjectArrayAssertstatic ShortAssertassertThat(Short actual) Creates a new instance of.ShortAssertstatic StringAssertassertThat(String actual) Creates a new instance of.StringAssertstatic ThrowableAssertassertThat(Throwable actual) Creates a new instance of.ThrowableAssertstatic BigDecimalAssertassertThat(BigDecimal actual) Creates a new instance of.BigDecimalAssertstatic CollectionAssertassertThat(Collection<?> actual) Creates a new instance of.CollectionAssertstatic CollectionAssertassertThat(Iterator<?> actual) Creates a new instance of.CollectionAssertstatic ListAssertassertThat(List<?> actual) Creates a new instance of.ListAssertstatic MapAssertassertThat(Map<?, ?> actual) Creates a new instance of.MapAssertstatic <T extends AssertExtension>
TassertThat(T assertion) Returns the given assertion.
-
Constructor Details
-
Assertions
protected Assertions()This constructor is protected to make it possible to subclass this class. Since all its methods are static, there is no point on creating a new instance of it.
-
-
Method Details
-
asCollection
-
assertThat
Creates a new instance of.BigDecimalAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.BooleanAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.BooleanAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.BooleanArrayAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.ImageAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.ByteAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.ByteAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.ByteArrayAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.CharAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.CharAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.CharArrayAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.CollectionAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.ListAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
- Since:
- 1.1
-
assertThat
Creates a new instance of.DoubleAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.DoubleAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.DoubleArrayAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.FileAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.FloatAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.FloatAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.FloatArrayAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.IntAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.IntAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.IntArrayAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.CollectionAssert- Parameters:
actual- anIterablewhose contents will be added to a newCollection.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.CollectionAssert- Parameters:
actual- anIteratorwhose contents will be added to a newCollection.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.LongAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.LongAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.LongArrayAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.MapAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.ObjectAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.ObjectArrayAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.ShortAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.ShortAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.ShortArrayAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.StringAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-
assertThat
Returns the given assertion. This method improves code readability by surrounding the given assertion with "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);
- Type Parameters:
T- the generic type of the user-defined assertion.- Parameters:
assertion- the assertion to return.- Returns:
- the given assertion.
-
assertThat
Creates a new instance of.ThrowableAssert- Parameters:
actual- the value to be the target of the assertions methods.- Returns:
- the created assertion object.
-