Package org.assertj.db.api
Class BDDAssertions
java.lang.Object
org.assertj.db.api.BDDAssertions
Behavior Driven Development style entry point for all assertion methods.
The difference with the Assertions class is that the entry point methods are named then
instead of assertThat.
The navigation methods are defined in navigation package.
The assertion methods are defined in assertions package.
Example with a ConnectionProvider and a Table with test on the content on the first row of the movie
table that the title column contains "Alien" as text and the next column contains 1979 as a number :
ConnectionProvider connectionProvider = ConnectionProviderFactory.of("jdbc:h2:mem:test", "sa", "").create();
Table table = new Table(connectionProvider, "movie");
then(table)
.row()
.value("title")
.isEqualTo("Alien")
.returnToRow()
.value()
.isEqualTo(1979);
It is possible to chain assertion on a value :
then(table)
.row()
.value("title")
.isText()
.isEqualTo("Alien");
It is not necessary to use the returnToXxxx methods. The next example is equivalent to the first :
ConnectionProvider connectionProvider = ConnectionProviderFactory.of("jdbc:h2:mem:test", "sa", "").create();
Table table = new Table(connectionProvider, "movie");
then(table)
.row()
.value("title")
.isEqualTo("Alien")
.value()
.isEqualTo(1979);
It is possible to do the same thing with column and the row :
then(table)
.row()
.value("title")
.isEqualTo("Alien")
.row()
.value()
.isEqualTo("The Village")
.column("year")
.value(1)
.equalTo(2004);
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]bytesContentFromClassPathOf(String resource) Reads the bytes from a file in the classpath and returns them.static byte[]bytesContentOf(File file) Reads the bytes from a file and returns them.static ChangesAssertCreates a new instance ofChangesAssert.static RequestAssertCreates a new instance ofRequestAssert.static TableAssertCreates a new instance ofTableAssert.
-
Method Details
-
then
Creates a new instance ofTableAssert.- Parameters:
table- The table to assert on.- Returns:
- The created assertion object.
-
then
Creates a new instance ofRequestAssert.- Parameters:
request- The request to assert on.- Returns:
- The created assertion object.
-
then
Creates a new instance ofChangesAssert.- Parameters:
changes- The changes to assert on.- Returns:
- The created assertion object.
-
bytesContentOf
Reads the bytes from a file and returns them.- Parameters:
file- TheFile- Returns:
- The bytes of the file.
- Throws:
NullPointerException- If thefilefield isnull.AssertJDBException- If triggered, this exception wrap a possibleIOExceptionduring the loading.
-
bytesContentFromClassPathOf
Reads the bytes from a file in the classpath and returns them.- Parameters:
resource- The name of the file in the classpath.- Returns:
- The bytes of the file.
- Throws:
NullPointerException- If theresourcefield isnull.
-