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

public abstract Class AbstractLocalTimeAssert<SELF extends AbstractLocalTimeAssert<SELF>>

extends AbstractTemporalAssert<SELF extends AbstractLocalTimeAssert<SELF>, LocalTime>
Class Inheritance
Known Direct Subclasses
org.assertj.core.api.LocalTimeAssert
Static Imports
org.assertj.core.error.ShouldBeAfter.shouldBeAfter, .ShouldBeAfterOrEqualTo.shouldBeAfterOrEqualTo, .ShouldBeBefore.shouldBeBefore, .ShouldBeBeforeOrEqualTo.shouldBeBeforeOrEqualTo, .ShouldBeEqualIgnoringNanos.shouldBeEqualIgnoringNanos, .ShouldBeEqualIgnoringSeconds.shouldBeEqualIgnoringSeconds, .ShouldHaveDateField.shouldHaveDateField, .ShouldHaveSameHourAs.shouldHaveSameHourAs, org.assertj.core.util.Preconditions.checkArgument

Assertions for LocalTime type from new Date & Time API introduced in Java 8.

Field Summary

Modifier and TypeField and Description
public static final String
Inherited from org.assertj.core.api.AbstractTemporalAssert:
comparables

Constructor Summary

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

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

Method Summary

Modifier and TypeMethod and Description
private static boolean

Returns:

true if both localtime are in the same year, month and day of month, hour, minute and second, false otherwise.
areEqualIgnoringNanos
(LocalTime
the actual localtime. expected not be null
actual
,
LocalTime
the other localtime. expected not be null
other
)

Returns true if both localtime are in the same year, month and day of month, hour, minute and second, false otherwise.

private static boolean

Returns:

true if both localtime are in the same year, month, day of month, hour and minute, false otherwise.
areEqualIgnoringSeconds
(LocalTime
the actual localtime. expected not be null
actual
,
LocalTime
the other localtime. expected not be null
other
)

Returns true if both localtime are in the same year, month, day of month, hour and minute, false otherwise.

private static void
assertLocalTimeAsStringParameterIsNotNull(String
String representing the LocalTime to compare actual with
localTimeAsString
)

Check that the LocalTime string representation to compare actual LocalTime to is not null, otherwise throws a IllegalArgumentException with an explicit message

private static void
assertLocalTimeParameterIsNotNull(LocalTime
the LocalTime to check
other
)

Check that the LocalTime to compare actual LocalTime to is not null, in that case throws a IllegalArgumentException with an explicit message

private void
private static Object[]
convertToLocalTimeArray(String... localTimesAsString)

public SELF

Returns:

this assertion object.
hasHour
(int
the given hour.
hour
)

Verifies that actual LocalTime is in the given hour.

public SELF

Returns:

this assertion object.
hasMinute
(int
the given minute.
minute
)

Verifies that actual LocalTime is in the given minute.

public SELF

Returns:

this assertion object.
hasNano
(int
the given nano.
nano
)

Verifies that actual LocalTime is in the given nano.

public SELF

Returns:

this assertion object.
hasSameHourAs
(LocalTime
the given LocalTime.
other
)

Verifies that actual and given LocalTime have same hour fields (minute, second and nanosecond fields are ignored in comparison).

public SELF

Returns:

this assertion object.
hasSecond
(int
the given second.
second
)

Verifies that actual LocalTime is in the given second.

private static boolean
public SELF

Returns:

this assertion object.
isAfter
(LocalTime
the given LocalTime.
other
)

Verifies that the actual LocalTime is strictly after the given one.

public SELF

Returns:

this assertion object.
isAfter
(String
String representing a LocalTime.
localTimeAsString
)

Same assertion as isAfter(LocalTime) but the LocalTime is built from given a String that must follow ISO LocalTime format to allow calling LocalTime#parse(CharSequence) method.

public SELF

Returns:

this assertion object.
isAfterOrEqualTo
(LocalTime
the given LocalTime.
other
)

