How to use parse method of org.assertj.core.api.AbstractLocalTimeAssert class

Best Assertj code snippet using org.assertj.core.api.AbstractLocalTimeAssert.parse

Source:AbstractLocalTimeAssert.java Github

copy

Full Screen

...42 /**43 * Verifies that the actual {@code LocalTime} is <b>strictly</b> before the given one.44 * <p>45 * Example :46 * <pre><code class='java'> assertThat(parse("12:00:00")).isBefore(parse("13:00:00"));</code></pre>47 *48 * @param other the given {@link LocalTime}.49 * @return this assertion object.50 * @throws AssertionError if the actual {@code LocalTime} is {@code null}.51 * @throws IllegalArgumentException if other {@code LocalTime} is {@code null}.52 * @throws AssertionError if the actual {@code LocalTime} is not strictly before the given one.53 */54 public SELF isBefore(LocalTime other) {55 Objects.instance().assertNotNull(info, actual);56 assertLocalTimeParameterIsNotNull(other);57 if (!actual.isBefore(other)) {58 throw Failures.instance().failure(info, shouldBeBefore(actual, other));59 }60 return myself;61 }62 /**63 * Same assertion as {@link #isBefore(LocalTime)} but the {@link LocalTime} is built from given String, which64 * must follow <a href=65 * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_LOCAL_TIME"66 * >ISO LocalTime format</a> to allow calling {@link LocalTime#parse(CharSequence)} method.67 * <p>68 * Example :69 * <pre><code class='java'> // you can express expected LocalTime as String (AssertJ taking care of the conversion)70 * assertThat(parse("12:59")).isBefore("13:00");</code></pre>71 *72 * @param localTimeAsString String representing a {@link LocalTime}.73 * @return this assertion object.74 * @throws AssertionError if the actual {@code LocalTime} is {@code null}.75 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link LocalTime}.76 * @throws AssertionError if the actual {@code LocalTime} is not strictly before the {@link LocalTime} built77 * from given String.78 */79 public SELF isBefore(String localTimeAsString) {80 assertLocalTimeAsStringParameterIsNotNull(localTimeAsString);81 return isBefore(parse(localTimeAsString));82 }83 /**84 * Verifies that the actual {@code LocalTime} is before or equals to the given one.85 * <p>86 * Example :87 * <pre><code class='java'> assertThat(parse("12:00:00")).isBeforeOrEqualTo(parse("12:00:00"))88 * .isBeforeOrEqualTo(parse("12:00:01"));</code></pre>89 *90 * @param other the given {@link LocalTime}.91 * @return this assertion object.92 * @throws AssertionError if the actual {@code LocalTime} is {@code null}.93 * @throws IllegalArgumentException if other {@code LocalTime} is {@code null}.94 * @throws AssertionError if the actual {@code LocalTime} is not before or equals to the given one.95 */96 public SELF isBeforeOrEqualTo(LocalTime other) {97 Objects.instance().assertNotNull(info, actual);98 assertLocalTimeParameterIsNotNull(other);99 if (actual.isAfter(other)) {100 throw Failures.instance().failure(info, shouldBeBeforeOrEqualsTo(actual, other));101 }102 return myself;103 }104 /**105 * Same assertion as {@link #isBeforeOrEqualTo(LocalTime)} but the {@link LocalTime} is built from given106 * String, which must follow <a href=107 * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_LOCAL_TIME"108 * >ISO LocalTime format</a> to allow calling {@link LocalTime#parse(CharSequence)} method.109 * <p>110 * Example :111 * <pre><code class='java'> // you can express expected LocalTime as String (AssertJ taking care of the conversion)112 * assertThat(parse("12:00:00")).isBeforeOrEqualTo("12:00:00")113 * .isBeforeOrEqualTo("13:00:00");</code></pre>114 *115 * @param localTimeAsString String representing a {@link LocalTime}.116 * @return this assertion object.117 * @throws AssertionError if the actual {@code LocalTime} is {@code null}.118 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link LocalTime}.119 * @throws AssertionError if the actual {@code LocalTime} is not before or equals to the {@link LocalTime} built from120 * given String.121 */122 public SELF isBeforeOrEqualTo(String localTimeAsString) {123 assertLocalTimeAsStringParameterIsNotNull(localTimeAsString);124 return isBeforeOrEqualTo(parse(localTimeAsString));125 }126 /**127 * Verifies that the actual {@code LocalTime} is after or equals to the given one.128 * <p>129 * Example :130 * <pre><code class='java'> assertThat(parse("13:00:00")).isAfterOrEqualTo(parse("13:00:00"))131 * .isAfterOrEqualTo(parse("12:00:00"));</code></pre>132 *133 * @param other the given {@link LocalTime}.134 * @return this assertion object.135 * @throws AssertionError if the actual {@code LocalTime} is {@code null}.136 * @throws IllegalArgumentException if other {@code LocalTime} is {@code null}.137 * @throws AssertionError if the actual {@code LocalTime} is not after or equals to the given one.138 */139 public SELF isAfterOrEqualTo(LocalTime other) {140 Objects.instance().assertNotNull(info, actual);141 assertLocalTimeParameterIsNotNull(other);142 if (actual.isBefore(other)) {143 throw Failures.instance().failure(info, shouldBeAfterOrEqualsTo(actual, other));144 }145 return myself;146 }147 /**148 * Same assertion as {@link #isAfterOrEqualTo(LocalTime)} but the {@link LocalTime} is built from given149 * String, which must follow <a href=150 * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_LOCAL_TIME"151 * >ISO LocalTime format</a> to allow calling {@link LocalTime#parse(CharSequence)} method.152 * <p>153 * Example :154 * <pre><code class='java'> // you can express expected LocalTime as String (AssertJ taking care of the conversion)155 * assertThat(parse("13:00:00")).isAfterOrEqualTo("13:00:00")156 * .isAfterOrEqualTo("12:00:00");</code></pre>157 *158 * @param localTimeAsString String representing a {@link LocalTime}.159 * @return this assertion object.160 * @throws AssertionError if the actual {@code LocalTime} is {@code null}.161 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link LocalTime}.162 * @throws AssertionError if the actual {@code LocalTime} is not after or equals to the {@link LocalTime} built from163 * given String.164 */165 public SELF isAfterOrEqualTo(String localTimeAsString) {166 assertLocalTimeAsStringParameterIsNotNull(localTimeAsString);167 return isAfterOrEqualTo(parse(localTimeAsString));168 }169 /**170 * Verifies that the actual {@code LocalTime} is <b>strictly</b> after the given one.171 * <p>172 * Example :173 * <pre><code class='java'> assertThat(parse("13:00:00")).isAfter(parse("12:00:00"));</code></pre>174 *175 * @param other the given {@link LocalTime}.176 * @return this assertion object.177 * @throws AssertionError if the actual {@code LocalTime} is {@code null}.178 * @throws IllegalArgumentException if other {@code LocalTime} is {@code null}.179 * @throws AssertionError if the actual {@code LocalTime} is not strictly after the given one.180 */181 public SELF isAfter(LocalTime other) {182 Objects.instance().assertNotNull(info, actual);183 assertLocalTimeParameterIsNotNull(other);184 if (!actual.isAfter(other)) {185 throw Failures.instance().failure(info, shouldBeAfter(actual, other));186 }187 return myself;188 }189 /**190 * Same assertion as {@link #isAfter(LocalTime)} but the {@link LocalTime} is built from given a String that191 * must follow <a href=192 * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_LOCAL_TIME"193 * >ISO LocalTime format</a> to allow calling {@link LocalTime#parse(CharSequence)} method.194 * <p>195 * Example :196 * <pre><code class='java'> // you can express expected LocalTime as String (AssertJ taking care of the conversion)197 * assertThat(parse("13:00:00")).isAfter("12:00:00");</code></pre>198 *199 * @param localTimeAsString String representing a {@link LocalTime}.200 * @return this assertion object.201 * @throws AssertionError if the actual {@code LocalTime} is {@code null}.202 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link LocalTime}.203 * @throws AssertionError if the actual {@code LocalTime} is not strictly after the {@link LocalTime} built204 * from given String.205 */206 public SELF isAfter(String localTimeAsString) {207 assertLocalTimeAsStringParameterIsNotNull(localTimeAsString);208 return isAfter(parse(localTimeAsString));209 }210 /**211 * Same assertion as {@link #isEqualTo(Object)} (where Object is expected to be {@link LocalTime}) but here you212 * pass {@link LocalTime} String representation that must follow <a href=213 * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_LOCAL_TIME"214 * >ISO LocalTime format</a> to allow calling {@link LocalTime#parse(CharSequence)} method.215 * <p>216 * Example :217 * <pre><code class='java'> // you can express expected LocalTime as String (AssertJ taking care of the conversion)218 * assertThat(parse("13:00:00")).isEqualTo("13:00:00");</code></pre>219 *220 * @param localTimeAsString String representing a {@link LocalTime}.221 * @return this assertion object.222 * @throws AssertionError if the actual {@code LocalTime} is {@code null}.223 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link LocalTime}.224 * @throws AssertionError if the actual {@code LocalTime} is not equal to the {@link LocalTime} built from225 * given String.226 */227 public SELF isEqualTo(String localTimeAsString) {228 assertLocalTimeAsStringParameterIsNotNull(localTimeAsString);229 return isEqualTo(parse(localTimeAsString));230 }231 /**232 * Same assertion as {@link #isNotEqualTo(Object)} (where Object is expected to be {@link LocalTime}) but here you233 * pass {@link LocalTime} String representation that must follow <a href=234 * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_LOCAL_TIME"235 * >ISO LocalTime format</a> to allow calling {@link LocalTime#parse(CharSequence)} method.236 * <p>237 * Example :238 * <pre><code class='java'> // you can express expected LocalTime as String (AssertJ taking care of the conversion)239 * assertThat(parse("13:00:00")).isNotEqualTo("12:00:00");</code></pre>240 *241 * @param localTimeAsString String representing a {@link LocalTime}.242 * @return this assertion object.243 * @throws AssertionError if the actual {@code LocalTime} is {@code null}.244 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link LocalTime}.245 * @throws AssertionError if the actual {@code LocalTime} is equal to the {@link LocalTime} built from given246 * String.247 */248 public SELF isNotEqualTo(String localTimeAsString) {249 assertLocalTimeAsStringParameterIsNotNull(localTimeAsString);250 return isNotEqualTo(parse(localTimeAsString));251 }252 /**253 * Same assertion as {@link #isIn(Object...)} (where Objects are expected to be {@link LocalTime}) but here you254 * pass {@link LocalTime} String representations that must follow <a href=255 * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_LOCAL_TIME"256 * >ISO LocalTime format</a> to allow calling {@link LocalTime#parse(CharSequence)} method.257 * <p>258 * Example :259 * <pre><code class='java'> // you can express expected LocalTimes as String (AssertJ taking care of the conversion)260 * assertThat(parse("13:00:00")).isIn("12:00:00", "13:00:00");</code></pre>261 *262 * @param localTimesAsString String array representing {@link LocalTime}s.263 * @return this assertion object.264 * @throws AssertionError if the actual {@code LocalTime} is {@code null}.265 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link LocalTime}.266 * @throws AssertionError if the actual {@code LocalTime} is not in the {@link LocalTime}s built from given267 * Strings.268 */269 public SELF isIn(String... localTimesAsString) {270 checkIsNotNullAndNotEmpty(localTimesAsString);271 return isIn(convertToLocalTimeArray(localTimesAsString));272 }273 /**274 * Same assertion as {@link #isNotIn(Object...)} (where Objects are expected to be {@link LocalTime}) but here you275 * pass {@link LocalTime} String representations that must follow <a href=276 * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_LOCAL_TIME"277 * >ISO LocalTime format</a> to allow calling {@link LocalTime#parse(CharSequence)} method.278 * <p>279 * Example :280 * <pre><code class='java'> // you can express expected LocalTimes as String (AssertJ taking care of the conversion)281 * assertThat(parse("13:00:00")).isNotIn("12:00:00", "14:00:00");</code></pre>282 *283 * @param localTimesAsString Array of String representing a {@link LocalTime}.284 * @return this assertion object.285 * @throws AssertionError if the actual {@code LocalTime} is {@code null}.286 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link LocalTime}.287 * @throws AssertionError if the actual {@code LocalTime} is in the {@link LocalTime}s built from given288 * Strings.289 */290 public SELF isNotIn(String... localTimesAsString) {291 checkIsNotNullAndNotEmpty(localTimesAsString);292 return isNotIn(convertToLocalTimeArray(localTimesAsString));293 }294 private static Object[] convertToLocalTimeArray(String... localTimesAsString) {295 return Arrays.stream(localTimesAsString).map(LocalTime::parse).toArray();296 }297 private void checkIsNotNullAndNotEmpty(Object[] values) {298 checkArgument(values != null, "The given LocalTime array should not be null");299 checkArgument(values.length > 0, "The given LocalTime array should not be empty");300 }301 /**302 * Check that the {@link LocalTime} string representation to compare actual {@link LocalTime} to is not null,303 * otherwise throws a {@link IllegalArgumentException} with an explicit message304 *305 * @param localTimeAsString String representing the {@link LocalTime} to compare actual with306 * @throws IllegalArgumentException with an explicit message if the given {@link String} is null307 */308 private static void assertLocalTimeAsStringParameterIsNotNull(String localTimeAsString) {309 checkArgument(localTimeAsString != null,310 "The String representing the LocalTime to compare actual with should not be null");311 }312 /**313 * Check that the {@link LocalTime} to compare actual {@link LocalTime} to is not null, in that case throws a314 * {@link IllegalArgumentException} with an explicit message315 *316 * @param other the {@link LocalTime} to check317 * @throws IllegalArgumentException with an explicit message if the given {@link LocalTime} is null318 */319 private static void assertLocalTimeParameterIsNotNull(LocalTime other) {320 checkArgument(other != null, "The LocalTime to compare actual with should not be null");321 }322 /**323 * Verifies that actual and given {@code LocalTime} have same hour, minute and second fields (nanosecond fields are324 * ignored in comparison).325 * <p>326 * Assertion can fail with localTimes in same chronological nanosecond time window, e.g :327 * <p>328 * 23:00:<b>01.000000000</b> and 23:00:<b>00.999999999</b>.329 * <p>330 * Assertion fails as second fields differ even if time difference is only 1ns.331 * <p>332 * Code example :333 * <pre><code class='java'> // successful assertions334 * LocalTime localTime1 = LocalTime.of(12, 0, 1, 0);335 * LocalTime localTime2 = LocalTime.of(12, 0, 1, 456);336 * assertThat(localTime1).isEqualToIgnoringNanos(localTime2);337 *338 * // failing assertions (even if time difference is only 1ns)339 * LocalTime localTimeA = LocalTime.of(12, 0, 1, 0);340 * LocalTime localTimeB = LocalTime.of(12, 0, 0, 999999999);341 * assertThat(localTimeA).isEqualToIgnoringNanos(localTimeB);</code></pre>342 *343 * @param other the given {@link LocalTime}.344 * @return this assertion object.345 * @throws AssertionError if the actual {@code LocalTime} is {@code null}.346 * @throws IllegalArgumentException if other {@code LocalTime} is {@code null}.347 * @throws AssertionError if the actual {@code LocalTime} is are not equal with nanoseconds ignored.348 */349 public SELF isEqualToIgnoringNanos(LocalTime other) {350 Objects.instance().assertNotNull(info, actual);351 assertLocalTimeParameterIsNotNull(other);352 if (!areEqualIgnoringNanos(actual, other)) {353 throw Failures.instance().failure(info, shouldBeEqualIgnoringNanos(actual, other));354 }355 return myself;356 }357 /**358 * Verifies that actual and given {@link LocalTime} have same hour and minute fields (second and nanosecond fields are359 * ignored in comparison).360 * <p>361 * Assertion can fail with LocalTimes in same chronological second time window, e.g :362 * <p>363 * 23:<b>01:00</b>.000 and 23:<b>00:59</b>.000.364 * <p>365 * Assertion fails as minute fields differ even if time difference is only 1s.366 * <p>367 * Code example :368 * <pre><code class='java'> // successful assertions369 * LocalTime localTime1 = LocalTime.of(23, 50, 0, 0);370 * LocalTime localTime2 = LocalTime.of(23, 50, 10, 456);371 * assertThat(localTime1).isEqualToIgnoringSeconds(localTime2);372 *373 * // failing assertions (even if time difference is only 1ms)374 * LocalTime localTimeA = LocalTime.of(23, 50, 00, 000);375 * LocalTime localTimeB = LocalTime.of(23, 49, 59, 999);376 * assertThat(localTimeA).isEqualToIgnoringSeconds(localTimeB);</code></pre>377 *378 * @param other the given {@link LocalTime}.379 * @return this assertion object.380 * @throws AssertionError if the actual {@code LocalTime} is {@code null}.381 * @throws IllegalArgumentException if other {@code LocalTime} is {@code null}.382 * @throws AssertionError if the actual {@code LocalTime} is are not equal with second and nanosecond fields383 * ignored.384 */385 public SELF isEqualToIgnoringSeconds(LocalTime other) {386 Objects.instance().assertNotNull(info, actual);387 assertLocalTimeParameterIsNotNull(other);388 if (!areEqualIgnoringSeconds(actual, other)) {389 throw Failures.instance().failure(info, shouldBeEqualIgnoringSeconds(actual, other));390 }391 return myself;392 }393 /**394 * Verifies that actual and given {@code LocalTime} have same hour fields (minute, second and nanosecond fields are395 * ignored in comparison).396 * <p>397 * Assertion can fail with localTimes in same chronological second time window, e.g :398 * <p>399 * <b>01:00</b>:00.000 and <b>00:59:59</b>.000.400 * <p>401 * Time difference is only 1s but hour fields differ.402 * <p>403 * Code example :404 * <pre><code class='java'> // successful assertions405 * LocalTime localTime1 = LocalTime.of(23, 50, 0, 0);406 * LocalTime localTime2 = LocalTime.of(23, 00, 2, 7);407 * assertThat(localTime1).hasSameHourAs(localTime2);408 *409 * // failing assertions (even if time difference is only 1ms)410 * LocalTime localTimeA = LocalTime.of(01, 00, 00, 000);411 * LocalTime localTimeB = LocalTime.of(00, 59, 59, 999);412 * assertThat(localTimeA).hasSameHourAs(localTimeB);</code></pre>413 *414 * @param other the given {@link LocalTime}.415 * @return this assertion object.416 * @throws AssertionError if the actual {@code LocalTime} is {@code null}.417 * @throws IllegalArgumentException if other {@code LocalTime} is {@code null}.418 * @throws AssertionError if the actual {@code LocalTime} is are not equal ignoring minute, second and nanosecond419 * fields.420 */421 public SELF hasSameHourAs(LocalTime other) {422 Objects.instance().assertNotNull(info, actual);423 assertLocalTimeParameterIsNotNull(other);424 if (!haveSameHourField(actual, other)) {425 throw Failures.instance().failure(info, shouldHaveSameHourAs(actual, other));426 }427 return myself;428 }429 /**430 * Verifies that the actual {@link LocalTime} is in the [start, end] period (start and end included).431 * <p>432 * Example:433 * <pre><code class='java'> LocalTime localTime = LocalTime.now();434 * 435 * // assertions succeed:436 * assertThat(localTime).isBetween(localTime.minusSeconds(1), localTime.plusSeconds(1))437 * .isBetween(localTime, localTime.plusSeconds(1))438 * .isBetween(localTime.minusSeconds(1), localTime)439 * .isBetween(localTime, localTime);440 * 441 * // assertions fail:442 * assertThat(localTime).isBetween(localTime.minusSeconds(10), localTime.minusSeconds(1));443 * assertThat(localTime).isBetween(localTime.plusSeconds(1), localTime.plusSeconds(10));</code></pre>444 * 445 * @param startInclusive the start value (inclusive), expected not to be null.446 * @param endInclusive the end value (inclusive), expected not to be null.447 * @return this assertion object.448 * @throws AssertionError if the actual value is {@code null}.449 * @throws NullPointerException if start value is {@code null}.450 * @throws NullPointerException if end value is {@code null}.451 * @throws AssertionError if the actual value is not in [start, end] period.452 * 453 * @since 3.7.1454 */455 public SELF isBetween(LocalTime startInclusive, LocalTime endInclusive) {456 comparables.assertIsBetween(info, actual, startInclusive, endInclusive, true, true);457 return myself;458 }459 /**460 * Same assertion as {@link #isBetween(LocalTime, LocalTime)} but here you pass {@link LocalTime} String representations 461 * which must follow <a href="http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_LOCAL_TIME">ISO LocalTime format</a> 462 * to allow calling {@link LocalTime#parse(CharSequence)} method.463 * <p>464 * Example:465 * <pre><code class='java'> LocalTime oneAm = LocalTime.parse("01:00:00");466 * 467 * // assertions succeed:468 * assertThat(oneAm).isBetween("00:59:59", "01:00:01") 469 * .isBetween("01:00:00", "01:00:01") 470 * .isBetween("00:59:59", "01:00:00") 471 * .isBetween("01:00:00", "01:00:00");472 * 473 * // assertion fails:474 * assertThat(oneAm).isBetween("00:59:00", "00:59:59");</code></pre>475 * 476 * @param startInclusive the start value (inclusive), expected not to be null.477 * @param endInclusive the end value (inclusive), expected not to be null.478 * @return this assertion object.479 * 480 * @throws AssertionError if the actual value is {@code null}.481 * @throws NullPointerException if start value is {@code null}.482 * @throws NullPointerException if end value is {@code null}.483 * @throws DateTimeParseException if any of the given String can't be converted to a {@link LocalTime}.484 * @throws AssertionError if the actual value is not in [start, end] period.485 * 486 * @since 3.7.1487 */488 public SELF isBetween(String startInclusive, String endInclusive) {489 return isBetween(parse(startInclusive), parse(endInclusive));490 }491 /**492 * Verifies that the actual {@link LocalTime} is in the ]start, end[ period (start and end excluded).493 * <p>494 * Example:495 * <pre><code class='java'> LocalTime localTime = LocalTime.now();496 * 497 * // assertion succeeds:498 * assertThat(localTime).isStrictlyBetween(localTime.minusSeconds(1), localTime.plusSeconds(1));499 * 500 * // assertions fail:501 * assertThat(localTime).isStrictlyBetween(localTime.minusSeconds(10), localTime.minusSeconds(1));502 * assertThat(localTime).isStrictlyBetween(localTime.plusSeconds(1), localTime.plusSeconds(10));503 * assertThat(localTime).isStrictlyBetween(localTime, localTime.plusSeconds(1));504 * assertThat(localTime).isStrictlyBetween(localTime.minusSeconds(1), localTime);</code></pre>505 * 506 * @param startInclusive the start value (inclusive), expected not to be null.507 * @param endInclusive the end value (inclusive), expected not to be null.508 * @return this assertion object.509 * @throws AssertionError if the actual value is {@code null}.510 * @throws NullPointerException if start value is {@code null}.511 * @throws NullPointerException if end value is {@code null}.512 * @throws AssertionError if the actual value is not in ]start, end[ period.513 * 514 * @since 3.7.1515 */516 public SELF isStrictlyBetween(LocalTime startInclusive, LocalTime endInclusive) {517 comparables.assertIsBetween(info, actual, startInclusive, endInclusive, false, false);518 return myself;519 }520 /**521 * Same assertion as {@link #isStrictlyBetween(LocalTime, LocalTime)} but here you pass {@link LocalTime} String representations 522 * which must follow <a href="http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_LOCAL_TIME">ISO LocalTime format</a> 523 * to allow calling {@link LocalTime#parse(CharSequence)} method.524 * <p>525 * Example:526 * <pre><code class='java'> LocalTime oneAm = LocalTime.parse("01:00:00");527 * 528 * // assertion succeeds:529 * assertThat(oneAm).isStrictlyBetween("00:59:59", "01:00:01");530 * 531 * // assertion fails:532 * assertThat(oneAm).isStrictlyBetween("00:59:00", "00:59:59"); 533 * assertThat(oneAm).isStrictlyBetween("01:00:00", "01:00:01"); 534 * assertThat(oneAm).isStrictlyBetween("00:59:59", "01:00:00");</code></pre>535 * 536 * @param startInclusive the start value (inclusive), expected not to be null.537 * @param endInclusive the end value (inclusive), expected not to be null.538 * @return this assertion object.539 * 540 * @throws AssertionError if the actual value is {@code null}.541 * @throws NullPointerException if start value is {@code null}.542 * @throws NullPointerException if end value is {@code null}.543 * @throws DateTimeParseException if any of the given String can't be converted to a {@link LocalTime}.544 * @throws AssertionError if the actual value is not in ]start, end[ period.545 * 546 * @since 3.7.1547 */548 public SELF isStrictlyBetween(String startInclusive, String endInclusive) {549 return isStrictlyBetween(parse(startInclusive), parse(endInclusive));550 }551 /**552 * {@inheritDoc}553 */554 @Override555 protected LocalTime parse(String localTimeAsString) {556 return LocalTime.parse(localTimeAsString);557 }558 /**559 * Returns true if both localtime are in the same year, month and day of month, hour, minute and second, false560 * otherwise.561 *562 * @param actual the actual localtime. expected not be null563 * @param other the other localtime. expected not be null564 * @return true if both localtime are in the same year, month and day of month, hour, minute and second, false565 * otherwise.566 */567 private static boolean areEqualIgnoringNanos(LocalTime actual, LocalTime other) {568 return areEqualIgnoringSeconds(actual, other) && actual.getSecond() == other.getSecond();569 }570 /**...

Full Screen

Full Screen

parse

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.assertThat;2import java.time.LocalTime;3public class LocalTimeExample {4 public static void main(String[] args) {5 LocalTime localTime = LocalTime.parse("12:00:00");6 assertThat(localTime).isNotNull();7 System.out.println(localTime);8 }9}

Full Screen

Full Screen

parse

Using AI Code Generation

copy

Full Screen

1LocalTime localTime = LocalTime.of(12, 30);2assertThat(localTime).parse("12:30");3LocalTime localTime = LocalTime.of(12, 30);4assertThat(localTime).parse("12:30", DateTimeFormatter.ISO_LOCAL_TIME);5LocalTime localTime = LocalTime.of(12, 30);6assertThat(localTime).parse("12:30", "HH:mm");7LocalTime localTime = LocalTime.of(12, 30);8assertThat(localTime).parse("12:30", "HH:mm", Locale.ENGLISH);9LocalTime localTime = LocalTime.of(12, 30);10assertThat(localTime).parse("12:30", "HH:mm", Locale.ENGLISH, ZoneId.of("UTC"));11LocalTime localTime = LocalTime.of(12, 30);12assertThat(localTime).parse("12:30", "HH:mm", Locale.ENGLISH, ZoneId.of("UTC"), Chronology.ofLocale(Locale.ENGLISH));13LocalTime localTime = LocalTime.of(12, 30);14assertThat(localTime).parse("12:30", "HH:mm", Locale.ENGLISH, ZoneId.of("UTC"), Chronology.ofLocale(Locale.ENGLISH), DateTimeFormatter.ISO_LOCAL_TIME);15LocalTime localTime = LocalTime.of(12, 30);16assertThat(localTime).parse("12:30", "HH:mm", Locale.ENGLISH, ZoneId.of("UTC"), Chronology.ofLocale(Locale.ENGLISH), DateTimeFormatter.ISO_LOCAL_TIME, DateTimeFormatter.ISO_LOCAL_TIME);17LocalTime localTime = LocalTime.of(12, 30);18assertThat(localTime).parse("12:30", "HH:mm", Locale.ENGLISH, ZoneId.of("UTC"), Chronology.of

Full Screen

Full Screen

parse

Using AI Code Generation

copy

Full Screen

1LocalTime time = LocalTime.parse("12:00:00.000");2assertThat(time).isAfterOrEqualTo("11:59:59.999");3assertThat(time).isAfterOrEqualTo("12:00:00.000");4assertThat(time).isBeforeOrEqualTo("12:00:00.001");5assertThat(time).isBeforeOrEqualTo("12:00:00.000");6LocalTime time = LocalTime.parse("12:00:00.000");7assertThat(time).isAfterOrEqualTo(LocalTime.parse("11:59:59.999"));8assertThat(time).isAfterOrEqualTo(LocalTime.parse("12:00:00.000"));9assertThat(time).isBeforeOrEqualTo(LocalTime.parse("12:00:00.001"));10assertThat(time).isBeforeOrEqualTo(LocalTime.parse("12:00:00.000"));11assertThat(time).isAfterOrEqualTo("11:59:59.999");12assertThat(time).isAfterOrEqualTo("12:00:00.000");13assertThat(time).isBeforeOrEqualTo("12:00:00.001");14assertThat(time).isBeforeOrEqualTo("12:00:00.000");15assertThat(time).isAfterOrEqualTo(LocalTime.parse("11:59:59.999"));16assertThat(time).isAfterOrEqualTo(LocalTime.parse("12:00:00.000"));17assertThat(time).isBeforeOrEqualTo(LocalTime.parse("12:00:00.001"));18assertThat(time).isBeforeOrEqualTo(LocalTime.parse("12:00:00.000"));19LocalTime time = LocalTime.parse("12:00:00.000");20assertThat(time).isAfterOrEqualTo("11:59:59.999");21assertThat(time).isAfterOrEqualTo("12:00:00.000");22assertThat(time).isBeforeOrEqualTo("12:00:00.001");23assertThat(time).isBeforeOrEqualTo("12:00:00.000");24LocalTime time = LocalTime.parse("12:00:00.000");25assertThat(time).isAfterOrEqualTo(LocalTime.parse("11:59:59.999"));26assertThat(time).isAfterOrEqualTo(LocalTime.parse("12:00:00.000"));27assertThat(time).isBeforeOrEqualTo(LocalTime.parse("12:00:00.001"));28assertThat(time).isBeforeOrEqualTo(LocalTime

Full Screen

Full Screen

parse

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.assertThat;2import java.time.LocalTime;3import org.junit.Test;4public class AssertJParseLocalTimeTest {5 public void givenLocalTime_whenParse_thenCorrect() {6 String time = "10:15:30";7 LocalTime localTime = LocalTime.parse(time);8 assertThat(localTime).isEqualTo(LocalTime.parse("10:15:30"));9 }10}

Full Screen

Full Screen

parse

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.*;2import java.time.LocalTime;3class LocalTimeAssertDemo {4 public static void main(String[] args) {5 LocalTime localTime = LocalTime.parse("12:00:00");6 assertThat(localTime).hasHour(12)7 .hasMinute(0)8 .hasSecond(0)9 .hasNano(0)10 .isAfter(LocalTime.parse("11:59:59"))11 .isBefore(LocalTime.parse("12:00:01"))12 .isBetween(LocalTime.parse("11:59:59"), LocalTime.parse("12:00:01"))13 .isIn(LocalTime.parse("11:59:59"), LocalTime.parse("12:00:00"), LocalTime.parse("12:00:01"))14 .isEqualTo(LocalTime.parse("12:00:00"))15 .isNotEqualTo(LocalTime.parse("12:00:01"))16 .hasSameHourAs(LocalTime.parse("12:00:01"))17 .hasSameMinuteAs(LocalTime.parse("12:01:00"))18 .hasSameSecondAs(LocalTime.parse("12:01:01"))19 .hasSameNanoOfSecondAs(LocalTime.parse("12:01:01.000000001"));20 }21}

Full Screen

Full Screen

parse

Using AI Code Generation

copy

Full Screen

1LocalTime time = LocalTime.of(3, 30, 0);2LocalTime time2 = LocalTime.of(3, 0, 0);3assertThat(time).isAfter(time2);4LocalTime time = LocalTime.of(3, 30, 0);5LocalTime time2 = LocalTime.of(3, 0, 0);6assertThat(time).isAfterOrEqualTo(time2);7LocalTime time = LocalTime.of(3, 0, 0);8LocalTime time2 = LocalTime.of(3, 30, 0);9assertThat(time).isBefore(time2);10LocalTime time = LocalTime.of(3, 0, 0);11LocalTime time2 = LocalTime.of(3, 30, 0);12assertThat(time).isBeforeOrEqualTo(time2);13LocalTime time = LocalTime.of(3, 0, 0);14LocalTime time2 = LocalTime.of(3, 0, 0);15assertThat(time).isEqualTo(time2);16LocalTime time = LocalTime.of(3, 0, 0);17LocalTime time2 = LocalTime.of(3, 30, 0);18assertThat(time).isNotEqualTo(time2);19LocalTime time = LocalTime.of(3, 0, 0);20LocalTime time2 = LocalTime.of(3, 0, 0);21assertThat(time).isIn(time2);22LocalTime time = LocalTime.of(3, 0, 0);23LocalTime time2 = LocalTime.of(3, 30, 0);24assertThat(time).isNotIn(time2);25LocalTime time = LocalTime.of(3, 0, 0);

Full Screen

Full Screen

parse

Using AI Code Generation

copy

Full Screen

1 public void testParse() {2 LocalTime time = LocalTime.parse("12:00:00.000");3 LocalTime time2 = LocalTime.parse("12:00:00.000", DateTimeFormatter.ISO_LOCAL_TIME);4 LocalTime time3 = LocalTime.parse("12:00:00.000", DateTimeFormatter.ISO_LOCAL_TIME, Locale.US);5 LocalTime time4 = LocalTime.parse("12:00:00.000", DateTimeFormatter.ISO_LOCAL_TIME, Locale.US, ResolverStyle.SMART);6 LocalTime time5 = LocalTime.parse("12:00:00.000", DateTimeFormatter.ISO_LOCAL_TIME, ResolverStyle.SMART);7 LocalTime time6 = LocalTime.parse("12:00:00.000", DateTimeFormatter.ISO_LOCAL_TIME, Locale.US, ResolverStyle.SMART, Chronology.ofLocale(Locale.US));8 LocalTime time7 = LocalTime.parse("12:00:00.000", DateTimeFormatter.ISO_LOCAL_TIME, Locale.US, ResolverStyle.SMART, Chronology.ofLocale(Locale.US), ZoneId.systemDefault());9 }10 public void testAssertParse() {11 Assertions.assertThat(LocalTime.parse("12:00:00.000")).isEqualTo(LocalTime.of(12, 0, 0));12 }13 public void testAssertParseWithFormat() {14 Assertions.assertThat(LocalTime.parse("12:00:00.000", DateTimeFormatter.ISO_LOCAL_TIME)).isEqualTo(LocalTime.of(12, 0, 0));15 }16 public void testAssertParseWithFormatLocale() {17 Assertions.assertThat(LocalTime.parse("12:00:00.000", DateTimeFormatter.ISO_LOCAL_TIME, Locale.US)).isEqualTo(LocalTime.of(12, 0, 0));18 }19 public void testAssertParseWithFormatLocaleResolverStyle() {20 Assertions.assertThat(LocalTime.parse("12:00:00.000", DateTimeFormatter.ISO_LOCAL_TIME, Locale.US, ResolverStyle.SMART)).isEqualTo(LocalTime.of(12, 0, 0));21 }22 public void testAssertParseWithFormatResolverStyle() {23 Assertions.assertThat(LocalTime.parse("12:00:00.000", DateTimeFormatter.ISO_LOCAL_TIME, ResolverStyle.SMART)).isEqualTo(LocalTime.of(12, 0, 0));

Full Screen

Full Screen

parse

Using AI Code Generation

copy

Full Screen

1LocalTime time = LocalTime.now();2LocalTime time1 = LocalTime.now();3LocalTime time2 = LocalTime.now();4assertThat(time).parse("12:00").isAfter(time1).isBefore(time2);5assertThat(time).parse("12:00").isAfter(time1).isBefore(time2);6LocalTime time = LocalTime.now();7LocalTime time1 = LocalTime.now();8LocalTime time2 = LocalTime.now();9assertThat(time).parse("12:00").isAfter(time1).isBefore(time2);10LocalTime time = LocalTime.now();11LocalTime time1 = LocalTime.now();12LocalTime time2 = LocalTime.now();13assertThat(time).parse("12:00").isAfter(time1).isBefore(time2);14LocalTime time = LocalTime.now();15LocalTime time1 = LocalTime.now();16LocalTime time2 = LocalTime.now();17assertThat(time).parse("12:00").isAfter(time1).isBefore(time2);

Full Screen

Full Screen

parse

Using AI Code Generation

copy

Full Screen

1LocalTime localTime = LocalTime.now();2LocalTime expectedTime = LocalTime.of(10, 30, 0);3assertThat(localTime).is(parse("10:30:00"));4LocalDate localDate = LocalDate.now();5LocalDate expectedDate = LocalDate.of(2017, 10, 30);6assertThat(localDate).is(parse("2017-10-30"));7LocalDateTime localDateTime = LocalDateTime.now();8LocalDateTime expectedDateTime = LocalDateTime.of(2017, 10, 30, 10, 30, 0);9assertThat(localDateTime).is(parse("2017-10-30T10:30:00"));10OffsetTime offsetTime = OffsetTime.now();11OffsetTime expectedOffsetTime = OffsetTime.of(10, 30, 0, 0, ZoneOffset.UTC);12assertThat(offsetTime).is(parse("10:30:00Z"));13OffsetDateTime offsetDateTime = OffsetDateTime.now();14OffsetDateTime expectedOffsetDateTime = OffsetDateTime.of(2017, 10, 30, 10, 30, 0, 0, ZoneOffset.UTC);15assertThat(offsetDateTime).is(parse("2017-10-30T10:30:00Z"));16ZonedDateTime zonedDateTime = ZonedDateTime.now();17ZonedDateTime expectedZonedDateTime = ZonedDateTime.of(2017, 10, 30, 10, 30, 0, 0, ZoneOffset.UTC);18assertThat(zonedDateTime).is(parse("2017-10-30T10:30:00Z"));19Instant instant = Instant.now();20Instant expectedInstant = Instant.parse("2017-10-30T10:30:00Z");21assertThat(instant).is(parse("2017-10-30T10:30:00Z"));22ChronoLocalDateTime<?> chronoLocalDateTime = LocalDateTime.now();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful