Package org.assertj.core.api
Class AbstractDurationAssert<SELF extends AbstractDurationAssert<SELF>>
java.lang.Object
org.assertj.core.api.AbstractAssert<SELF,Duration>
org.assertj.core.api.AbstractObjectAssert<SELF,Duration>
org.assertj.core.api.AbstractComparableAssert<SELF,Duration>
org.assertj.core.api.AbstractDurationAssert<SELF>
- All Implemented Interfaces:
Assert<SELF,,Duration> ComparableAssert<SELF,,Duration> Descriptable<SELF>,ExtensionPoints<SELF,Duration>
- Direct Known Subclasses:
DurationAssert
public abstract class AbstractDurationAssert<SELF extends AbstractDurationAssert<SELF>>
extends AbstractComparableAssert<SELF,Duration>
Assertions for
Duration type.- Since:
- 3.15.0
- Author:
- Filip Hrisafov
-
Field Summary
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself, objects, throwUnsupportedExceptionOnEquals -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractDurationAssert(Duration duration, Class<?> selfType) Creates a newAbstractDurationAssert -
Method Summary
Modifier and TypeMethodDescriptionhasDays(long otherDays) Verifies that the actualDurationhas the given days.hasHours(long otherHours) Verifies that the actualDurationhas the given hours.hasMillis(long otherMillis) Verifies that the actualDurationhas the given millis.hasMinutes(long otherMinutes) Verifies that the actualDurationhas the given minutes.hasNanos(long otherNanos) Verifies that the actualDurationhas the given nanos.hasSeconds(long otherSeconds) Verifies that the actualDurationhas the given seconds.Verifies that the actualDurationis close to the given one within the given allowed difference (assertion succeeds if difference = allowed difference).Verifies that the actualDurationis negative (i.e.Verifies that the actualDurationis positive (i.e.isZero()Verifies that the actualDurationis equal toDuration.ZERO.Methods inherited from class org.assertj.core.api.AbstractComparableAssert
inBinary, inHexadecimal, isBetween, isEqualByComparingTo, isGreaterThan, isGreaterThanOrEqualTo, isLessThan, isLessThanOrEqualTo, isNotEqualByComparingTo, isStrictlyBetween, usingComparator, usingComparator, usingDefaultComparatorMethods inherited from class org.assertj.core.api.AbstractObjectAssert
as, 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, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparisonMethods inherited from class org.assertj.core.api.AbstractAssert
actual, areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, doesNotMatch, doesNotMatch, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, 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, usingEquals, usingEquals, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnErrorMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.assertj.core.api.Descriptable
as, describedAs, describedAs
-
Constructor Details
-
AbstractDurationAssert
Creates a newAbstractDurationAssert- Parameters:
duration- the actual value to verifyselfType- the "self type"
-
-
Method Details
-
isZero
Verifies that the actualDurationis equal toDuration.ZERO.Example :
// assertion will pass assertThat(Duration.ZERO).isZero(); // assertion will fail assertThat(Duration.ofMinutes(3)).isZero();- Returns:
- this assertion object
- Throws:
AssertionError- if the actualDurationisnullAssertionError- if the actualDurationis notDuration.ZERO- Since:
- 3.15.0
-
isNegative
Verifies that the actualDurationis negative (i.e. is less thanDuration.ZERO).Example :
// assertion will pass assertThat(Duration.ofMinutes(-15)).isNegative(); // assertion will fail assertThat(Duration.ofMinutes(10)).isNegative();- Returns:
- this assertion object
- Throws:
AssertionError- if the actualDurationisnullAssertionError- if the actualDurationis not less thanDuration.ZERO- Since:
- 3.15.0
-
isPositive
Verifies that the actualDurationis positive (i.e. is greater thanDuration.ZERO).Example :
// assertion will pass assertThat(Duration.ofHours(5)).isPositive(); // assertion will fail assertThat(Duration.ofHours(-2)).isPositive();- Returns:
- this assertion object
- Throws:
AssertionError- if the actualDurationisnullAssertionError- if the actualDurationis not greater thanDuration.ZERO- Since:
- 3.15.0
-
hasNanos
Verifies that the actualDurationhas the given nanos.Example :
// assertion will pass assertThat(Duration.ofNanos(145)).hasNanos(145); // assertion will fail assertThat(Duration.ofNanos(145)).hasNanos(50);- Parameters:
otherNanos- the expected nanoseconds value- Returns:
- this assertion object
- Throws:
AssertionError- if the actualDurationisnullAssertionError- if the actualDurationdoes not have the given nanos- Since:
- 3.15.0
-
hasMillis
Verifies that the actualDurationhas the given millis.Example :
// assertion will pass assertThat(Duration.ofMillis(250)).hasMillis(250); // assertion will fail assertThat(Duration.ofMillis(250)).hasMillis(700);- Parameters:
otherMillis- the expected milliseconds value- Returns:
- this assertion object
- Throws:
AssertionError- if the actualDurationisnullAssertionError- if the actualDurationdoes not have the given millis- Since:
- 3.15.0
-
hasSeconds
Verifies that the actualDurationhas the given seconds.Example :
// assertion will pass assertThat(Duration.ofSeconds(250)).hasSeconds(250); // assertion will fail assertThat(Duration.ofSeconds(250)).hasSeconds(700);- Parameters:
otherSeconds- the expected seconds value- Returns:
- this assertion object
- Throws:
AssertionError- if the actualDurationisnullAssertionError- if the actualDurationdoes not have the given seconds- Since:
- 3.15.0
-
hasMinutes
Verifies that the actualDurationhas the given minutes.Example :
// assertion will pass assertThat(Duration.ofMinutes(65)).hasMinutes(65); // assertion will fail assertThat(Duration.ofMinutes(65)).hasMinutes(25);- Parameters:
otherMinutes- the expected minutes value- Returns:
- this assertion object
- Throws:
AssertionError- if the actualDurationisnullAssertionError- if the actualDurationdoes not have the given minutes- Since:
- 3.15.0
-
hasHours
Verifies that the actualDurationhas the given hours.Example :
// assertion will pass assertThat(Duration.ofHours(15)).hasHours(15); // assertion will fail assertThat(Duration.ofHours(15)).hasHours(5);- Parameters:
otherHours- the expected hours value- Returns:
- this assertion object
- Throws:
AssertionError- if the actualDurationisnullAssertionError- if the actualDurationdoes not have the given hours- Since:
- 3.15.0
-
hasDays
Verifies that the actualDurationhas the given days.Example :
// assertion will pass assertThat(Duration.ofDays(5)).hasDays(5); // assertion will fail assertThat(Duration.ofDays(5)).hasDays(1);- Parameters:
otherDays- the expected days value- Returns:
- this assertion object
- Throws:
AssertionError- if the actualDurationisnullAssertionError- if the actualDurationdoes not have the given days- Since:
- 3.15.0
-
isCloseTo
Verifies that the actualDurationis 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)));- Parameters:
expected- the givenDurationto compare to actual.allowedDifference- a positiveDurationto express the maximum allowed difference.- Returns:
thisassertion object.- Throws:
IllegalArgumentException- if the expected Duration isnull.IllegalArgumentException- if the allowed difference Duration isnullor negative.AssertionError- if the actual value is not close enough to the given one.- Since:
- 3.18.0
-