Class DefaultFailureHandler

java.lang.Object
org.dbunit.assertion.DefaultFailureHandler
All Implemented Interfaces:
DifferenceListener, FailureFactory, FailureHandler
Direct Known Subclasses:
DiffCollectingFailureHandler

public class DefaultFailureHandler extends Object implements FailureHandler
Default implementation of the FailureHandler.
Since:
2.4.0
Author:
gommma (gommma AT users.sourceforge.net)
  • Constructor Details

    • DefaultFailureHandler

      public DefaultFailureHandler()
      Default constructor which does not provide any additional column information.
    • DefaultFailureHandler

      public DefaultFailureHandler(Column[] additionalColumnInfo)
      Create a default failure handler
      Parameters:
      additionalColumnInfo - the column names of the columns for which additional information should be printed when an assertion failed.
    • DefaultFailureHandler

      public DefaultFailureHandler(String[] additionalColumnInfo)
      Create a default failure handler
      Parameters:
      additionalColumnInfo - the column names of the columns for which additional information should be printed when an assertion failed.
  • Method Details

    • setFailureFactory

      public void setFailureFactory(FailureFactory failureFactory)
      Sets the failure factory used to create assertion errors.
      Parameters:
      failureFactory - The FailureFactory to be used for creating assertion errors.
    • createFailure

      public Error createFailure(String message, String expected, String actual)
      Description copied from interface: FailureFactory
      Creates a new failure object which can have different types, depending on the testing framework you are currently using (e.g. JUnit, TestNG, ...)
      Specified by:
      createFailure in interface FailureFactory
      Parameters:
      message - The reason for the failure
      expected - The expected result
      actual - The actual result
      Returns:
      The comparison failure object for this handler (can be JUnit or some other) which can be thrown on an assertion failure
    • createFailure

      public Error createFailure(String message)
      Description copied from interface: FailureFactory
      Creates a new assertion failure object with only a message and no expected/actual values.
      Specified by:
      createFailure in interface FailureFactory
      Parameters:
      message - The reason for the failure
      Returns:
      The assertion failure object for this handler (can be JUnit or some other) which can be thrown on an assertion failure
    • getAdditionalInfo

      public String getAdditionalInfo(ITable expectedTable, ITable actualTable, int row, String columnName)
      Description copied from interface: FailureHandler
      Returns a string to be appended to the assertion failure message. Is used to provide some more information about a failure (for example to print out some PK columns for identifying the failed rows in the DB).
      Specified by:
      getAdditionalInfo in interface FailureHandler
      Parameters:
      expectedTable - the table containing the expected results.
      actualTable - the table containing the actual results.
      row - The row for which the assertion failed
      columnName - The column for which the assertion failed
      Returns:
      A string that is appended to the assertion failure message
    • getColumnValue

      protected Object getColumnValue(ITable table, int rowIndex, String columnName)
      Returns the value of the given column, resolving through a ColumnFilterTable wrapper if needed.
      Parameters:
      table - the table to read the value from.
      rowIndex - the row index to read.
      columnName - the column name to read.
      Returns:
      the column value, or an error message string if it could not be retrieved.
    • makeAdditionalColumnInfoErrorMessage

      protected String makeAdditionalColumnInfoErrorMessage(String columnName, DataSetException e)
      Builds an error message describing why additional column info could not be retrieved.
      Parameters:
      columnName - the column name that could not be read.
      e - the exception raised while reading the column.
      Returns:
      the formatted error message.
    • handle

      public void handle(Difference diff)
      Description copied from interface: DifferenceListener
      Is invoked by the DbUnitAssert when a data cell difference has been found.
      Specified by:
      handle in interface DifferenceListener
      Parameters:
      diff - The difference that has been found
    • buildMessage

      protected String buildMessage(Difference diff)
      Builds the failure message for the given difference.
      Parameters:
      diff - the difference to describe.
      Returns:
      the formatted failure message.
    • addFailMessage

      protected void addFailMessage(Difference diff, StringBuilder builder)
      Appends the difference's fail message, if any, to the given builder.
      Parameters:
      diff - the difference whose fail message should be appended.
      builder - the builder to append to.
    • isFailMessage

      protected boolean isFailMessage(String failMessage)
      Returns whether the given fail message is non-empty.
      Parameters:
      failMessage - the fail message to check.
      Returns:
      true if the given fail message is non-null and non-empty.
    • toString

      public String toString()
      Overrides:
      toString in class Object