How to use areEqualIgnoringMinutes method of org.assertj.core.api.AbstractZonedDateTimeAssert class

Best Assertj code snippet using org.assertj.core.api.AbstractZonedDateTimeAssert.areEqualIgnoringMinutes

Source:AbstractZonedDateTimeAssert.java Github

copy

Full Screen

...413 public SELF isEqualToIgnoringMinutes(ZonedDateTime other) {414 Objects.instance().assertNotNull(info, actual);415 assertDateTimeParameterIsNotNull(other);416 ZonedDateTime otherInActualTimeZone = sameInstantInActualTimeZone(other);417 if (!areEqualIgnoringMinutes(actual, otherInActualTimeZone)) {418 throw Failures.instance().failure(info, shouldBeEqualIgnoringMinutes(actual, otherInActualTimeZone));419 }420 return myself;421 }422 /**423 * Verifies that actual and given {@code ZonedDateTime} have same year, month and day fields (hour, minute, second and424 * nanosecond fields are ignored in comparison).425 * <p>426 * Note that given {@link ZonedDateTime} is converted in the actual's {@link java.time.ZoneId} before comparison.427 * <p>428 * Assertion can fail with dateTimes in same chronological minute time window, e.g :429 * <p>430 * 2000-01-<b>01T23:59</b>:00.000 and 2000-01-02T<b>00:00</b>:00.000.431 * <p>432 * Time difference is only 1min but day fields differ.433 * <p>434 * Code example :435 * <pre><code class='java'> // successful assertions436 * ZonedDateTime dateTime1 = ZonedDateTime.of(2000, 1, 1, 23, 59, 59, 999, ZoneId.systemDefault());437 * ZonedDateTime dateTime2 = ZonedDateTime.of(2000, 1, 1, 00, 00, 00, 000, ZoneId.systemDefault());438 * assertThat(dateTime1).isEqualToIgnoringHours(dateTime2);439 *440 * // failing assertions (even if time difference is only 1ms)441 * ZonedDateTime dateTimeA = ZonedDateTime.of(2000, 1, 2, 00, 00, 00, 000, ZoneId.systemDefault());442 * ZonedDateTime dateTimeB = ZonedDateTime.of(2000, 1, 1, 23, 59, 59, 999, ZoneId.systemDefault());443 * assertThat(dateTimeA).isEqualToIgnoringHours(dateTimeB);</code></pre>444 *445 * @param other the given {@link ZonedDateTime}.446 * @return this assertion object.447 * @throws AssertionError if the actual {@code ZonedDateTime} is {@code null}.448 * @throws IllegalArgumentException if other {@code ZonedDateTime} is {@code null}.449 * @throws AssertionError if the actual {@code ZonedDateTime} is are not equal with second and nanosecond fields450 * ignored.451 */452 public SELF isEqualToIgnoringHours(ZonedDateTime other) {453 Objects.instance().assertNotNull(info, actual);454 assertDateTimeParameterIsNotNull(other);455 ZonedDateTime otherInActualTimeZone = sameInstantInActualTimeZone(other);456 if (!haveSameYearMonthAndDayOfMonth(actual, otherInActualTimeZone)) {457 throw Failures.instance().failure(info, shouldBeEqualIgnoringHours(actual, otherInActualTimeZone));458 }459 return myself;460 }461 /**462 * Verifies that the actual {@link ZonedDateTime} is equal to the given one according to the comparator in use.463 * <p>464 * <b>Breaking change</b>: since 3.15.0 the default comparator uses {@link ChronoZonedDateTime#timeLineOrder()} which only465 * compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.<br>466 * This behaviour can be overridden by {@link AbstractZonedDateTimeAssert#usingComparator(Comparator)}.467 * <p>468 * Example :469 * <pre><code class='java'> ZonedDateTime firstOfJanuary2000InUTC = ZonedDateTime.parse("2000-01-01T00:00:00Z");470 *471 * // both assertions succeed, the second one because the comparison based on the instant they are referring to472 * // 2000-01-01T01:00:00+01:00 = 2000-01-01T00:00:00 in UTC473 * assertThat(firstOfJanuary2000InUTC).isEqualTo(parse("2000-01-01T00:00:00Z"))474 * .isEqualTo(parse("2000-01-01T01:00:00+01:00"));475 *476 * // assertions fail477 * assertThat(firstOfJanuary2000InUTC).isEqualTo(parse("1999-01-01T01:00:00Z"));478 * // fails as the comparator compares the offsets479 * assertThat(firstOfJanuary2000InUTC).usingComparator(ZonedDateTime::compareTo)480 * .isEqualTo(parse("2000-01-01T01:00:00+01:00"));</code></pre>481 *482 * @param expected the given value to compare the actual value to.483 * @return {@code this} assertion object.484 * @throws AssertionError if the actual {@code ZonedDateTime} is not equal to the {@link ZonedDateTime} according485 * to the comparator in use.486 */487 @Override488 public SELF isEqualTo(Object expected) {489 if (actual == null || expected == null) {490 super.isEqualTo(expected);491 } else {492 comparables.assertEqual(info, actual, expected);493 }494 return myself;495 }496 /**497 * Same assertion as {@link #isEqualTo(Object)} but the {@link ZonedDateTime} is built from given String which must follow498 * <a href="http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_DATE_TIME"499 * >ISO date-time format</a> to allow calling {@link ZonedDateTime#parse(CharSequence, DateTimeFormatter)} method.500 * <p>501 * <b>Breaking change</b>: since 3.15.0 the default comparator uses {@link ChronoZonedDateTime#timeLineOrder()} which only502 * compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.<br>503 * This behaviour can be overridden by {@link AbstractZonedDateTimeAssert#usingComparator(Comparator)}.504 * <p>505 * Example :506 * <pre><code class='java'> ZonedDateTime firstOfJanuary2000InUTC = ZonedDateTime.parse("2000-01-01T00:00:00Z");507 *508 * // both assertions succeed, the second one because the comparison based on the instant they are referring to509 * // 2000-01-01T01:00:00+01:00 = 2000-01-01T00:00:00 in UTC510 * assertThat(firstOfJanuary2000InUTC).isEqualTo("2000-01-01T00:00:00Z")511 * .isEqualTo("2000-01-01T01:00:00+01:00");512 *513 * // assertions fail514 * assertThat(firstOfJanuary2000InUTC).isEqualTo("1999-01-01T01:00:00Z");515 * // fails as the comparator compares the offsets516 * assertThat(firstOfJanuary2000InUTC).usingComparator(ZonedDateTime::compareTo)517 * .isEqualTo("2000-01-01T01:00:00+01:00");</code></pre>518 *519 * @param dateTimeAsString String representing a {@link ZonedDateTime}.520 * @return this assertion object.521 * @throws AssertionError if the actual {@code ZonedDateTime} is {@code null}.522 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link ZonedDateTime}.523 * @throws AssertionError if the actual {@code ZonedDateTime} is not equal to the {@link ZonedDateTime} built from the given String.524 */525 public SELF isEqualTo(String dateTimeAsString) {526 assertDateTimeAsStringParameterIsNotNull(dateTimeAsString);527 return isEqualTo(parse(dateTimeAsString));528 }529 /**530 * Verifies that the actual value is not equal to the given one according to the comparator in use.531 * <p>532 * <b>Breaking change</b>: since 3.15.0 the default comparator uses {@link ChronoZonedDateTime#timeLineOrder()} which only533 * compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.<br>534 * This behaviour can be overridden by {@link AbstractZonedDateTimeAssert#usingComparator(Comparator)}.535 * <p>536 * Example :537 * <pre><code class='java'> // assertions succeed538 * assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo(parse("2020-01-01T00:00:00Z"));539 * // even though they refer to the same instant, succeeds as the ZonedDateTime comparator checks the offsets540 * assertThat(parse("2000-01-01T00:00:00Z")).usingComparator(ZonedDateTime::compareTo)541 * .isNotEqualTo(parse("2000-01-01T02:00:00+02:00"));542 *543 * // assertions fail544 * assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo(parse("2000-01-01T00:00:00Z"));545 * // fails because the default comparator only checks the instant and they refer to the same546 * assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo(parse("2000-01-01T02:00:00+02:00"));</code></pre>547 *548 * @param expected the given value to compare the actual value to.549 * @return {@code this} assertion object.550 * @throws AssertionError if the actual {@code ZonedDateTime} is equal to the {@link ZonedDateTime} according551 * to the comparator in use.552 */553 @Override554 public SELF isNotEqualTo(Object expected) {555 if (actual == null || expected == null) {556 super.isNotEqualTo(expected);557 } else {558 comparables.assertNotEqual(info, actual, expected);559 }560 return myself;561 }562 /**563 * Same assertion as {@code #isNotEqualTo(Object)} but the {@link ZonedDateTime} is built from given String which must follow564 * <a href="http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_DATE_TIME">ISO date-time format</a>565 * to allow calling {@link ZonedDateTime#parse(CharSequence, DateTimeFormatter)} method.566 * <p>567 * <b>Breaking change</b>: since 3.15.0 the default comparator uses {@link ChronoZonedDateTime#timeLineOrder()} which only568 * compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.<br>569 * This behaviour can be overridden by {@link AbstractZonedDateTimeAssert#usingComparator(Comparator)}.570 * <p>571 * Example :572 * <pre><code class='java'> // assertions succeed573 * assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo("2020-01-01T00:00:00Z");574 * // even though they refer to the same instant, succeeds as the ZonedDateTime comparator checks the offsets575 * assertThat(parse("2000-01-01T00:00:00Z")).usingComparator(ZonedDateTime::compareTo)576 * .isNotEqualTo("2000-01-01T02:00:00+02:00");577 *578 * // assertions fail579 * assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo("2000-01-01T00:00:00Z");580 * // fails because the default comparator only checks the instant and they refer to the same581 * assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo("2000-01-01T02:00:00+02:00");</code></pre>582 *583 * @param dateTimeAsString String representing a {@link ZonedDateTime}.584 * @return this assertion object.585 * @throws AssertionError if the actual {@code ZonedDateTime} is {@code null}.586 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link ZonedDateTime}.587 * @throws AssertionError if the actual {@code ZonedDateTime} is equal to the {@link ZonedDateTime} built from given {@link String}.588 */589 public SELF isNotEqualTo(String dateTimeAsString) {590 assertDateTimeAsStringParameterIsNotNull(dateTimeAsString);591 return isNotEqualTo(parse(dateTimeAsString));592 }593 /**594 * Verifies that the actual {@link ZonedDateTime} is equal to one of the given {@link ZonedDateTime} <b>in the actual595 * ZonedDateTime's {@link java.time.ZoneId}</b>.596 * <p>597 * Example :598 * <pre><code class='java'> assertThat(parse("2000-01-01T00:00:00Z")).isIn(parse("1999-12-31T23:59:59Z"),599 * parse("2000-01-01T00:00:00Z"));</code></pre>600 *601 * @param expected the given {@link ZonedDateTime}s to compare the actual value to.602 * @return {@code this} assertion object.603 * @throws AssertionError if the actual {@code ZonedDateTime} is {@code null}.604 * @throws AssertionError if the actual {@code ZonedDateTime} is not in the given {@link ZonedDateTime}s.605 */606 public SELF isIn(ZonedDateTime... expected) {607 return isIn((Object[]) changeToActualTimeZone(expected));608 }609 /**610 * Same assertion as {@link #isIn(ZonedDateTime...)} but the {@link ZonedDateTime} are built from given String, which611 * must follow <a612 * href="http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_DATE_TIME"613 * >ISO date-time format</a> to allow calling {@link ZonedDateTime#parse(CharSequence, DateTimeFormatter)} method.614 * <p>615 * Note that the {@link ZonedDateTime}s created from the given Strings are built in the {@link java.time.ZoneId} of616 * the {@link ZonedDateTime} to check..617 * <p>618 * Example :619 * <pre><code class='java'> // use String based representation of LocalDateTime620 * assertThat(parse("2000-01-01T00:00:00Z")).isIn("1999-12-31T23:59:59Z",621 * "2000-01-01T00:00:00Z");</code></pre>622 *623 * @param dateTimesAsString String array representing {@link ZonedDateTime}s.624 * @return this assertion object.625 * @throws AssertionError if the actual {@code ZonedDateTime} is {@code null}.626 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link ZonedDateTime}.627 * @throws AssertionError if the actual {@code ZonedDateTime} is not in the {@link ZonedDateTime}s built from given628 * Strings.629 */630 public SELF isIn(String... dateTimesAsString) {631 checkIsNotNullAndNotEmpty(dateTimesAsString);632 return isIn(convertToDateTimeArray(dateTimesAsString));633 }634 /**635 * Verifies that the actual {@link ZonedDateTime} is equal to one of the given {@link ZonedDateTime} <b>in the actual636 * ZonedDateTime's {@link java.time.ZoneId}</b>.637 * <p>638 * Example :639 * <pre><code class='java'> assertThat(parse("2000-01-01T00:00:00Z")).isNotIn(parse("1999-12-31T23:59:59Z"),640 * parse("2000-01-02T00:00:00Z"));</code></pre>641 *642 * @param expected the given {@link ZonedDateTime}s to compare the actual value to.643 * @return {@code this} assertion object.644 * @throws AssertionError if the actual {@code ZonedDateTime} is {@code null}.645 * @throws AssertionError if the actual {@code ZonedDateTime} is not in the given {@link ZonedDateTime}s.646 */647 public SELF isNotIn(ZonedDateTime... expected) {648 return isNotIn((Object[]) changeToActualTimeZone(expected));649 }650 /**651 * Same assertion as {@link #isNotIn(ZonedDateTime...)} but the {@link ZonedDateTime} is built from given String,652 * which must follow <a653 * href="http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_DATE_TIME"654 * >ISO date-time format</a> to allow calling {@link ZonedDateTime#parse(CharSequence, DateTimeFormatter)} method.655 * <p>656 * Note that the {@link ZonedDateTime}s created from the given Strings are built in the {@link java.time.ZoneId} of657 * the {@link ZonedDateTime} to check..658 * <p>659 * Example :660 * <pre><code class='java'> // use String based representation of ZonedDateTime661 * assertThat(parse("2000-01-01T00:00:00Z")).isNotIn("1999-12-31T23:59:59Z",662 * "2000-01-02T00:00:00Z");</code></pre>663 *664 * @param dateTimesAsString String array representing {@link ZonedDateTime}s.665 * @return this assertion object.666 * @throws AssertionError if the actual {@code ZonedDateTime} is {@code null}.667 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link ZonedDateTime}.668 * @throws AssertionError if the actual {@code ZonedDateTime} is not equal to the {@link ZonedDateTime} built from669 * given String.670 */671 public SELF isNotIn(String... dateTimesAsString) {672 checkIsNotNullAndNotEmpty(dateTimesAsString);673 return isNotIn(convertToDateTimeArray(dateTimesAsString));674 }675 /**676 * Verifies that the actual {@link ZonedDateTime} is in the [start, end] period (start and end included) according to677 * the comparator in use.678 * <p>679 * <b>Breaking change</b>: since 3.15.0 the default comparator uses {@link ChronoZonedDateTime#timeLineOrder()} which only680 * compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.<br>681 * This behaviour can be overridden by {@link AbstractZonedDateTimeAssert#usingComparator(Comparator)}.682 * <p>683 * Example:684 * <pre><code class='java'> ZonedDateTime zonedDateTime = ZonedDateTime.now();685 *686 * // assertions succeed:687 * assertThat(zonedDateTime).isBetween(zonedDateTime.minusSeconds(1), zonedDateTime.plusSeconds(1))688 * .isBetween(zonedDateTime, zonedDateTime.plusSeconds(1))689 * .isBetween(zonedDateTime.minusSeconds(1), zonedDateTime)690 * .isBetween(zonedDateTime, zonedDateTime);691 * // succeeds with default comparator which compares the point in time692 * assertThat(parse("2010-01-01T00:00:00Z")).isBetween(parse("2010-01-01T01:00:00+01:00"),693 * parse("2010-01-01T01:00:00+01:00"));694 *695 * // assertions fail:696 * assertThat(zonedDateTime).isBetween(zonedDateTime.minusSeconds(10), zonedDateTime.minusSeconds(1));697 * assertThat(zonedDateTime).isBetween(zonedDateTime.plusSeconds(1), zonedDateTime.plusSeconds(10));698 * // fails because the comparator checks the offsets are the same699 * assertThat(parse("2010-01-01T00:00:00Z")).usingComparator(ZonedDateTime::compareTo)700 * .isBetween(parse("2010-01-01T01:00:00+01:00"),701 * parse("2010-01-01T01:00:00+01:00"));</code></pre>702 *703 * @param startInclusive the start value (inclusive), expected not to be null.704 * @param endInclusive the end value (inclusive), expected not to be null.705 * @return this assertion object.706 * @throws AssertionError if the actual value is {@code null}.707 * @throws NullPointerException if start value is {@code null}.708 * @throws NullPointerException if end value is {@code null}.709 * @throws AssertionError if the actual value is not in [start, end] period.710 *711 * @since 3.7.1712 */713 public SELF isBetween(ZonedDateTime startInclusive, ZonedDateTime endInclusive) {714 comparables.assertIsBetween(info, actual, startInclusive, endInclusive, true, true);715 return myself;716 }717 /**718 * Same assertion as {@link #isBetween(ZonedDateTime, ZonedDateTime)} but here you pass {@link ZonedDateTime} String representations719 * which must follow <a href="http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_ZONED_DATE_TIME">ISO ZonedDateTime format</a>720 * to allow calling {@link ZonedDateTime#parse(CharSequence)} method.721 * <p>722 * <b>Breaking change</b>: since 3.15.0 the default comparator uses {@link ChronoZonedDateTime#timeLineOrder()} which only723 * compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.<br>724 * This behaviour can be overridden by {@link AbstractZonedDateTimeAssert#usingComparator(Comparator)}.725 * <p>726 * Example:727 * <pre><code class='java'> ZonedDateTime firstOfJanuary2000 = ZonedDateTime.parse("2000-01-01T00:00:00Z");728 *729 * // assertions succeed:730 * assertThat(firstOfJanuary2000).isBetween("1999-12-31T23:59:59Z", "2000-01-01T00:00:01Z")731 * .isBetween("2000-01-01T00:00:00Z", "2000-01-01T00:00:01Z")732 * .isBetween("1999-12-31T23:59:59Z", "2000-01-01T00:00:00Z")733 * .isBetween("2000-01-01T00:00:00Z", "2000-01-01T00:00:00Z")734 * // same instant as firstOfJanuary2000 but on a different offset735 * .isBetween("2000-01-01T01:00:00+01:00", "2000-01-01T01:00:00+01:00");736 *737 * // assertion fails:738 * assertThat(firstOfJanuary2000).isBetween("1999-01-01T00:00:01Z", "1999-12-31T23:59:59Z");</code></pre>739 *740 * @param startInclusive the start value (inclusive), expected not to be null.741 * @param endInclusive the end value (inclusive), expected not to be null.742 * @return this assertion object.743 *744 * @throws AssertionError if the actual value is {@code null}.745 * @throws NullPointerException if start value is {@code null}.746 * @throws NullPointerException if end value is {@code null}.747 * @throws DateTimeParseException if any of the given String can't be converted to a {@link ZonedDateTime}.748 * @throws AssertionError if the actual value is not in [start, end] period.749 *750 * @since 3.7.1751 */752 public SELF isBetween(String startInclusive, String endInclusive) {753 return isBetween(parse(startInclusive), parse(endInclusive));754 }755 /**756 * Verifies that the actual {@link ZonedDateTime} is in the ]start, end[ period (start and end excluded) according to757 * the comparator in use.758 * <p>759 * <b>Breaking change</b>: since 3.15.0 the default comparator uses {@link ChronoZonedDateTime#timeLineOrder()} which only760 * compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.<br>761 * This behaviour can be overridden by {@link AbstractZonedDateTimeAssert#usingComparator(Comparator)}.762 * <p>763 * Example:764 * <pre><code class='java'> ZonedDateTime zonedDateTime = ZonedDateTime.now();765 *766 * // assertions succeed:767 * assertThat(zonedDateTime).isStrictlyBetween(zonedDateTime.minusSeconds(1), zonedDateTime.plusSeconds(1));768 * // succeeds with a different comparator even though the end value refers to the same instant as the actual769 * assertThat(parse("2010-01-01T12:00:00Z")).usingComparator(ZonedDateTime::compareTo)770 * .isStrictlyBetween(parse("2010-01-01T12:59:59+01:00"),771 * parse("2010-01-01T13:00:00+01:00"));772 *773 * // assertions fail:774 * assertThat(zonedDateTime).isStrictlyBetween(zonedDateTime.minusSeconds(10), zonedDateTime.minusSeconds(1));775 * assertThat(zonedDateTime).isStrictlyBetween(zonedDateTime.plusSeconds(1), zonedDateTime.plusSeconds(10));776 * assertThat(zonedDateTime).isStrictlyBetween(zonedDateTime, zonedDateTime.plusSeconds(1));777 * assertThat(zonedDateTime).isStrictlyBetween(zonedDateTime.minusSeconds(1), zonedDateTime);778 * // fails with default comparator since the end value refers to the same instant as the actual779 * assertThat(parse("2010-01-01T12:00:00Z")).isStrictlyBetween(parse("2010-01-01T12:59:59+01:00"),780 * parse("2010-01-01T13:00:00+01:00"));</code></pre>781 *782 * @param startExclusive the start value (exclusive), expected not to be null.783 * @param endExclusive the end value (exclusive), expected not to be null.784 * @return this assertion object.785 * @throws AssertionError if the actual value is {@code null}.786 * @throws NullPointerException if start value is {@code null}.787 * @throws NullPointerException if end value is {@code null}.788 * @throws AssertionError if the actual value is not in ]start, end[ period.789 *790 * @since 3.7.1791 */792 public SELF isStrictlyBetween(ZonedDateTime startExclusive, ZonedDateTime endExclusive) {793 comparables.assertIsBetween(info, actual, startExclusive, endExclusive, false, false);794 return myself;795 }796 /**797 * Same assertion as {@link #isStrictlyBetween(ZonedDateTime, ZonedDateTime)} but here you pass {@link ZonedDateTime} String representations798 * which must follow <a href="http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_ZONED_DATE_TIME">ISO ZonedDateTime format</a>799 * to allow calling {@link ZonedDateTime#parse(CharSequence)} method.800 * <p>801 * <b>Breaking change</b>: since 3.15.0 the default comparator uses {@link ChronoZonedDateTime#timeLineOrder()} which only802 * compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.<br>803 * This behaviour can be overridden by {@link AbstractZonedDateTimeAssert#usingComparator(Comparator)}.804 * <p>805 * Example:806 * <pre><code class='java'> ZonedDateTime firstOfJanuary2000 = ZonedDateTime.parse("2000-01-01T00:00:00Z");807 *808 * // assertions succeed:809 * assertThat(firstOfJanuary2000).isStrictlyBetween("1999-12-31T23:59:59Z", "2000-01-01T00:00:01Z")810 * // succeeds with a different comparator even though the end value refers to the same instant as the actual811 * .usingComparator(ZonedDateTime::compareTo)812 * .isStrictlyBetween("1999-12-31T23:59:59Z", "2000-01-01T01:00:00+01:00");813 *814 * // assertions fail:815 * assertThat(firstOfJanuary2000).isStrictlyBetween("1999-01-01T00:00:01Z", "1999-12-31T23:59:59Z");816 * assertThat(firstOfJanuary2000).isStrictlyBetween("2000-01-01T00:00:00Z", "2000-01-01T00:00:01Z");817 * assertThat(firstOfJanuary2000).isStrictlyBetween("1999-12-31T23:59:59Z", "2000-01-01T00:00:00Z");818 * // fails with default comparator since the end value refers to the same instant as the actual819 * assertThat(parse("2010-01-01T12:00:00Z")).isStrictlyBetween("2010-01-01T12:59:59+01:00", "2010-01-01T13:00:00+01:00");</code></pre>820 *821 * @param startExclusive the start value (exclusive), expected not to be null.822 * @param endExclusive the end value (exclusive), expected not to be null.823 * @return this assertion object.824 *825 * @throws AssertionError if the actual value is {@code null}.826 * @throws NullPointerException if start value is {@code null}.827 * @throws NullPointerException if end value is {@code null}.828 * @throws DateTimeParseException if any of the given String can't be converted to a {@link ZonedDateTime}.829 * @throws AssertionError if the actual value is not in ]start, end[ period.830 *831 * @since 3.7.1832 */833 public SELF isStrictlyBetween(String startExclusive, String endExclusive) {834 return isStrictlyBetween(parse(startExclusive), parse(endExclusive));835 }836 /** {@inheritDoc} */837 @Override838 @CheckReturnValue839 public SELF usingDefaultComparator() {840 SELF self = super.usingDefaultComparator();841 self.comparables = buildDefaultComparables();842 return self;843 }844 private Comparables buildDefaultComparables() {845 ChronoZonedDateTimeByInstantComparator defaultComparator = ChronoZonedDateTimeByInstantComparator.getInstance();846 return new Comparables(new ComparatorBasedComparisonStrategy(defaultComparator, defaultComparator.description()));847 }848 private ZonedDateTime[] convertToDateTimeArray(String... dateTimesAsString) {849 ZonedDateTime[] dates = new ZonedDateTime[dateTimesAsString.length];850 for (int i = 0; i < dateTimesAsString.length; i++) {851 dates[i] = parse(dateTimesAsString[i]);852 }853 return dates;854 }855 private ZonedDateTime[] changeToActualTimeZone(ZonedDateTime... dateTimes) {856 ZonedDateTime[] dates = new ZonedDateTime[dateTimes.length];857 for (int i = 0; i < dateTimes.length; i++) {858 dates[i] = sameInstantInActualTimeZone(dateTimes[i]);859 }860 return dates;861 }862 private void checkIsNotNullAndNotEmpty(Object[] values) {863 checkArgument(values != null, "The given ZonedDateTime array should not be null");864 checkArgument(values.length > 0, "The given ZonedDateTime array should not be empty");865 }866 /**867 * Obtains an instance of {@link ZonedDateTime} from a string representation in ISO date format.868 *869 * @param dateTimeAsString the string to parse870 * @return the parsed {@link ZonedDateTime}871 */872 @Override873 protected ZonedDateTime parse(String dateTimeAsString) {874 return ZonedDateTime.parse(dateTimeAsString, DateTimeFormatter.ISO_DATE_TIME);875 }876 private ZonedDateTime sameInstantInActualTimeZone(ZonedDateTime zonedDateTime) {877 if (zonedDateTime == null) return null; // nothing to convert in actual's TZ878 if (actual == null) return zonedDateTime; // no actual => let's keep zonedDateTime as it is.879 return zonedDateTime.withZoneSameInstant(actual.getZone());880 }881 /**882 * Check that the {@link ZonedDateTime} string representation to compare actual {@link ZonedDateTime} to is not null,883 * otherwise throws a {@link IllegalArgumentException} with an explicit message884 *885 * @param dateTimeAsString String representing the ZonedDateTime to compare actual with886 * @throws IllegalArgumentException with an explicit message if the given {@link String} is null887 */888 private static void assertDateTimeAsStringParameterIsNotNull(String dateTimeAsString) {889 checkArgument(dateTimeAsString != null,890 "The String representing the ZonedDateTime to compare actual with should not be null");891 }892 /**893 * Returns true if both datetime are in the same year, month and day of month, hour, minute and second, false894 * otherwise.895 *896 * @param actual the actual datetime. expected not be null897 * @param other the other datetime. expected not be null898 * @return true if both datetime are in the same year, month and day of month, hour, minute and second, false899 * otherwise.900 */901 private static boolean areEqualIgnoringNanos(ZonedDateTime actual, ZonedDateTime other) {902 return areEqualIgnoringSeconds(actual, other) && actual.getSecond() == other.getSecond();903 }904 /**905 * Returns true if both datetime are in the same year, month, day of month, hour and minute, false otherwise.906 *907 * @param actual the actual datetime. expected not be null908 * @param other the other datetime. expected not be null909 * @return true if both datetime are in the same year, month, day of month, hour and minute, false otherwise.910 */911 private static boolean areEqualIgnoringSeconds(ZonedDateTime actual, ZonedDateTime other) {912 return areEqualIgnoringMinutes(actual, other) && actual.getMinute() == other.getMinute();913 }914 /**915 * Returns true if both datetime are in the same year, month, day of month and hour, false otherwise.916 *917 * @param actual the actual datetime. expected not be null918 * @param other the other datetime. expected not be null919 * @return true if both datetime are in the same year, month, day of month and hour, false otherwise.920 */921 private static boolean areEqualIgnoringMinutes(ZonedDateTime actual, ZonedDateTime other) {922 return haveSameYearMonthAndDayOfMonth(actual, other) && actual.getHour() == other.getHour();923 }924 /**925 * Returns true if both datetime are in the same year, month and day of month, false otherwise.926 *927 * @param actual the actual datetime. expected not be null928 * @param other the other datetime. expected not be null929 * @return true if both datetime are in the same year, month and day of month, false otherwise930 */931 private static boolean haveSameYearMonthAndDayOfMonth(ZonedDateTime actual, ZonedDateTime other) {932 return haveSameYearAndMonth(actual, other) && actual.getDayOfMonth() == other.getDayOfMonth();933 }934 /**935 * Returns true if both datetime are in the same year and month, false otherwise....

Full Screen

Full Screen

areEqualIgnoringMinutes

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.assertThat;2import static org.assertj.core.api.Assertions.within;3import java.time.ZonedDateTime;4import org.junit.Test;5public class AssertJZonedDateTimeTest {6 public void test() {7 ZonedDateTime zdt1 = ZonedDateTime.parse("2018-03-27T09:30:00+05:30[Asia/Calcutta]");8 ZonedDateTime zdt2 = ZonedDateTime.parse("2018-03-27T09:30:00+05:30[Asia/Calcutta]");9 ZonedDateTime zdt3 = ZonedDateTime.parse("2018-03-27T09:30:00+05:30[Asia/Calcutta]");10 ZonedDateTime zdt4 = ZonedDateTime.parse("2018-03-27T09:30:00+05:30[Asia/Calcutta]");11 ZonedDateTime zdt5 = ZonedDateTime.parse("2018-03-27T09:30:00+05:30[Asia/Calcutta]");12 ZonedDateTime zdt6 = ZonedDateTime.parse("2018-03-27T09:30:00+05:30[Asia/Calcutta]");13 ZonedDateTime zdt7 = ZonedDateTime.parse("2018-03-27T09:30:00+05:30[Asia/Calcutta]");14 ZonedDateTime zdt8 = ZonedDateTime.parse("2018-03-27T09:30:00+05:30[Asia/Calcutta]");15 ZonedDateTime zdt9 = ZonedDateTime.parse("2018-03-27T09:30:00+05:30[Asia/Calcutta]");16 ZonedDateTime zdt10 = ZonedDateTime.parse("2018-03-27T09:30:00+05:30[Asia/Calcutta]");17 ZonedDateTime zdt11 = ZonedDateTime.parse("2018-03-27T09:30:00+05:30[Asia/Calcutta]");18 ZonedDateTime zdt12 = ZonedDateTime.parse("2018-03-27T09:30:00+05:30[Asia/Calcutta]");19 ZonedDateTime zdt13 = ZonedDateTime.parse("2018-03-27T09:30:00+05:30[Asia/Calcutta]");

Full Screen

Full Screen

areEqualIgnoringMinutes

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.AbstractZonedDateTimeAssert2import org.assertj.core.api.Assertions.assertThat3def now = ZonedDateTime.now()4def nowPlusOneMinute = now.plusMinutes(1)5assertThat(now).areEqualIgnoringMinutes(nowPlusOneMinute)6assertThat(now).areEqualIgnoringSeconds(nowPlusOneMinute)7assertThat(now).areEqualIgnoringNanos(nowPlusOneMinute)8assertThat(now).areEqualIgnoringNanos(nowPlusOneMinute)

Full Screen

Full Screen

areEqualIgnoringMinutes

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.assertThat;2import java.time.ZonedDateTime;3import java.time.ZoneId;4public class AssertjExample {5 public static void main(String[] args) {6 ZonedDateTime date1 = ZonedDateTime.of(2018, 1, 2, 10, 0, 0, 0, ZoneId.of("UTC"));7 ZonedDateTime date2 = ZonedDateTime.of(2018, 1, 2, 10, 30, 0, 0, ZoneId.of("UTC"));8 assertThat(date1).isNotEqualTo(date2);9 assertThat(date1).isNotEqualToIgnoringMinutes(date2);10 }11}12import static org.assertj.core.api.Assertions.assertThat;13import java.time.ZonedDateTime;14import java.time.ZoneId;15public class AssertjExample {16 public static void main(String[] args) {17 ZonedDateTime date1 = ZonedDateTime.of(2018, 1, 2, 10, 0, 0, 0, ZoneId.of("UTC"));18 ZonedDateTime date2 = ZonedDateTime.of(2018, 1, 2, 10, 30, 0, 0, ZoneId.of("UTC"));19 assertThat(date1).isNotEqualToIgnoringMinutes(date2);20 }21}

Full Screen

Full Screen

areEqualIgnoringMinutes

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.*;2import java.time.ZonedDateTime;3import org.junit.Test;4public class AssertJZonedDateTimeTest {5 public void testAssertJZonedDateTime() {6 ZonedDateTime zonedDateTime = ZonedDateTime.parse("2015-11-07T13:14:15+01:00[Europe/Paris]");7 ZonedDateTime sameZonedDateTime = ZonedDateTime.parse("2015-11-07T13:15:15+01:00[Europe/Paris]");8 ZonedDateTime differentZonedDateTime = ZonedDateTime.parse("2015-11-07T14:14:15+01:00[Europe/Paris]");9 assertThat(zonedDateTime).isEqualTo(sameZonedDateTime);10 assertThat(zonedDateTime).isNotEqualTo(differentZonedDateTime);11 assertThat(zonedDateTime).isEqualToIgnoringMinutes(sameZonedDateTime);12 assertThat(zonedDateTime).isNotEqualToIgnoringMinutes(differentZonedDateTime);13 }14}15 at org.assertj.core.api.AbstractZonedDateTimeAssert.isEqualTo(AbstractZonedDateTimeAssert.java:98)16 at org.assertj.core.api.AbstractZonedDateTimeAssert.isEqualTo(AbstractZonedDateTimeAssert.java:37)17 at org.jugbd.mnet.assertj.AssertJZonedDateTimeTest.testAssertJZonedDateTime(AssertJZonedDateTimeTest.java:17)18 at org.assertj.core.api.AbstractZonedDateTimeAssert.isNotEqualTo(AbstractZonedDateTimeAssert.java:108)19 at org.assertj.core.api.AbstractZonedDateTimeAssert.isNotEqualTo(AbstractZonedDateTimeAssert.java:37)20 at org.jugbd.mnet.assertj.AssertJZonedDateTimeTest.testAssertJZonedDateTime(AssertJZonedDateTimeTest.java:18)

Full Screen

Full Screen

areEqualIgnoringMinutes

Using AI Code Generation

copy

Full Screen

1public class ZonedDateTimeAssert_areEqualIgnoringMinutes_Test extends ZonedDateTimeAssertBaseTest {2 protected ZonedDateTimeAssert invoke_api_method() {3 return assertions.areEqualIgnoringMinutes(getInfo(assertions), getActual(assertions));4 }5 protected void verify_internal_effects() {6 verify(zonedDateTimes).assertIsEqualIgnoringMinutes(getInfo(assertions), getActual(assertions), getActual(assertions));7 }8}

Full Screen

Full Screen

areEqualIgnoringMinutes

Using AI Code Generation

copy

Full Screen

1ZonedDateTime actual = ZonedDateTime.now();2ZonedDateTime other = ZonedDateTime.now();3assertThat(actual).isNotEqualToIgnoringMinutes(other);4ZonedDateTime actual = ZonedDateTime.now();5ZonedDateTime other = ZonedDateTime.now();6assertThat(actual).isNotEqualToIgnoringMinutes(other);7ZonedDateTime actual = ZonedDateTime.now();8ZonedDateTime other = ZonedDateTime.now();9assertThat(actual).isNotEqualToIgnoringMinutes(other);10ZonedDateTime actual = ZonedDateTime.now();11ZonedDateTime other = ZonedDateTime.now();12assertThat(actual).isNotEqualToIgnoringMinutes(other);13ZonedDateTime actual = ZonedDateTime.now();14ZonedDateTime other = ZonedDateTime.now();15assertThat(actual).isNotEqualToIgnoringMinutes(other);16ZonedDateTime actual = ZonedDateTime.now();17ZonedDateTime other = ZonedDateTime.now();18assertThat(actual).isNotEqualToIgnoringMinutes(other);19ZonedDateTime actual = ZonedDateTime.now();20ZonedDateTime other = ZonedDateTime.now();21assertThat(actual).isNotEqualToIgnoringMinutes(other);22ZonedDateTime actual = ZonedDateTime.now();23ZonedDateTime other = ZonedDateTime.now();24assertThat(actual).isNotEqualToIgnoringMinutes(other);25ZonedDateTime actual = ZonedDateTime.now();26ZonedDateTime other = ZonedDateTime.now();27assertThat(actual).isNotEqualToIgnoringMinutes(other);28ZonedDateTime actual = ZonedDateTime.now();29ZonedDateTime other = ZonedDateTime.now();30assertThat(actual).isNotEqualToIgnoringMinutes(other);31ZonedDateTime actual = ZonedDateTime.now();32ZonedDateTime other = ZonedDateTime.now();33assertThat(actual

Full Screen

Full Screen

areEqualIgnoringMinutes

Using AI Code Generation

copy

Full Screen

1@DisplayName("Test ZonedDateTime with AssertJ")2public class ZonedDateTimeTest {3 @DisplayName("Test ZonedDateTime with AssertJ")4 void testZonedDateTimeWithAssertJ() {5 ZonedDateTime zonedDateTime = ZonedDateTime.now();6 ZonedDateTime zonedDateTime1 = ZonedDateTime.now();7 ZonedDateTime zonedDateTime2 = ZonedDateTime.now().plusMinutes(1);8 assertThat(zonedDateTime).isEqualTo(zonedDateTime1);9 assertThat(zonedDateTime).isNotEqualTo(zonedDateTime2);10 assertThat(zonedDateTime).isBefore(zonedDateTime2);11 assertThat(zonedDateTime2).isAfter(zonedDateTime);12 assertThat(zonedDateTime).isBeforeOrEqualTo(zonedDateTime1);13 assertThat(zonedDateTime).isBeforeOrEqualTo(zonedDateTime2);14 assertThat(zonedDateTime2).isAfterOrEqualTo(zonedDateTime);15 assertThat(zonedDateTime2).isAfterOrEqualTo(zonedDateTime2);16 assertThat(zonedDateTime).isEqualToIgnoringMinutes(zonedDateTime2);17 assertThat(zonedDateTime).isNotEqualToIgnoringMinutes(zonedDateTime1);18 }19}

Full Screen

Full Screen

areEqualIgnoringMinutes

Using AI Code Generation

copy

Full Screen

1assertThat(ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()))2 .isNotEqualTo(ZonedDateTime.of(2000, 1, 1, 0, 1, 0, 0, ZoneId.systemDefault()));3assertThat(ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()))4 .isEqualToIgnoringMinutes(ZonedDateTime.of(2000, 1, 1, 0, 1, 0, 0, ZoneId.systemDefault()));5assertThat(ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()))6 .isNotEqualToIgnoringMinutes(ZonedDateTime.of(2000, 1, 1, 1, 0, 0, 0, ZoneId.systemDefault()));7assertThat(ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()))8 .isNotEqualToIgnoringMinutes(ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC")));9assertThat(ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()))10 .isEqualToIgnoringMinutes(ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC")));11assertThat(ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()))12 .isNotEqualToIgnoringMinutes(ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC+1")));13assertThat(ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()))14 .isEqualToIgnoringMinutes(ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC

Full Screen

Full Screen

areEqualIgnoringMinutes

Using AI Code Generation

copy

Full Screen

1void testZonedDateTimeEqualIgnoringMinutes() {2 ZonedDateTime zonedDateTime1 = ZonedDateTime.parse("2019-05-02T12:00:00+05:30[Asia/Kolkata]");3 ZonedDateTime zonedDateTime2 = ZonedDateTime.parse("2019-05-02T12:01:00+05:30[Asia/Kolkata]");4 assertThat(zonedDateTime1).isNotEqualTo(zonedDateTime2);5 assertThat(zonedDateTime1).isNotEqualToIgnoringMinutes(zonedDateTime2);6}7void testZonedDateTimeEqualIgnoringMinutes() {8 ZonedDateTime zonedDateTime1 = ZonedDateTime.parse("2019-05-02T12:00:00+05:30[Asia/Kolkata]");9 ZonedDateTime zonedDateTime2 = ZonedDateTime.parse("2019-05-02T12:00:00+05:30[Asia/Kolkata]");10 assertThat(zonedDateTime1).isNotEqualTo(zonedDateTime2);11 assertThat(zonedDateTime1).isNotEqualToIgnoringMinutes(zonedDateTime2);12}13void testZonedDateTimeEqualIgnoringMinutes() {14 ZonedDateTime zonedDateTime1 = ZonedDateTime.parse("2019-05-02T12:00:00+05:30[Asia/Kolkata]");15 ZonedDateTime zonedDateTime2 = ZonedDateTime.parse("2019-05-02T12:00:01+05:30[Asia/Kolkata]");16 assertThat(zonedDateTime1).isNotEqualTo(zonedDateTime2);17 assertThat(zonedDateTime1).isNotEqualToIgnoringMinutes(zonedDateTime2);18}19void testZonedDateTimeEqualIgnoringMinutes() {20 ZonedDateTime zonedDateTime1 = ZonedDateTime.parse("2019-05-02T12:00:00+05:30[Asia/Kolkata]");21 ZonedDateTime zonedDateTime2 = ZonedDateTime.parse("2019-05-02T12:00:00+05:00[Asia/Kolkata]");22 assertThat(zonedDateTime1).isNotEqualTo(zonedDateTime2);23 assertThat(zonedDateTime1).isNotEqualToIgnoringMinutes(zonedDateTime2);24}25void testZonedDateTimeEqualIgnoringMinutes() {26 ZonedDateTime zonedDateTime1 = ZonedDateTime.parse("2019

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