Class BDDAssertions

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

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

    • then

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

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

      public static ChangesAssert then(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.