Verifies that the actual LocalTime is after or equals to the given one.

public SELF

Returns:

this assertion object.
isAfterOrEqualTo
(String
String representing a LocalTime.
localTimeAsString
)

Same assertion as isAfterOrEqualTo(LocalTime) but the LocalTime is built from given String, which must follow ISO LocalTime format to allow calling LocalTime#parse(CharSequence) method.

public SELF

Returns:

this assertion object.
isBefore
(LocalTime
the given LocalTime.
other
)

Verifies that the actual LocalTime is strictly before the given one.

public SELF

Returns:

this assertion object.
isBefore
(String
String representing a LocalTime.
localTimeAsString
)

Same assertion as isBefore(LocalTime) but the LocalTime is built from given String, which must follow ISO LocalTime format to allow calling LocalTime#parse(CharSequence) method.

public SELF

Returns:

this assertion object.
isBeforeOrEqualTo
(LocalTime
the given LocalTime.
other
)

Verifies that the actual LocalTime is before or equals to the given one.

public SELF

Returns:

this assertion object.
isBeforeOrEqualTo
(String
String representing a LocalTime.
localTimeAsString
)

Same assertion as isBeforeOrEqualTo(LocalTime) but the LocalTime is built from given String, which must follow ISO LocalTime format to allow calling LocalTime#parse(CharSequence) method.

public SELF

Returns:

this assertion object.
isBetween
(LocalTime
the start value (inclusive), expected not to be null.
startInclusive
,
LocalTime
the end value (inclusive), expected not to be null.
endInclusive
)

Verifies that the actual LocalTime is in the [start, end] period (start and end included).

public SELF

Returns:

this assertion object.
isBetween
(String
the start value (inclusive), expected not to be null.
startInclusive
,
String
the end value (inclusive), expected not to be null.
endInclusive
)

Same assertion as isBetween(LocalTime, LocalTime) but here you pass LocalTime String representations which must follow ISO LocalTime format to allow calling LocalTime#parse(CharSequence) method.

public SELF
isCloseTo(LocalTime
the temporal to compare actual to
other
,
TemporalOffset<? super LocalTime>
the offset used for comparison
offset
)

Overrides org.assertj.core.api.AbstractTemporalAssert.isCloseTo.

Verifies that the actual Temporal is close to the other according to the given TemporalOffset.
public SELF

Returns:

this assertion object.
isEqualTo
(String
String representing a LocalTime.
localTimeAsString
)

Same assertion as isEqualTo(Object) (where Object is expected to be LocalTime) but here you pass LocalTime String representation that must follow ISO LocalTime format to allow calling LocalTime#parse(CharSequence) method.

public SELF

Returns:

this assertion object.
isEqualToIgnoringNanos
(LocalTime
the given LocalTime.
other
)

Deprecated Use isCloseTo(LocalTime, TemporalOffset) instead, although not exactly the same semantics, this is the right way to compare with a given precision.
Verifies that actual and given LocalTime have same hour, minute and second fields (nanosecond fields are ignored in comparison).
public SELF

Returns:

this assertion object.
isEqualToIgnoringSeconds
(LocalTime
the given LocalTime.
other
)

Deprecated Use isCloseTo(LocalTime, TemporalOffset) instead, although not exactly the same semantics, this is the right way to compare with a given precision.
Verifies that actual and given LocalTime have same hour and minute fields (second and nanosecond fields are ignored in comparison).
public SELF

Returns:

this assertion object.
isIn
(String...
String array representing LocalTimes.
localTimesAsString
)

Same assertion as isIn(Object...) (where Objects are expected to be LocalTime) but here you pass LocalTime String representations that must follow ISO LocalTime format to allow calling LocalTime#parse(CharSequence) method.

public SELF

Returns:

this assertion object.
isNotEqualTo
(String
String representing a LocalTime.
localTimeAsString
)

