Class Assertions

java.lang.Object
org.assertj.db.api.Assertions

public final class Assertions extends Object
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 Details

    • assertThat

      public static TableAssert assertThat(Table table)
      Creates a new instance of TableAssert.
      Parameters:
      table - The table to assert on.
      Returns:
      The created assertion object.
    • assertThat

      public static RequestAssert assertThat(Request request)
      Creates a new instance of RequestAssert.
      Parameters:
      request - The request to assert on.
      Returns:
      The created assertion object.
    • assertThat

      public static ChangesAssert assertThat(Changes changes)
      Creates a new instance of ChangesAssert.
      Parameters:
      changes - The changes to assert on.
      Returns:
      The created assertion object.
    • bytesContentOf

      public static byte[] bytesContentOf(File file)
      Reads the bytes from a file and returns them.
      Parameters:
      file - The File
      Returns:
      The bytes of the file.
      Throws:
      NullPointerException - If the file field is null.
      AssertJDBException - If triggered, this exception wrap a possible IOException during the loading.
    • bytesContentFromClassPathOf

      public static byte[] bytesContentFromClassPathOf(String resource)
      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 the resource field is null.