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)
      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)
      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 -
      actualTable -
      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)
    • makeAdditionalColumnInfoErrorMessage

      protected String makeAdditionalColumnInfoErrorMessage(String columnName, DataSetException e)
    • 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)
    • addFailMessage

      protected void addFailMessage(Difference diff, StringBuilder builder)
    • isFailMessage

      protected boolean isFailMessage(String failMessage)
    • toString

      public String toString()
      Overrides:
      toString in class Object