Package org.assertj.db.api
Class Assertions
java.lang.Object
org.assertj.db.api.Assertions
Entry point of all the assertions.
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" like text and the next column contains 1979 like number :
ConnectionProvider connectionProvider = ConnectionProviderFactory.of("jdbc:h2:mem:test", "sa", "").create();
Table table = new Table(connectionProvider, "movie");
assertThat(table)
.row()
.value("title")
.isEqualTo("Alien")
.returnToRow()
.value()
.isEqualTo(1979);
It is possible to chain assertion on a value :
assertThat(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");
assertThat(table)
.row()
.value("title")
.isEqualTo("Alien")
.value()
.isEqualTo(1979);
It is possible to do the same thing with column and the row :
assertThat(table)
.row()
.value("title")
.isEqualTo("Alien")
.row()
.value()
.isEqualTo("The Village")
.column("year")
.value(1)
.equalTo(2004);
- Author:
- Régis Pouiller
-
Method Summary
Modifier and TypeMethodDescriptionstatic ChangesAssertassertThat(Changes changes) Creates a new instance ofChangesAssert.static RequestAssertassertThat(Request request) Creates a new instance ofRequestAssert.static TableAssertassertThat(Table table) Creates a new instance ofTableAssert.static 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.
-
Method Details
-
assertThat
Creates a new instance ofTableAssert.- Parameters:
table- The table to assert on.- Returns:
- The created assertion object.
-
assertThat
Creates a new instance ofRequestAssert.- Parameters:
request- The request to assert on.- Returns:
- The created assertion object.
-
assertThat
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.
-