Top Description Fields Constructors Methods
org.assertj.core.api

public abstract Class AbstractPeriodAssert<SELF extends AbstractPeriodAssert<SELF>>

extends AbstractAssert<SELF extends AbstractPeriodAssert<SELF>, Period>
Class Inheritance
Known Direct Subclasses
org.assertj.core.api.PeriodAssert
Static Imports
org.assertj.core.error.ShouldBePeriod.shouldBeNegative, .ShouldBePeriod.shouldBePositive, .ShouldHavePeriod.shouldHaveDays, .ShouldHavePeriod.shouldHaveMonths, .ShouldHavePeriod.shouldHaveYears

Assertions for Period type.
Author
Hayden Meloche
Since
3.17.0

Field Summary

Inherited from org.assertj.core.api.AbstractAssert:
actualassertionErrorCreatorconditionscustomRepresentationinfomyselfobjectsprintAssertionsDescriptionthrowUnsupportedExceptionOnEquals

Constructor Summary

AccessConstructor and Description
protected
AbstractPeriodAssert(Period
the actual value to verify
period
,
Class<?>
the "self type"
selfType
)

Creates a new org.assertj.core.api.AbstractPeriodAssert

Method Summary

Modifier and TypeMethod and Description
public SELF

Returns:

this assertion object
hasDays
(int
the expected days value
expectedDays
)

Verifies that the actual Period has the given days.

public SELF

Returns:

this assertion object
hasMonths
(int
the expected months value
expectedMonths
)

Verifies that the actual Period has the given months.

public SELF

Returns:

this assertion object
hasYears
(int
the expected years value
expectedYears
)

Verifies that the actual Period has the given years.

public SELF

Returns:

this assertion object
isNegative
()

Verifies that the actual Period is negative (i.e. is less than Period#ZERO).

public SELF

Returns:

this assertion object
isPositive
()

Verifies that the actual Period is positive (i.e. is greater than Period#ZERO).

Inherited from org.assertj.core.api.AbstractAssert:
areEqualasInstanceOfasListassertionErrorasStringdescribedAsdescriptionTextdoesNotHavedoesNotHaveSameClassAsdoesNotHaveSameHashCodeAsdoesNotHaveToStringdoesNotHaveToStringequalsextractingextractingfailurefailureWithActualExpectedfailWithActualExpectedAndMessagefailWithMessagegetWritableAssertionInfohashashCodehasSameClassAshasSameHashCodeAshasToStringhasToStringinBinaryinHexadecimalisisElementOfCustomAssertisEqualToisExactlyInstanceOfisInisInisInstanceOfisInstanceOfAnyisInstanceOfSatisfyingisNotisNotEqualToisNotExactlyInstanceOfisNotInisNotInisNotInstanceOfisNotInstanceOfAnyisNotNullisNotOfAnyClassInisNotSameAsisNullisOfAnyClassInisSameAsmatchesmatchesnewListAssertInstanceoverridingErrorMessageoverridingErrorMessagesatisfiessatisfiessatisfiessatisfiesAnyOfsatisfiesAnyOfsatisfiesAnyOfForProxysatisfiesForProxysetCustomRepresentationsetDescriptionConsumersetPrintAssertionsDescriptionthrowAssertionErrorusingComparatorusingComparatorusingDefaultComparatorusingRecursiveAssertionusingRecursiveAssertionusingRecursiveComparisonusingRecursiveComparisonwithAssertionStatewithFailMessagewithFailMessagewithRepresentationwithThreadDumpOnError

Constructor Detail

AbstractPeriodAssertback to summary
protected AbstractPeriodAssert(Period period, Class<?> selfType)

Creates a new org.assertj.core.api.AbstractPeriodAssert

Parameters
period:Period

the actual value to verify

selfType:Class<?>

the "self type"

Method Detail

hasDaysback to summary
public SELF hasDays(int expectedDays)

Verifies that the actual Period has the given days.

Example :

 // assertion will pass
assertThat(Period.ofDays(5)).hasDays(5);

// assertion will fail
assertThat(Period.ofDays(5)).hasDays(1);
Parameters
expectedDays:int

the expected days value

Returns:SELF

this assertion object

Exceptions
AssertionError:
  • if the actual Period is null
  • if the actual Period does not have the given days
Since
3.17.0
hasMonthsback to summary
public SELF hasMonths(int expectedMonths)

Verifies that the actual Period has the given months.

Example :

 // assertion will pass
assertThat(Period.ofMonths(5)).hasMonths(5);

// assertion will fail
assertThat(Period.ofMonths(5)).hasMonths(1);
Parameters
expectedMonths:int

the expected months value

Returns:SELF

this assertion object

Exceptions
AssertionError:
  • if the actual Period is null
  • if the actual Period does not have the given months
Since
3.17.0
hasYearsback to summary
public SELF hasYears(int expectedYears)

Verifies that the actual Period has the given years.

Example :

 // assertion will pass
assertThat(Period.ofYears(5)).hasYears(5);

// assertion will fail
assertThat(Period.ofYears(5)).hasYears(1);
Parameters
expectedYears:int

the expected years value

Returns:SELF

this assertion object

Exceptions
AssertionError:
  • if the actual Period is null
  • if the actual Period does not have the given years
Since
3.17.0
isNegativeback to summary
public SELF isNegative()

Verifies that the actual Period is negative (i.e. is less than Period#ZERO).

Example :

 // assertion will pass
assertThat(Period.ofMonths(-5)).isNegative();

// assertion will fail
assertThat(Period.ofMonths(2)).isNegative();
Returns:SELF

this assertion object

Exceptions
AssertionError:
  • if the actual Period is null
  • if the actual Period is not greater than Period#ZERO
Since
3.17.0
isPositiveback to summary
public SELF isPositive()

Verifies that the actual Period is positive (i.e. is greater than Period#ZERO).

Example :

 // assertion will pass
assertThat(Period.ofMonths(5)).isPositive();

// assertion will fail
assertThat(Period.ofMonths(-2)).isPositive();
Returns:SELF

this assertion object

Exceptions
AssertionError:
  • if the actual Period is null
  • if the actual Period is not greater than Period#ZERO
Since
3.17.0