Same assertion as isNotEqualTo(Object) (where Object is expected to be LocalTime) but here you pass LocalTime String representation that must follow ISO LocalTime format to allow calling LocalTime#parse(CharSequence) method.

public SELF

Returns:

this assertion object.
isNotIn
(String...
Array of String representing a LocalTime.
localTimesAsString
)

Same assertion as isNotIn(Object...) (where Objects are expected to be LocalTime) but here you pass LocalTime String representations that must follow ISO LocalTime format to allow calling LocalTime#parse(CharSequence) method.

public SELF

Returns:

this assertion object.
isStrictlyBetween
(LocalTime
the start value (exclusive), expected not to be null.
startExclusive
,
LocalTime
the end value (exclusive), expected not to be null.
endExclusive
)

Verifies that the actual LocalTime is in the ]start, end[ period (start and end excluded).

public SELF

Returns:

this assertion object.
isStrictlyBetween
(String
the start value (exclusive), expected not to be null.
startExclusive
,
String
the end value (exclusive), expected not to be null.
endExclusive
)

Same assertion as isStrictlyBetween(LocalTime, LocalTime) but here you pass LocalTime String representations which must follow ISO LocalTime format to allow calling LocalTime#parse(CharSequence) method.

protected LocalTime
parse(String
the string to parse, not null
localTimeAsString
)

Implements abstract org.assertj.core.api.AbstractTemporalAssert.parse.

Obtains an instance of TEMPORAL from a string representation in ISO date format.
Inherited from org.assertj.core.api.AbstractTemporalAssert:
getActualisCloseTousingComparatorusingComparatorusingDefaultComparator

Field Detail

NULL_LOCAL_TIME_PARAMETER_MESSAGEback to summary
public static final String NULL_LOCAL_TIME_PARAMETER_MESSAGE

Constructor Detail

AbstractLocalTimeAssertback to summary
protected AbstractLocalTimeAssert(LocalTime actual, Class<?> selfType)

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

Parameters
actual:LocalTime

the actual value to verify

selfType:Class<?>

the "self type"

Method Detail

areEqualIgnoringNanosback to summary
private static boolean areEqualIgnoringNanos(LocalTime actual, LocalTime other)

Returns true if both localtime are in the same year, month and day of month, hour, minute and second, false otherwise.

Parameters
actual:LocalTime

the actual localtime. expected not be null

other:LocalTime

the other localtime. expected not be null

Returns:boolean

true if both localtime are in the same year, month and day of month, hour, minute and second, false otherwise.

areEqualIgnoringSecondsback to summary
private static boolean areEqualIgnoringSeconds(LocalTime actual, LocalTime other)

Returns true if both localtime are in the same year, month, day of month, hour and minute, false otherwise.

Parameters
actual:LocalTime

the actual localtime. expected not be null

other:LocalTime

the other localtime. expected not be null

Returns:boolean

true if both localtime are in the same year, month, day of month, hour and minute, false otherwise.

assertLocalTimeAsStringParameterIsNotNullback to summary
private static void assertLocalTimeAsStringParameterIsNotNull(String localTimeAsString)

Check that the LocalTime string representation to compare actual LocalTime to is not null, otherwise throws a IllegalArgumentException with an explicit message

Parameters
localTimeAsString:String

String representing the LocalTime to compare actual with

Exceptions
IllegalArgumentException:
with an explicit message if the given String is null
assertLocalTimeParameterIsNotNullback to summary
private static void assertLocalTimeParameterIsNotNull(LocalTime other)

Check that the LocalTime to compare actual LocalTime to is not null, in that case throws a IllegalArgumentException with an explicit message

Parameters
other:LocalTime

the LocalTime to check

Exceptions
IllegalArgumentException:
with an explicit message if the given LocalTime is null
checkIsNotNullAndNotEmptyback to summary
private void checkIsNotNullAndNotEmpty(Object[] values)
convertToLocalTimeArrayback to summary
private static Object[] convertToLocalTimeArray(String... localTimesAsString)
hasHourback to summary
public SELF hasHour(int hour)

Verifies that actual LocalTime is in the given hour.

Example:

 // Assertion succeeds:
assertThat(LocalTime.of(23, 59, 59)).hasHour(23);

// Assertion fails:
assertThat(LocalTime.of(23, 59, 59)).hasHour(22);
Parameters
hour:int

the given hour.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual LocalTime is null.
  • if the actual LocalTime is not in the given hour.
Since
3.23.0
hasMinuteback to summary
public SELF hasMinute(int minute)

Verifies that actual LocalTime is in the given minute.

Example:

 // Assertion succeeds:
assertThat(LocalTime.of(23, 59, 0)).hasMinute(59);

// Assertion fails:
assertThat(LocalTime.of(23, 59, 0)).hasMinute(58);
Parameters
minute:int

the given minute.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual LocalTime is null.
  • if the actual LocalTime is not in the given minute.
Since
3.23.0
hasNanoback to summary
public SELF hasNano(int nano)

Verifies that actual LocalTime is in the given nano.

Example:

 // Assertion succeeds:
assertThat(LocalTime.of(23, 59, 59, 59)).hasNano(59);

// Assertion fails:
assertThat(LocalTime.of(23, 59, 59, 59)).hasNano(58);
Parameters
nano:int

the given nano.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual LocalTime is null.
  • if the actual LocalTime is not in the given second.
Since
3.23.0
hasSameHourAsback to summary
public SELF hasSameHourAs(LocalTime other)

Verifies that actual and given LocalTime have same hour fields (minute, second and nanosecond fields are ignored in comparison).

Assertion can fail with localTimes in same chronological second time window, e.g :

01:00:00.000 and 00:59:59.000.

Time difference is only 1s but hour fields differ.

Code example :

 // successful assertions
LocalTime localTime1 = LocalTime.of(23, 50, 0, 0);
LocalTime localTime2 = LocalTime.of(23, 00, 2, 7);
assertThat(localTime1).hasSameHourAs(localTime2);

// failing assertions (even if time difference is only 1ms)
LocalTime localTimeA = LocalTime.of(01, 00, 00, 000);
LocalTime localTimeB = LocalTime.of(00, 59, 59, 999);
assertThat(localTimeA).hasSameHourAs(localTimeB);
Parameters
other:LocalTime

the given LocalTime.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual LocalTime is null.
  • if the actual LocalTime is are not equal ignoring minute, second and nanosecond fields.
IllegalArgumentException:
if other LocalTime is null.
hasSecondback to summary
public SELF hasSecond(int second)

Verifies that actual LocalTime is in the given second.

Example:

 // Assertion succeeds:
assertThat(LocalTime.of(23, 00, 59)).hasSecond(59);

// Assertion fails:
assertThat(LocalTime.of(23, 00, 59)).hasSecond(58);
Parameters
second:int

the given second.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual LocalTime is null.
  • if the actual LocalTime is not in the given second.
Since
3.23.0
haveSameHourFieldback to summary
private static boolean haveSameHourField(LocalTime actual, LocalTime other)
isAfterback to summary
public SELF isAfter(LocalTime other)

Verifies that the actual LocalTime is strictly after the given one.

Example :

 assertThat(parse("13:00:00")).isAfter(parse("12:00:00"));
Parameters
other:LocalTime

the given LocalTime.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual LocalTime is null.
  • if the actual LocalTime is not strictly after the given one.
IllegalArgumentException:
if other LocalTime is null.
isAfterback to summary
public SELF isAfter(String localTimeAsString)

Same assertion as isAfter(LocalTime) but the LocalTime is built from given a String that must follow ISO LocalTime format to allow calling LocalTime#parse(CharSequence) method.

Example :

 // you can express expected LocalTime as String (AssertJ taking care of the conversion)
assertThat(parse("13:00:00")).isAfter("12:00:00");
Parameters
localTimeAsString:String

String representing a LocalTime.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual LocalTime is null.
  • if the actual LocalTime is not strictly after the LocalTime built from given String.
IllegalArgumentException:
if given String is null or can't be converted to a LocalTime.
isAfterOrEqualToback to summary
public SELF isAfterOrEqualTo(LocalTime other)

Verifies that the actual LocalTime is after or equals to the given one.

Example :

 assertThat(parse("13:00:00")).isAfterOrEqualTo(parse("13:00:00"))
                             .isAfterOrEqualTo(parse("12:00:00"));
Parameters
other:LocalTime

the given LocalTime.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual LocalTime is null.
  • if the actual LocalTime is not after or equals to the given one.
IllegalArgumentException:
if other LocalTime is null.
isAfterOrEqualToback to summary
public SELF isAfterOrEqualTo(String localTimeAsString)

Same assertion as isAfterOrEqualTo(LocalTime) but the LocalTime is built from given String, which must follow ISO LocalTime format to allow calling LocalTime#parse(CharSequence) method.

Example :

 // you can express expected LocalTime as String (AssertJ taking care of the conversion)
assertThat(parse("13:00:00")).isAfterOrEqualTo("13:00:00")
                             .isAfterOrEqualTo("12:00:00");
Parameters
localTimeAsString:String

String representing a LocalTime.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual LocalTime is null.
  • if the actual LocalTime is not after or equals to the LocalTime built from given String.
IllegalArgumentException:
if given String is null or can't be converted to a LocalTime.
isBeforeback to summary
public SELF isBefore(LocalTime other)

Verifies that the actual LocalTime is strictly before the given one.

Example :

 assertThat(parse("12:00:00")).isBefore(parse("13:00:00"));
Parameters
other:LocalTime

the given LocalTime.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual LocalTime is null.
  • if the actual LocalTime is not strictly before the given one.
IllegalArgumentException:
if other LocalTime is null.
isBeforeback to summary
public SELF isBefore(String localTimeAsString)

Same assertion as isBefore(LocalTime) but the LocalTime is built from given String, which must follow ISO LocalTime format to allow calling LocalTime#parse(CharSequence) method.

Example :

 // you can express expected LocalTime as String (AssertJ taking care of the conversion)
assertThat(parse("12:59")).isBefore("13:00");
Parameters
localTimeAsString:String

String representing a LocalTime.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual LocalTime is null.
  • if the actual LocalTime is not strictly before the LocalTime built from given String.
IllegalArgumentException:
if given String is null or can't be converted to a LocalTime.
isBeforeOrEqualToback to summary
public SELF isBeforeOrEqualTo(LocalTime other)

Verifies that the actual LocalTime is before or equals to the given one.

Example :

 assertThat(parse("12:00:00")).isBeforeOrEqualTo(parse("12:00:00"))
                                       .isBeforeOrEqualTo(parse("12:00:01"));
Parameters
other:LocalTime

the given LocalTime.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual LocalTime is null.
  • if the actual LocalTime is not before or equals to the given one.
IllegalArgumentException:
if other LocalTime is null.
isBeforeOrEqualToback to summary
public SELF isBeforeOrEqualTo(String localTimeAsString)

Same assertion as isBeforeOrEqualTo(LocalTime) but the LocalTime is built from given String, which must follow ISO LocalTime format to allow calling LocalTime#parse(CharSequence) method.

Example :

 // you can express expected LocalTime as String (AssertJ taking care of the conversion)
assertThat(parse("12:00:00")).isBeforeOrEqualTo("12:00:00")
                             .isBeforeOrEqualTo("13:00:00");
Parameters
localTimeAsString:String

String representing a LocalTime.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual LocalTime is null.
  • if the actual LocalTime is not before or equals to the LocalTime built from given String.
IllegalArgumentException:
if given String is null or can't be converted to a LocalTime.
isBetweenback to summary
public SELF isBetween(LocalTime startInclusive, LocalTime endInclusive)

Verifies that the actual LocalTime is in the [start, end] period (start and end included).

Example:

 LocalTime localTime = LocalTime.now();

// assertions succeed:
assertThat(localTime).isBetween(localTime.minusSeconds(1), localTime.plusSeconds(1))
                     .isBetween(localTime, localTime.plusSeconds(1))
                     .isBetween(localTime.minusSeconds(1), localTime)
                     .isBetween(localTime, localTime);

// assertions fail:
assertThat(localTime).isBetween(localTime.minusSeconds(10), localTime.minusSeconds(1));
assertThat(localTime).isBetween(localTime.plusSeconds(1), localTime.plusSeconds(10));
Parameters
startInclusive:LocalTime

the start value (inclusive), expected not to be null.

endInclusive:LocalTime

the end value (inclusive), expected not to be null.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is not in [start, end] period.
NullPointerException:
  • if start value is null.
  • if end value is null.
Since
3.7.1
isBetweenback to summary
public SELF isBetween(String startInclusive, String endInclusive)

Same assertion as isBetween(LocalTime, LocalTime) but here you pass LocalTime String representations which must follow ISO LocalTime format to allow calling LocalTime#parse(CharSequence) method.

Example:

 LocalTime oneAm = LocalTime.parse("01:00:00");

// assertions succeed:
assertThat(oneAm).isBetween("00:59:59", "01:00:01")
                 .isBetween("01:00:00", "01:00:01")
                 .isBetween("00:59:59", "01:00:00")
                 .isBetween("01:00:00", "01:00:00");

// assertion fails:
assertThat(oneAm).isBetween("00:59:00", "00:59:59");
Parameters
startInclusive:String

the start value (inclusive), expected not to be null.

endInclusive:String

the end value (inclusive), expected not to be null.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is not in [start, end] period.
NullPointerException:
  • if start value is null.
  • if end value is null.
DateTimeParseException:
if any of the given String can't be converted to a LocalTime.
Since
3.7.1
isCloseToback to summary
public SELF isCloseTo(LocalTime other, TemporalOffset<? super LocalTime> offset)

Overrides org.assertj.core.api.AbstractTemporalAssert.isCloseTo.

Doc from org.assertj.core.api.AbstractTemporalAssert.isCloseTo.

Verifies that the actual Temporal is close to the other according to the given TemporalOffset.

You can build the offset parameter using Assertions#within(long, TemporalUnit) or Assertions#byLessThan(long, TemporalUnit).

Example:

 LocalTime _07_10 = LocalTime.of(7, 10);
LocalTime _07_42 = LocalTime.of(7, 42);

// assertions succeed:
assertThat(_07_10).isCloseTo(_07_42, within(1, ChronoUnit.HOURS));
assertThat(_07_10).isCloseTo(_07_42, within(32, ChronoUnit.MINUTES));

// assertions fail:
assertThat(_07_10).isCloseTo(_07_42, byLessThan(32, ChronoUnit.MINUTES));
assertThat(_07_10).isCloseTo(_07_42, within(10, ChronoUnit.SECONDS));
Parameters
other:LocalTime

the temporal to compare actual to

offset:TemporalOffset<? super LocalTime>

the offset used for comparison

Returns:SELF

this assertion object

Annotations
@Override
isEqualToback to summary
public SELF isEqualTo(String localTimeAsString)

Same assertion as isEqualTo(Object) (where Object is expected to be LocalTime) but here you pass LocalTime String representation that must follow ISO LocalTime format to allow calling LocalTime#parse(CharSequence) method.

Example :

 // you can express expected LocalTime as String (AssertJ taking care of the conversion)
assertThat(parse("13:00:00")).isEqualTo("13:00:00");
Parameters
localTimeAsString:String

String representing a LocalTime.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual LocalTime is null.
  • if the actual LocalTime is not equal to the LocalTime built from given String.
IllegalArgumentException:
if given String is null or can't be converted to a LocalTime.
isEqualToIgnoringNanosback to summary
public SELF isEqualToIgnoringNanos(LocalTime other)

Deprecated

Use isCloseTo(LocalTime, TemporalOffset) instead, although not exactly the same semantics, this is the right way to compare with a given precision.

Verifies that actual and given LocalTime have same hour, minute and second fields (nanosecond fields are ignored in comparison).

Assertion can fail with localTimes in same chronological nanosecond time window, e.g :

23:00:01.000000000 and 23:00:00.999999999.

Assertion fails as second fields differ even if time difference is only 1ns.

Code example :

 // successful assertions
LocalTime localTime1 = LocalTime.of(12, 0, 1, 0);
LocalTime localTime2 = LocalTime.of(12, 0, 1, 456);
assertThat(localTime1).isEqualToIgnoringNanos(localTime2);

// failing assertions (even if time difference is only 1ns)
LocalTime localTimeA = LocalTime.of(12, 0, 1, 0);
LocalTime localTimeB = LocalTime.of(12, 0, 0, 999999999);
assertThat(localTimeA).isEqualToIgnoringNanos(localTimeB);
Parameters
other:LocalTime

the given LocalTime.

Returns:SELF

this assertion object.

Annotations
@Deprecated
Exceptions
AssertionError:
  • if the actual LocalTime is null.
  • if the actual LocalTime is are not equal with nanoseconds ignored.
IllegalArgumentException:
if other LocalTime is null.
isEqualToIgnoringSecondsback to summary
public SELF isEqualToIgnoringSeconds(LocalTime other)

Deprecated

Use isCloseTo(LocalTime, TemporalOffset) instead, although not exactly the same semantics, this is the right way to compare with a given precision.

Verifies that actual and given LocalTime have same hour and minute fields (second and nanosecond fields are ignored in comparison).

Assertion can fail with LocalTimes in same chronological second time window, e.g :

23:01:00.000 and 23:00:59.000.

Assertion fails as minute fields differ even if time difference is only 1s.

Code example :

 // successful assertions
LocalTime localTime1 = LocalTime.of(23, 50, 0, 0);
LocalTime localTime2 = LocalTime.of(23, 50, 10, 456);
assertThat(localTime1).isEqualToIgnoringSeconds(localTime2);

// failing assertions (even if time difference is only 1ms)
LocalTime localTimeA = LocalTime.of(23, 50, 00, 000);
LocalTime localTimeB = LocalTime.of(23, 49, 59, 999);
assertThat(localTimeA).isEqualToIgnoringSeconds(localTimeB);
Parameters
other:LocalTime

the given LocalTime.

Returns:SELF

this assertion object.

Annotations
@Deprecated
Exceptions
AssertionError:
  • if the actual LocalTime is null.
  • if the actual LocalTime is are not equal with second and nanosecond fields ignored.
IllegalArgumentException:
if other LocalTime is null.
isInback to summary
public SELF isIn(String... localTimesAsString)

Same assertion as isIn(Object...) (where Objects are expected to be LocalTime) but here you pass LocalTime String representations that must follow ISO LocalTime format to allow calling LocalTime#parse(CharSequence) method.

Example :

 // you can express expected LocalTimes as String (AssertJ taking care of the conversion)
assertThat(parse("13:00:00")).isIn("12:00:00", "13:00:00");
Parameters
localTimesAsString:String[]

String array representing LocalTimes.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual LocalTime is null.
  • if the actual LocalTime is not in the LocalTimes built from given Strings.
IllegalArgumentException:
if given String is null or can't be converted to a LocalTime.
isNotEqualToback to summary
public SELF isNotEqualTo(String localTimeAsString)

Same assertion as isNotEqualTo(Object) (where Object is expected to be LocalTime) but here you pass LocalTime String representation that must follow ISO LocalTime format to allow calling LocalTime#parse(CharSequence) method.

Example :

 // you can express expected LocalTime as String (AssertJ taking care of the conversion)
assertThat(parse("13:00:00")).isNotEqualTo("12:00:00");
Parameters
localTimeAsString:String

String representing a LocalTime.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual LocalTime is null.
  • if the actual LocalTime is equal to the LocalTime built from given String.
IllegalArgumentException:
if given String is null or can't be converted to a LocalTime.
isNotInback to summary
public SELF isNotIn(String... localTimesAsString)

Same assertion as isNotIn(Object...) (where Objects are expected to be LocalTime) but here you pass LocalTime String representations that must follow ISO LocalTime format to allow calling LocalTime#parse(CharSequence) method.

Example :

 // you can express expected LocalTimes as String (AssertJ taking care of the conversion)
assertThat(parse("13:00:00")).isNotIn("12:00:00", "14:00:00");
Parameters
localTimesAsString:String[]

Array of String representing a LocalTime.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual LocalTime is null.
  • if the actual LocalTime is in the LocalTimes built from given Strings.
IllegalArgumentException:
if given String is null or can't be converted to a LocalTime.
isStrictlyBetweenback to summary
public SELF isStrictlyBetween(LocalTime startExclusive, LocalTime endExclusive)

Verifies that the actual LocalTime is in the ]start, end[ period (start and end excluded).

Example:

 LocalTime localTime = LocalTime.now();

// assertion succeeds:
assertThat(localTime).isStrictlyBetween(localTime.minusSeconds(1), localTime.plusSeconds(1));

// assertions fail:
assertThat(localTime).isStrictlyBetween(localTime.minusSeconds(10), localTime.minusSeconds(1));
assertThat(localTime).isStrictlyBetween(localTime.plusSeconds(1), localTime.plusSeconds(10));
assertThat(localTime).isStrictlyBetween(localTime, localTime.plusSeconds(1));
assertThat(localTime).isStrictlyBetween(localTime.minusSeconds(1), localTime);
Parameters
startExclusive:LocalTime

the start value (exclusive), expected not to be null.

endExclusive:LocalTime

the end value (exclusive), expected not to be null.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is not in ]start, end[ period.
NullPointerException:
  • if start value is null.
  • if end value is null.
Since
3.7.1
isStrictlyBetweenback to summary
public SELF isStrictlyBetween(String startExclusive, String endExclusive)

Same assertion as isStrictlyBetween(LocalTime, LocalTime) but here you pass LocalTime String representations which must follow ISO LocalTime format to allow calling LocalTime#parse(CharSequence) method.

Example:

 LocalTime oneAm = LocalTime.parse("01:00:00");

// assertion succeeds:
assertThat(oneAm).isStrictlyBetween("00:59:59", "01:00:01");

// assertion fails:
assertThat(oneAm).isStrictlyBetween("00:59:00", "00:59:59");
assertThat(oneAm).isStrictlyBetween("01:00:00", "01:00:01");
assertThat(oneAm).isStrictlyBetween("00:59:59", "01:00:00");
Parameters
startExclusive:String

the start value (exclusive), expected not to be null.

endExclusive:String

the end value (exclusive), expected not to be null.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is not in ]start, end[ period.
NullPointerException:
  • if start value is null.
  • if end value is null.
DateTimeParseException:
if any of the given String can't be converted to a LocalTime.
Since
3.7.1
parseback to summary
protected LocalTime parse(String localTimeAsString)

Implements abstract org.assertj.core.api.AbstractTemporalAssert.parse.

Doc from org.assertj.core.api.AbstractTemporalAssert.parse.

Obtains an instance of TEMPORAL from a string representation in ISO date format.

Parameters
localTimeAsString:String

the string to parse, not null

Returns:LocalTime

the parsed TEMPORAL, not null

Annotations
@Override