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

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

Source:AbstractZonedDateTimeAssert.java Github

copy

Full Screen

...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.936 *937 * @param actual the actual datetime. expected not be null938 * @param other the other datetime. expected not be null939 * @return true if both datetime are in the same year and month, false otherwise940 */941 private static boolean haveSameYearAndMonth(ZonedDateTime actual, ZonedDateTime other) {942 return haveSameYear(actual, other) && actual.getMonth() == other.getMonth();943 }944 /**945 * Returns true if both datetime are in the same year, false otherwise.946 *947 * @param actual the actual datetime. expected not be null948 * @param other the other datetime. expected not be null949 * @return true if both datetime are in the same year, false otherwise950 */951 private static boolean haveSameYear(ZonedDateTime actual, ZonedDateTime other) {952 return actual.getYear() == other.getYear();953 }954 protected AbstractZonedDateTimeAssert(ZonedDateTime actual, Class<?> selfType) {955 super(actual, selfType);956 comparables = buildDefaultComparables();957 }958}...

Full Screen

Full Screen

haveSameYear

Using AI Code Generation

copy

Full Screen

1assertThat(ZonedDateTime.now()).hasSameYearAs(ZonedDateTime.now());2assertThat(ZonedDateTime.now()).hasSameMonthAs(ZonedDateTime.now());3assertThat(ZonedDateTime.now()).hasSameDayAs(ZonedDateTime.now());4assertThat(ZonedDateTime.now()).hasSameHourAs(ZonedDateTime.now());5assertThat(ZonedDateTime.now()).hasSameMinuteAs(ZonedDateTime.now());6assertThat(ZonedDateTime.now()).hasSameSecondAs(ZonedDateTime.now());7assertThat(ZonedDateTime.now()).hasSameMillisecondAs(ZonedDateTime.now());8assertThat(ZonedDateTime.now()).hasSameInstantAs(ZonedDateTime.now());9assertThat(ZonedDateTime.now()).hasSameLocalDateTimeAs(ZonedDateTime.now());10assertThat(ZonedDateTime.now()).hasSameLocalTimeAs(ZonedDateTime.now());11assertThat(ZonedDateTime.now()).hasSameLocalDateAs(ZonedDateTime.now());12assertThat(ZonedDateTime.now()).hasSameOffsetAs(ZonedDateTime.now());13assertThat(ZonedDateTime.now()).hasSameZoneAs(ZonedDateTime.now());14assertThat(ZonedDateTime.now()).hasSameZoneAndSameInstantAs(ZonedDateTime.now());15assertThat(ZonedDateTime.now()).hasSameZoneAndSameLocalDateTimeAs(ZonedDateTime.now());16assertThat(ZonedDateTime.now()).hasSameZoneAndSameLocalDateAs(ZonedDateTime.now());17assertThat(ZonedDateTime.now()).hasSameZoneAndSameLocalTimeAs(ZonedDateTime.now());18assertThat(ZonedDateTime.now()).hasSameZoneAndSameOffsetAs(ZonedDateTime.now());19assertThat(ZonedDateTime.now()).isAfter(ZonedDateTime.now());20assertThat(ZonedDateTime.now()).isBefore(ZonedDateTime.now());21assertThat(ZonedDateTime.now()).isAfterOrEqualTo(ZonedDateTime.now());22assertThat(ZonedDateTime.now()).isBeforeOrEqualTo(ZonedDateTime.now());23assertThat(ZonedDateTime.now()).isBetween(ZonedDateTime.now(), ZonedDateTime.now());24assertThat(ZonedDateTime.now()).isBetweenOrEqualTo(ZonedDateTime.now(), ZonedDateTime.now());25assertThat(ZonedDateTime.now()).isStrictlyBetween(ZonedDateTime.now(), ZonedDateTime.now());26assertThat(ZonedDateTime.now

Full Screen

Full Screen

haveSameYear

Using AI Code Generation

copy

Full Screen

1assertThat(ZonedDateTime.now()).hasSameYearAs(ZonedDateTime.now());2assertThat(ZonedDateTime.now()).hasSameMonthAs(ZonedDateTime.now());3assertThat(ZonedDateTime.now()).hasSameDayOfMonthAs(ZonedDateTime.now());4assertThat(ZonedDateTime.now()).hasSameHourAs(ZonedDateTime.now());5assertThat(ZonedDateTime.now()).hasSameMinuteAs(ZonedDateTime.now());6assertThat(ZonedDateTime.now()).hasSameSecondAs(ZonedDateTime.now());7assertThat(ZonedDateTime.now()).hasSameMillisecondAs(ZonedDateTime.now());8assertThat(ZonedDateTime.now()).hasSameNanoOfSecondAs(ZonedDateTime.now());9assertThat(ZonedDateTime.now()).hasSameNanoOfDayAs(ZonedDateTime.now());10assertThat(ZonedDateTime.now()).hasSameNanoOfSecondAs(ZonedDateTime.now());

Full Screen

Full Screen

haveSameYear

Using AI Code Generation

copy

Full Screen

1assertThat(LOCAL_DATE_TIME).hasSameYearAs(LOCAL_DATE_TIME);2assertThat(LOCAL_DATE_TIME).hasSameMonthOfYearAs(LOCAL_DATE_TIME);3assertThat(LOCAL_DATE_TIME).hasSameDayOfYearAs(LOCAL_DATE_TIME);4assertThat(LOCAL_DATE_TIME).hasSameDayOfMonthAs(LOCAL_DATE_TIME);5assertThat(LOCAL_DATE_TIME).hasSameHourOfDayAs(LOCAL_DATE_TIME);6assertThat(LOCAL_DATE_TIME).hasSameMinuteOfHourAs(LOCAL_DATE_TIME);7assertThat(LOCAL_DATE_TIME).hasSameSecondOfMinuteAs(LOCAL_DATE_TIME);8assertThat(LOCAL_DATE_TIME).hasSameNanoOfSecondAs(LOCAL_DATE_TIME);9public static void main(String[] args) {10 assertThat(ZonedDateTime.now()).hasSameYearAs(ZonedDateTime.now());11 assertThat(ZonedDateTime.now()).hasSameMonthOfYearAs(ZonedDateTime.now());12 assertThat(ZonedDateTime.now()).hasSameDayOfYearAs(ZonedDateTime.now());13 assertThat(ZonedDateTime.now()).hasSameDayOfMonthAs(ZonedDateTime.now());14 assertThat(ZonedDateTime.now()).hasSameHourOfDayAs(ZonedDateTime.now());15 assertThat(ZonedDateTime.now()).hasSame

Full Screen

Full Screen

haveSameYear

Using AI Code Generation

copy

Full Screen

1ZonedDateTime zonedDateTime = ZonedDateTime.now();2ZonedDateTime sameYear = ZonedDateTime.now();3ZonedDateTime differentYear = ZonedDateTime.now().plusYears(1);4assertThat(zonedDateTime).hasSameYearAs(sameYear);5assertThat(zonedDateTime).hasSameYearAs(differentYear);6LocalDate localDate = LocalDate.now();7LocalDate sameYear = LocalDate.now();8LocalDate differentYear = LocalDate.now().plusYears(1);9assertThat(localDate).hasSameYearAs(sameYear);10assertThat(localDate).hasSameYearAs(differentYear);11LocalDateTime localDateTime = LocalDateTime.now();12LocalDateTime sameYear = LocalDateTime.now();13LocalDateTime differentYear = LocalDateTime.now().plusYears(1);14assertThat(localDateTime).hasSameYearAs(sameYear);15assertThat(localDateTime).hasSameYearAs(differentYear);16OffsetDateTime offsetDateTime = OffsetDateTime.now();17OffsetDateTime sameYear = OffsetDateTime.now();18OffsetDateTime differentYear = OffsetDateTime.now().plusYears(1);19assertThat(offsetDateTime).hasSameYearAs(sameYear);20assertThat(offsetDateTime).hasSameYearAs(differentYear);21OffsetTime offsetTime = OffsetTime.now();22OffsetTime sameYear = OffsetTime.now();23OffsetTime differentYear = OffsetTime.now().plusYears(1);24assertThat(offsetTime).hasSameYearAs(sameYear);25assertThat(offsetTime).hasSameYearAs(differentYear);26Year year = Year.now();27Year sameYear = Year.now();28Year differentYear = Year.now().plusYears(1);29assertThat(year).hasSameYearAs(sameYear);30assertThat(year).hasSameYearAs(differentYear);31YearMonth yearMonth = YearMonth.now();32YearMonth sameYear = YearMonth.now();33YearMonth differentYear = YearMonth.now().plusYears(1);34assertThat(yearMonth).hasSameYearAs(sameYear);35assertThat(yearMonth).hasSame

Full Screen

Full Screen

haveSameYear

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.assertThat;2import java.time.ZonedDateTime;3public class ZonedDateTimeAssert_hasSameYear_Test {4 public void test() {5 ZonedDateTime actual = ZonedDateTime.now();6 ZonedDateTime expected = ZonedDateTime.now();7 assertThat(actual).hasSameYear(expected);8 }9}10import static org.assertj.core.api.Assertions.assertThat;11import java.time.ZonedDateTime;12public class ZonedDateTimeAssert_hasSameYear_Test {13 public void test() {14 ZonedDateTime actual = ZonedDateTime.now();15 ZonedDateTime expected = ZonedDateTime.now();16 assertThat(actual).hasSameYear(expected);17 }18}

Full Screen

Full Screen

haveSameYear

Using AI Code Generation

copy

Full Screen

1ZonedDateTime date = ZonedDateTime.of(2010, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault());2assertThat(date).hasSameYear(2010);3ZonedDateTime date = ZonedDateTime.of(2010, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault());4assertThat(date).hasSameYear(2010);5ZonedDateTime date = ZonedDateTime.of(2010, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault());6assertThat(date).hasSameYear(2010);7ZonedDateTime date = ZonedDateTime.of(2010, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault());8assertThat(date).hasSameYear(2010);9ZonedDateTime date = ZonedDateTime.of(2010, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault());10assertThat(date).hasSameYear(2010);11ZonedDateTime date = ZonedDateTime.of(2010, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault());12assertThat(date).hasSameYear(2010);13ZonedDateTime date = ZonedDateTime.of(2010, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault());14assertThat(date).hasSameYear(2010);15ZonedDateTime date = ZonedDateTime.of(2010, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault());16assertThat(date).hasSameYear(2010);

Full Screen

Full Screen

haveSameYear

Using AI Code Generation

copy

Full Screen

1assertThat( ZonedDateTime.parse("2007-12-03T10:15:30+01:00") ).hasSameYearAs( ZonedDateTime.parse("2007-10-03T10:15:30+01:00") );2assertThat( ZonedDateTime.parse("2007-12-03T10:15:30+01:00") ).hasSameYearAs( ZonedDateTime.parse("2007-10-03T10:15:30+01:00") );3assertThat( ZonedDateTime.parse("2007-12-03T10:15:30+01:00") ).hasSameYearAs( ZonedDateTime.parse("2007-10-03T10:15:30+01:00") );4assertThat( ZonedDateTime.parse("2007-12-03T10:15:30+01:00") ).hasSameYearAs( ZonedDateTime.parse("2007-10-03T10:15:30+01:00") );5assertThat( ZonedDateTime.parse("2007-12-03T10:15:30+01:00") ).hasSameYearAs( ZonedDateTime.parse("2007-10-03T10:15:30+01:00") );6assertThat( ZonedDateTime.parse("2007-12-03T10:15:30+01:00") ).hasSameYearAs( ZonedDateTime.parse("2007-10-03T10:15:30+01:00") );7assertThat( ZonedDateTime.parse("2007-12-03T10:15:30+01:00") ).hasSameYearAs( ZonedDateTime.parse("2007-10-03T10:15:30+01:00") );8assertThat( ZonedDateTime.parse("2007-12-03T10:15:30+01:00") ).hasSameYearAs( ZonedDateTime.parse("2007-10-03T10:15:30+01:00") );9assertThat( ZonedDateTime.parse("2007-12-03T10:15:30+01:00") ).hasSameYearAs( ZonedDateTime.parse("2007-10-03T10:15:30+01:00") );10assertThat( ZonedDateTime.parse("2007-12-03T10:15:30+01:00") ).hasSameYearAs(

Full Screen

Full Screen

haveSameYear

Using AI Code Generation

copy

Full Screen

1ZonedDateTime zdt1 = ZonedDateTime.parse("2017-01-01T12:00:00+01:00[Europe/Paris]");2ZonedDateTime zdt2 = ZonedDateTime.parse("2017-01-01T12:00:00+01:00[Europe/Paris]");3AbstractZonedDateTimeAssert<?> assertion = assertThat(zdt1);4assertion.hasSameYearAs(zdt2);5assertion.hasSameYearAs("2017-01-01T12:00:00+01:00[Europe/Paris]");6assertion.hasSameYearAs("2017-01-01T12:00:00+01:00[Europe/Paris]", DateTimeFormatter.ISO_ZONED_DATE_TIME);7assertion.hasSameYearAs(zdt2);8assertion.hasSameYearAs(zdt2, ChronoUnit.DAYS);9assertion.hasSameYearAs("2017-01-01T12:00:00+01:00[Europe/Paris]", DateTimeFormatter.ISO_ZONED_DATE_TIME, ChronoUnit.DAYS);10assertion.hasSameYearAs("2017-01-01T12:00:00+01:00[Europe/Paris]", DateTimeFormatter.ISO_ZONED_DATE_TIME, ChronoUnit.DAYS);11assertion.hasSameYearAs("2017-01-01T12:00:00+01:00[Europe/Paris]", DateTimeFormatter.ISO_ZONED_DATE_TIME, ChronoUnit.DAYS);

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