How to use toDateArray method of org.assertj.core.api.AbstractDateAssert class

Best Assertj code snippet using org.assertj.core.api.AbstractDateAssert.toDateArray

Source:AbstractDateAssert.java Github

copy

Full Screen

...616 * @throws AssertionError if actual is not in given Dates represented as String.617 * @throws AssertionError if one of the given date as String could not be converted to a Date.618 */619 public SELF isIn(String... datesAsString) {620 Date[] dates = toDateArray(datesAsString, this::parse);621 return isIn((Object[]) dates);622 }623 /**624 * Same assertion as {@link Assert#isIn(Object...) }but given dates are represented as an {@code java.time.Instant}.625 * <p>626 * Example:627 * <pre><code class='java'> // assertion will fail628 * // theTwoTowers release date : 2002-12-18629 * Instant now = Instant.now()630 * assertThat(theTwoTowers.getReleaseDate()).isIn(now, now.plusSeconds(5), now.minusSeconds(5));</code></pre>631 *632 * @param instants the given dates represented as {@code Instant}.633 * @return this assertion object.634 * @throws AssertionError if actual is not in given dates represented as {@code Instant}.635 */636 public SELF isIn(Instant... instants) {637 Date[] dates = toDateArray(instants, Date::from);638 return isIn((Object[]) dates);639 }640 /**641 * Same assertion as {@link Assert#isIn(Iterable)} but given dates are represented as String either with one of the642 * supported defaults date format or a user custom date format (set with method {@link #withDateFormat(DateFormat)}).643 * <p>644 * User custom date format take precedence over the default ones.645 * <p>646 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.647 * <p>648 * Example:649 * <pre><code class='java'> // assertion will pass650 * // theTwoTowers release date : 2002-12-18651 * assertThat(theTwoTowers.getReleaseDate()).isInWithStringDateCollection(asList("2002-12-17", "2002-12-18", "2002-12-19"));652 *653 * // assertion will fail654 * assertThat(theTwoTowers.getReleaseDate()).isInWithStringDateCollection(asList("2002-12-17", "2002-12-19", "2002-12-20"))</code></pre>655 * <p>656 * Defaults date format (expressed in the local time zone unless specified otherwise) are:657 * <ul>658 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>659 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>660 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>661 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>662 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>663 * <li><code>yyyy-MM-dd</code></li>664 * </ul>665 * <p>666 * Example of valid string date representations:667 * <ul>668 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>669 * <li><code>2003-04-26T03:01:02.999</code></li>670 * <li><code>2003-04-26 03:01:02.999</code></li>671 * <li><code>2003-04-26T03:01:02+00:00</code></li>672 * <li><code>2003-04-26T13:01:02</code></li>673 * <li><code>2003-04-26</code></li>674 * </ul>675 * <p>676 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),677 * you can explicitly specify the date format to use so that the default ones are bypassed.678 * <p>679 * Method signature could not be <code>isIn(Collection&lt;String&gt;)</code> because it would be same signature as680 * <code>isIn(Collection&lt;Date&gt;)</code> since java collection type are erased at runtime.681 *682 * @param datesAsString the given Dates represented as String in default or custom date format.683 * @return this assertion object.684 * @throws AssertionError if actual is not in given Dates represented as String.685 * @throws AssertionError if one of the given date as String could not be converted to a Date.686 */687 public SELF isInWithStringDateCollection(Collection<String> datesAsString) {688 return isIn(datesAsString.stream().map(this::parse).collect(toList()));689 }690 /**691 * Same assertion as {@link Assert#isNotIn(Object...)} but given dates are represented as String either with one of the692 * supported defaults date format or a user custom date format (set with method {@link #withDateFormat(DateFormat)}).693 * <p>694 * User custom date format take precedence over the default ones.695 * <p>696 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.697 * <p>698 * Example:699 * <pre><code class='java'> // assertion will pass700 * // theTwoTowers release date : 2002-12-18701 * assertThat(theTwoTowers.getReleaseDate()).isNotIn("2002-12-17", "2002-12-19");702 *703 * // assertion will fail704 * assertThat(theTwoTowers.getReleaseDate()).isNotIn("2002-12-17", "2002-12-18")</code></pre>705 * <p>706 * Defaults date format (expressed in the local time zone unless specified otherwise) are:707 * <ul>708 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>709 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>710 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>711 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>712 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>713 * <li><code>yyyy-MM-dd</code></li>714 * </ul>715 * <p>716 * Example of valid string date representations:717 * <ul>718 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>719 * <li><code>2003-04-26T03:01:02.999</code></li>720 * <li><code>2003-04-26 03:01:02.999</code></li>721 * <li><code>2003-04-26T03:01:02+00:00</code></li>722 * <li><code>2003-04-26T13:01:02</code></li>723 * <li><code>2003-04-26</code></li>724 * </ul>725 * <p>726 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),727 * you can explicitly specify the date format to use so that the default ones are bypassed.728 *729 * @param datesAsString the given Dates represented as String in default or custom date format.730 * @return this assertion object.731 * @throws AssertionError if actual is in given Dates represented as String.732 * @throws AssertionError if one of the given date as String could not be converted to a Date.733 */734 public SELF isNotIn(String... datesAsString) {735 Date[] dates = toDateArray(datesAsString, this::parse);736 return isNotIn((Object[]) dates);737 }738 /**739 * Same assertion as {@link Assert#isNotIn(Object...)} but given dates are represented as {@code java.time.Instant}.740 * <p>741 * Example:742 * <pre><code class='java'> // assertion will pass743 * // theTwoTowers release date : 2002-12-18744 * Instant now = Instant.now()745 * assertThat(theTwoTowers.getReleaseDate()).isIn(now, now.plusSeconds(5), now.minusSeconds(5));</code></pre>746 *747 * @param instants the given dates represented as {@code Instant}.748 * @return this assertion object.749 * @throws AssertionError if actual is not in given dates represented as {@code Instant}.750 * @since 3.19.0751 */752 public SELF isNotIn(Instant... instants) {753 Date[] dates = toDateArray(instants, Date::from);754 return isNotIn((Object[]) dates);755 }756 /**757 * Same assertion as {@link Assert#isNotIn(Iterable)} but given date is represented as String either with one of the758 * supported defaults date format or a user custom date format (set with method {@link #withDateFormat(DateFormat)}).759 * <p>760 * User custom date format take precedence over the default ones.761 * <p>762 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.763 * <p>764 * Example:765 * <pre><code class='java'> // assertion will pass766 * // theTwoTowers release date : 2002-12-18767 * assertThat(theTwoTowers.getReleaseDate()).isNotInWithStringDateCollection(Arrays.asList("2002-12-17", "2002-12-19"));768 *769 * // assertion will fail770 * assertThat(theTwoTowers.getReleaseDate()).isNotInWithStringDateCollection(Arrays.asList("2002-12-17", "2002-12-18"))</code></pre>771 * <p>772 * Defaults date format (expressed in the local time zone unless specified otherwise) are:773 * <ul>774 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>775 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>776 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>777 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>778 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>779 * <li><code>yyyy-MM-dd</code></li>780 * </ul>781 * <p>782 * Example of valid string date representations:783 * <ul>784 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>785 * <li><code>2003-04-26T03:01:02.999</code></li>786 * <li><code>2003-04-26 03:01:02.999</code></li>787 * <li><code>2003-04-26T03:01:02+00:00</code></li>788 * <li><code>2003-04-26T13:01:02</code></li>789 * <li><code>2003-04-26</code></li>790 * </ul>791 * <p>792 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),793 * you can explicitly specify the date format to use so that the default ones are bypassed.794 * Method signature could not be <code>isNotIn(Collection&lt;String&gt;)</code> because it would be same signature as795 * <code>isNotIn(Collection&lt;Date&gt;)</code> since java collection type are erased at runtime.796 *797 * @param datesAsString the given Dates represented as String in default or custom date format.798 * @return this assertion object.799 * @throws AssertionError if actual is in given Dates represented as String.800 * @throws AssertionError if one of the given date as String could not be converted to a Date.801 */802 public SELF isNotInWithStringDateCollection(Collection<String> datesAsString) {803 return isNotIn(datesAsString.stream().map(this::parse).collect(toList()));804 }805 /**806 * Verifies that the actual {@code Date} is <b>strictly</b> before the given one.807 * <p>808 * Example:809 * <pre><code class='java'> // assertion will pass810 * // theTwoTowers release date : 2002-12-18811 * assertThat(theTwoTowers.getReleaseDate()).isBefore(theReturnOfTheKing.getReleaseDate());812 *813 * // assertion will fail814 * assertThat(theTwoTowers.getReleaseDate()).isBefore(theFellowshipOfTheRing.getReleaseDate());</code></pre>815 *816 * @param other the given Date.817 * @return this assertion object.818 * @throws AssertionError if the actual {@code Date} is {@code null}.819 * @throws NullPointerException if other {@code Date} is {@code null}.820 * @throws AssertionError if the actual {@code Date} is not strictly before the given one.821 */822 public SELF isBefore(Date other) {823 dates.assertIsBefore(info, actual, other);824 return myself;825 }826 /**827 * Verifies that the actual {@code Date} is <b>strictly</b> before the given {@link Instant}.828 * <p>829 * Example:830 * <pre><code class='java'> // assertion succeeds831 * // theTwoTowers release date : 2002-12-18832 * assertThat(theTwoTowers.getReleaseDate()).isBefore(Instant.parse("2002-12-19T00:00:00.00Z"));833 *834 * // assertions fail835 * assertThat(theTwoTowers.getReleaseDate()).isBefore(Instant.parse("2002-12-17T00:00:00.00Z"));836 * assertThat(theTwoTowers.getReleaseDate()).isBefore(Instant.parse("2002-12-18T00:00:00.00Z"));</code></pre>837 *838 * @param other the given {@code Instant}.839 * @return this assertion object.840 * @throws AssertionError if the actual {@code Date} is {@code null}.841 * @throws NullPointerException if other {@code Instant} is {@code null}.842 * @throws AssertionError if the actual {@code Date} is not strictly before the given {@code Instant}.843 * @since 3.19.0844 */845 public SELF isBefore(Instant other) {846 dates.assertIsBefore(info, actual, Date.from(other));847 return myself;848 }849 /**850 * Same assertion as {@link #isBefore(Date)} but given date is represented as String either with one of the851 * supported defaults date format or a user custom date format (set with method {@link #withDateFormat(DateFormat)}).852 * <p>853 * User custom date format take precedence over the default ones.854 * <p>855 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.856 * <p>857 * Example:858 * <pre><code class='java'> // assertion will pass859 * // theTwoTowers release date : 2002-12-18860 * assertThat(theTwoTowers.getReleaseDate()).isBefore("2002-12-19");861 *862 * // assertion will fail863 * assertThat(theTwoTowers.getReleaseDate()).isBefore("2002-12-17");864 * assertThat(theTwoTowers.getReleaseDate()).isBefore("2002-12-18")</code></pre>865 * <p>866 * Defaults date format (expressed in the local time zone unless specified otherwise) are:867 * <ul>868 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>869 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>870 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>871 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>872 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>873 * <li><code>yyyy-MM-dd</code></li>874 * </ul>875 * <p>876 * Example of valid string date representations:877 * <ul>878 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>879 * <li><code>2003-04-26T03:01:02.999</code></li>880 * <li><code>2003-04-26 03:01:02.999</code></li>881 * <li><code>2003-04-26T03:01:02+00:00</code></li>882 * <li><code>2003-04-26T13:01:02</code></li>883 * <li><code>2003-04-26</code></li>884 * </ul>885 * <p>886 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),887 * you can explicitly specify the date format to use so that the default ones are bypassed.888 *889 * @param dateAsString the given Date represented as String in default or custom date format.890 * @return this assertion object.891 * @throws AssertionError if the actual {@code Date} is {@code null}.892 * @throws NullPointerException if given date as String is {@code null}.893 * @throws AssertionError if the actual {@code Date} is not strictly before the given Date represented as894 * String.895 * @throws AssertionError if the given date as String could not be converted to a Date.896 */897 public SELF isBefore(String dateAsString) {898 return isBefore(parse(dateAsString));899 }900 /**901 * Verifies that the actual {@code Date} is before or equals to the given one.902 * <p>903 * Example:904 * <pre><code class='java'> SimpleDateFormat dateFormat = new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);905 *906 * // assertions will pass907 * assertThat(dateFormat.parse(&quot;1990-12-01&quot;)).isBeforeOrEqualsTo(dateFormat.parse(&quot;2000-12-01&quot;));908 * assertThat(dateFormat.parse(&quot;2000-12-01&quot;)).isBeforeOrEqualsTo(dateFormat.parse(&quot;2000-12-01&quot;));909 *910 * // assertion will fail911 * assertThat(dateFormat.parse(&quot;2000-12-01&quot;)).isBeforeOrEqualsTo(dateFormat.parse(&quot;1990-12-01&quot;));</code></pre>912 *913 * @param other the given Date.914 * @return this assertion object.915 * @throws AssertionError if the actual {@code Date} is {@code null}.916 * @throws NullPointerException if other {@code Date} is {@code null}.917 * @throws AssertionError if the actual {@code Date} is not before or equals to the given one.918 * @deprecated prefer calling {@link #isBeforeOrEqualTo(Date)}919 */920 @Deprecated921 public SELF isBeforeOrEqualsTo(Date other) {922 return isBeforeOrEqualTo(other);923 }924 /**925 * Verifies that the actual {@code Date} is before or equal to the given one.926 * <p>927 * Example:928 * <pre><code class='java'> SimpleDateFormat dateFormat = new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);929 *930 * // assertions will pass931 * assertThat(dateFormat.parse(&quot;1990-12-01&quot;)).isBeforeOrEqualTo(dateFormat.parse(&quot;2000-12-01&quot;));932 * assertThat(dateFormat.parse(&quot;2000-12-01&quot;)).isBeforeOrEqualTo(dateFormat.parse(&quot;2000-12-01&quot;));933 *934 * // assertion will fail935 * assertThat(dateFormat.parse(&quot;2000-12-01&quot;)).isBeforeOrEqualTo(dateFormat.parse(&quot;1990-12-01&quot;));</code></pre>936 *937 * @param other the given Date.938 * @return this assertion object.939 * @throws AssertionError if the actual {@code Date} is {@code null}.940 * @throws NullPointerException if other {@code Date} is {@code null}.941 * @throws AssertionError if the actual {@code Date} is not before or equals to the given one.942 */943 public SELF isBeforeOrEqualTo(Date other) {944 dates.assertIsBeforeOrEqualTo(info, actual, other);945 return myself;946 }947 /**948 * Verifies that the actual {@code Date} is before or equal to the given {@link Instant}.949 * <p>950 * Example:951 * <pre><code class='java'> // assertions succeed952 * // theTwoTowers release date : 2002-12-18953 * assertThat(theTwoTowers.getReleaseDate()).isBeforeOrEqualTo(Instant.parse("2002-12-19T00:00:00.00Z"));954 * assertThat(theTwoTowers.getReleaseDate()).isBeforeOrEqualTo(Instant.parse("2002-12-18T00:00:00.00Z"));955 *956 * // assertion fails957 * assertThat(theTwoTowers.getReleaseDate()).isBeforeOrEqualTo(Instant.parse("2002-12-17T00:00:00.00Z"));</code></pre>958 *959 * @param other the given {@code Instant}.960 * @return this assertion object.961 * @throws AssertionError if the actual {@code Date} is {@code null}.962 * @throws NullPointerException if other {@code Instant} is {@code null}.963 * @throws AssertionError if the actual {@code Date} is not before or equal to the given {@code Instant}.964 * @since 3.19.0965 */966 public SELF isBeforeOrEqualTo(Instant other) {967 dates.assertIsBeforeOrEqualTo(info, actual, Date.from(other));968 return myself;969 }970 /**971 * Same assertion as {@link #isBeforeOrEqualsTo(Date)} but given date is represented as String either with one of the972 * supported defaults date format or a user custom date format (set with method {@link #withDateFormat(DateFormat)}).973 * <p>974 * User custom date format take precedence over the default ones.975 * <p>976 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.977 * <p>978 * Example:979 * <pre><code class='java'> // assertion will pass980 * // theTwoTowers release date : 2002-12-18981 * assertThat(theTwoTowers.getReleaseDate()).isBeforeOrEqualsTo("2002-12-19");982 * assertThat(theTwoTowers.getReleaseDate()).isBeforeOrEqualsTo("2002-12-18");983 *984 * // assertion will fail985 * assertThat(theTwoTowers.getReleaseDate()).isBeforeOrEqualsTo("2002-12-17")</code></pre>986 * <p>987 * Defaults date format (expressed in the local time zone unless specified otherwise) are:988 * <ul>989 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>990 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>991 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>992 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>993 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>994 * <li><code>yyyy-MM-dd</code></li>995 * </ul>996 * <p>997 * Example of valid string date representations:998 * <ul>999 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>1000 * <li><code>2003-04-26T03:01:02.999</code></li>1001 * <li><code>2003-04-26 03:01:02.999</code></li>1002 * <li><code>2003-04-26T03:01:02+00:00</code></li>1003 * <li><code>2003-04-26T13:01:02</code></li>1004 * <li><code>2003-04-26</code></li>1005 * </ul>1006 * <p>1007 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),1008 * you can explicitly specify the date format to use so that the default ones are bypassed.1009 *1010 * @param dateAsString the given Date represented as String in default or custom date format.1011 * @return this assertion object.1012 * @throws AssertionError if the actual {@code Date} is {@code null}.1013 * @throws NullPointerException if given date as String is {@code null}.1014 * @throws AssertionError if the actual {@code Date} is not before or equals to the given Date represented as1015 * String.1016 * @throws AssertionError if the given date as String could not be converted to a Date.1017 * @deprecated prefer calling {@link #isBeforeOrEqualTo(String)}1018 */1019 @Deprecated1020 public SELF isBeforeOrEqualsTo(String dateAsString) {1021 return isBeforeOrEqualTo(dateAsString);1022 }1023 /**1024 * Same assertion as {@link #isBeforeOrEqualTo(Date)} but given date is represented as String either with one of the1025 * supported defaults date format or a user custom date format (set with method {@link #withDateFormat(DateFormat)}).1026 * <p>1027 * User custom date format take precedence over the default ones.1028 * <p>1029 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.1030 * <p>1031 * Example:1032 * <pre><code class='java'> // assertion will pass1033 * // theTwoTowers release date : 2002-12-181034 * assertThat(theTwoTowers.getReleaseDate()).isBeforeOrEqualTo("2002-12-19");1035 * assertThat(theTwoTowers.getReleaseDate()).isBeforeOrEqualTo("2002-12-18");1036 *1037 * // assertion will fail1038 * assertThat(theTwoTowers.getReleaseDate()).isBeforeOrEqualTo("2002-12-17")</code></pre>1039 * <p>1040 * Defaults date format (expressed in the local time zone unless specified otherwise) are:1041 * <ul>1042 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>1043 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>1044 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>1045 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>1046 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>1047 * <li><code>yyyy-MM-dd</code></li>1048 * </ul>1049 * <p>1050 * Example of valid string date representations:1051 * <ul>1052 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>1053 * <li><code>2003-04-26T03:01:02.999</code></li>1054 * <li><code>2003-04-26 03:01:02.999</code></li>1055 * <li><code>2003-04-26T03:01:02+00:00</code></li>1056 * <li><code>2003-04-26T13:01:02</code></li>1057 * <li><code>2003-04-26</code></li>1058 * </ul>1059 * <p>1060 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),1061 * you can explicitly specify the date format to use so that the default ones are bypassed.1062 *1063 * @param dateAsString the given Date represented as String in default or custom date format.1064 * @return this assertion object.1065 * @throws AssertionError if the actual {@code Date} is {@code null}.1066 * @throws NullPointerException if given date as String is {@code null}.1067 * @throws AssertionError if the actual {@code Date} is not before or equals to the given Date represented as1068 * String.1069 * @throws AssertionError if the given date as String could not be converted to a Date.1070 */1071 public SELF isBeforeOrEqualTo(String dateAsString) {1072 return isBeforeOrEqualTo(parse(dateAsString));1073 }1074 /**1075 * Verifies that the actual {@code Date} is <b>strictly</b> after the given one.1076 * <p>1077 * Example:1078 * <pre><code class='java'> // assertion will pass1079 * // theTwoTowers release date : 2002-12-181080 * assertThat(theTwoTowers.getReleaseDate()).isAfter(theFellowshipOfTheRing.getReleaseDate());1081 *1082 * // assertion will fail1083 * assertThat(theTwoTowers.getReleaseDate()).isAfter(theReturnOfTheKing.getReleaseDate());</code></pre>1084 *1085 * @param other the given Date.1086 * @return this assertion object.1087 * @throws AssertionError if the actual {@code Date} is {@code null}.1088 * @throws NullPointerException if other {@code Date} is {@code null}.1089 * @throws AssertionError if the actual {@code Date} is not strictly after the given one.1090 */1091 public SELF isAfter(Date other) {1092 dates.assertIsAfter(info, actual, other);1093 return myself;1094 }1095 /**1096 * Verifies that the actual {@code Date} is <b>strictly</b> after the given {@link Instant}.1097 * <p>1098 * Example:1099 * <pre><code class='java'> // assertion succeeds1100 * // theTwoTowers release date : 2002-12-181101 * assertThat(theTwoTowers.getReleaseDate()).isAfter(Instant.parse("2002-12-17T00:00:00.00Z"));1102 *1103 * // assertions fail1104 * assertThat(theTwoTowers.getReleaseDate()).isAfter(Instant.parse("2002-12-18T00:00:00.00Z"));1105 * assertThat(theTwoTowers.getReleaseDate()).isAfter(Instant.parse("2002-12-19T00:00:00.00Z"));</code></pre>1106 *1107 * @param other the given {@code Instant}.1108 * @return this assertion object.1109 * @throws AssertionError if the actual {@code Date} is {@code null}.1110 * @throws NullPointerException if other {@code Instant} is {@code null}.1111 * @throws AssertionError if the actual {@code Date} is not strictly after the given {@code Instant}.1112 * @since 3.19.01113 */1114 public SELF isAfter(Instant other) {1115 dates.assertIsAfter(info, actual, Date.from(other));1116 return myself;1117 }1118 /**1119 * Same assertion as {@link #isAfter(Date)} but given date is represented as String either with one of the1120 * supported defaults date format or a user custom date format (set with method {@link #withDateFormat(DateFormat)}).1121 * <p>1122 * User custom date format take precedence over the default ones.1123 * <p>1124 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.1125 * <p>1126 * Example:1127 * <pre><code class='java'> // assertion will pass1128 * // theTwoTowers release date : 2002-12-181129 * assertThat(theTwoTowers.getReleaseDate()).isAfter("2002-12-17");1130 *1131 * // assertion will fail1132 * assertThat(theTwoTowers.getReleaseDate()).isAfter("2002-12-18");1133 * assertThat(theTwoTowers.getReleaseDate()).isAfter("2002-12-19")</code></pre>1134 * <p>1135 * Defaults date format (expressed in the local time zone unless specified otherwise) are:1136 * <ul>1137 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>1138 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>1139 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>1140 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>1141 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>1142 * <li><code>yyyy-MM-dd</code></li>1143 * </ul>1144 * <p>1145 * Example of valid string date representations:1146 * <ul>1147 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>1148 * <li><code>2003-04-26T03:01:02.999</code></li>1149 * <li><code>2003-04-26 03:01:02.999</code></li>1150 * <li><code>2003-04-26T03:01:02+00:00</code></li>1151 * <li><code>2003-04-26T13:01:02</code></li>1152 * <li><code>2003-04-26</code></li>1153 * </ul>1154 * <p>1155 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),1156 * you can explicitly specify the date format to use so that the default ones are bypassed.1157 *1158 * @param dateAsString the given Date represented as String in default or custom date format.1159 * @return this assertion object.1160 * @throws AssertionError if the actual {@code Date} is {@code null}.1161 * @throws NullPointerException if given date as String is {@code null}.1162 * @throws AssertionError if the actual {@code Date} is not strictly after the given Date represented as1163 * String.1164 * @throws AssertionError if the given date as String could not be converted to a Date.1165 */1166 public SELF isAfter(String dateAsString) {1167 return isAfter(parse(dateAsString));1168 }1169 /**1170 * Verifies that the actual {@code Date} is after or equals to the given one.1171 * <p>1172 * Example:1173 * <pre><code class='java'> SimpleDateFormat dateFormat = new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);1174 *1175 * // assertions will pass1176 * assertThat(dateFormat.parse(&quot;2000-12-01&quot;)).isAfterOrEqualsTo(dateFormat.parse(&quot;1990-12-01&quot;));1177 * assertThat(dateFormat.parse(&quot;2000-12-01&quot;)).isAfterOrEqualsTo(dateFormat.parse(&quot;2000-12-01&quot;));1178 *1179 * // assertion will fail1180 * assertThat(dateFormat.parse(&quot;1990-12-01&quot;)).isAfterOrEqualsTo(dateFormat.parse(&quot;2000-12-01&quot;));</code></pre>1181 *1182 * @param other the given Date.1183 * @return this assertion object.1184 * @throws AssertionError if the actual {@code Date} is {@code null}.1185 * @throws NullPointerException if other {@code Date} is {@code null}.1186 * @throws AssertionError if the actual {@code Date} is not after or equals to the given one.1187 * @deprecated prefer calling {@link #isAfterOrEqualTo(Date)}1188 */1189 @Deprecated1190 public SELF isAfterOrEqualsTo(Date other) {1191 return isAfterOrEqualTo(other);1192 }1193 /**1194 * Verifies that the actual {@code Date} is after or equal to the given one.1195 * <p>1196 * Example:1197 * <pre><code class='java'> SimpleDateFormat dateFormat = new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);1198 *1199 * // assertions will pass1200 * assertThat(dateFormat.parse(&quot;2000-12-01&quot;)).isAfterOrEqualTo(dateFormat.parse(&quot;1990-12-01&quot;));1201 * assertThat(dateFormat.parse(&quot;2000-12-01&quot;)).isAfterOrEqualTo(dateFormat.parse(&quot;2000-12-01&quot;));1202 *1203 * // assertion will fail1204 * assertThat(dateFormat.parse(&quot;1990-12-01&quot;)).isAfterOrEqualTo(dateFormat.parse(&quot;2000-12-01&quot;));</code></pre>1205 *1206 * @param other the given Date.1207 * @return this assertion object.1208 * @throws AssertionError if the actual {@code Date} is {@code null}.1209 * @throws NullPointerException if other {@code Date} is {@code null}.1210 * @throws AssertionError if the actual {@code Date} is not after or equals to the given one.1211 */1212 public SELF isAfterOrEqualTo(Date other) {1213 dates.assertIsAfterOrEqualTo(info, actual, other);1214 return myself;1215 }1216 /**1217 * Verifies that the actual {@code Date} is after or equal to the given {@link Instant}.1218 * <p>1219 * Example:1220 * <pre><code class='java'> // assertions succeed1221 * // theTwoTowers release date : 2002-12-181222 * assertThat(theTwoTowers.getReleaseDate()).assertIsAfterOrEqualTo(Instant.parse("2002-12-17T00:00:00.00Z"))1223 * .assertIsAfterOrEqualTo(Instant.parse("2002-12-18T00:00:00.00Z"));1224 * // assertion fails1225 * assertThat(theTwoTowers.getReleaseDate()).assertIsAfterOrEqualTo(Instant.parse("2002-12-19T00:00:00.00Z"));</code></pre>1226 *1227 * @param other the given {@code Instant}.1228 * @return this assertion object.1229 * @throws AssertionError if the actual {@code Date} is {@code null}.1230 * @throws NullPointerException if other {@code Instant} is {@code null}.1231 * @throws AssertionError if the actual {@code Date} is not after or equal to the given {@code Instant}.1232 * @since 3.19.01233 */1234 public SELF isAfterOrEqualTo(Instant other) {1235 dates.assertIsAfterOrEqualTo(info, actual, Date.from(other));1236 return myself;1237 }1238 /**1239 * Same assertion as {@link #isAfterOrEqualsTo(Date)} but given date is represented as String either with one of the1240 * supported defaults date format or a user custom date format (set with method {@link #withDateFormat(DateFormat)}).1241 * <p>1242 * User custom date format take precedence over the default ones.1243 * <p>1244 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.1245 * <p>1246 * Example:1247 * <pre><code class='java'> // assertion will pass1248 * // theTwoTowers release date : 2002-12-181249 * assertThat(theTwoTowers.getReleaseDate()).isAfterOrEqualsTo("2002-12-17");1250 * assertThat(theTwoTowers.getReleaseDate()).isAfterOrEqualsTo("2002-12-18");1251 *1252 * // assertion will fail1253 * assertThat(theTwoTowers.getReleaseDate()).isAfterOrEqualsTo("2002-12-19")</code></pre>1254 * <p>1255 * Defaults date format (expressed in the local time zone unless specified otherwise) are:1256 * <ul>1257 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>1258 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>1259 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>1260 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>1261 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>1262 * <li><code>yyyy-MM-dd</code></li>1263 * </ul>1264 * <p>1265 * Example of valid string date representations:1266 * <ul>1267 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>1268 * <li><code>2003-04-26T03:01:02.999</code></li>1269 * <li><code>2003-04-26 03:01:02.999</code></li>1270 * <li><code>2003-04-26T03:01:02+00:00</code></li>1271 * <li><code>2003-04-26T13:01:02</code></li>1272 * <li><code>2003-04-26</code></li>1273 * </ul>1274 * <p>1275 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),1276 * you can explicitly specify the date format to use so that the default ones are bypassed.1277 *1278 * @param dateAsString the given Date represented as String in default or custom date format.1279 * @return this assertion object.1280 * @throws AssertionError if the actual {@code Date} is {@code null}.1281 * @throws NullPointerException if given date as String is {@code null}.1282 * @throws AssertionError if the actual {@code Date} is not after or equals to the given Date represented as1283 * String.1284 * @throws AssertionError if the given date as String could not be converted to a Date.1285 * @deprecated prefer calling {@link #isAfterOrEqualTo(String)}1286 */1287 @Deprecated1288 public SELF isAfterOrEqualsTo(String dateAsString) {1289 return isAfterOrEqualTo(dateAsString);1290 }1291 /**1292 * Same assertion as {@link #isAfterOrEqualTo(Date)} but given date is represented as String either with one of the1293 * supported defaults date format or a user custom date format (set with method {@link #withDateFormat(DateFormat)}).1294 * <p>1295 * User custom date format take precedence over the default ones.1296 * <p>1297 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.1298 * <p>1299 * Example:1300 * <pre><code class='java'> // assertion will pass1301 * // theTwoTowers release date : 2002-12-181302 * assertThat(theTwoTowers.getReleaseDate()).isAfterOrEqualTo("2002-12-17");1303 * assertThat(theTwoTowers.getReleaseDate()).isAfterOrEqualTo("2002-12-18");1304 *1305 * // assertion will fail1306 * assertThat(theTwoTowers.getReleaseDate()).isAfterOrEqualTo("2002-12-19")</code></pre>1307 * <p>1308 * Defaults date format (expressed in the local time zone unless specified otherwise) are:1309 * <ul>1310 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>1311 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>1312 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>1313 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>1314 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>1315 * <li><code>yyyy-MM-dd</code></li>1316 * </ul>1317 * <p>1318 * Example of valid string date representations:1319 * <ul>1320 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>1321 * <li><code>2003-04-26T03:01:02.999</code></li>1322 * <li><code>2003-04-26 03:01:02.999</code></li>1323 * <li><code>2003-04-26T03:01:02+00:00</code></li>1324 * <li><code>2003-04-26T13:01:02</code></li>1325 * <li><code>2003-04-26</code></li>1326 * </ul>1327 * <p>1328 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),1329 * you can explicitly specify the date format to use so that the default ones are bypassed.1330 *1331 * @param dateAsString the given Date represented as String in default or custom date format.1332 * @return this assertion object.1333 * @throws AssertionError if the actual {@code Date} is {@code null}.1334 * @throws NullPointerException if given date as String is {@code null}.1335 * @throws AssertionError if the actual {@code Date} is not after or equals to the given Date represented as1336 * String.1337 * @throws AssertionError if the given date as String could not be converted to a Date.1338 */1339 public SELF isAfterOrEqualTo(String dateAsString) {1340 return isAfterOrEqualTo(parse(dateAsString));1341 }1342 /**1343 * Verifies that the actual {@code Date} is in [start, end[ period (start included, end excluded).1344 * <p>1345 * Example:1346 * <pre><code class='java'> // assertion will pass1347 * // theTwoTowers release date : 2002-12-181348 * assertThat(theTwoTowers.getReleaseDate()).isBetween(theFellowshipOfTheRing.getReleaseDate(), theReturnOfTheKing.getReleaseDate());1349 *1350 * // assertion will fail1351 * assertThat(theFellowshipOfTheRing.getReleaseDate()).isBetween(theTwoTowers.getReleaseDate(), theReturnOfTheKing.getReleaseDate());</code></pre>1352 *1353 * @param start the period start (inclusive), expected not to be null.1354 * @param end the period end (exclusive), expected not to be null.1355 * @return this assertion object.1356 * @throws AssertionError if the actual {@code Date} is {@code null}.1357 * @throws NullPointerException if start {@code Date} is {@code null}.1358 * @throws NullPointerException if end {@code Date} is {@code null}.1359 * @throws AssertionError if the actual {@code Date} is not in [start, end[ period.1360 */1361 public SELF isBetween(Date start, Date end) {1362 return isBetween(start, end, true, false);1363 }1364 /**1365 * Same assertion as {@link #isBetween(Date, Date)} but given date is represented as String either with one of the1366 * supported defaults date format or a user custom date format (set with method {@link #withDateFormat(DateFormat)}).1367 * <p>1368 * User custom date format take precedence over the default ones.1369 * <p>1370 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.1371 * <p>1372 * Example:1373 * <pre><code class='java'> // assertion will pass1374 * // theTwoTowers release date : 2002-12-181375 * assertThat(theTwoTowers.getReleaseDate()).isBetween("2002-12-17", "2002-12-19");1376 *1377 * // assertion will fail1378 * assertThat(theTwoTowers.getReleaseDate()).isBetween("2002-12-15", "2002-12-17")</code></pre>1379 * <p>1380 * Defaults date format (expressed in the local time zone unless specified otherwise) are:1381 * <ul>1382 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>1383 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>1384 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>1385 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>1386 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>1387 * <li><code>yyyy-MM-dd</code></li>1388 * </ul>1389 * <p>1390 * Example of valid string date representations:1391 * <ul>1392 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>1393 * <li><code>2003-04-26T03:01:02.999</code></li>1394 * <li><code>2003-04-26 03:01:02.999</code></li>1395 * <li><code>2003-04-26T03:01:02+00:00</code></li>1396 * <li><code>2003-04-26T13:01:02</code></li>1397 * <li><code>2003-04-26</code></li>1398 * </ul>1399 * <p>1400 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),1401 * you can explicitly specify the date format to use so that the default ones are bypassed.1402 *1403 * @param start the period start (inclusive), expected not to be null.1404 * @param end the period end (exclusive), expected not to be null.1405 * @return this assertion object.1406 * @throws AssertionError if the actual {@code Date} is {@code null}.1407 * @throws NullPointerException if start Date as String is {@code null}.1408 * @throws NullPointerException if end Date as String is {@code null}.1409 * @throws AssertionError if the actual {@code Date} is not in [start, end[ period.1410 * @throws AssertionError if one of the given date as String could not be converted to a Date.1411 */1412 public SELF isBetween(String start, String end) {1413 return isBetween(parse(start), parse(end));1414 }1415 /**1416 * Same assertion as {@link #isBetween(Date, Date)} but given period is represented with {@link java.time.Instant}.1417 * <p>1418 * Example:1419 * <pre><code class='java'> assertThat(new Date()).isBetween(Instant.now().minusSeconds(5), Instant.now().plusSeconds(5));</code></pre>1420 *1421 * @param start the period start (inclusive), expected not to be null.1422 * @param end the period end (exclusive), expected not to be null.1423 * @return this assertion object.1424 * @throws AssertionError if the actual {@code Date} is {@code null}.1425 * @throws NullPointerException if start Instant as String is {@code null}.1426 * @throws NullPointerException if end Instant as String is {@code null}.1427 * @throws AssertionError if the actual {@code Date} is not in [start, end[ period.1428 * @since 3.19.01429 */1430 public SELF isBetween(Instant start, Instant end) {1431 return isBetween(Date.from(start), Date.from(end));1432 }1433 /**1434 * Verifies that the actual {@code Date} is in the given period defined by start and end dates.<br>1435 * To include start1436 * in the period set inclusiveStart parameter to <code>true</code>.<br>1437 * To include end in the period set inclusiveEnd1438 * parameter to <code>true</code>.<br>1439 * <p>1440 * Example:1441 * <pre><code class='java'> SimpleDateFormat format = new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);1442 * // assertions will pass1443 * assertThat(format.parse(&quot;2000-01-01&quot;)).isBetween(format.parse(&quot;2000-01-01&quot;), format.parse(&quot;2100-12-01&quot;), true, true);1444 * assertThat(format.parse(&quot;2000-01-01&quot;)).isBetween(format.parse(&quot;1900-01-01&quot;), format.parse(&quot;2000-01-01&quot;), true, true);1445 * assertThat(format.parse(&quot;2000-01-01&quot;)).isBetween(format.parse(&quot;1900-01-01&quot;), format.parse(&quot;2100-01-01&quot;), false, false);1446 *1447 * // assertions will fail1448 * assertThat(format.parse(&quot;2000-01-01&quot;)).isBetween(format.parse(&quot;2000-01-01&quot;), format.parse(&quot;2100-12-01&quot;), false, true);1449 * assertThat(format.parse(&quot;2000-01-01&quot;)).isBetween(format.parse(&quot;1900-01-01&quot;), format.parse(&quot;2000-01-01&quot;), true, false);</code></pre>1450 *1451 * @param start the period start, expected not to be null.1452 * @param end the period end, expected not to be null.1453 * @param inclusiveStart whether to include start date in period.1454 * @param inclusiveEnd whether to include end date in period.1455 * @return this assertion object.1456 * @throws AssertionError if {@code actual} is {@code null}.1457 * @throws NullPointerException if start {@code Date} is {@code null}.1458 * @throws NullPointerException if end {@code Date} is {@code null}.1459 * @throws AssertionError if the actual {@code Date} is not in (start, end) period.1460 */1461 public SELF isBetween(Date start, Date end, boolean inclusiveStart, boolean inclusiveEnd) {1462 dates.assertIsBetween(info, actual, start, end, inclusiveStart, inclusiveEnd);1463 return myself;1464 }1465 /**1466 * Same assertion as {@link #isBetween(Date, Date, boolean, boolean)} but given date is represented as String either1467 * with one of the supported defaults date format or a user custom date format (set with method1468 * {@link #withDateFormat(DateFormat)}).1469 * <p>1470 * User custom date format take precedence over the default ones.1471 * <p>1472 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.1473 * <p>1474 * Example:1475 * <pre><code class='java'> // assertion will pass1476 * // theTwoTowers release date : 2002-12-181477 * assertThat(theTwoTowers.getReleaseDate()).isBetween("2002-12-17", "2002-12-18", false, true);1478 * assertThat(theTwoTowers.getReleaseDate()).isBetween("2002-12-18", "2002-12-19", true, false);1479 *1480 * // assertion will fail1481 * assertThat(theTwoTowers.getReleaseDate()).isBetween("2002-12-17", "2002-12-18", false, false)</code></pre>1482 * <p>1483 * Defaults date format (expressed in the local time zone unless specified otherwise) are:1484 * <ul>1485 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>1486 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>1487 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>1488 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>1489 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>1490 * <li><code>yyyy-MM-dd</code></li>1491 * </ul>1492 * <p>1493 * Example of valid string date representations:1494 * <ul>1495 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>1496 * <li><code>2003-04-26T03:01:02.999</code></li>1497 * <li><code>2003-04-26 03:01:02.999</code></li>1498 * <li><code>2003-04-26T03:01:02+00:00</code></li>1499 * <li><code>2003-04-26T13:01:02</code></li>1500 * <li><code>2003-04-26</code></li>1501 * </ul>1502 * <p>1503 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),1504 * you can explicitly specify the date format to use so that the default ones are bypassed.1505 *1506 * @param start the period start, expected not to be null.1507 * @param end the period end, expected not to be null.1508 * @param inclusiveStart whether to include start date in period.1509 * @param inclusiveEnd whether to include end date in period.1510 * @return this assertion object.1511 * @throws AssertionError if {@code actual} is {@code null}.1512 * @throws NullPointerException if start Date as String is {@code null}.1513 * @throws NullPointerException if end Date as String is {@code null}.1514 * @throws AssertionError if the actual {@code Date} is not in (start, end) period.1515 * @throws AssertionError if one of the given date as String could not be converted to a Date.1516 */1517 public SELF isBetween(String start, String end, boolean inclusiveStart, boolean inclusiveEnd) {1518 dates.assertIsBetween(info, actual, parse(start), parse(end), inclusiveStart, inclusiveEnd);1519 return myself;1520 }1521 /**1522 * Same assertion as {@link #isBetween(Date, Date, boolean, boolean)} but given period is represented with {@link java.time.Instant}.1523 * <p>1524 * Example:1525 * <pre><code class='java'> assertThat(new Date()).isBetween(Instant.now().minusSeconds(5), Instant.now().plusSeconds(5), true, true);</code></pre>1526 *1527 * @param start the period start, expected not to be null.1528 * @param end the period end, expected not to be null.1529 * @param inclusiveStart whether to include start date in period.1530 * @param inclusiveEnd whether to include end date in period.1531 * @return this assertion object.1532 * @throws AssertionError if {@code actual} is {@code null}.1533 * @throws NullPointerException if start Date as Instant is {@code null}.1534 * @throws NullPointerException if end Date as Instant is {@code null}.1535 * @throws AssertionError if the actual {@code Date} is not in (start, end) period.1536 * @since 3.19.01537 */1538 public SELF isBetween(Instant start, Instant end, boolean inclusiveStart, boolean inclusiveEnd) {1539 dates.assertIsBetween(info, actual, Date.from(start), Date.from(end), inclusiveStart, inclusiveEnd);1540 return myself;1541 }1542 /**1543 * Verifies that the actual {@code Date} is not in the given period defined by start and end dates.<br>1544 * To include start in the period set inclusiveStart parameter to <code>true</code>.<br>1545 * To include end in the period set inclusiveEnd parameter to <code>true</code>.<br>1546 * <p>1547 * Example:1548 * <pre><code class='java'> SimpleDateFormat format = new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);1549 * // assertions will pass1550 * assertThat(format.parse("2000-01-01")).isNotBetween(format.parse("2000-01-01"), format.parse("2100-12-01"), false, true);1551 * assertThat(format.parse("2000-01-01")).isNotBetween(format.parse("1900-01-01"), format.parse("2000-01-01"), true, false);1552 *1553 * // assertions will fail1554 * assertThat(format.parse("2000-01-01")).isNotBetween(format.parse("2000-01-01"), format.parse("2100-12-01"), true, true);1555 * assertThat(format.parse("2000-01-01")).isNotBetween(format.parse("1900-01-01"), format.parse("2000-01-01"), true, true);1556 * assertThat(format.parse("2000-01-01")).isNotBetween(format.parse("1900-01-01"), format.parse("2100-01-01"), false, false);</code></pre>1557 *1558 * @param start the period start (inclusive), expected not to be null.1559 * @param end the period end (exclusive), expected not to be null.1560 * @param inclusiveStart whether to include start date in period.1561 * @param inclusiveEnd whether to include end date in period.1562 * @return this assertion object.1563 * @throws AssertionError if {@code actual} is {@code null}.1564 * @throws NullPointerException if start {@code Date} is {@code null}.1565 * @throws NullPointerException if end {@code Date} is {@code null}.1566 * @throws AssertionError if the actual {@code Date} is not in (start, end) period.1567 */1568 public SELF isNotBetween(Date start, Date end, boolean inclusiveStart, boolean inclusiveEnd) {1569 dates.assertIsNotBetween(info, actual, start, end, inclusiveStart, inclusiveEnd);1570 return myself;1571 }1572 /**1573 * Verifies that the actual {@code Date} is not in the given period defined by start and end dates.<br>1574 * To include start in the period set inclusiveStart parameter to <code>true</code>.<br>1575 * To include end in the period set inclusiveEnd parameter to <code>true</code>.<br>1576 * <p>1577 * Example:1578 * <pre><code class='java'> SimpleDateFormat format = new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);1579 * // assertions will pass1580 * assertThat(format.parse("2000-01-01")).isNotBetween(format.parse("2000-01-01T00:00:00Z"), format.parse("2100-12-01T00:00:00Z"), false, true);1581 * assertThat(format.parse("2000-01-01")).isNotBetween(format.parse("1900-01-01T00:00:00Z"), format.parse("2000-01-01T00:00:00Z"), true, false);1582 *1583 * // assertions will fail1584 * assertThat(format.parse("2000-01-01")).isNotBetween(format.parse("2000-01-01T00:00:00Z"), format.parse("2100-12-01T00:00:00Z"), true, true);1585 * assertThat(format.parse("2000-01-01")).isNotBetween(format.parse("1900-01-01T00:00:00Z"), format.parse("2000-01-01T00:00:00Z"), true, true);1586 * assertThat(format.parse("2000-01-01")).isNotBetween(format.parse("1900-01-01T00:00:00Z"), format.parse("2100-01-01T00:00:00Z"), false, false);</code></pre>1587 *1588 * @param start the period start (inclusive), expected not to be null.1589 * @param end the period end (exclusive), expected not to be null.1590 * @param inclusiveStart whether to include start date in period.1591 * @param inclusiveEnd whether to include end date in period.1592 * @return this assertion object.1593 * @throws AssertionError if {@code actual} is {@code null}.1594 * @throws NullPointerException if start {@code Instant} is {@code null}.1595 * @throws NullPointerException if end {@code Instant} is {@code null}.1596 * @throws AssertionError if the actual {@code Date} is not in (start, end) period.1597 * @since 3.19.01598 */1599 public SELF isNotBetween(Instant start, Instant end, boolean inclusiveStart, boolean inclusiveEnd) {1600 dates.assertIsNotBetween(info, actual, Date.from(start), Date.from(end), inclusiveStart, inclusiveEnd);1601 return myself;1602 }1603 /**1604 * Same assertion as {@link #isNotBetween(Date, Date, boolean, boolean)} but given date is represented as String1605 * either with one of the supported defaults date format or a user custom date format (set with method1606 * {@link #withDateFormat(DateFormat)}).1607 * <p>1608 * User custom date format take precedence over the default ones.1609 * <p>1610 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.1611 * <p>1612 * Example:1613 * <pre><code class='java'> // assertion will pass1614 * // theTwoTowers release date : 2002-12-181615 * assertThat(theTwoTowers.getReleaseDate()).isNotBetween("2002-12-17", "2002-12-18", false, false);1616 *1617 * // assertion will fail1618 * assertThat(theTwoTowers.getReleaseDate()).isNotBetween("2002-12-17", "2002-12-18", false, true);1619 * assertThat(theTwoTowers.getReleaseDate()).isNotBetween("2002-12-18", "2002-12-19", true, false)</code></pre>1620 * <p>1621 * Defaults date format (expressed in the local time zone unless specified otherwise) are:1622 * <ul>1623 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>1624 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>1625 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>1626 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>1627 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>1628 * <li><code>yyyy-MM-dd</code></li>1629 * </ul>1630 * <p>1631 * Example of valid string date representations:1632 * <ul>1633 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>1634 * <li><code>2003-04-26T03:01:02.999</code></li>1635 * <li><code>2003-04-26 03:01:02.999</code></li>1636 * <li><code>2003-04-26T03:01:02+00:00</code></li>1637 * <li><code>2003-04-26T13:01:02</code></li>1638 * <li><code>2003-04-26</code></li>1639 * </ul>1640 * <p>1641 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),1642 * you can explicitly specify the date format to use so that the default ones are bypassed.1643 *1644 * @param start the period start (inclusive), expected not to be null.1645 * @param end the period end (exclusive), expected not to be null.1646 * @param inclusiveStart whether to include start date in period.1647 * @param inclusiveEnd whether to include end date in period.1648 * @return this assertion object.1649 * @throws AssertionError if {@code actual} is {@code null}.1650 * @throws NullPointerException if start Date as String is {@code null}.1651 * @throws NullPointerException if end Date as String is {@code null}.1652 * @throws AssertionError if the actual {@code Date} is not in (start, end) period.1653 * @throws AssertionError if one of the given date as String could not be converted to a Date.1654 */1655 public SELF isNotBetween(String start, String end, boolean inclusiveStart, boolean inclusiveEnd) {1656 return isNotBetween(parse(start), parse(end), inclusiveStart, inclusiveEnd);1657 }1658 /**1659 * Verifies that the actual {@code Date} is not in [start, end[ period1660 * <p>1661 * Example:1662 * <pre><code class='java'> SimpleDateFormat format = new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);1663 * // assertions will pass1664 * assertThat(format.parse(&quot;1900-01-01&quot;)).isNotBetween(format.parse(&quot;2000-01-01&quot;), format.parse(&quot;2100-12-01&quot;));1665 * assertThat(format.parse(&quot;2200-01-01&quot;)).isNotBetween(format.parse(&quot;2000-01-01&quot;), format.parse(&quot;2100-12-01&quot;));1666 * assertThat(format.parse(&quot;2000-01-01&quot;)).isNotBetween(format.parse(&quot;1900-01-01&quot;), format.parse(&quot;2000-01-01&quot;));1667 *1668 * // assertions will fail1669 * assertThat(format.parse(&quot;2001-12-24&quot;)).isNotBetween(format.parse(&quot;2000-01-01&quot;), format.parse(&quot;2100-01-01&quot;));1670 * assertThat(format.parse(&quot;1900-01-01&quot;)).isNotBetween(format.parse(&quot;1900-01-01&quot;), format.parse(&quot;2000-01-01&quot;));</code></pre>1671 *1672 * @param start the period start (inclusive), expected not to be null.1673 * @param end the period end (exclusive), expected not to be null.1674 * @return this assertion object.1675 * @throws AssertionError if the actual {@code Date} is {@code null}.1676 * @throws NullPointerException if start {@code Date} is {@code null}.1677 * @throws NullPointerException if end {@code Date} is {@code null}.1678 * @throws AssertionError if the actual {@code Date} is in [start, end[ period.1679 */1680 public SELF isNotBetween(Date start, Date end) {1681 return isNotBetween(start, end, true, false);1682 }1683 /**1684 * Verifies that the actual {@code Date} is not in [start, end[ period1685 * <p>1686 * Example:1687 * <pre><code class='java'> SimpleDateFormat format = new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);1688 * // assertions will pass1689 * assertThat(format.parse(&quot;1900-01-01&quot;)).isNotBetween(Instant.parse(&quot;2000-01-01T00:00:00Z&quot;), Instant.parse(&quot;2100-12-01T00:00:00Z&quot;));1690 * assertThat(format.parse(&quot;2200-01-01&quot;)).isNotBetween(Instant.parse(&quot;2000-01-01T00:00:00Z&quot;), Instant.parse(&quot;2100-12-01T00:00:00Z&quot;));1691 * assertThat(format.parse(&quot;2000-01-01&quot;)).isNotBetween(Instant.parse(&quot;1900-01-01T00:00:00Z&quot;), Instant.parse(&quot;2000-01-01T00:00:00Z&quot;));1692 *1693 * // assertions will fail1694 * assertThat(format.parse(&quot;2001-12-24&quot;)).isNotBetween(Instant.parse(&quot;2000-01-01T00:00:00Z&quot;), Instant.parse(&quot;2100-01-01T00:00:00Z&quot;));1695 * assertThat(format.parse(&quot;1900-01-01&quot;)).isNotBetween(Instant.parse(&quot;1900-01-01T00:00:00Z&quot;), Instant.parse(&quot;2000-01-01T00:00:00Z&quot;));</code></pre>1696 *1697 * @param start the period start (inclusive), expected not to be null.1698 * @param end the period end (exclusive), expected not to be null.1699 * @return this assertion object.1700 * @throws AssertionError if the actual {@code Date} is {@code null}.1701 * @throws NullPointerException if start {@code Instant} is {@code null}.1702 * @throws NullPointerException if end {@code Instant} is {@code null}.1703 * @throws AssertionError if the actual {@code Date} is in [start, end[ period.1704 * @since 3.19.01705 */1706 public SELF isNotBetween(Instant start, Instant end) {1707 return isNotBetween(Date.from(start), Date.from(end), true, false);1708 }1709 /**1710 * Same assertion as {@link #isNotBetween(Date, Date)} but given date is represented as String either with one of the1711 * supported defaults date format or a user custom date format (set with method {@link #withDateFormat(DateFormat)}).1712 * <p>1713 * User custom date format take precedence over the default ones.1714 * <p>1715 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.1716 * <p>1717 * Example:1718 * <pre><code class='java'> // assertion will pass1719 * assertThat(theFellowshipOfTheRing.getReleaseDate()).isNotBetween("2002-12-01", "2002-12-10");1720 *1721 * // assertion will fail1722 * assertThat(theFellowshipOfTheRing.getReleaseDate()).isNotBetween("2002-12-01", "2002-12-19")</code></pre>1723 * <p>1724 * Defaults date format (expressed in the local time zone unless specified otherwise) are:1725 * <ul>1726 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>1727 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>1728 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>1729 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>1730 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>1731 * <li><code>yyyy-MM-dd</code></li>1732 * </ul>1733 * <p>1734 * Example of valid string date representations:1735 * <ul>1736 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>1737 * <li><code>2003-04-26T03:01:02.999</code></li>1738 * <li><code>2003-04-26 03:01:02.999</code></li>1739 * <li><code>2003-04-26T03:01:02+00:00</code></li>1740 * <li><code>2003-04-26T13:01:02</code></li>1741 * <li><code>2003-04-26</code></li>1742 * </ul>1743 * <p>1744 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),1745 * you can explicitly specify the date format to use so that the default ones are bypassed.1746 *1747 * @param start the period start (inclusive), expected not to be null.1748 * @param end the period end (exclusive), expected not to be null.1749 * @return this assertion object.1750 * @throws AssertionError if the actual {@code Date} is {@code null}.1751 * @throws NullPointerException if start Date as String is {@code null}.1752 * @throws NullPointerException if end Date as String is {@code null}.1753 * @throws AssertionError if the actual {@code Date} is in [start, end[ period.1754 * @throws AssertionError if one of the given date as String could not be converted to a Date.1755 */1756 public SELF isNotBetween(String start, String end) {1757 return isNotBetween(parse(start), parse(end), true, false);1758 }1759 /**1760 * Verifies that the actual {@code Date} is strictly in the past.1761 * <p>1762 * Example:1763 * <pre><code class='java'> // assertion will pass1764 * assertThat(theTwoTowers.getReleaseDate()).isInThePast();</code></pre>1765 *1766 * @return this assertion object.1767 * @throws AssertionError if the actual {@code Date} is {@code null}.1768 * @throws AssertionError if the actual {@code Date} is not in the past.1769 */1770 public SELF isInThePast() {1771 dates.assertIsInThePast(info, actual);1772 return myself;1773 }1774 /**1775 * Verifies that the actual {@code Date} is today, that is matching current year, month and day (no check on hour,1776 * minute, second, milliseconds).1777 * <p>1778 * Example:1779 * <pre><code class='java'> // assertion will pass1780 * assertThat(new Date()).isToday();1781 *1782 * // assertion will fail1783 * assertThat(theFellowshipOfTheRing.getReleaseDate()).isToday();</code></pre>1784 *1785 * @return this assertion object.1786 * @throws AssertionError if the actual {@code Date} is {@code null}.1787 * @throws AssertionError if the actual {@code Date} is not today.1788 */1789 public SELF isToday() {1790 dates.assertIsToday(info, actual);1791 return myself;1792 }1793 /**1794 * Verifies that the actual {@code Date} is strictly in the future.1795 * <p>1796 * Example:1797 * <pre><code class='java'> // assertion will fail1798 * assertThat(theTwoTowers.getReleaseDate()).isInTheFuture();</code></pre>1799 *1800 * @return this assertion object.1801 * @throws AssertionError if the actual {@code Date} is {@code null}.1802 * @throws AssertionError if the actual {@code Date} is not in the future.1803 */1804 public SELF isInTheFuture() {1805 dates.assertIsInTheFuture(info, actual);1806 return myself;1807 }1808 /**1809 * Verifies that the actual {@code Date} is <b>strictly</b> before the given year.1810 * <p>1811 * Example:1812 * <pre><code class='java'> // assertion will pass1813 * // theTwoTowers release date : 2002-12-181814 * assertThat(theTwoTowers.getReleaseDate()).isBeforeYear(2004);1815 *1816 * // assertion will fail1817 * assertThat(theTwoTowers.getReleaseDate()).isBeforeYear(2002);1818 * assertThat(theTwoTowers.getReleaseDate()).isBeforeYear(2000);</code></pre>1819 *1820 * @param year the year to compare actual year to1821 * @return this assertion object.1822 * @throws AssertionError if the actual {@code Date} is {@code null}.1823 * @throws AssertionError if the actual {@code Date} year is after or equals to the given year.1824 */1825 public SELF isBeforeYear(int year) {1826 dates.assertIsBeforeYear(info, actual, year);1827 return myself;1828 }1829 /**1830 * Verifies that the actual {@code Date} is <b>strictly</b> after the given year.1831 * <p>1832 * Example:1833 * <pre><code class='java'> // assertion will pass1834 * // theTwoTowers release date : 2002-12-181835 * assertThat(theTwoTowers.getReleaseDate()).isAfterYear(2001);1836 *1837 * // assertion will fail1838 * assertThat(theTwoTowers.getReleaseDate()).isAfterYear(2002);1839 * assertThat(theTwoTowers.getReleaseDate()).isAfterYear(2004);</code></pre>1840 *1841 * @param year the year to compare actual year to1842 * @return this assertion object.1843 * @throws AssertionError if the actual {@code Date} is {@code null}.1844 * @throws AssertionError if the actual {@code Date} year is before or equals to the given year.1845 */1846 public SELF isAfterYear(int year) {1847 dates.assertIsAfterYear(info, actual, year);1848 return myself;1849 }1850 /**1851 * Verifies that the actual {@code Date} year is equal to the given year.1852 * <p>1853 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.1854 * <p>1855 * Example:1856 * <pre><code class='java'> // assertion will pass1857 * // theTwoTowers release date : 2002-12-181858 * assertThat(theTwoTowers.getReleaseDate()).hasYear(2002);1859 *1860 * // assertion will fail1861 * assertThat(theTwoTowers.getReleaseDate()).hasYear(2004);</code></pre>1862 *1863 * @param year the year to compare actual year to1864 * @return this assertion object.1865 * @throws AssertionError if the actual {@code Date} is {@code null}.1866 * @throws AssertionError if the actual {@code Date} year is not equal to the given year.1867 */1868 public SELF hasYear(int year) {1869 dates.assertHasYear(info, actual, year);1870 return myself;1871 }1872 /**1873 * @deprecated use {@link #hasYear(int)} instead.1874 * @param year the year to compare actual year to1875 * @return this assertion object.1876 */1877 @Deprecated1878 public SELF isWithinYear(int year) {1879 return hasYear(year);1880 }1881 /**1882 * Verifies that the actual {@code Date} month is equal to the given month, <b>month value starting at 1</b>1883 * (January=1, February=2, ...).1884 * <p>1885 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.1886 * <p>1887 * Example:1888 * <pre><code class='java'> // assertion will pass1889 * // theTwoTowers release date : 2002-12-181890 * assertThat(theTwoTowers.getReleaseDate()).hasMonth(12);1891 *1892 * // assertion will fail1893 * assertThat(theTwoTowers.getReleaseDate()).hasMonth(10);</code></pre>1894 *1895 * @param month the month to compare actual month to, <b>month value starting at 1</b> (January=1, February=2, ...).1896 * @return this assertion object.1897 * @throws AssertionError if the actual {@code Date} is {@code null}.1898 * @throws AssertionError if the actual {@code Date} month is not equal to the given month.1899 */1900 public SELF hasMonth(int month) {1901 dates.assertHasMonth(info, actual, month);1902 return myself;1903 }1904 /**1905 * @deprecated use {@link #hasMonth(int)} instead.1906 * @param month the month to compare actual month to, <b>month value starting at 1</b> (January=1, February=2, ...).1907 * @return this assertion object.1908 */1909 @Deprecated1910 public SELF isWithinMonth(int month) {1911 return hasMonth(month);1912 }1913 /**1914 * Verifies that the actual {@code Date} day of month is equal to the given day of month.1915 * <p>1916 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.1917 * <p>1918 * Example:1919 * <pre><code class='java'> // assertion will pass1920 * // theTwoTowers release date : 2002-12-181921 * assertThat(theTwoTowers.getReleaseDate()).hasDayOfMonth(18);1922 *1923 * // assertion will fail1924 * assertThat(theTwoTowers.getReleaseDate()).hasDayOfMonth(20);</code></pre>1925 *1926 * @param dayOfMonth the day of month to compare actual day of month to1927 * @return this assertion object.1928 * @throws AssertionError if the actual {@code Date} is {@code null}.1929 * @throws AssertionError if the actual {@code Date} month is not equal to the given day of month.1930 */1931 public SELF hasDayOfMonth(int dayOfMonth) {1932 dates.assertHasDayOfMonth(info, actual, dayOfMonth);1933 return myself;1934 }1935 /**1936 * @deprecated use {@link #hasDayOfMonth(int)} instead.1937 * @param dayOfMonth the day of month to compare actual day of month to1938 * @return this assertion object.1939 */1940 @Deprecated1941 public SELF isWithinDayOfMonth(int dayOfMonth) {1942 return hasDayOfMonth(dayOfMonth);1943 }1944 /**1945 * Verifies that the actual {@code Date} day of week is equal to the given day of week (see1946 * {@link Calendar#DAY_OF_WEEK} for valid values).1947 * <p>1948 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.1949 * <p>1950 * Example:1951 * <pre><code class='java'> // assertion will pass1952 * assertThat(new Date(parseDatetime("2003-04-26T13:20:35").getTime()).hasDayOfWeek(Calendar.SATURDAY);1953 *1954 * // assertion will fail1955 * assertThat(new Date(parseDatetime("2003-04-26T13:20:35").getTime()).hasDayOfWeek(Calendar.MONDAY);</code></pre>1956 *1957 * @param dayOfWeek the day of week to compare actual day of week to, see {@link Calendar#DAY_OF_WEEK} for valid1958 * values1959 * @return this assertion object.1960 * @throws AssertionError if the actual {@code Date} is {@code null}.1961 * @throws AssertionError if the actual {@code Date} week is not equal to the given day of week.1962 */1963 public SELF hasDayOfWeek(int dayOfWeek) {1964 dates.assertHasDayOfWeek(info, actual, dayOfWeek);1965 return myself;1966 }1967 /**1968 * @deprecated use {@link #hasDayOfWeek(int)} instead.1969 * @param dayOfWeek the day of week to compare actual day of week to, see {@link Calendar#DAY_OF_WEEK} for valid1970 * values1971 * @return this assertion object.1972 */1973 @Deprecated1974 public SELF isWithinDayOfWeek(int dayOfWeek) {1975 return hasDayOfWeek(dayOfWeek);1976 }1977 /**1978 * Verifies that the actual {@code Date} hour of day is equal to the given hour of day (24-hour clock).1979 * <p>1980 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.1981 * <p>1982 * Example:1983 * <pre><code class='java'> // assertion will pass1984 * assertThat(new Date(parseDatetime("2003-04-26T13:20:35").getTime()).hasHourOfDay(13);1985 *1986 * // assertion will fail1987 * assertThat(new Date(parseDatetime("2003-04-26T13:20:35").getTime()).hasHourOfDay(22);</code></pre>1988 *1989 * @param hourOfDay the hour of day to compare actual hour of day to (24-hour clock)1990 * @return this assertion object.1991 * @throws AssertionError if the actual {@code Date} is {@code null}.1992 * @throws AssertionError if the actual {@code Date} hour is not equal to the given hour.1993 */1994 public SELF hasHourOfDay(int hourOfDay) {1995 dates.assertHasHourOfDay(info, actual, hourOfDay);1996 return myself;1997 }1998 /**1999 * @deprecated use {@link #hasHourOfDay(int)} instead.2000 * @param hourOfDay the hour of day to compare actual hour of day to (24-hour clock)2001 * @return this assertion object.2002 */2003 @Deprecated2004 public SELF isWithinHourOfDay(int hourOfDay) {2005 return hasHourOfDay(hourOfDay);2006 }2007 /**2008 * Verifies that the actual {@code Date} minute is equal to the given minute.2009 * <p>2010 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.2011 * <p>2012 * Example:2013 * <pre><code class='java'> // assertion will pass2014 * assertThat(new Date(parseDatetime("2003-04-26T13:20:35").getTime()).hasMinute(20);2015 *2016 * // assertion will fail2017 * assertThat(new Date(parseDatetime("2003-04-26T13:20:35").getTime()).hasMinute(17);</code></pre>2018 *2019 * @param minute the minute to compare actual minute to2020 * @return this assertion object.2021 * @throws AssertionError if the actual {@code Date} is {@code null}.2022 * @throws AssertionError if the actual {@code Date} minute is not equal to the given minute.2023 */2024 public SELF hasMinute(int minute) {2025 dates.assertHasMinute(info, actual, minute);2026 return myself;2027 }2028 /**2029 * @deprecated use {@link #hasMinute(int)} instead.2030 * @param minute the minute to compare actual minute to2031 * @return this assertion object.2032 */2033 @Deprecated2034 public SELF isWithinMinute(int minute) {2035 return hasMinute(minute);2036 }2037 /**2038 * Verifies that the actual {@code Date} second is equal to the given second.2039 * <p>2040 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.2041 * <p>2042 * Example:2043 * <pre><code class='java'> // assertion will pass2044 * assertThat(new Date(parseDatetime("2003-04-26T13:20:35").getTime()).hasSecond(35);2045 *2046 * // assertion will fail2047 * assertThat(new Date(parseDatetime("2003-04-26T13:20:35").getTime()).hasSecond(11);</code></pre>2048 *2049 * @param second the second to compare actual second to2050 * @return this assertion object.2051 * @throws AssertionError if the actual {@code Date} is {@code null}.2052 * @throws AssertionError if the actual {@code Date} second is not equal to the given second.2053 */2054 public SELF hasSecond(int second) {2055 dates.assertHasSecond(info, actual, second);2056 return myself;2057 }2058 /**2059 * @deprecated use {@link #hasSecond(int)} instead.2060 * @param second the second to compare actual second to2061 * @return this assertion object.2062 */2063 @Deprecated2064 public SELF isWithinSecond(int second) {2065 return hasSecond(second);2066 }2067 /**2068 * Verifies that the actual {@code Date} millisecond is equal to the given millisecond.2069 * <p>2070 * Examples:2071 * <pre><code class='java'> // assertion will pass2072 * assertThat(parseDatetimeWithMs("2003-04-26T13:20:35.017")).hasMillisecond(17);2073 *2074 * // assertion will fail2075 * assertThat(parseDatetimeWithMs("2003-04-26T13:20:35.017")).hasMillisecond(25);</code></pre>2076 *2077 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.2078 *2079 * @param millisecond the millisecond to compare actual millisecond to2080 * @return this assertion object.2081 * @throws AssertionError if the actual {@code Date} is {@code null}.2082 * @throws AssertionError if the actual {@code Date} millisecond is not equal to the given millisecond.2083 */2084 public SELF hasMillisecond(int millisecond) {2085 dates.assertHasMillisecond(info, actual, millisecond);2086 return myself;2087 }2088 /**2089 * @deprecated use {@link #hasMillisecond(int)} instead.2090 * @param millisecond the millisecond to compare actual millisecond to2091 * @return this assertion object.2092 */2093 @Deprecated2094 public SELF isWithinMillisecond(int millisecond) {2095 return hasMillisecond(millisecond);2096 }2097 /**2098 * Verifies that actual and given {@code Date} are in the same year.2099 * <p>2100 * Example:2101 * <pre><code class='java'> Date date1 = parse("2003-04-26");2102 * Date date2 = parse("2003-05-27");2103 *2104 * assertThat(date1).isInSameYearAs(date2);</code></pre>2105 *2106 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.2107 *2108 * @param other the given {@code Date} to compare actual {@code Date} to.2109 * @return this assertion object.2110 * @throws NullPointerException if {@code Date} parameter is {@code null}.2111 * @throws AssertionError if the actual {@code Date} is {@code null}.2112 * @throws AssertionError if actual and given {@code Date} are not in the same year.2113 */2114 public SELF isInSameYearAs(Date other) {2115 dates.assertIsInSameYearAs(info, actual, other);2116 return myself;2117 }2118 /**2119 * Verifies that actual {@code Date} and given {@code Instant} are in the same year.2120 * <p>2121 * Example:2122 * <pre><code class='java'> Date date = parse("2003-04-26");2123 * Instant instant = Instant.parse("2003-04-26T12:30:00Z");2124 *2125 * assertThat(date).isInSameYearAs(instant);</code></pre>2126 *2127 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.2128 *2129 * @param other the given {@code Instant} to compare actual {@code Date} to.2130 * @return this assertion object.2131 * @throws NullPointerException if {@code Instant} parameter is {@code null}.2132 * @throws AssertionError if the actual {@code Date} is {@code null}.2133 * @throws AssertionError if actual {@code Date} and given {@code Instant} are not in the same year.2134 * @since 3.19.02135 */2136 public SELF isInSameYearAs(Instant other) {2137 dates.assertIsInSameYearAs(info, actual, Date.from(other));2138 return myself;2139 }2140 /**2141 * Same assertion as {@link #isInSameYearAs(Date)} but given date is represented as String either with one of the2142 * supported defaults date format or a user custom date format (set with method {@link #withDateFormat(DateFormat)}).2143 * <p>2144 * User custom date format take precedence over the default ones.2145 * <p>2146 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.2147 * <p>2148 * Example:2149 * <pre><code class='java'> Date date1 = parse("2003-04-26");2150 * assertThat(date1).isInSameYearAs("2003-05-27")</code></pre>2151 * <p>2152 * Defaults date format (expressed in the local time zone unless specified otherwise) are:2153 * <ul>2154 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>2155 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>2156 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>2157 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>2158 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>2159 * <li><code>yyyy-MM-dd</code></li>2160 * </ul>2161 * <p>2162 * Example of valid string date representations:2163 * <ul>2164 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>2165 * <li><code>2003-04-26T03:01:02.999</code></li>2166 * <li><code>2003-04-26 03:01:02.999</code></li>2167 * <li><code>2003-04-26T03:01:02+00:00</code></li>2168 * <li><code>2003-04-26T13:01:02</code></li>2169 * <li><code>2003-04-26</code></li>2170 * </ul>2171 * <p>2172 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),2173 * you can explicitly specify the date format to use so that the default ones are bypassed.2174 *2175 * @param dateAsString the given Date represented as String in default or custom date format.2176 * @return this assertion object.2177 * @throws NullPointerException if dateAsString parameter is {@code null}.2178 * @throws AssertionError if the actual {@code Date} is {@code null}.2179 * @throws AssertionError if actual and given Date represented as String are not in the same year.2180 * @throws AssertionError if the given date as String could not be converted to a Date.2181 */2182 public SELF isInSameYearAs(String dateAsString) {2183 return isInSameYearAs(parse(dateAsString));2184 }2185 /**2186 * Verifies that actual and given {@code Date} have same month and year fields.2187 * <p>2188 * Example:2189 * <pre><code class='java'> Date date1 = parse("2003-04-26");2190 * Date date2 = parse("2003-04-27");2191 *2192 * assertThat(date1).isInSameMonthAs(date2);</code></pre>2193 *2194 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.2195 *2196 * @param other the given {@code Date} to compare actual {@code Date} to.2197 * @return this assertion object.2198 * @throws NullPointerException if {@code Date} parameter is {@code null}.2199 * @throws AssertionError if the actual {@code Date} is {@code null}.2200 * @throws AssertionError if actual and given {@code Date} are not in the same month and year.2201 */2202 public SELF isInSameMonthAs(Date other) {2203 dates.assertIsInSameMonthAs(info, actual, other);2204 return myself;2205 }2206 /**2207 * Verifies that actual {@code Date} and given {@code Instant} have same month and year fields.2208 * <p>2209 * Example:2210 * <pre><code class='java'> Date date = parse("2003-04-26");2211 * Instant instant = Instant.parse("2003-04-27T12:30:00Z");2212 *2213 * assertThat(date).isInSameMonthAs(instant);</code></pre>2214 * <p>2215 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.2216 *2217 * @param other the given {@code Instant} to compare actual {@code Date} to.2218 * @return this assertion object.2219 * @throws NullPointerException if {@code Instant} parameter is {@code null}.2220 * @throws AssertionError if the actual {@code Date} is {@code null}.2221 * @throws AssertionError if actual {@code Date} and given {@code Instant} are not in the same month and year.2222 * @since 3.19.02223 */2224 public SELF isInSameMonthAs(Instant other) {2225 dates.assertIsInSameMonthAs(info, actual, Date.from(other));2226 return myself;2227 }2228 /**2229 * Same assertion as {@link #isInSameMonthAs(Date)}but given date is represented as String either with one of the2230 * supported defaults date format or a user custom date format (set with method {@link #withDateFormat(DateFormat)}).2231 * <p>2232 * User custom date format take precedence over the default ones.2233 * <p>2234 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.2235 * <p>2236 * Example:2237 * <pre><code class='java'> Date date1 = parse("2003-04-26");2238 * assertThat(date1).isInSameMonthAs("2003-04-27")</code></pre>2239 * <p>2240 * Defaults date format (expressed in the local time zone unless specified otherwise) are:2241 * <ul>2242 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>2243 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>2244 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>2245 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>2246 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>2247 * <li><code>yyyy-MM-dd</code></li>2248 * </ul>2249 * <p>2250 * Example of valid string date representations:2251 * <ul>2252 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>2253 * <li><code>2003-04-26T03:01:02.999</code></li>2254 * <li><code>2003-04-26 03:01:02.999</code></li>2255 * <li><code>2003-04-26T03:01:02+00:00</code></li>2256 * <li><code>2003-04-26T13:01:02</code></li>2257 * <li><code>2003-04-26</code></li>2258 * </ul>2259 * <p>2260 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),2261 * you can explicitly specify the date format to use so that the default ones are bypassed.2262 *2263 * @param dateAsString the given Date represented as String in default or custom date format.2264 * @return this assertion object.2265 * @throws NullPointerException if dateAsString parameter is {@code null}.2266 * @throws AssertionError if the actual {@code Date} is {@code null}.2267 * @throws AssertionError if actual and given {@code Date} are not in the same month.2268 */2269 public SELF isInSameMonthAs(String dateAsString) {2270 return isInSameMonthAs(parse(dateAsString));2271 }2272 /**2273 * Verifies that actual and given {@code Date} have the same day of month, month and year fields values.2274 * <p>2275 * Example:2276 * <pre><code class='java'> Date date1 = parseDatetime("2003-04-26T23:17:00");2277 * Date date2 = parseDatetime("2003-04-26T12:30:00");2278 *2279 * assertThat(date1).isInSameDayAs(date2);</code></pre>2280 * <p>2281 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.2282 * <p>2283 * This assertion is logically equivalent to {@link #isEqualToIgnoringHours(Date)}.2284 *2285 * @param other the given {@code Date} to compare actual {@code Date} to.2286 * @return this assertion object.2287 * @throws NullPointerException if {@code Date} parameter is {@code null}.2288 * @throws AssertionError if the actual {@code Date} is {@code null}.2289 * @throws AssertionError if actual and given {@code Date} are not in the same day, month and year.2290 */2291 public SELF isInSameDayAs(Date other) {2292 dates.assertIsInSameDayAs(info, actual, other);2293 return myself;2294 }2295 /**2296 * Verifies that actual {@code Date} and given {@code Instant} have the same day of month, month and year fields values.2297 * <p>2298 * Example:2299 * <pre><code class='java'> Date date = parseDatetime("2003-04-26T23:17:00");2300 * Instant instant = Instant.parse("2003-04-26T12:30:00Z");2301 *2302 * assertThat(date).isInSameDayAs(instant);</code></pre>2303 *2304 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.2305 * <p>2306 * This assertion is logically equivalent to {@link #isEqualToIgnoringHours(Instant)}.2307 *2308 * @param other the given {@code Date} to compare actual {@code Date} to.2309 * @return this assertion object.2310 * @throws NullPointerException if {@code Instant} parameter is {@code null}.2311 * @throws AssertionError if the actual {@code Date} is {@code null}.2312 * @throws AssertionError if actual {@code Date} and given {@code Instant} are not in the same day, month and year.2313 * @since 3.19.02314 */2315 public SELF isInSameDayAs(Instant other) {2316 dates.assertIsInSameDayAs(info, actual, Date.from(other));2317 return myself;2318 }2319 /**2320 * Same assertion as {@link #isInSameDayAs(Date)} but given date is represented as String either with one of the2321 * supported defaults date format or a user custom date format (set with method {@link #withDateFormat(DateFormat)}).2322 * <p>2323 * User custom date format take precedence over the default ones.2324 * <p>2325 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.2326 * <p>2327 * Example:2328 * <pre><code class='java'> Date date1 = parseDatetime("2003-04-26T23:17:00");2329 * assertThat(date1).isInSameDayAs("2003-04-26")</code></pre>2330 * <p>2331 * Defaults date format (expressed in the local time zone unless specified otherwise) are:2332 * <ul>2333 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>2334 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>2335 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>2336 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>2337 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>2338 * <li><code>yyyy-MM-dd</code></li>2339 * </ul>2340 * <p>2341 * Example of valid string date representations:2342 * <ul>2343 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>2344 * <li><code>2003-04-26T03:01:02.999</code></li>2345 * <li><code>2003-04-26 03:01:02.999</code></li>2346 * <li><code>2003-04-26T03:01:02+00:00</code></li>2347 * <li><code>2003-04-26T13:01:02</code></li>2348 * <li><code>2003-04-26</code></li>2349 * </ul>2350 * <p>2351 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),2352 * you can explicitly specify the date format to use so that the default ones are bypassed.2353 * <p>2354 * This assertion is logically equivalent to {@link #isEqualToIgnoringHours(String)}.2355 *2356 * @param dateAsString the given Date represented as String in default or custom date format.2357 * @return this assertion object.2358 * @throws NullPointerException if dateAsString parameter is {@code null}.2359 * @throws AssertionError if the actual {@code Date} is {@code null}.2360 * @throws AssertionError if actual and given {@code Date} are not in the same day of month.2361 */2362 public SELF isInSameDayAs(String dateAsString) {2363 return isInSameDayAs(parse(dateAsString));2364 }2365 /**2366 * Verifies that actual and given {@code Date} are chronologically in the same hour (i.e. their time difference &lt; 1 hour).2367 * <p>2368 * This assertion succeeds as time difference is exactly &lt; 1h:2369 * <pre><code class='java'> Date date1 = parseDatetime("2003-04-26T13:00:00");2370 * Date date2 = parseDatetime("2003-04-26T13:30:00");2371 * assertThat(date1).isInSameHourWindowAs(date2);</code></pre>2372 *2373 * Two dates can have different hour fields and yet be in the same chronological hour, example:2374 * <pre><code class='java'> Date date1 = parseDatetime("2003-04-26T13:00:00");2375 * Date date2 = parseDatetime("2003-04-26T12:59:59");2376 * // succeeds as time difference == 1s2377 * assertThat(date1).isInSameHourWindowAs(date2);</code></pre>2378 *2379 * These assertions fail as time difference is equal to or greater than one hour:2380 * <pre><code class='java'> Date date1 = parseDatetime("2003-04-26T13:00:00");2381 * Date date2 = parseDatetime("2003-04-26T14:00:01");2382 * Date date3 = parseDatetime("2003-04-26T14:00:00");2383 * assertThat(date1).isInSameHourWindowAs(date2);2384 * assertThat(date1).isInSameHourWindowAs(date3);</code></pre>2385 * <p>2386 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.2387 *2388 * @param other the given {@code Date} to compare actual {@code Date} to.2389 * @return this assertion object.2390 * @throws NullPointerException if {@code Date} parameter is {@code null}.2391 * @throws AssertionError if the actual {@code Date} is {@code null}.2392 * @throws AssertionError if actual and given {@code Date} are not in the same hour.2393 */2394 public SELF isInSameHourWindowAs(Date other) {2395 dates.assertIsInSameHourWindowAs(info, actual, other);2396 return myself;2397 }2398 /**2399 * Verifies that actual {@code Date} and given {@code Instant} are chronologically in the same hour (i.e. their time2400 * difference &lt; 1 hour).2401 * <p>2402 * This assertion succeeds as time difference is exactly = 1h:2403 * <pre><code class='java'> Date date = parseDatetime("2003-04-26T13:00:00Z");2404 * Instant instant = Instant.parse("2003-04-26T14:00:00Z");2405 * assertThat(date).isInSameHourWindowAs(instant);</code></pre>2406 *2407 * Two date/instant can have different hour fields and yet be in the same chronological hour, example:2408 * <pre><code class='java'> Date date = parseDatetime("2003-04-26T13:00:00Z");2409 * Instant instant = Instant.parse("2003-04-26T12:59:59Z");2410 * // succeeds as time difference == 1s2411 * assertThat(date).isInSameHourWindowAs(instant);</code></pre>2412 *2413 * These assertions fail as time difference is equal to or greater than one hour:2414 * <pre><code class='java'> Date date = parseDatetime("2003-04-26T13:00:00Z");2415 * Instant instant = Instant.parse("2003-04-26T14:00:01Z");2416 * Instant instant2 = Instant.parse("2003-04-26T14:00:00Z");2417 * assertThat(date).isInSameHourWindowAs(instant);2418 * assertThat(date).isInSameHourWindowAs(instant2);</code></pre>2419 * <p>2420 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.2421 *2422 * @param other the given {@code Instant} to compare actual {@code Date} to.2423 * @return this assertion object.2424 * @throws NullPointerException if {@code Instant} parameter is {@code null}.2425 * @throws AssertionError if the actual {@code Date} is {@code null}.2426 * @throws AssertionError if actual {@code Date} and given {@code Instant} are not in the same hour.2427 * @since 3.19.02428 */2429 public SELF isInSameHourWindowAs(Instant other) {2430 dates.assertIsInSameHourWindowAs(info, actual, Date.from(other));2431 return myself;2432 }2433 /**2434 * Same assertion as {@link #isInSameHourWindowAs(java.util.Date)} but given date is represented as String either2435 * with one of the supported defaults date format or a user custom date format (set with method2436 * {@link #withDateFormat(DateFormat)}).2437 * <p>2438 * User custom date format take precedence over the default ones.2439 * <p>2440 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.2441 * <p>2442 * Defaults date format (expressed in the local time zone unless specified otherwise) are:2443 * <ul>2444 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>2445 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>2446 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>2447 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>2448 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>2449 * <li><code>yyyy-MM-dd</code></li>2450 * </ul>2451 * <p>2452 * Example of valid string date representations:2453 * <ul>2454 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>2455 * <li><code>2003-04-26T03:01:02.999</code></li>2456 * <li><code>2003-04-26 03:01:02.999</code></li>2457 * <li><code>2003-04-26T03:01:02+00:00</code></li>2458 * <li><code>2003-04-26T13:01:02</code></li>2459 * <li><code>2003-04-26</code></li>2460 * </ul>2461 * <p>2462 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),2463 * you can explicitly specify the date format to use so that the default ones are bypassed.2464 *2465 * @param dateAsString the given Date represented as String in default or custom date format.2466 * @return this assertion object.2467 * @throws NullPointerException if dateAsString parameter is {@code null}.2468 * @throws AssertionError if the actual {@code Date} is {@code null}.2469 * @throws AssertionError if actual and given {@code Date} are not in the same day of month.2470 */2471 public SELF isInSameHourWindowAs(String dateAsString) {2472 return isInSameHourWindowAs(parse(dateAsString));2473 }2474 /**2475 * Verifies that actual and given {@code Date} have same hour, day, month and year fields values.2476 * <p>2477 * Example:2478 * <pre><code class='java'> Date date1 = parseDatetime("2003-01-01T12:00:00");2479 * Date date2 = parseDatetime("2003-01-01T12:30:00");2480 *2481 * // succeeds2482 * assertThat(date1).isInSameHourAs(date2);</code></pre>2483 *2484 * <b>This assertion does not make a true chronological comparison</b> since two dates can have different hour fields2485 * and yet be in the same chronological hour, e.g:2486 *2487 * <pre><code class='java'> // dates in the same hour time window but with different hour fields2488 * Date date1 = parseDatetime("2003-01-01T12:00:00");2489 * Date date2 = parseDatetime("2003-01-01T11:59:00");</code></pre>2490 *2491 * If you want to assert that two dates are chronologically in the same hour time window use2492 * {@link #isInSameHourWindowAs(java.util.Date) isInSameHourWindowAs} assertion (note that if2493 * <code>isInSameHourAs</code> succeeds then <code>isInSameHourWindowAs</code> will succeed too).2494 * <p>2495 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.2496 * <p>2497 * This assertion is logically equivalent to {@link #isEqualToIgnoringMinutes(Date)}.2498 *2499 * @param other the given {@code Date} to compare actual {@code Date} to.2500 * @return this assertion object.2501 * @throws NullPointerException if {@code Date} parameter is {@code null}.2502 * @throws AssertionError if the actual {@code Date} is {@code null}.2503 * @throws AssertionError if actual and given {@code Date} are not in the same hour, day, month and year.2504 */2505 public SELF isInSameHourAs(Date other) {2506 dates.assertIsInSameHourAs(info, actual, other);2507 return myself;2508 }2509 /**2510 * Same assertion as {@link #isInSameHourAs(Date)} but given date is represented as String either with one of the2511 * supported defaults date format or a user custom date format (set with method {@link #withDateFormat(DateFormat)}).2512 * <p>2513 * User custom date format take precedence over the default ones.2514 * <p>2515 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.2516 * <p>2517 * Defaults date format (expressed in the local time zone unless specified otherwise) are:2518 * <ul>2519 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>2520 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>2521 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>2522 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>2523 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>2524 * <li><code>yyyy-MM-dd</code></li>2525 * </ul>2526 * <p>2527 * Example of valid string date representations:2528 * <ul>2529 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>2530 * <li><code>2003-04-26T03:01:02.999</code></li>2531 * <li><code>2003-04-26 03:01:02.999</code></li>2532 * <li><code>2003-04-26T03:01:02+00:00</code></li>2533 * <li><code>2003-04-26T13:01:02</code></li>2534 * <li><code>2003-04-26</code></li>2535 * </ul>2536 * <p>2537 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),2538 * you can explicitly specify the date format to use so that the default ones are bypassed.2539 * <p>2540 * This assertion is logically equivalent to {@link #isEqualToIgnoringMinutes(String)}.2541 *2542 * @param dateAsString the given Date represented as String in default or custom date format.2543 * @return this assertion object.2544 * @throws NullPointerException if dateAsString parameter is {@code null}.2545 * @throws AssertionError if the actual {@code Date} is {@code null}.2546 * @throws AssertionError if actual and given {@code Date} are not in the same hour.2547 */2548 public SELF isInSameHourAs(String dateAsString) {2549 return isInSameHourAs(parse(dateAsString));2550 }2551 /**2552 * Verifies that actual and given {@code Date} are chronologically in the same minute (i.e. their time difference &lt; 12553 * minute).2554 * <p>2555 * Example:2556 * <pre><code class='java'> Date date1 = parseDatetime("2003-01-01T12:01:00");2557 * Date date2 = parseDatetime("2003-01-01T12:01:30");2558 *2559 * // succeeds because date time difference &lt; 1 min2560 * assertThat(date1).isInSameMinuteWindowAs(date2);</code></pre>2561 *2562 * Two dates can have different minute fields and yet be in the same chronological minute, example:2563 * <pre><code class='java'> Date date1 = parseDatetime("2003-01-01T12:01:00");2564 * Date date3 = parseDatetime("2003-01-01T12:00:59");2565 *2566 * // succeeds as time difference == 1s even though minute fields differ2567 * assertThat(date1).isInSameMinuteWindowAs(date3);</code></pre>2568 *2569 * This assertion fails as time difference is &ge; 1 min:2570 * <pre><code class='java'> Date date1 = parseDatetime("2003-01-01T12:01:00");2571 * Date date2 = parseDatetime("2003-01-01T12:02:00");2572 * assertThat(date1).isInSameMinuteWindowAs(date2);</code></pre>2573 *2574 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.2575 *2576 * @param other the given {@code Date} to compare actual {@code Date} to.2577 * @return this assertion object.2578 * @throws NullPointerException if {@code Date} parameter is {@code null}.2579 * @throws AssertionError if the actual {@code Date} is {@code null}.2580 * @throws AssertionError if actual and given {@code Date} are not in the same minute.2581 */2582 public SELF isInSameMinuteWindowAs(Date other) {2583 dates.assertIsInSameMinuteWindowAs(info, actual, other);2584 return myself;2585 }2586 /**2587 * Verifies that actual {@code Date} and given {@code Instant} are chronologically in the same minute (i.e. their time difference &lt; 12588 * minute).2589 * <p>2590 * Example:2591 * <pre><code class='java'> Date date = parseDatetime("2003-01-01T12:01:00Z");2592 * Instant instant = Instant.parse("2003-01-01T12:01:30Z");2593 *2594 * // succeeds because date time difference &lt; 1 min2595 * assertThat(date).isInSameMinuteWindowAs(instant);</code></pre>2596 *2597 * Two date/instant can have different minute fields and yet be in the same chronological minute, example:2598 * <pre><code class='java'> Date date = parseDatetime("2003-01-01T12:01:00Z");2599 * Instant instant = Instant.parse("2003-01-01T12:00:59Z");2600 *2601 * // succeeds as time difference == 1s even though minute fields differ2602 * assertThat(date).isInSameMinuteWindowAs(instant);</code></pre>2603 *2604 * This assertion fails as time difference is &ge; 1 min:2605 * <pre><code class='java'> Date date = parseDatetime("2003-01-01T12:01:00Z");2606 * Instant instant = Instant.parse("2003-01-01T12:02:00Z");2607 * assertThat(date).isInSameMinuteWindowAs(instant);</code></pre>2608 *2609 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.2610 *2611 * @param other the given {@code Instant} to compare actual {@code Date} to.2612 * @return this assertion object.2613 * @throws NullPointerException if {@code Instant} parameter is {@code null}.2614 * @throws AssertionError if the actual {@code Date} is {@code null}.2615 * @throws AssertionError if actual {@code Date} and given {@code Instant} are not in the same minute.2616 * @since 3.19.02617 */2618 public SELF isInSameMinuteWindowAs(Instant other) {2619 dates.assertIsInSameMinuteWindowAs(info, actual, Date.from(other));2620 return myself;2621 }2622 /**2623 * Same assertion as {@link #isInSameMinuteWindowAs(Date)} but given date is represented as String either with one of2624 * the supported defaults date format or a user custom date format (set with method2625 * {@link #withDateFormat(DateFormat)}).2626 * <p>2627 * User custom date format take precedence over the default ones.2628 * <p>2629 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.2630 * <p>2631 * Defaults date format (expressed in the local time zone unless specified otherwise) are:2632 * <ul>2633 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>2634 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>2635 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>2636 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>2637 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>2638 * <li><code>yyyy-MM-dd</code></li>2639 * </ul>2640 * <p>2641 * Example of valid string date representations:2642 * <ul>2643 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>2644 * <li><code>2003-04-26T03:01:02.999</code></li>2645 * <li><code>2003-04-26 03:01:02.999</code></li>2646 * <li><code>2003-04-26T03:01:02+00:00</code></li>2647 * <li><code>2003-04-26T13:01:02</code></li>2648 * <li><code>2003-04-26</code></li>2649 * </ul>2650 * <p>2651 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),2652 * you can explicitly specify the date format to use so that the default ones are bypassed.2653 *2654 * @param dateAsString the given Date represented as String in default or custom date format.2655 * @return this assertion object.2656 * @throws NullPointerException if dateAsString parameter is {@code null}.2657 * @throws AssertionError if the actual {@code Date} is {@code null}.2658 * @throws AssertionError if actual and given {@code Date} are not in the same minute.2659 */2660 public SELF isInSameMinuteWindowAs(String dateAsString) {2661 return isInSameMinuteWindowAs(parse(dateAsString));2662 }2663 /**2664 * Verifies that actual and given {@code Date} have same minute, same hour, day, month and year fields values.2665 * <p>2666 * Example:2667 * <pre><code class='java'> Date date1 = parseDatetime("2003-01-01T12:01:00");2668 * Date date2 = parseDatetime("2003-01-01T12:01:30");2669 *2670 * // succeeds because the all the fields up to minutes are the same2671 * assertThat(date1).isInSameMinuteAs(date2);</code></pre>2672 *2673 * <b>It does not make a true chronological comparison</b> since two dates can have different minute fields and yet be2674 * in the same chronological minute, e.g:2675 * <pre><code class='java'> // dates in the same minute time window but with different minute fields2676 * Date date1 = parseDatetime("2003-01-01T12:01:00");2677 * Date date3 = parseDatetime("2003-01-01T12:00:59");2678 *2679 * // fails because minutes fields differ even though time difference is only 1s !2680 * assertThat(date1).isInSameMinuteAs(date3); // ERROR</code></pre>2681 *2682 * If you want to assert that two dates are in the same minute time window use2683 * {@link #isInSameMinuteWindowAs(java.util.Date) isInSameMinuteWindowAs} assertion (note that if2684 * <code>isInSameMinuteAs</code> succeeds then <code>isInSameMinuteWindowAs</code> will succeed too).2685 * <p>2686 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.2687 * <p>2688 * This assertion is logically equivalent to {@link #isEqualToIgnoringSeconds(Date)}.2689 *2690 * @param other the given {@code Date} to compare actual {@code Date} to.2691 * @return this assertion object.2692 * @throws NullPointerException if {@code Date} parameter is {@code null}.2693 * @throws AssertionError if the actual {@code Date} is {@code null}.2694 * @throws AssertionError if actual and given {@code Date} are not in the same minute.2695 */2696 public SELF isInSameMinuteAs(Date other) {2697 dates.assertIsInSameMinuteAs(info, actual, other);2698 return myself;2699 }2700 /**2701 * Same assertion as {@link #isInSameMinuteAs(Date)} but given date is represented as String either with one of the2702 * supported defaults date format or a user custom date format (set with method {@link #withDateFormat(DateFormat)}).2703 * <p>2704 * User custom date format take precedence over the default ones.2705 * <p>2706 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.2707 * <p>2708 * Defaults date format (expressed in the local time zone unless specified otherwise) are:2709 * <ul>2710 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>2711 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>2712 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>2713 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>2714 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>2715 * <li><code>yyyy-MM-dd</code></li>2716 * </ul>2717 * <p>2718 * Example of valid string date representations:2719 * <ul>2720 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>2721 * <li><code>2003-04-26T03:01:02.999</code></li>2722 * <li><code>2003-04-26 03:01:02.999</code></li>2723 * <li><code>2003-04-26T03:01:02+00:00</code></li>2724 * <li><code>2003-04-26T13:01:02</code></li>2725 * <li><code>2003-04-26</code></li>2726 * </ul>2727 * <p>2728 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),2729 * you can explicitly specify the date format to use so that the default ones are bypassed.2730 * <p>2731 * This assertion is logically equivalent to {@link #isEqualToIgnoringSeconds(String)}.2732 *2733 * @param dateAsString the given Date represented as String in default or custom date format.2734 * @return this assertion object.2735 * @throws NullPointerException if dateAsString parameter is {@code null}.2736 * @throws AssertionError if the actual {@code Date} is {@code null}.2737 * @throws AssertionError if actual and given {@code Date} are not in the same minute.2738 */2739 public SELF isInSameMinuteAs(String dateAsString) {2740 return isInSameMinuteAs(parse(dateAsString));2741 }2742 /**2743 * Verifies that actual and given {@code Date} are chronologically strictly in the same second (i.e. their time2744 * difference &lt; 1 second).2745 * <p>2746 * Example:2747 * <pre><code class='java'> Date date1 = parseDatetimeWithMs("2003-04-26T13:01:02.123");2748 * Date date2 = parseDatetimeWithMs("2003-04-26T13:01:02.456");2749 *2750 * // succeeds as time difference is &lt; 1s2751 * assertThat(date1).isInSameSecondWindowAs(date2);</code></pre>2752 *2753 * Two dates can have different second fields and yet be in the same chronological second, example:2754 * <pre><code class='java'> Date date1 = parseDatetimeWithMs("2003-04-26T13:01:02.999");2755 * Date date2 = parseDatetimeWithMs("2003-04-26T13:01:03.000");2756 *2757 * // succeeds as time difference is 1ms &lt; 1s2758 * assertThat(date1).isInSameSecondWindowAs(date2);</code></pre>2759 *2760 * Those assertions fail as time difference is greater or equal to one second:2761 * <pre><code class='java'> Date date1 = parseDatetimeWithMs("2003-04-26T13:01:01.000");2762 * Date date2 = parseDatetimeWithMs("2003-04-26T13:01:02.000");2763 *2764 * // fails as time difference = 1s2765 * assertThat(date1).isInSameSecondWindowAs(date2);2766 *2767 * Date date3 = parseDatetimeWithMs("2003-04-26T13:01:02.001");2768 * // fails as time difference &gt; 1s2769 * assertThat(date1).isInSameSecondWindowAs(date3);</code></pre>2770 *2771 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.2772 *2773 * @param other the given {@code Date} to compare actual {@code Date} to.2774 * @return this assertion object.2775 * @throws NullPointerException if {@code Date} parameter is {@code null}.2776 * @throws AssertionError if the actual {@code Date} is {@code null}.2777 * @throws AssertionError if actual and given {@code Date} are not in the same second.2778 */2779 public SELF isInSameSecondWindowAs(Date other) {2780 dates.assertIsInSameSecondWindowAs(info, actual, other);2781 return myself;2782 }2783 /**2784 * Verifies that actual {@code Date} and given {@code Instant} are chronologically strictly in the same second (i.e. their time2785 * difference &lt; 1 second).2786 * <p>2787 * Example:2788 * <pre><code class='java'> Date date = parseDatetimeWithMs("2003-04-26T13:01:02.123Z");2789 * Instant instant = Instant.parse("2003-04-26T13:01:02.456Z");2790 *2791 * // succeeds as time difference is &lt; 1s2792 * assertThat(date).isInSameSecondWindowAs(instant);</code></pre>2793 *2794 * Two dates can have different second fields and yet be in the same chronological second, example:2795 * <pre><code class='java'> Date date = parseDatetimeWithMs("2003-04-26T13:01:02.999Z");2796 * Instant instant = Instant.parse("2003-04-26T13:01:03.000Z");2797 *2798 * // succeeds as time difference is 1ms &lt; 1s2799 * assertThat(date).isInSameSecondWindowAs(instant);</code></pre>2800 *2801 * Those assertions fail as time difference is greater or equal to one second:2802 * <pre><code class='java'> Date date = parseDatetimeWithMs("2003-04-26T13:01:01.000Z");2803 * Instant instant = Instant.parse("2003-04-26T13:01:02.000Z");2804 *2805 * // fails as time difference = 1s2806 * assertThat(date).isInSameSecondWindowAs(instant);2807 *2808 * Instant instant2 = Instant.parse("2003-04-26T13:01:02.001Z");2809 * // fails as time difference &gt; 1s2810 * assertThat(date).isInSameSecondWindowAs(instant2);</code></pre>2811 *2812 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.2813 *2814 * @param other the given {@code Instant} to compare actual {@code Date} to.2815 * @return this assertion object.2816 * @throws NullPointerException if {@code Instant} parameter is {@code null}.2817 * @throws AssertionError if the actual {@code Date} is {@code null}.2818 * @throws AssertionError if actual {@code Date} and given {@code Instant} are not in the same second.2819 * @since 3.19.02820 */2821 public SELF isInSameSecondWindowAs(Instant other) {2822 dates.assertIsInSameSecondWindowAs(info, actual, Date.from(other));2823 return myself;2824 }2825 /**2826 * Same assertion as {@link #isInSameSecondWindowAs(Date)} but given date is represented as String either with one of2827 * the supported defaults date format or a user custom date format (set with method2828 * {@link #withDateFormat(DateFormat)}).2829 * <p>2830 * User custom date format take precedence over the default ones.2831 * <p>2832 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.2833 * <p>2834 * Defaults date format (expressed in the local time zone unless specified otherwise) are:2835 * <ul>2836 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>2837 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>2838 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>2839 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>2840 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>2841 * <li><code>yyyy-MM-dd</code></li>2842 * </ul>2843 * <p>2844 * Example of valid string date representations:2845 * <ul>2846 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>2847 * <li><code>2003-04-26T03:01:02.999</code></li>2848 * <li><code>2003-04-26 03:01:02.999</code></li>2849 * <li><code>2003-04-26T03:01:02+00:00</code></li>2850 * <li><code>2003-04-26T13:01:02</code></li>2851 * <li><code>2003-04-26</code></li>2852 * </ul>2853 * <p>2854 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),2855 * you can explicitly specify the date format to use so that the default ones are bypassed.2856 *2857 * @param dateAsString the given Date represented as String.2858 * @return this assertion object.2859 * @throws NullPointerException if dateAsString parameter is {@code null}.2860 * @throws AssertionError if the actual {@code Date} is {@code null}.2861 * @throws AssertionError if actual and given {@code Date} are not in the same second.2862 */2863 public SELF isInSameSecondWindowAs(String dateAsString) {2864 return isInSameSecondWindowAs(parse(dateAsString));2865 }2866 /**2867 * Verifies that actual and given {@code Date} have same second, minute, hour, day, month and year fields values.2868 *2869 * <pre><code class='java'> Date date1 = parseDatetimeWithMs("2003-01-01T12:00:01.000");2870 * Date date2 = parseDatetimeWithMs("2003-01-01T12:00:01.250");2871 *2872 * // succeeds because the all the time fields up to seconds are the same2873 * assertThat(date1).isInSameSecondAs(date2);</code></pre>2874 *2875 * <b>It does not make a true chronological comparison</b> since two dates can have different second fields and yet2876 * be2877 * in the same chronological second, e.g:2878 * <pre><code class='java'> Date date1 = parseDatetimeWithMs("2003-01-01T12:00:01.000");2879 * Date date3 = parseDatetimeWithMs("2003-01-01T12:00:00.999");2880 *2881 * // fails because seconds fields differ even though time difference is only 1ms !2882 * assertThat(date1).isInSameSecondAs(date3); // ERROR</code></pre>2883 *2884 * If you want to assert that two dates are in the same second time window use2885 * {@link #isInSameSecondWindowAs(java.util.Date) isInSameSecondWindowAs} assertion.2886 * <p>2887 * If you want to compare second fields only (without minute, hour, day, month and year), you could write :2888 * <code>assertThat(myDate).hasSecond(secondOf(otherDate))</code><br>2889 * using {@link org.assertj.core.util.DateUtil#secondOf(Date)} to get the second of a given Date.2890 * <p>2891 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.2892 * <p>2893 * This assertion is logically equivalent to {@link #isEqualToIgnoringMillis(Date)}.2894 *2895 * @param other the given {@code Date} to compare actual {@code Date} to.2896 * @return this assertion object.2897 * @throws NullPointerException if {@code Date} parameter is {@code null}.2898 * @throws AssertionError if the actual {@code Date} is {@code null}.2899 * @throws AssertionError if actual and given {@code Date} are not in the same second.2900 */2901 public SELF isInSameSecondAs(Date other) {2902 dates.assertIsInSameSecondAs(info, actual, other);2903 return myself;2904 }2905 /**2906 * Same assertion as {@link #isInSameSecondAs(Date)} but given date is represented as String either with one of the2907 * supported defaults date format or a user custom date format (set with method {@link #withDateFormat(DateFormat)}).2908 * <p>2909 * User custom date format take precedence over the default ones.2910 * <p>2911 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.2912 * <p>2913 * Defaults date format (expressed in the local time zone unless specified otherwise) are:2914 * <ul>2915 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>2916 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>2917 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>2918 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>2919 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>2920 * <li><code>yyyy-MM-dd</code></li>2921 * </ul>2922 * <p>2923 * Example of valid string date representations:2924 * <ul>2925 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>2926 * <li><code>2003-04-26T03:01:02.999</code></li>2927 * <li><code>2003-04-26 03:01:02.999</code></li>2928 * <li><code>2003-04-26T03:01:02+00:00</code></li>2929 * <li><code>2003-04-26T13:01:02</code></li>2930 * <li><code>2003-04-26</code></li>2931 * </ul>2932 * <p>2933 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),2934 * you can explicitly specify the date format to use so that the default ones are bypassed.2935 * <p>2936 * This assertion is logically equivalent to {@link #isEqualToIgnoringMillis(String)}.2937 *2938 * @param dateAsString the given Date represented as String.2939 * @return this assertion object.2940 */2941 public SELF isInSameSecondAs(String dateAsString) {2942 return isInSameSecondAs(parse(dateAsString));2943 }2944 /**2945 * Verifies that the actual {@code Date} is close to the other date by less than delta (expressed in milliseconds),2946 * if2947 * difference is equal to delta it's ok.2948 * <p>2949 * One can use handy {@link TimeUnit} to convert a duration in milliseconds, for example you can express a delta of 52950 * seconds with <code>TimeUnit.SECONDS.toMillis(5)</code>.2951 * <p>2952 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.2953 * <p>2954 * Example:2955 * <pre><code class='java'> Date date1 = new Date();2956 * Date date2 = new Date(date1.getTime() + 100);2957 *2958 * // assertion succeeds2959 * assertThat(date1).isCloseTo(date2, 80)2960 * .isCloseTo(date2, 100);2961 *2962 * // assertion fails2963 * assertThat(date1).isCloseTo(date2, 101);</code></pre>2964 *2965 * @param other the date to compare actual to2966 * @param deltaInMilliseconds the delta used for date comparison, expressed in milliseconds2967 * @return this assertion object.2968 * @throws NullPointerException if {@code Date} parameter is {@code null}.2969 * @throws AssertionError if the actual {@code Date} is {@code null}.2970 * @throws AssertionError if the actual {@code Date} is not close to the given date by less than delta.2971 */2972 public SELF isCloseTo(Date other, long deltaInMilliseconds) {2973 dates.assertIsCloseTo(info, actual, other, deltaInMilliseconds);2974 return myself;2975 }2976 /**2977 * Verifies that the actual {@code Date} is close to the given {@code Instant} by less than delta (expressed in milliseconds),2978 * if the difference is equal to delta the assertion succeeds.2979 * <p>2980 * One can use handy {@link TimeUnit} to convert a duration in milliseconds, for example you can express a delta of 52981 * seconds with <code>TimeUnit.SECONDS.toMillis(5)</code>.2982 * <p>2983 * Note that using a {@link #usingComparator(Comparator) custom comparator} has no effect on this assertion.2984 * <p>2985 * Example:2986 * <pre><code class='java'> Date date = new Date();2987 *2988 * // assertions succeed2989 * assertThat(date).isCloseTo(date.toInstant().plusMillis(80), 80)2990 * .isCloseTo(date.toInstant().plusMillis(80), 100);2991 *2992 * // assertions fails2993 * assertThat(date).isCloseTo(date.toInstant().minusMillis(101), 100);</code></pre>2994 *2995 * @param other the Instant to compare actual to2996 * @param deltaInMilliseconds the delta used for date comparison, expressed in milliseconds2997 * @return this assertion object.2998 * @throws NullPointerException if {@code Instant} parameter is {@code null}.2999 * @throws AssertionError if the actual {@code Date} is {@code null}.3000 * @throws AssertionError if the actual {@code Date} is not close to the given Instant by less than delta.3001 * @since 3.19.03002 */3003 public SELF isCloseTo(Instant other, long deltaInMilliseconds) {3004 dates.assertIsCloseTo(info, actual, Date.from(other), deltaInMilliseconds);3005 return myself;3006 }3007 /**3008 * Same assertion as {@link #isCloseTo(Date, long)} but given date is represented as String either with one of the3009 * supported defaults date format or a user custom date format (set with method {@link #withDateFormat(DateFormat)}).3010 * <p>3011 * User custom date format take precedence over the default ones.3012 * <p>3013 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.3014 * <p>3015 * Defaults date format (expressed in the local time zone unless specified otherwise) are:3016 * <ul>3017 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>3018 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>3019 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>3020 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>3021 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>3022 * <li><code>yyyy-MM-dd</code></li>3023 * </ul>3024 * <p>3025 * Example of valid string date representations:3026 * <ul>3027 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>3028 * <li><code>2003-04-26T03:01:02.999</code></li>3029 * <li><code>2003-04-26 03:01:02.999</code></li>3030 * <li><code>2003-04-26T03:01:02+00:00</code></li>3031 * <li><code>2003-04-26T13:01:02</code></li>3032 * <li><code>2003-04-26</code></li>3033 * </ul>3034 * <p>3035 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),3036 * you can explicitly specify the date format to use so that the default ones are bypassed.3037 *3038 * @param dateAsString the given Date represented as String in default or custom date format.3039 * @param deltaInMilliseconds the delta used for date comparison, expressed in milliseconds3040 * @return this assertion object.3041 * @throws NullPointerException if dateAsString parameter is {@code null}.3042 * @throws AssertionError if the actual {@code Date} is {@code null}.3043 * @throws AssertionError if the actual {@code Date} is not close to the given date by less than delta.3044 */3045 public SELF isCloseTo(String dateAsString, long deltaInMilliseconds) {3046 return isCloseTo(parse(dateAsString), deltaInMilliseconds);3047 }3048 /**3049 * Verifies that the actual {@code Date} has the same time as the given timestamp.3050 * <p>3051 * Both time or timestamp express a number of milliseconds since January 1, 1970, 00:00:00 GMT.3052 * <p>3053 * Example:3054 * <pre><code class='java'> assertThat(new Date(42)).hasTime(42);</code></pre>3055 *3056 * @param timestamp the timestamp to compare actual time to.3057 * @return this assertion object.3058 * @throws AssertionError if the actual {@code Date} is {@code null}.3059 * @throws AssertionError if the actual {@code Date} time is not equal to the given timestamp.3060 * @see Date#getTime()3061 */3062 public SELF hasTime(long timestamp) {3063 dates.assertHasTime(info, actual, timestamp);3064 return myself;3065 }3066 /**3067 * Verifies that the actual {@code Date} has the same time as the given date, useful to compare {@link Date} and3068 * {@link java.sql.Timestamp}.3069 * <p>3070 * Example:3071 * <pre><code class='java'> Date date = new Date();3072 * Timestamp timestamp = new Timestamp(date.getTime());3073 *3074 * // Fail as date is not an instance of Timestamp3075 * assertThat(date).isEqualTo(timestamp);3076 *3077 * // Succeed as we compare date and timestamp time.3078 * assertThat(date).hasSameTimeAs(timestamp);</code></pre>3079 *3080 * @param date the date to compare actual time to.3081 * @return this assertion object.3082 * @throws AssertionError if the actual {@code Date} is {@code null}.3083 * @throws AssertionError if the actual {@code Date} time is not equal to the given date time.3084 * @throws NullPointerException if {@code Date} parameter is {@code null}.3085 * @see Date#getTime()3086 */3087 public SELF hasSameTimeAs(Date date) {3088 dates.hasSameTimeAs(info, actual, date);3089 return myself;3090 }3091 /**3092 * Verifies that the actual {@code Date} represents the same time as the given date in {@code String} format.3093 * <p>3094 * It is the same assertion as {@link #hasSameTimeAs(Date)} but given date is represented as String either with one of3095 * the supported default date formats or a user custom date format (set with method3096 * {@link #withDateFormat(DateFormat)}).3097 * <p>3098 * User custom date format take precedence over the default ones.3099 * <p>3100 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.3101 * <p>3102 * Example:3103 * <pre><code class='java'> Date date = parseDatetime("2003-04-26T12:00:00");3104 *3105 * // assertion will pass3106 * assertThat(date).hasSameTimeAs("2003-04-26T12:00:00");3107 *3108 * // assertion will fail3109 * assertThat(date).hasSameTimeAs("2003-04-26T12:00:01");3110 * assertThat(date).hasSameTimeAs("2003-04-27T12:00:00")</code></pre>3111 * <p>3112 * Defaults date format (expressed in the local time zone unless specified otherwise) are:3113 * <ul>3114 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>3115 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>3116 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>3117 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>3118 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>3119 * <li><code>yyyy-MM-dd</code></li>3120 * </ul>3121 * <p>3122 * Example of valid string date representations:3123 * <ul>3124 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>3125 * <li><code>2003-04-26T03:01:02.999</code></li>3126 * <li><code>2003-04-26 03:01:02.999</code></li>3127 * <li><code>2003-04-26T03:01:02+00:00</code></li>3128 * <li><code>2003-04-26T13:01:02</code></li>3129 * <li><code>2003-04-26</code></li>3130 * </ul>3131 * <p>3132 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),3133 * you can explicitly specify the date format to use so that the default ones are bypassed.3134 *3135 * @param dateAsString the given {@code Date} represented as {@code String} in default or custom date format.3136 * @return this assertion object.3137 * @throws AssertionError if the actual {@code Date} is {@code null}.3138 * @throws NullPointerException if given date as String is {@code null}.3139 * @throws AssertionError if the actual {@code Date} time is not equal to the time from date represented as3140 * String.3141 * @throws AssertionError if the given date as String could not be converted to a Date.3142 */3143 public SELF hasSameTimeAs(String dateAsString) {3144 dates.hasSameTimeAs(info, actual, parse(dateAsString));3145 return myself;3146 }3147 /**3148 * Instead of using default date formats for the date String based Date assertions like {@link #isEqualTo(String)},3149 * AssertJ is gonna use any date formats registered with one of these methods :3150 * <ul>3151 * <li>{@link #withDateFormat(String)}</li>3152 * <li>this method</li>3153 * <li>{@link #registerCustomDateFormat(java.text.DateFormat)}</li>3154 * <li>{@link #registerCustomDateFormat(String)}</li>3155 * </ul>3156 * <p>3157 * Beware that :3158 * <ul>3159 * <li>this will be the case for <b>all future Date assertions in the test suite</b></li>3160 * <li>once a custom date format is registered, the default date formats are not used anymore</li>3161 * </ul>3162 * <p>3163 * To revert to default format, call {@link #useDefaultDateFormatsOnly()} or {@link #withDefaultDateFormatsOnly()}.3164 *3165 * @param userCustomDateFormat the new Date format used for String based Date assertions.3166 * @return this assertion object.3167 */3168 @CheckReturnValue3169 public SELF withDateFormat(DateFormat userCustomDateFormat) {3170 registerCustomDateFormat(userCustomDateFormat);3171 return myself;3172 }3173 /**3174 * Instead of using default date formats for the date String based Date assertions like {@link #isEqualTo(String)},3175 * AssertJ is gonna use any date formats registered with one of these methods :3176 * <ul>3177 * <li>this method</li>3178 * <li>{@link #withDateFormat(java.text.DateFormat)}</li>3179 * <li>{@link #registerCustomDateFormat(java.text.DateFormat)}</li>3180 * <li>{@link #registerCustomDateFormat(String)}</li>3181 * </ul>3182 * <p>3183 * Beware that :3184 * <ul>3185 * <li>this will be the case for <b>all future Date assertions in the test suite</b></li>3186 * <li>once a custom date format is registered, the default date formats are not used anymore</li>3187 * </ul>3188 * <p>3189 * To revert to default format, call {@link #useDefaultDateFormatsOnly()} or {@link #withDefaultDateFormatsOnly()}.3190 *3191 * @param userCustomDateFormatPattern the new Date format string pattern used for String based Date assertions.3192 * @return this assertion object.3193 */3194 @CheckReturnValue3195 public SELF withDateFormat(String userCustomDateFormatPattern) {3196 requireNonNull(userCustomDateFormatPattern, DATE_FORMAT_PATTERN_SHOULD_NOT_BE_NULL);3197 return withDateFormat(new SimpleDateFormat(userCustomDateFormatPattern));3198 }3199 /**3200 * Instead of using default strict date/time parsing, it is possible to use lenient parsing mode for default date3201 * formats parser to interpret inputs that do not precisely match supported date formats (lenient parsing).3202 * <p>3203 * With strict parsing, inputs must match exactly date/time format.3204 * <p>3205 * Example:3206 * <pre><code class='java'> final Date date = Dates.parse("2001-02-03");3207 * final Date dateTime = parseDatetime("2001-02-03T04:05:06");3208 * final Date dateTimeWithMs = parseDatetimeWithMs("2001-02-03T04:05:06.700");3209 *3210 * AbstractDateAssert.setLenientDateParsing(true);3211 *3212 * // assertions will pass3213 * assertThat(date).isEqualTo("2001-02-03");3214 * assertThat(date).isEqualTo("2001-02-02T24:00:00");3215 * assertThat(date).isEqualTo("2001-02-04T-24:00:00.000");3216 * assertThat(dateTime).isEqualTo("2001-02-03T04:05:05.1000");3217 * assertThat(dateTime).isEqualTo("2001-02-03T04:04:66");3218 * assertThat(dateTimeWithMs).isEqualTo("2001-02-03T04:05:07.-300");3219 *3220 * // assertions will fail3221 * assertThat(date).hasSameTimeAs("2001-02-04"); // different date3222 * assertThat(dateTime).hasSameTimeAs("2001-02-03 04:05:06"); // leniency does not help here</code></pre>3223 *3224 * To revert to default strict date parsing, call {@code setLenientDateParsing(false)}.3225 *3226 * @param value whether lenient parsing mode should be enabled or not3227 */3228 public static void setLenientDateParsing(boolean value) {3229 ConfigurationProvider.loadRegisteredConfiguration();3230 for (DateFormat defaultDateFormat : DEFAULT_DATE_FORMATS) {3231 defaultDateFormat.setLenient(value);3232 }3233 }3234 /**3235 * Add the given date format to the ones used to parse date String in String based Date assertions like3236 * {@link #isEqualTo(String)}.3237 * <p>3238 * User date formats are used before default ones in the order they have been registered (first registered, first3239 * used).3240 * <p>3241 * AssertJ is gonna use any date formats registered with one of these methods :3242 * <ul>3243 * <li>{@link #withDateFormat(String)}</li>3244 * <li>{@link #withDateFormat(java.text.DateFormat)}</li>3245 * <li>this method</li>3246 * <li>{@link #registerCustomDateFormat(String)}</li>3247 * </ul>3248 * <p>3249 * Beware that AssertJ will use the newly registered format for <b>all remaining Date assertions in the test suite</b>3250 * <p>3251 * To revert to default formats only, call {@link #useDefaultDateFormatsOnly()} or3252 * {@link #withDefaultDateFormatsOnly()}.3253 * <p>3254 * Code examples:3255 * <pre><code class='java'> Date date = ... // set to 2003 April the 26th3256 * assertThat(date).isEqualTo("2003-04-26");3257 *3258 * try {3259 * // date with a custom format : failure since the default formats don't match.3260 * assertThat(date).isEqualTo("2003/04/26");3261 * } catch (AssertionError e) {3262 * assertThat(e).hasMessage("Failed to parse 2003/04/26 with any of these date formats: " +3263 * "[yyyy-MM-dd'T'HH:mm:ss.SSS, yyyy-MM-dd'T'HH:mm:ss, yyyy-MM-dd]");3264 * }3265 *3266 * // registering a custom date format to make the assertion pass3267 * registerCustomDateFormat(new SimpleDateFormat("yyyy/MM/dd")); // registerCustomDateFormat("yyyy/MM/dd") would work to.3268 * assertThat(date).isEqualTo("2003/04/26");3269 *3270 * // the default formats are still available and should work3271 * assertThat(date).isEqualTo("2003-04-26");</code></pre>3272 *3273 * @param userCustomDateFormat the new Date format used for String based Date assertions.3274 */3275 public static void registerCustomDateFormat(DateFormat userCustomDateFormat) {3276 ConfigurationProvider.loadRegisteredConfiguration();3277 requireNonNull(userCustomDateFormat, DATE_FORMAT_SHOULD_NOT_BE_NULL);3278 userDateFormats.get().add(userCustomDateFormat);3279 }3280 /**3281 * Add the given date format to the ones used to parse date String in String based Date assertions like3282 * {@link #isEqualTo(String)}.3283 * <p>3284 * User date formats are used before default ones in the order they have been registered (first registered, first3285 * used).3286 * <p>3287 * AssertJ is gonna use any date formats registered with one of these methods :3288 * <ul>3289 * <li>{@link #withDateFormat(String)}</li>3290 * <li>{@link #withDateFormat(java.text.DateFormat)}</li>3291 * <li>{@link #registerCustomDateFormat(java.text.DateFormat)}</li>3292 * <li>this method</li>3293 * </ul>3294 * <p>3295 * Beware that AssertJ will use the newly registered format for <b>all remaining Date assertions in the test suite</b>3296 * <p>3297 * To revert to default formats only, call {@link #useDefaultDateFormatsOnly()} or3298 * {@link #withDefaultDateFormatsOnly()}.3299 * <p>3300 * Code examples:3301 * <pre><code class='java'> Date date = ... // set to 2003 April the 26th3302 * assertThat(date).isEqualTo("2003-04-26");3303 *3304 * try {3305 * // date with a custom format : failure since the default formats don't match.3306 * assertThat(date).isEqualTo("2003/04/26");3307 * } catch (AssertionError e) {3308 * assertThat(e).hasMessage("Failed to parse 2003/04/26 with any of these date formats: " +3309 * "[yyyy-MM-dd'T'HH:mm:ss.SSS, yyyy-MM-dd'T'HH:mm:ss, yyyy-MM-dd]");3310 * }3311 *3312 * // registering a custom date format to make the assertion pass3313 * registerCustomDateFormat("yyyy/MM/dd");3314 * assertThat(date).isEqualTo("2003/04/26");3315 *3316 * // the default formats are still available and should work3317 * assertThat(date).isEqualTo("2003-04-26");</code></pre>3318 *3319 * @param userCustomDateFormatPattern the new Date format pattern used for String based Date assertions.3320 */3321 public static void registerCustomDateFormat(String userCustomDateFormatPattern) {3322 requireNonNull(userCustomDateFormatPattern, DATE_FORMAT_PATTERN_SHOULD_NOT_BE_NULL);3323 registerCustomDateFormat(new SimpleDateFormat(userCustomDateFormatPattern));3324 }3325 /**3326 * Remove all registered custom date formats =&gt; use only the defaults date formats to parse string as date.3327 * <p>3328 * User custom date format take precedence over the default ones.3329 * <p>3330 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.3331 * <p>3332 * Defaults date format (expressed in the local time zone unless specified otherwise) are:3333 * <ul>3334 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>3335 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>3336 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>3337 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>3338 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>3339 * <li><code>yyyy-MM-dd</code></li>3340 * </ul>3341 * <p>3342 * Example of valid string date representations:3343 * <ul>3344 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>3345 * <li><code>2003-04-26T03:01:02.999</code></li>3346 * <li><code>2003-04-26 03:01:02.999</code></li>3347 * <li><code>2003-04-26T03:01:02+00:00</code></li>3348 * <li><code>2003-04-26T13:01:02</code></li>3349 * <li><code>2003-04-26</code></li>3350 * </ul>3351 * <p>3352 * If you are getting an {@code IllegalArgumentException} with <i>"Unknown pattern character 'X'"</i> message (some Android versions don't support it),3353 * you can explicitly specify the date format to use so that the default ones are bypassed.3354 */3355 public static void useDefaultDateFormatsOnly() {3356 userDateFormats.get().clear();3357 }3358 /**3359 * Remove all registered custom date formats =&gt; use only the defaults date formats to parse string as date.3360 * <p>3361 * User custom date format take precedence over the default ones.3362 * <p>3363 * Unless specified otherwise, beware that the default formats are expressed in the current local timezone.3364 * <p>3365 * Defaults date format (expressed in the local time zone unless specified otherwise) are:3366 * <ul>3367 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSSX</code> (in ISO Time zone)</li>3368 * <li><code>yyyy-MM-dd'T'HH:mm:ss.SSS</code></li>3369 * <li><code>yyyy-MM-dd HH:mm:ss.SSS</code></li>3370 * <li><code>yyyy-MM-dd'T'HH:mm:ssX</code> (in ISO Time zone)</li>3371 * <li><code>yyyy-MM-dd'T'HH:mm:ss</code></li>3372 * <li><code>yyyy-MM-dd</code></li>3373 * </ul>3374 * <p>3375 * Example of valid string date representations:3376 * <ul>3377 * <li><code>2003-04-26T03:01:02.758+00:00</code></li>3378 * <li><code>2003-04-26T03:01:02.999</code></li>3379 * <li><code>2003-04-26 03:01:02.999</code></li>3380 * <li><code>2003-04-26T03:01:02+00:00</code></li>3381 * <li><code>2003-04-26T13:01:02</code></li>3382 * <li><code>2003-04-26</code></li>3383 * </ul>3384 *3385 * @return this assertion3386 */3387 @CheckReturnValue3388 public SELF withDefaultDateFormatsOnly() {3389 useDefaultDateFormatsOnly();3390 return myself;3391 }3392 /**3393 * Thread safe utility method to parse a Date with {@link #userDateFormats} first, then {@link #DEFAULT_DATE_FORMATS}.3394 * <p>3395 * Returns <code>null</code> if dateAsString parameter is <code>null</code>.3396 *3397 * @param dateAsString the string to parse as a Date with {@link #userDateFormats}3398 * @return the corresponding Date, null if dateAsString parameter is null.3399 * @throws AssertionError if the string can't be parsed as a Date3400 */3401 @VisibleForTesting3402 Date parse(String dateAsString) {3403 if (dateAsString == null) return null;3404 // parse with date format specified by user if any, otherwise use default formats3405 // no synchronization needed as userCustomDateFormat is thread local3406 Date date = parseDateWith(dateAsString, userDateFormats.get());3407 if (date != null) return date;3408 // no matching user date format, let's try default format3409 date = parseDateWithDefaultDateFormats(dateAsString);3410 if (date != null) return date;3411 // no matching date format, throw an error3412 throw new AssertionError(String.format("Failed to parse %s with any of these date formats:%n %s", dateAsString,3413 info.representation().toStringOf(dateFormatsInOrderOfUsage())));3414 }3415 private Date parseDateWithDefaultDateFormats(final String dateAsString) {3416 synchronized (DEFAULT_DATE_FORMATS) {3417 return parseDateWith(dateAsString, DEFAULT_DATE_FORMATS);3418 }3419 }3420 private List<DateFormat> dateFormatsInOrderOfUsage() {3421 List<DateFormat> allDateFormatsInOrderOfUsage = newArrayList(userDateFormats.get());3422 allDateFormatsInOrderOfUsage.addAll(DEFAULT_DATE_FORMATS);3423 return allDateFormatsInOrderOfUsage;3424 }3425 private Date parseDateWith(final String dateAsString, final Collection<DateFormat> dateFormats) {3426 for (DateFormat defaultDateFormat : dateFormats) {3427 try {3428 return defaultDateFormat.parse(dateAsString);3429 } catch (@SuppressWarnings("unused") ParseException e) {3430 // ignore and try next date format3431 }3432 }3433 return null;3434 }3435 private static <T> Date[] toDateArray(T[] values, Function<T, Date> converter) {3436 Date[] dates = new Date[values.length];3437 for (int i = 0; i < values.length; i++) {3438 dates[i] = converter.apply(values[i]);3439 }3440 return dates;3441 }3442 @Override3443 @CheckReturnValue3444 public SELF usingComparator(Comparator<? super Date> customComparator) {3445 return usingComparator(customComparator, null);3446 }3447 @Override3448 @CheckReturnValue3449 public SELF usingComparator(Comparator<? super Date> customComparator, String customComparatorDescription) {...

Full Screen

Full Screen

toDateArray

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.Assertions;2import org.junit.Test;3import java.util.Date;4public class DateAssertTest {5 public void testDateAssert() {6 Date date = new Date();7 Assertions.assertThat(date).isInSameMinuteWindowAs(date);8 }9}10 Assertions.assertThat(date).isInSameMinuteWindowAs(date)

Full Screen

Full Screen

toDateArray

Using AI Code Generation

copy

Full Screen

1assertThat(date).toDateArray().containsExactly(2018, 11, 5);2assertThat(instant).toDateArray().containsExactly(2018, 11, 5, 12, 30, 40, 123);3assertThat(localDate).toDateArray().containsExactly(2018, 11, 5);4assertThat(localDateTime).toDateArray().containsExactly(2018, 11, 5, 12, 30, 40, 123);5assertThat(offsetDateTime).toDateArray().containsExactly(2018, 11, 5, 12, 30, 40, 123);6assertThat(zonedDateTime).toDateArray().containsExactly(2018, 11, 5, 12, 30, 40, 123);7assertThat(offsetTime).toDateArray().containsExactly(12, 30, 40, 123);8assertThat(localTime).toDateArray().containsExactly(12, 30, 40, 123);9assertThat(year).toDateArray().containsExactly(2018);10assertThat(yearMonth).toDateArray().containsExactly(2018, 11);11assertThat(monthDay).toDateArray().containsExactly(11, 5);12assertThat(month).toDateArray().containsExactly(11);13assertThat(duration).toDateArray().containsExactly(0, 0, 0

Full Screen

Full Screen

toDateArray

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.*;2import static org.assertj.core.api.Assertions.within;3import static org.assertj.core.api.Assertions.withinPercentage;4import static org.assertj.core.api.Assertions.withinPercentage;5import java.util.Date;6import org.assertj.core.api.Assertions;7import org.assertj.core.api.AbstractDateAssert;8import org.assertj.core.api.AbstractObjectAssert;9import org.assertj.core.api.Assertions;10import org.assertj.core.api.DateAssert;11public class AssertJDateArray {12 public static void main(String[] args) {13 String[] dateStr = {"2014-04-01", "2014-04-02"};14 Date[] dateArray = toDateArray(dateStr);15 System.out.println(dateArray[0].toString());16 System.out.println(dateArray[1].toString());17 }18 public static Date[] toDateArray(String... dates) {19 Date[] dateArray = new Date[dates.length];20 int i = 0;21 for (String date : dates) {22 dateArray[i] = AbstractDateAssert.parse(date);23 i++;24 }25 return dateArray;26 }27}

Full Screen

Full Screen

toDateArray

Using AI Code Generation

copy

Full Screen

1import java.time.LocalDate;2import static org.assertj.core.api.Assertions.assertThat;3public class AssertJDateAssertExamples {4 public static void main(String[] args) {5 LocalDate date = LocalDate.of(2018, 8, 22);6 assertThat(date).isBetween(LocalDate.of(2018, 8, 21), LocalDate.of(2018, 8, 23));7 assertThat(date).isBetween(LocalDate.of(2018, 8, 21), LocalDate.of(2018, 8, 23)).toDateArray();8 }9}

Full Screen

Full Screen

toDateArray

Using AI Code Generation

copy

Full Screen

1import org.assertj.core.api.Assertions.*2import org.assertj.core.api.AbstractDateAssert.*3def dateArray = toDateArray("2011-01-01", "2012-01-01", "2013-01-01")4assertThat(dateArray).containsOnly(5 date(2011, 1, 1), 6 date(2012, 1, 1), 7 date(2013, 1, 1))8import org.assertj.core.api.Assertions.*9import org.assertj.core.api.AbstractDateAssert.*10import java.text.SimpleDateFormat11def dateFormat = new SimpleDateFormat("yyyy-MM-dd")12def dateArray = toDateArray(dateFormat, "2011-01-01", "2012-01-01", "2013-01-01")13assertThat(dateArray).containsOnly(14 date(2011, 1, 1), 15 date(2012, 1, 1), 16 date(2013, 1, 1))17import org.assertj.core.api.Assertions.*18import org.assertj.core.api.AbstractDateAssert.*19import java.text.SimpleDateFormat20def dateFormat = new SimpleDateFormat("yyyy-MM-dd")21def dateArray = toDateArray(dateFormat, "2011-01-01", "2012-01-01", "2013-01-01")22assertThat(dateArray).containsOnly(23 date(2011, 1, 1), 24 date(2012, 1, 1), 25 date(2013, 1, 1))26import org.assertj.core.api.Assertions.*27import org.assertj.core.api.AbstractDateAssert.*28import java.text.SimpleDateFormat29import java.time.format.DateTimeFormatter30def dateFormat = new SimpleDateFormat("yyyy-MM-dd")31def dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")32def dateArray = toDateArray(dateFormat, dateTimeFormatter, "2011-01-01

Full Screen

Full Screen

toDateArray

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.*;2import static java.util.Arrays.*;3import static java.time.Month.*;4import static java.time.MonthDay.*;5import java.time.*;6import java.time.MonthDay;7public class AssertJDateAssert {8 public static void main(String[] args) {9 MonthDay monthDay = of(MAY, 25);10 MonthDay[] monthDays = assertThat(monthDay).toDateArray("2017-05-25", "2018-05-25");11 System.out.println(asList(monthDays));12 }13}

Full Screen

Full Screen

toDateArray

Using AI Code Generation

copy

Full Screen

1import java.util.Date;2import java.util.Calendar;3import java.util.GregorianCalendar;4public class DateAssertToDateArray {5 public static void main(String[] args) {6 Calendar calendar = new GregorianCalendar();7 calendar.set(2016, 4, 1, 0, 0, 0);8 calendar.set(Calendar.MILLISECOND, 0);9 Date date = calendar.getTime();10 int[] dateArray = Assertions.assertThat(date).toDateArray();11 System.out.println("dateArray: " + dateArray);12 }13}

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