Class IsActualWithinToleranceOfExpectedTimestampValueComparer

java.lang.Object
org.dbunit.assertion.comparer.value.ValueComparerBase
org.dbunit.assertion.comparer.value.ValueComparerTemplateBase
org.dbunit.assertion.comparer.value.IsActualWithinToleranceOfExpectedTimestampValueComparer
All Implemented Interfaces:
ValueComparer

public class IsActualWithinToleranceOfExpectedTimestampValueComparer extends ValueComparerTemplateBase
ValueComparer implementation for Timestamps that verifies actual value is within a low and high milliseconds tolerance range of expected value. Note: If actual and expected values are both null, the comparison passes.
Since:
2.6.0
Author:
Jeff Jensen
  • Field Details

    • ONE_SECOND_IN_MILLIS

      public static final long ONE_SECOND_IN_MILLIS
      One second, in milliseconds.
      See Also:
    • TWO_SECONDS_IN_MILLIS

      public static final long TWO_SECONDS_IN_MILLIS
      Two seconds, in milliseconds.
      See Also:
    • THREE_SECONDS_IN_MILLIS

      public static final long THREE_SECONDS_IN_MILLIS
      Three seconds, in milliseconds.
      See Also:
    • FOUR_SECONDS_IN_MILLIS

      public static final long FOUR_SECONDS_IN_MILLIS
      Four seconds, in milliseconds.
      See Also:
    • FIVE_SECONDS_IN_MILLIS

      public static final long FIVE_SECONDS_IN_MILLIS
      Five seconds, in milliseconds.
      See Also:
    • ONE_MINUTE_IN_MILLIS

      public static final long ONE_MINUTE_IN_MILLIS
      One minute, in milliseconds.
      See Also:
    • TWO_MINUTES_IN_MILLIS

      public static final long TWO_MINUTES_IN_MILLIS
      Two minutes, in milliseconds.
      See Also:
    • THREE_MINUTES_IN_MILLIS

      public static final long THREE_MINUTES_IN_MILLIS
      Three minutes, in milliseconds.
      See Also:
    • FOUR_MINUTES_IN_MILLIS

      public static final long FOUR_MINUTES_IN_MILLIS
      Four minutes, in milliseconds.
      See Also:
    • FIVE_MINUTES_IN_MILLIS

      public static final long FIVE_MINUTES_IN_MILLIS
      Five minutes, in milliseconds.
      See Also:
    • TEN_MINUTES_IN_MILLIS

      public static final long TEN_MINUTES_IN_MILLIS
      Ten minutes, in milliseconds.
      See Also:
  • Constructor Details

    • IsActualWithinToleranceOfExpectedTimestampValueComparer

      public IsActualWithinToleranceOfExpectedTimestampValueComparer(long lowToleranceValueInMillis, long highToleranceValueInMillis)
      Create instance specifying the allowed actual time difference range from expected.
      Parameters:
      lowToleranceValueInMillis - The minimum time difference allowed.
      highToleranceValueInMillis - The maximum time difference allowed.
  • Method Details

    • isExpected

      protected boolean isExpected(ITable expectedTable, ITable actualTable, int rowNum, String columnName, DataType dataType, Object expectedValue, Object actualValue) throws DatabaseUnitException
      Description copied from class: ValueComparerTemplateBase
      Determines whether the actual value compares as expected against the expected value.
      Specified by:
      isExpected in class ValueComparerTemplateBase
      Parameters:
      expectedTable - Table containing all expected results.
      actualTable - Table containing all actual results.
      rowNum - The current row number comparing.
      columnName - The name of the current column comparing.
      dataType - The DataType for the current column comparing.
      expectedValue - The current expected value for the column.
      actualValue - The current actual value for the column.
      Returns:
      true if comparing actual to expected is as expected.
      Throws:
      DatabaseUnitException - if the comparison cannot be performed.
    • isExpectedWithNull

      protected boolean isExpectedWithNull(Object expectedValue, Object actualValue)
      Since one is a known null, isExpected=true when they equal.
      Parameters:
      expectedValue - the expected value, possibly null.
      actualValue - the actual value, possibly null.
      Returns:
      true if expectedValue and actualValue are the same reference (both null, or the same non-null instance).
    • isExpectedWithoutNull

      protected boolean isExpectedWithoutNull(Object expectedValue, Object actualValue, DataType dataType) throws TypeCastException
      Neither is null so compare values with tolerance.
      Parameters:
      expectedValue - the expected value, not null.
      actualValue - the actual value, not null.
      dataType - the data type used to cast both values to a Timestamp.
      Returns:
      true if actualValue is within tolerance of expectedValue.
      Throws:
      TypeCastException - if either value cannot be cast using dataType.
    • getCastedValue

      protected Object getCastedValue(Object value, DataType type) throws TypeCastException
      Casts the given value using the given data type, or returns it unchanged if the type is null or DataType.UNKNOWN.
      Parameters:
      value - the value to cast.
      type - the data type to cast with, may be null.
      Returns:
      the cast value.
      Throws:
      TypeCastException - if the value cannot be cast using the given type.
    • isTolerant

      protected boolean isTolerant(long diffTime)
      Returns whether the given time difference is within the configured tolerance range.
      Parameters:
      diffTime - the (non-negative) time difference, in milliseconds.
      Returns:
      true if diffTime is within the configured tolerance range.
    • convertValueToTimeInMillis

      protected long convertValueToTimeInMillis(Object timestampValue)
      Returns the given Timestamp value's time in milliseconds.
      Parameters:
      timestampValue - the value to convert, must be a Timestamp.
      Returns:
      the timestamp's time in milliseconds.
    • calcTimeDifference

      protected long calcTimeDifference(long actualTimeInMillis, long expectedTimeInMillis)
      Returns the absolute time difference between the given times.
      Parameters:
      actualTimeInMillis - the actual time, in milliseconds.
      expectedTimeInMillis - the expected time, in milliseconds.
      Returns:
      the absolute difference between the two times, in milliseconds.
    • getFailPhrase

      protected String getFailPhrase()
      Description copied from class: ValueComparerTemplateBase
      Returns the text snippet for substitution in ValueComparerBase.BASE_FAIL_MSG.
      Specified by:
      getFailPhrase in class ValueComparerTemplateBase
      Returns:
      The text snippet for substitution in ValueComparerBase.BASE_FAIL_MSG.