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 Summary
FieldsModifier and TypeFieldDescriptionstatic final longFive minutes, in milliseconds.static final longFive seconds, in milliseconds.static final longFour minutes, in milliseconds.static final longFour seconds, in milliseconds.static final longOne minute, in milliseconds.static final longOne second, in milliseconds.static final longTen minutes, in milliseconds.static final longThree minutes, in milliseconds.static final longThree seconds, in milliseconds.static final longTwo minutes, in milliseconds.static final longTwo seconds, in milliseconds.Fields inherited from class org.dbunit.assertion.comparer.value.ValueComparerBase
BASE_FAIL_MSG -
Constructor Summary
ConstructorsConstructorDescriptionIsActualWithinToleranceOfExpectedTimestampValueComparer(long lowToleranceValueInMillis, long highToleranceValueInMillis) Create instance specifying the allowed actual time difference range from expected. -
Method Summary
Modifier and TypeMethodDescriptionprotected longcalcTimeDifference(long actualTimeInMillis, long expectedTimeInMillis) Returns the absolute time difference between the given times.protected longconvertValueToTimeInMillis(Object timestampValue) Returns the givenTimestampvalue's time in milliseconds.protected ObjectgetCastedValue(Object value, DataType type) Casts the given value using the given data type, or returns it unchanged if the type isnullorDataType.UNKNOWN.protected StringReturns the text snippet for substitution inValueComparerBase.BASE_FAIL_MSG.protected booleanisExpected(ITable expectedTable, ITable actualTable, int rowNum, String columnName, DataType dataType, Object expectedValue, Object actualValue) Determines whether the actual value compares as expected against the expected value.protected booleanisExpectedWithNull(Object expectedValue, Object actualValue) Since one is a known null, isExpected=true when they equal.protected booleanisExpectedWithoutNull(Object expectedValue, Object actualValue, DataType dataType) Neither is null so compare values with tolerance.protected booleanisTolerant(long diffTime) Returns whether the given time difference is within the configured tolerance range.Methods inherited from class org.dbunit.assertion.comparer.value.ValueComparerTemplateBase
doCompare, makeFailMessageMethods inherited from class org.dbunit.assertion.comparer.value.ValueComparerBase
compare, toString
-
Field Details
-
ONE_SECOND_IN_MILLIS
public static final long ONE_SECOND_IN_MILLISOne second, in milliseconds.- See Also:
-
TWO_SECONDS_IN_MILLIS
public static final long TWO_SECONDS_IN_MILLISTwo seconds, in milliseconds.- See Also:
-
THREE_SECONDS_IN_MILLIS
public static final long THREE_SECONDS_IN_MILLISThree seconds, in milliseconds.- See Also:
-
FOUR_SECONDS_IN_MILLIS
public static final long FOUR_SECONDS_IN_MILLISFour seconds, in milliseconds.- See Also:
-
FIVE_SECONDS_IN_MILLIS
public static final long FIVE_SECONDS_IN_MILLISFive seconds, in milliseconds.- See Also:
-
ONE_MINUTE_IN_MILLIS
public static final long ONE_MINUTE_IN_MILLISOne minute, in milliseconds.- See Also:
-
TWO_MINUTES_IN_MILLIS
public static final long TWO_MINUTES_IN_MILLISTwo minutes, in milliseconds.- See Also:
-
THREE_MINUTES_IN_MILLIS
public static final long THREE_MINUTES_IN_MILLISThree minutes, in milliseconds.- See Also:
-
FOUR_MINUTES_IN_MILLIS
public static final long FOUR_MINUTES_IN_MILLISFour minutes, in milliseconds.- See Also:
-
FIVE_MINUTES_IN_MILLIS
public static final long FIVE_MINUTES_IN_MILLISFive minutes, in milliseconds.- See Also:
-
TEN_MINUTES_IN_MILLIS
public static final long TEN_MINUTES_IN_MILLISTen 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:ValueComparerTemplateBaseDetermines whether the actual value compares as expected against the expected value.- Specified by:
isExpectedin classValueComparerTemplateBase- 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- TheDataTypefor 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
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:
trueif 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 aTimestamp.- Returns:
trueif actualValue is within tolerance of expectedValue.- Throws:
TypeCastException- if either value cannot be cast using dataType.
-
getCastedValue
Casts the given value using the given data type, or returns it unchanged if the type isnullorDataType.UNKNOWN.- Parameters:
value- the value to cast.type- the data type to cast with, may benull.- 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:
trueif diffTime is within the configured tolerance range.
-
convertValueToTimeInMillis
Returns the givenTimestampvalue's time in milliseconds.- Parameters:
timestampValue- the value to convert, must be aTimestamp.- 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
Description copied from class:ValueComparerTemplateBaseReturns the text snippet for substitution inValueComparerBase.BASE_FAIL_MSG.- Specified by:
getFailPhrasein classValueComparerTemplateBase- Returns:
- The text snippet for substitution in
ValueComparerBase.BASE_FAIL_MSG.
-