Package org.dbunit.assertion
Class DefaultFailureHandler
java.lang.Object
org.dbunit.assertion.DefaultFailureHandler
- All Implemented Interfaces:
DifferenceListener,FailureFactory,FailureHandler
- Direct Known Subclasses:
DiffCollectingFailureHandler
Default implementation of the
FailureHandler.- Since:
- 2.4.0
- Author:
- gommma (gommma AT users.sourceforge.net)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDefault failure factory which returns DBUnits own assertion error instances. -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor which does not provide any additional column information.DefaultFailureHandler(String[] additionalColumnInfo) Create a default failure handlerDefaultFailureHandler(Column[] additionalColumnInfo) Create a default failure handler -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddFailMessage(Difference diff, StringBuilder builder) Appends the difference's fail message, if any, to the given builder.protected StringbuildMessage(Difference diff) Builds the failure message for the given difference.createFailure(String message) Creates a new assertion failure object with only a message and no expected/actual values.createFailure(String message, String expected, String actual) Creates a new failure object which can have different types, depending on the testing framework you are currently using (e.g.getAdditionalInfo(ITable expectedTable, ITable actualTable, int row, String columnName) Returns a string to be appended to the assertion failure message.protected ObjectgetColumnValue(ITable table, int rowIndex, String columnName) Returns the value of the given column, resolving through aColumnFilterTablewrapper if needed.voidhandle(Difference diff) Is invoked by theDbUnitAssertwhen a data cell difference has been found.protected booleanisFailMessage(String failMessage) Returns whether the given fail message is non-empty.protected StringmakeAdditionalColumnInfoErrorMessage(String columnName, DataSetException e) Builds an error message describing why additional column info could not be retrieved.voidsetFailureFactory(FailureFactory failureFactory) Sets the failure factory used to create assertion errors.toString()
-
Constructor Details
-
DefaultFailureHandler
public DefaultFailureHandler()Default constructor which does not provide any additional column information. -
DefaultFailureHandler
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
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
Sets the failure factory used to create assertion errors.- Parameters:
failureFactory- TheFailureFactoryto be used for creating assertion errors.
-
createFailure
Description copied from interface:FailureFactoryCreates a new failure object which can have different types, depending on the testing framework you are currently using (e.g. JUnit, TestNG, ...)- Specified by:
createFailurein interfaceFailureFactory- Parameters:
message- The reason for the failureexpected- The expected resultactual- 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
Description copied from interface:FailureFactoryCreates a new assertion failure object with only a message and no expected/actual values.- Specified by:
createFailurein interfaceFailureFactory- 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:FailureHandlerReturns 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:
getAdditionalInfoin interfaceFailureHandler- Parameters:
expectedTable- the table containing the expected results.actualTable- the table containing the actual results.row- The row for which the assertion failedcolumnName- The column for which the assertion failed- Returns:
- A string that is appended to the assertion failure message
-
getColumnValue
Returns the value of the given column, resolving through aColumnFilterTablewrapper 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
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
Description copied from interface:DifferenceListenerIs invoked by theDbUnitAssertwhen a data cell difference has been found.- Specified by:
handlein interfaceDifferenceListener- Parameters:
diff- The difference that has been found
-
buildMessage
Builds the failure message for the given difference.- Parameters:
diff- the difference to describe.- Returns:
- the formatted failure message.
-
addFailMessage
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
Returns whether the given fail message is non-empty.- Parameters:
failMessage- the fail message to check.- Returns:
trueif the given fail message is non-nulland non-empty.
-
toString
-