public abstract class AbstractDurationAssert<SELF extends AbstractDurationAssert<SELF>> extends AbstractComparableAssert<SELF,Duration>
Duration type.actual, info, myself, objects, throwUnsupportedExceptionOnEquals| Modifier | Constructor and Description |
|---|---|
protected |
AbstractDurationAssert(Duration duration,
Class<?> selfType)
Creates a new
|
| Modifier and Type | Method and Description |
|---|---|
SELF |
hasDays(long otherDays)
Verifies that the actual
Duration has the given days. |
SELF |
hasHours(long otherHours)
Verifies that the actual
Duration has the given hours. |
SELF |
hasMillis(long otherMillis)
Verifies that the actual
Duration has the given millis. |
SELF |
hasMinutes(long otherMinutes)
Verifies that the actual
Duration has the given minutes. |
SELF |
hasNanos(long otherNanos)
Verifies that the actual
Duration has the given nanos. |
SELF |
hasSeconds(long otherSeconds)
Verifies that the actual
Duration has the given seconds. |
SELF |
isCloseTo(Duration expected,
Duration allowedDifference)
Verifies that the actual
Duration is close to the given one within the given allowed difference (assertion succeeds if difference = allowed difference). |
SELF |
isNegative()
Verifies that the actual
Duration is negative (i.e. |
SELF |
isPositive()
Verifies that the actual
Duration is positive (i.e. |
SELF |
isZero()
Verifies that the actual
Duration is equal to Duration.ZERO. |
inBinary, inHexadecimal, isBetween, isEqualByComparingTo, isGreaterThan, isGreaterThanOrEqualTo, isLessThan, isLessThanOrEqualTo, isNotEqualByComparingTo, isStrictlyBetween, usingComparator, usingComparator, usingDefaultComparatoras, as, doesNotReturn, extracting, extracting, extracting, extracting, extracting, extracting, extractingForProxy, getComparatorsByType, hasAllNullFieldsOrProperties, hasAllNullFieldsOrPropertiesExcept, hasFieldOrProperty, hasFieldOrPropertyWithValue, hasNoNullFieldsOrProperties, hasNoNullFieldsOrPropertiesExcept, hasOnlyFields, isEqualToComparingFieldByField, isEqualToComparingFieldByFieldRecursively, isEqualToComparingOnlyGivenFields, isEqualToIgnoringGivenFields, isEqualToIgnoringNullFields, newObjectAssert, returns, usingComparatorForFields, usingComparatorForType, usingRecursiveComparison, usingRecursiveComparisonareEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, is, isElementOfCustomAssert, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnErrorclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitas, describedAsprotected AbstractDurationAssert(Duration duration, Class<?> selfType)
AbstractDurationAssertduration - the actual value to verifyselfType - the "self type"public SELF isZero()
Duration is equal to Duration.ZERO.
Example :
// assertion will pass
assertThat(Duration.ZERO).isZero();
// assertion will fail
assertThat(Duration.ofMinutes(3)).isZero();AssertionError - if the actual Duration is nullAssertionError - if the actual Duration is not Duration.ZEROpublic SELF isNegative()
Duration is negative (i.e. is less than Duration.ZERO).
Example :
// assertion will pass
assertThat(Duration.ofMinutes(-15)).isNegative();
// assertion will fail
assertThat(Duration.ofMinutes(10)).isNegative();AssertionError - if the actual Duration is nullAssertionError - if the actual Duration is not less than Duration.ZEROpublic SELF isPositive()
Duration is positive (i.e. is greater than Duration.ZERO).
Example :
// assertion will pass
assertThat(Duration.ofHours(5)).isPositive();
// assertion will fail
assertThat(Duration.ofHours(-2)).isPositive();AssertionError - if the actual Duration is nullAssertionError - if the actual Duration is not greater than Duration.ZEROpublic SELF hasNanos(long otherNanos)
Duration has the given nanos.
Example :
// assertion will pass
assertThat(Duration.ofNanos(145)).hasNanos(145);
// assertion will fail
assertThat(Duration.ofNanos(145)).hasNanos(50);otherNanos - the expected nanoseconds valueAssertionError - if the actual Duration is nullAssertionError - if the actual Duration does not have the given nanospublic SELF hasMillis(long otherMillis)
Duration has the given millis.
Example :
// assertion will pass
assertThat(Duration.ofMillis(250)).hasMillis(250);
// assertion will fail
assertThat(Duration.ofMillis(250)).hasMillis(700);otherMillis - the expected milliseconds valueAssertionError - if the actual Duration is nullAssertionError - if the actual Duration does not have the given millispublic SELF hasSeconds(long otherSeconds)
Duration has the given seconds.
Example :
// assertion will pass
assertThat(Duration.ofSeconds(250)).hasSeconds(250);
// assertion will fail
assertThat(Duration.ofSeconds(250)).hasSeconds(700);otherSeconds - the expected seconds valueAssertionError - if the actual Duration is nullAssertionError - if the actual Duration does not have the given secondspublic SELF hasMinutes(long otherMinutes)
Duration has the given minutes.
Example :
// assertion will pass
assertThat(Duration.ofMinutes(65)).hasMinutes(65);
// assertion will fail
assertThat(Duration.ofMinutes(65)).hasMinutes(25);otherMinutes - the expected minutes valueAssertionError - if the actual Duration is nullAssertionError - if the actual Duration does not have the given minutespublic SELF hasHours(long otherHours)
Duration has the given hours.
Example :
// assertion will pass
assertThat(Duration.ofHours(15)).hasHours(15);
// assertion will fail
assertThat(Duration.ofHours(15)).hasHours(5);otherHours - the expected hours valueAssertionError - if the actual Duration is nullAssertionError - if the actual Duration does not have the given hourspublic SELF hasDays(long otherDays)
Duration has the given days.
Example :
// assertion will pass
assertThat(Duration.ofDays(5)).hasDays(5);
// assertion will fail
assertThat(Duration.ofDays(5)).hasDays(1);otherDays - the expected days valueAssertionError - if the actual Duration is nullAssertionError - if the actual Duration does not have the given dayspublic SELF isCloseTo(Duration expected, Duration allowedDifference)
Duration is close to the given one within the given allowed difference (assertion succeeds if difference = allowed difference).
This is equivalent of: abs(actual - expected) <= allowed difference.
For readability you can use Assertions.withMarginOf(Duration) to express the allowed difference.
Examples:
Duration twoMinutes = Duration.ofMinutes(2);
// assertions succeed:
assertThat(twoMinutes).isCloseTo(Duration.ofMinutes(3), Duration.ofMinutes(5));
assertThat(twoMinutes).isCloseTo(Duration.ofMinutes(-3), Duration.ofMinutes(10));
// assertion succeeds when difference is exactly equals to the allowed difference
assertThat(twoMinutes).isCloseTo(Duration.ofMinutes(3), Duration.ofMinutes(1));
assertThat(twoMinutes).isCloseTo(Duration.ofMinutes(-3), Duration.ofMinutes(5));
// assertions using within syntactic sugar
assertThat(twoMinutes).isCloseTo(Duration.ofMinutes(3), withMarginOf(Duration.ofMinutes(5)));
assertThat(twoMinutes).isCloseTo(Duration.ofMinutes(3), withMarginOf(Duration.ofMinutes(1)));
// assertions fail
assertThat(twoMinutes).isCloseTo(Duration.ofMinutes(5), withMarginOf(Duration.ofMinutes(1)));
assertThat(twoMinutes).isCloseTo(Duration.ofMinutes(-3), withMarginOf(Duration.ofMinutes(4)));expected - the given Duration to compare to actual.allowedDifference - a positive Duration to express the maximum allowed difference.this assertion object.IllegalArgumentException - if the expected Duration is null.IllegalArgumentException - if the allowed difference Duration is null or negative.AssertionError - if the actual value is not close enough to the given one.Copyright © 2025. All rights reserved.