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

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

Source:AbstractZonedDateTimeAssert.java Github

copy

Full Screen

...103 * @throws AssertionError if the actual {@code ZonedDateTime} is not strictly before the {@link ZonedDateTime} built104 * from given String.105 */106 public SELF isBefore(String dateTimeAsString) {107 assertDateTimeAsStringParameterIsNotNull(dateTimeAsString);108 return isBefore(parse(dateTimeAsString));109 }110 /**111 * Verifies that the actual {@code ZonedDateTime} is before or equals to the given one according to the comparator in use.112 * <p>113 * <b>Breaking change</b>: since 3.15.0 the default comparator uses {@link ChronoZonedDateTime#timeLineOrder()} which only114 * compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.<br>115 * This behaviour can be overridden by {@link AbstractZonedDateTimeAssert#usingComparator(Comparator)}.116 * <p>117 * Example :118 * <pre><code class='java'> // assertions succeed119 * assertThat(parse("2000-01-01T01:00:00Z")).isBeforeOrEqualTo(parse("2020-01-01T01:00:00Z"))120 * .isBeforeOrEqualTo(parse("2000-01-01T01:00:00Z"))121 * // same instant (on different offsets)122 * .isBeforeOrEqualTo(parse("2000-01-01T00:00:00-01:00"));123 *124 * // assertions fail125 * assertThat(parse("2000-01-01T01:00:00Z")).isBeforeOrEqualTo(parse("1999-01-01T01:00:00Z"));126 * // even though the same instant, fails because of ZonedDateTime natural comparator is used and ZonedDateTime are on different offsets127 * assertThat(parse("2000-01-01T01:00:00Z")).usingComparator(ZonedDateTime::compareTo)128 * .isBeforeOrEqualTo(parse("2000-01-01T00:00:00-01:00")); </code></pre>129 *130 * @param other the given {@link ZonedDateTime}.131 * @return this assertion object.132 * @throws AssertionError if the actual {@code ZonedDateTime} is {@code null}.133 * @throws IllegalArgumentException if other {@code ZonedDateTime} is {@code null}.134 * @throws AssertionError if the actual {@code ZoneDateTime} is not before or equals to the given one.135 */136 public SELF isBeforeOrEqualTo(ZonedDateTime other) {137 assertDateTimeParameterIsNotNull(other);138 comparables.assertIsBeforeOrEqualTo(info, actual, other);139 return myself;140 }141 /**142 * Same assertion as {@link #isBeforeOrEqualTo(ZonedDateTime)} but the {@link ZonedDateTime} is built from given143 * String which must follow <a144 * href="http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_DATE_TIME"145 * >ISO date-time format</a> to allow calling {@link ZonedDateTime#parse(CharSequence, DateTimeFormatter)} method.146 * <p>147 * <b>Breaking change</b>: since 3.15.0 the default comparator uses {@link ChronoZonedDateTime#timeLineOrder()} which only148 * compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.<br>149 * This behaviour can be overridden by {@link AbstractZonedDateTimeAssert#usingComparator(Comparator)}.150 * <p>151 * Example :152 * <pre><code class='java'> // assertions succeed153 * assertThat(parse("2000-01-01T01:00:00Z")).isBeforeOrEqualTo("2020-01-01T01:00:00Z")154 * .isBeforeOrEqualTo("2000-01-01T01:00:00Z")155 * // same instant (on different offsets)156 * .isBeforeOrEqualTo("2000-01-01T00:00:00-01:00");157 *158 * // assertions fail159 * assertThat(parse("2000-01-01T01:00:00Z")).isBeforeOrEqualTo("1999-01-01T01:00:00Z");160 * // even though the same instant, fails because of ZonedDateTime natural comparator is used and ZonedDateTime are on different offsets161 * assertThat(parse("2000-01-01T01:00:00Z")).usingComparator(ZonedDateTime::compareTo)162 * .isBeforeOrEqualTo("2000-01-01T00:00:00-01:00"); </code></pre>163 *164 * @param dateTimeAsString String representing a {@link ZonedDateTime}.165 * @return this assertion object.166 * @throws AssertionError if the actual {@code ZonedDateTime} is {@code null}.167 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link ZonedDateTime}.168 * @throws AssertionError if the actual {@code ZonedDateTime} is not before or equals to the {@link ZonedDateTime}169 * built from given String.170 */171 public SELF isBeforeOrEqualTo(String dateTimeAsString) {172 assertDateTimeAsStringParameterIsNotNull(dateTimeAsString);173 return isBeforeOrEqualTo(parse(dateTimeAsString));174 }175 /**176 * Verifies that the actual {@code ZonedDateTime} is after or equals to the given one according to the comparator in use.177 * <p>178 * <b>Breaking change</b>: since 3.15.0 the default comparator uses {@link ChronoZonedDateTime#timeLineOrder()} which only179 * compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.<br>180 * This behaviour can be overridden by {@link AbstractZonedDateTimeAssert#usingComparator(Comparator)}.181 * <p>182 * Example :183 * <pre><code class='java'> // assertions succeed184 * assertThat(parse("2000-01-01T00:00:00Z")).isAfterOrEqualTo(parse("2000-01-01T00:00:00Z"))185 * .isAfterOrEqualTo(parse("1999-12-31T23:59:59Z"))186 * // same instant in different offset187 * .isAfterOrEqualTo(parse("2000-01-01T00:00:00-01:00"));188 *189 * // assertions fail190 * assertThat(parse("2000-01-01T00:00:00Z")).isAfterOrEqualTo(parse("2001-01-01T00:00:00Z"));191 * // fails even though they refer to the same instant due to ZonedDateTime natural comparator192 * assertThat(parse("2000-01-01T00:00:00Z")).usingComparator(ZonedDateTime::compareTo)193 * .isAfterOrEqualTo(parse("2000-01-01T01:00:00+01:00"));</code></pre>194 *195 * @param other the given {@link ZonedDateTime}.196 * @return this assertion object.197 * @throws AssertionError if the actual {@code ZonedDateTime} is {@code null}.198 * @throws IllegalArgumentException if other {@code ZonedDateTime} is {@code null}.199 * @throws AssertionError if the actual {@code ZonedDateTime} is not after or equals to the given one.200 */201 public SELF isAfterOrEqualTo(ZonedDateTime other) {202 assertDateTimeParameterIsNotNull(other);203 comparables.assertIsAfterOrEqualTo(info, actual, other);204 return myself;205 }206 /**207 * Same assertion as {@link #isAfterOrEqualTo(ZonedDateTime)} but the {@link ZonedDateTime} is built from given208 * String which must follow <a209 * href="http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_DATE_TIME"210 * >ISO date-time format</a> to allow calling {@link ZonedDateTime#parse(CharSequence, DateTimeFormatter)} method.211 * <p>212 * <b>Breaking change</b>: since 3.15.0 the default comparator uses {@link ChronoZonedDateTime#timeLineOrder()} which only213 * compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.<br>214 * This behaviour can be overridden by {@link AbstractZonedDateTimeAssert#usingComparator(Comparator)}.215 * <p>216 * Example :217 * <pre><code class='java'> // assertions succeed218 * assertThat(parse("2000-01-01T00:00:00Z")).isAfterOrEqualTo("2000-01-01T00:00:00Z")219 * .isAfterOrEqualTo("1999-12-31T23:59:59Z")220 * // same instant in different offset221 * .isAfter("2000-01-01T00:00:00-01:00");222 *223 * // assertions fail224 * assertThat(parse("2000-01-01T00:00:00Z")).isAfterOrEqualTo("2001-01-01T00:00:00Z");225 * // fails even though they refer to the same instant due to ZonedDateTime natural comparator226 * assertThat(parse("2000-01-01T00:00:00Z")).usingComparator(ZonedDateTime::compareTo)227 * .isAfterOrEqualTo("2000-01-01T01:00:00+01:00");</code></pre>228 *229 * @param dateTimeAsString String representing a {@link ZonedDateTime}.230 * @return this assertion object.231 * @throws AssertionError if the actual {@code ZonedDateTime} is {@code null}.232 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link ZonedDateTime}.233 * @throws AssertionError if the actual {@code ZonedDateTime} is not after or equals to the {@link ZonedDateTime}234 * built from given String.235 */236 public SELF isAfterOrEqualTo(String dateTimeAsString) {237 assertDateTimeAsStringParameterIsNotNull(dateTimeAsString);238 return isAfterOrEqualTo(parse(dateTimeAsString));239 }240 /**241 * Verifies that the actual {@code ZonedDateTime} is <b>strictly</b> after the given one according to the comparator in use.242 * <p>243 * <b>Breaking change</b>: since 3.15.0 the default comparator uses {@link ChronoZonedDateTime#timeLineOrder()} which only244 * compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.<br>245 * This behaviour can be overridden by {@link AbstractZonedDateTimeAssert#usingComparator(Comparator)}.246 * <p>247 * Example :248 * <pre><code class='java'> // assertion succeeds249 * assertThat(parse("2000-01-01T01:00:00Z")).isAfter(parse("1999-01-01T00:00:00Z"));250 *251 * // assertions fail252 * assertThat(parse("2000-01-01T01:00:00Z")).isAfter(parse("2001-01-01T01:00:00Z"));253 * assertThat(parse("2000-01-01T01:00:00Z")).isAfter(parse("2000-01-01T01:00:00Z"));254 * // fails because both ZonedDateTime refer to the same instant (on different offsets)255 * assertThat(parse("2000-01-01T01:00:00Z")).isAfter(parse("2000-01-01T00:00:00-01:00"));256 *257 * // even though they refer to the same instant assertion succeeds because of different offset258 * assertThat(parse("2000-01-01T01:00:00Z")).usingComparator(ZonedDateTime::compareTo)259 * .isAfter(parse("2000-01-01T00:00:00-01:00"));</code></pre>260 *261 * @param other the given {@link ZonedDateTime}.262 * @return this assertion object.263 * @throws AssertionError if the actual {@code ZonedDateTime} is {@code null}.264 * @throws IllegalArgumentException if other {@code ZonedDateTime} is {@code null}.265 * @throws AssertionError if the actual {@code ZonedDateTime} is not strictly after the given one.266 */267 public SELF isAfter(ZonedDateTime other) {268 assertDateTimeParameterIsNotNull(other);269 comparables.assertIsAfter(info, actual, other);270 return myself;271 }272 /**273 * Same assertion as {@link #isAfter(ZonedDateTime)} but the {@link ZonedDateTime} is built from given String, which274 * must follow <a275 * href="http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_DATE_TIME"276 * >ISO date-time format</a> to allow calling {@link ZonedDateTime#parse(CharSequence, DateTimeFormatter)} method.277 * <p>278 * <b>Breaking change</b>: since 3.15.0 the default comparator uses {@link ChronoZonedDateTime#timeLineOrder()} which only279 * compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.<br>280 * This behaviour can be overridden by {@link AbstractZonedDateTimeAssert#usingComparator(Comparator)}.281 * <p>282 * Example :283 * <pre><code class='java'> // assertion succeeds284 * assertThat(parse("2000-01-01T01:00:00Z")).isAfter("1999-01-01T00:00:00Z");285 *286 * // assertions fail287 * assertThat(parse("2000-01-01T01:00:00Z")).isAfter("2001-01-01T01:00:00Z");288 * assertThat(parse("2000-01-01T01:00:00Z")).isAfter("2000-01-01T01:00:00Z");289 * // fails because both ZonedDateTime refer to the same instant (on different offsets)290 * assertThat(parse("2000-01-01T01:00:00Z")).isAfter("2000-01-01T00:00:00-01:00");291 *292 * // even though they refer to the same instant assertion succeeds because of different offset293 * assertThat(parse("2000-01-01T01:00:00Z")).usingComparator(ZonedDateTime::compareTo)294 * .isAfter("2000-01-01T00:00:00-01:00");</code></pre>295 *296 * @param dateTimeAsString String representing a {@link ZonedDateTime}.297 * @return this assertion object.298 * @throws AssertionError if the actual {@code ZonedDateTime} is {@code null}.299 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link ZonedDateTime}.300 * @throws AssertionError if the actual {@code ZonedDateTime} is not strictly after the {@link ZonedDateTime} built from the given String.301 */302 public SELF isAfter(String dateTimeAsString) {303 assertDateTimeAsStringParameterIsNotNull(dateTimeAsString);304 return isAfter(parse(dateTimeAsString));305 }306 /**307 * Verifies that actual and given {@code ZonedDateTime} have same year, month, day, hour, minute and second fields,308 * (nanosecond fields are ignored in comparison).309 * <p>310 * Note that given {@link ZonedDateTime} is converted in the actual's {@link java.time.ZoneId} before comparison.311 * <p>312 * Assertion can fail with dateTimes in same chronological nanosecond time window, e.g :313 * <p>314 * 2000-01-01T00:00:<b>01.000000000</b> and 2000-01-01T00:00:<b>00.999999999</b>.315 * <p>316 * Assertion fails as second fields differ even if time difference is only 1ns.317 * <p>318 * Code example :319 * <pre><code class='java'> // successful assertions320 * ZonedDateTime dateTime1 = ZonedDateTime.of(2000, 1, 1, 0, 0, 1, 0);321 * ZonedDateTime dateTime2 = ZonedDateTime.of(2000, 1, 1, 0, 0, 1, 456);322 * assertThat(dateTime1).isEqualToIgnoringNanos(dateTime2);323 *324 * // failing assertions (even if time difference is only 1ms)325 * ZonedDateTime dateTimeA = ZonedDateTime.of(2000, 1, 1, 0, 0, 1, 0);326 * ZonedDateTime dateTimeB = ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 999999999);327 * assertThat(dateTimeA).isEqualToIgnoringNanos(dateTimeB);</code></pre>328 *329 * @param other the given {@link ZonedDateTime}.330 * @return this assertion object.331 * @throws AssertionError if the actual {@code ZonedDateTime} is {@code null}.332 * @throws IllegalArgumentException if other {@code ZonedDateTime} is {@code null}.333 * @throws AssertionError if the actual {@code ZonedDateTime} is are not equal with nanoseconds ignored.334 */335 public SELF isEqualToIgnoringNanos(ZonedDateTime other) {336 Objects.instance().assertNotNull(info, actual);337 assertDateTimeParameterIsNotNull(other);338 ZonedDateTime otherInActualTimeZone = sameInstantInActualTimeZone(other);339 if (!areEqualIgnoringNanos(actual, otherInActualTimeZone)) {340 throw Failures.instance().failure(info, shouldBeEqualIgnoringNanos(actual, otherInActualTimeZone));341 }342 return myself;343 }344 /**345 * Verifies that actual and given {@link ZonedDateTime} have same year, month, day, hour and minute fields (second and346 * nanosecond fields are ignored in comparison).347 * <p>348 * Note that given {@link ZonedDateTime} is converted in the actual's {@link java.time.ZoneId} before comparison.349 * <p>350 * Assertion can fail with ZonedDateTimes in same chronological second time window, e.g :351 * <p>352 * 2000-01-01T00:<b>01:00</b>.000 and 2000-01-01T00:<b>00:59</b>.000.353 * <p>354 * Assertion fails as minute fields differ even if time difference is only 1ns.355 * <p>356 * Code example :357 * <pre><code class='java'> // successful assertions358 * ZonedDateTime dateTime1 = ZonedDateTime.of(2000, 1, 1, 23, 50, 0, 0);359 * ZonedDateTime dateTime2 = ZonedDateTime.of(2000, 1, 1, 23, 50, 10, 456);360 * assertThat(dateTime1).isEqualToIgnoringSeconds(dateTime2);361 *362 * // failing assertions (even if time difference is only 1ns)363 * ZonedDateTime dateTimeA = ZonedDateTime.of(2000, 1, 1, 23, 50, 00, 0);364 * ZonedDateTime dateTimeB = ZonedDateTime.of(2000, 1, 1, 23, 49, 59, 999999999);365 * assertThat(dateTimeA).isEqualToIgnoringSeconds(dateTimeB);</code></pre>366 *367 * @param other the given {@link ZonedDateTime}.368 * @return this assertion object.369 * @throws AssertionError if the actual {@code ZonedDateTime} is {@code null}.370 * @throws IllegalArgumentException if other {@code ZonedDateTime} is {@code null}.371 * @throws AssertionError if the actual {@code ZonedDateTime} is are not equal with second and nanosecond fields372 * ignored.373 */374 public SELF isEqualToIgnoringSeconds(ZonedDateTime other) {375 Objects.instance().assertNotNull(info, actual);376 assertDateTimeParameterIsNotNull(other);377 ZonedDateTime otherInActualTimeZone = sameInstantInActualTimeZone(other);378 if (!areEqualIgnoringSeconds(actual, otherInActualTimeZone)) {379 throw Failures.instance().failure(info, shouldBeEqualIgnoringSeconds(actual, otherInActualTimeZone));380 }381 return myself;382 }383 /**384 * Verifies that actual and given {@code ZonedDateTime} have same year, month, day and hour fields (minute, second and385 * nanosecond fields are ignored in comparison).386 * <p>387 * Note that given {@link ZonedDateTime} is converted in the actual's {@link java.time.ZoneId} before comparison.388 * <p>389 * Assertion can fail with dateTimes in same chronological second time window, e.g :390 * <p>391 * 2000-01-01T<b>01:00</b>:00.000 and 2000-01-01T<b>00:59:59</b>.000.392 * <p>393 * Time difference is only 1s but hour fields differ.394 * <p>395 * Code example :396 * <pre><code class='java'> // successful assertions397 * ZonedDateTime dateTime1 = ZonedDateTime.of(2000, 1, 1, 23, 50, 0, 0);398 * ZonedDateTime dateTime2 = ZonedDateTime.of(2000, 1, 1, 23, 00, 2, 7);399 * assertThat(dateTime1).isEqualToIgnoringMinutes(dateTime2);400 *401 * // failing assertions (even if time difference is only 1ms)402 * ZonedDateTime dateTimeA = ZonedDateTime.of(2000, 1, 1, 01, 00, 00, 000);403 * ZonedDateTime dateTimeB = ZonedDateTime.of(2000, 1, 1, 00, 59, 59, 999);404 * assertThat(dateTimeA).isEqualToIgnoringMinutes(dateTimeB);</code></pre>405 *406 * @param other the given {@link ZonedDateTime}.407 * @return this assertion object.408 * @throws AssertionError if the actual {@code ZonedDateTime} is {@code null}.409 * @throws IllegalArgumentException if other {@code ZonedDateTime} is {@code null}.410 * @throws AssertionError if the actual {@code ZonedDateTime} is are not equal ignoring minute, second and nanosecond411 * fields.412 */413 public SELF isEqualToIgnoringMinutes(ZonedDateTime other) {414 Objects.instance().assertNotNull(info, actual);415 assertDateTimeParameterIsNotNull(other);416 ZonedDateTime otherInActualTimeZone = sameInstantInActualTimeZone(other);417 if (!areEqualIgnoringMinutes(actual, otherInActualTimeZone)) {418 throw Failures.instance().failure(info, shouldBeEqualIgnoringMinutes(actual, otherInActualTimeZone));419 }420 return myself;421 }422 /**423 * Verifies that actual and given {@code ZonedDateTime} have same year, month and day fields (hour, minute, second and424 * nanosecond fields are ignored in comparison).425 * <p>426 * Note that given {@link ZonedDateTime} is converted in the actual's {@link java.time.ZoneId} before comparison.427 * <p>428 * Assertion can fail with dateTimes in same chronological minute time window, e.g :429 * <p>430 * 2000-01-<b>01T23:59</b>:00.000 and 2000-01-02T<b>00:00</b>:00.000.431 * <p>432 * Time difference is only 1min but day fields differ.433 * <p>434 * Code example :435 * <pre><code class='java'> // successful assertions436 * ZonedDateTime dateTime1 = ZonedDateTime.of(2000, 1, 1, 23, 59, 59, 999, ZoneId.systemDefault());437 * ZonedDateTime dateTime2 = ZonedDateTime.of(2000, 1, 1, 00, 00, 00, 000, ZoneId.systemDefault());438 * assertThat(dateTime1).isEqualToIgnoringHours(dateTime2);439 *440 * // failing assertions (even if time difference is only 1ms)441 * ZonedDateTime dateTimeA = ZonedDateTime.of(2000, 1, 2, 00, 00, 00, 000, ZoneId.systemDefault());442 * ZonedDateTime dateTimeB = ZonedDateTime.of(2000, 1, 1, 23, 59, 59, 999, ZoneId.systemDefault());443 * assertThat(dateTimeA).isEqualToIgnoringHours(dateTimeB);</code></pre>444 *445 * @param other the given {@link ZonedDateTime}.446 * @return this assertion object.447 * @throws AssertionError if the actual {@code ZonedDateTime} is {@code null}.448 * @throws IllegalArgumentException if other {@code ZonedDateTime} is {@code null}.449 * @throws AssertionError if the actual {@code ZonedDateTime} is are not equal with second and nanosecond fields450 * ignored.451 */452 public SELF isEqualToIgnoringHours(ZonedDateTime other) {453 Objects.instance().assertNotNull(info, actual);454 assertDateTimeParameterIsNotNull(other);455 ZonedDateTime otherInActualTimeZone = sameInstantInActualTimeZone(other);456 if (!haveSameYearMonthAndDayOfMonth(actual, otherInActualTimeZone)) {457 throw Failures.instance().failure(info, shouldBeEqualIgnoringHours(actual, otherInActualTimeZone));458 }459 return myself;460 }461 /**462 * Verifies that the actual {@link ZonedDateTime} is equal to the given one according to the comparator in use.463 * <p>464 * <b>Breaking change</b>: since 3.15.0 the default comparator uses {@link ChronoZonedDateTime#timeLineOrder()} which only465 * compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.<br>466 * This behaviour can be overridden by {@link AbstractZonedDateTimeAssert#usingComparator(Comparator)}.467 * <p>468 * Example :469 * <pre><code class='java'> ZonedDateTime firstOfJanuary2000InUTC = ZonedDateTime.parse("2000-01-01T00:00:00Z");470 *471 * // both assertions succeed, the second one because the comparison based on the instant they are referring to472 * // 2000-01-01T01:00:00+01:00 = 2000-01-01T00:00:00 in UTC473 * assertThat(firstOfJanuary2000InUTC).isEqualTo(parse("2000-01-01T00:00:00Z"))474 * .isEqualTo(parse("2000-01-01T01:00:00+01:00"));475 *476 * // assertions fail477 * assertThat(firstOfJanuary2000InUTC).isEqualTo(parse("1999-01-01T01:00:00Z"));478 * // fails as the comparator compares the offsets479 * assertThat(firstOfJanuary2000InUTC).usingComparator(ZonedDateTime::compareTo)480 * .isEqualTo(parse("2000-01-01T01:00:00+01:00"));</code></pre>481 *482 * @param expected the given value to compare the actual value to.483 * @return {@code this} assertion object.484 * @throws AssertionError if the actual {@code ZonedDateTime} is not equal to the {@link ZonedDateTime} according485 * to the comparator in use.486 */487 @Override488 public SELF isEqualTo(Object expected) {489 if (actual == null || expected == null) {490 super.isEqualTo(expected);491 } else {492 comparables.assertEqual(info, actual, expected);493 }494 return myself;495 }496 /**497 * Same assertion as {@link #isEqualTo(Object)} but the {@link ZonedDateTime} is built from given String which must follow498 * <a href="http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_DATE_TIME"499 * >ISO date-time format</a> to allow calling {@link ZonedDateTime#parse(CharSequence, DateTimeFormatter)} method.500 * <p>501 * <b>Breaking change</b>: since 3.15.0 the default comparator uses {@link ChronoZonedDateTime#timeLineOrder()} which only502 * compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.<br>503 * This behaviour can be overridden by {@link AbstractZonedDateTimeAssert#usingComparator(Comparator)}.504 * <p>505 * Example :506 * <pre><code class='java'> ZonedDateTime firstOfJanuary2000InUTC = ZonedDateTime.parse("2000-01-01T00:00:00Z");507 *508 * // both assertions succeed, the second one because the comparison based on the instant they are referring to509 * // 2000-01-01T01:00:00+01:00 = 2000-01-01T00:00:00 in UTC510 * assertThat(firstOfJanuary2000InUTC).isEqualTo("2000-01-01T00:00:00Z")511 * .isEqualTo("2000-01-01T01:00:00+01:00");512 *513 * // assertions fail514 * assertThat(firstOfJanuary2000InUTC).isEqualTo("1999-01-01T01:00:00Z");515 * // fails as the comparator compares the offsets516 * assertThat(firstOfJanuary2000InUTC).usingComparator(ZonedDateTime::compareTo)517 * .isEqualTo("2000-01-01T01:00:00+01:00");</code></pre>518 *519 * @param dateTimeAsString String representing a {@link ZonedDateTime}.520 * @return this assertion object.521 * @throws AssertionError if the actual {@code ZonedDateTime} is {@code null}.522 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link ZonedDateTime}.523 * @throws AssertionError if the actual {@code ZonedDateTime} is not equal to the {@link ZonedDateTime} built from the given String.524 */525 public SELF isEqualTo(String dateTimeAsString) {526 assertDateTimeAsStringParameterIsNotNull(dateTimeAsString);527 return isEqualTo(parse(dateTimeAsString));528 }529 /**530 * Verifies that the actual value is not equal to the given one according to the comparator in use.531 * <p>532 * <b>Breaking change</b>: since 3.15.0 the default comparator uses {@link ChronoZonedDateTime#timeLineOrder()} which only533 * compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.<br>534 * This behaviour can be overridden by {@link AbstractZonedDateTimeAssert#usingComparator(Comparator)}.535 * <p>536 * Example :537 * <pre><code class='java'> // assertions succeed538 * assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo(parse("2020-01-01T00:00:00Z"));539 * // even though they refer to the same instant, succeeds as the ZonedDateTime comparator checks the offsets540 * assertThat(parse("2000-01-01T00:00:00Z")).usingComparator(ZonedDateTime::compareTo)541 * .isNotEqualTo(parse("2000-01-01T02:00:00+02:00"));542 *543 * // assertions fail544 * assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo(parse("2000-01-01T00:00:00Z"));545 * // fails because the default comparator only checks the instant and they refer to the same546 * assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo(parse("2000-01-01T02:00:00+02:00"));</code></pre>547 *548 * @param expected the given value to compare the actual value to.549 * @return {@code this} assertion object.550 * @throws AssertionError if the actual {@code ZonedDateTime} is equal to the {@link ZonedDateTime} according551 * to the comparator in use.552 */553 @Override554 public SELF isNotEqualTo(Object expected) {555 if (actual == null || expected == null) {556 super.isNotEqualTo(expected);557 } else {558 comparables.assertNotEqual(info, actual, expected);559 }560 return myself;561 }562 /**563 * Same assertion as {@code #isNotEqualTo(Object)} but the {@link ZonedDateTime} is built from given String which must follow564 * <a href="http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_DATE_TIME">ISO date-time format</a>565 * to allow calling {@link ZonedDateTime#parse(CharSequence, DateTimeFormatter)} method.566 * <p>567 * <b>Breaking change</b>: since 3.15.0 the default comparator uses {@link ChronoZonedDateTime#timeLineOrder()} which only568 * compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.<br>569 * This behaviour can be overridden by {@link AbstractZonedDateTimeAssert#usingComparator(Comparator)}.570 * <p>571 * Example :572 * <pre><code class='java'> // assertions succeed573 * assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo("2020-01-01T00:00:00Z");574 * // even though they refer to the same instant, succeeds as the ZonedDateTime comparator checks the offsets575 * assertThat(parse("2000-01-01T00:00:00Z")).usingComparator(ZonedDateTime::compareTo)576 * .isNotEqualTo("2000-01-01T02:00:00+02:00");577 *578 * // assertions fail579 * assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo("2000-01-01T00:00:00Z");580 * // fails because the default comparator only checks the instant and they refer to the same581 * assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo("2000-01-01T02:00:00+02:00");</code></pre>582 *583 * @param dateTimeAsString String representing a {@link ZonedDateTime}.584 * @return this assertion object.585 * @throws AssertionError if the actual {@code ZonedDateTime} is {@code null}.586 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link ZonedDateTime}.587 * @throws AssertionError if the actual {@code ZonedDateTime} is equal to the {@link ZonedDateTime} built from given {@link String}.588 */589 public SELF isNotEqualTo(String dateTimeAsString) {590 assertDateTimeAsStringParameterIsNotNull(dateTimeAsString);591 return isNotEqualTo(parse(dateTimeAsString));592 }593 /**594 * Verifies that the actual {@link ZonedDateTime} is equal to one of the given {@link ZonedDateTime} <b>in the actual595 * ZonedDateTime's {@link java.time.ZoneId}</b>.596 * <p>597 * Example :598 * <pre><code class='java'> assertThat(parse("2000-01-01T00:00:00Z")).isIn(parse("1999-12-31T23:59:59Z"),599 * parse("2000-01-01T00:00:00Z"));</code></pre>600 *601 * @param expected the given {@link ZonedDateTime}s to compare the actual value to.602 * @return {@code this} assertion object.603 * @throws AssertionError if the actual {@code ZonedDateTime} is {@code null}.604 * @throws AssertionError if the actual {@code ZonedDateTime} is not in the given {@link ZonedDateTime}s.605 */606 public SELF isIn(ZonedDateTime... expected) {607 return isIn((Object[]) changeToActualTimeZone(expected));608 }609 /**610 * Same assertion as {@link #isIn(ZonedDateTime...)} but the {@link ZonedDateTime} are built from given String, which611 * must follow <a612 * href="http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_DATE_TIME"613 * >ISO date-time format</a> to allow calling {@link ZonedDateTime#parse(CharSequence, DateTimeFormatter)} method.614 * <p>615 * Note that the {@link ZonedDateTime}s created from the given Strings are built in the {@link java.time.ZoneId} of616 * the {@link ZonedDateTime} to check..617 * <p>618 * Example :619 * <pre><code class='java'> // use String based representation of LocalDateTime620 * assertThat(parse("2000-01-01T00:00:00Z")).isIn("1999-12-31T23:59:59Z",621 * "2000-01-01T00:00:00Z");</code></pre>622 *623 * @param dateTimesAsString String array representing {@link ZonedDateTime}s.624 * @return this assertion object.625 * @throws AssertionError if the actual {@code ZonedDateTime} is {@code null}.626 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link ZonedDateTime}.627 * @throws AssertionError if the actual {@code ZonedDateTime} is not in the {@link ZonedDateTime}s built from given628 * Strings.629 */630 public SELF isIn(String... dateTimesAsString) {631 checkIsNotNullAndNotEmpty(dateTimesAsString);632 return isIn(convertToDateTimeArray(dateTimesAsString));633 }634 /**635 * Verifies that the actual {@link ZonedDateTime} is equal to one of the given {@link ZonedDateTime} <b>in the actual636 * ZonedDateTime's {@link java.time.ZoneId}</b>.637 * <p>638 * Example :639 * <pre><code class='java'> assertThat(parse("2000-01-01T00:00:00Z")).isNotIn(parse("1999-12-31T23:59:59Z"),640 * parse("2000-01-02T00:00:00Z"));</code></pre>641 *642 * @param expected the given {@link ZonedDateTime}s to compare the actual value to.643 * @return {@code this} assertion object.644 * @throws AssertionError if the actual {@code ZonedDateTime} is {@code null}.645 * @throws AssertionError if the actual {@code ZonedDateTime} is not in the given {@link ZonedDateTime}s.646 */647 public SELF isNotIn(ZonedDateTime... expected) {648 return isNotIn((Object[]) changeToActualTimeZone(expected));649 }650 /**651 * Same assertion as {@link #isNotIn(ZonedDateTime...)} but the {@link ZonedDateTime} is built from given String,652 * which must follow <a653 * href="http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_DATE_TIME"654 * >ISO date-time format</a> to allow calling {@link ZonedDateTime#parse(CharSequence, DateTimeFormatter)} method.655 * <p>656 * Note that the {@link ZonedDateTime}s created from the given Strings are built in the {@link java.time.ZoneId} of657 * the {@link ZonedDateTime} to check..658 * <p>659 * Example :660 * <pre><code class='java'> // use String based representation of ZonedDateTime661 * assertThat(parse("2000-01-01T00:00:00Z")).isNotIn("1999-12-31T23:59:59Z",662 * "2000-01-02T00:00:00Z");</code></pre>663 *664 * @param dateTimesAsString String array representing {@link ZonedDateTime}s.665 * @return this assertion object.666 * @throws AssertionError if the actual {@code ZonedDateTime} is {@code null}.667 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link ZonedDateTime}.668 * @throws AssertionError if the actual {@code ZonedDateTime} is not equal to the {@link ZonedDateTime} built from669 * given String.670 */671 public SELF isNotIn(String... dateTimesAsString) {672 checkIsNotNullAndNotEmpty(dateTimesAsString);673 return isNotIn(convertToDateTimeArray(dateTimesAsString));674 }675 /**676 * Verifies that the actual {@link ZonedDateTime} is in the [start, end] period (start and end included) according to677 * the comparator in use.678 * <p>679 * <b>Breaking change</b>: since 3.15.0 the default comparator uses {@link ChronoZonedDateTime#timeLineOrder()} which only680 * compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.<br>681 * This behaviour can be overridden by {@link AbstractZonedDateTimeAssert#usingComparator(Comparator)}.682 * <p>683 * Example:684 * <pre><code class='java'> ZonedDateTime zonedDateTime = ZonedDateTime.now();685 *686 * // assertions succeed:687 * assertThat(zonedDateTime).isBetween(zonedDateTime.minusSeconds(1), zonedDateTime.plusSeconds(1))688 * .isBetween(zonedDateTime, zonedDateTime.plusSeconds(1))689 * .isBetween(zonedDateTime.minusSeconds(1), zonedDateTime)690 * .isBetween(zonedDateTime, zonedDateTime);691 * // succeeds with default comparator which compares the point in time692 * assertThat(parse("2010-01-01T00:00:00Z")).isBetween(parse("2010-01-01T01:00:00+01:00"),693 * parse("2010-01-01T01:00:00+01:00"));694 *695 * // assertions fail:696 * assertThat(zonedDateTime).isBetween(zonedDateTime.minusSeconds(10), zonedDateTime.minusSeconds(1));697 * assertThat(zonedDateTime).isBetween(zonedDateTime.plusSeconds(1), zonedDateTime.plusSeconds(10));698 * // fails because the comparator checks the offsets are the same699 * assertThat(parse("2010-01-01T00:00:00Z")).usingComparator(ZonedDateTime::compareTo)700 * .isBetween(parse("2010-01-01T01:00:00+01:00"),701 * parse("2010-01-01T01:00:00+01:00"));</code></pre>702 *703 * @param startInclusive the start value (inclusive), expected not to be null.704 * @param endInclusive the end value (inclusive), expected not to be null.705 * @return this assertion object.706 * @throws AssertionError if the actual value is {@code null}.707 * @throws NullPointerException if start value is {@code null}.708 * @throws NullPointerException if end value is {@code null}.709 * @throws AssertionError if the actual value is not in [start, end] period.710 *711 * @since 3.7.1712 */713 public SELF isBetween(ZonedDateTime startInclusive, ZonedDateTime endInclusive) {714 comparables.assertIsBetween(info, actual, startInclusive, endInclusive, true, true);715 return myself;716 }717 /**718 * Same assertion as {@link #isBetween(ZonedDateTime, ZonedDateTime)} but here you pass {@link ZonedDateTime} String representations719 * which must follow <a href="http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_ZONED_DATE_TIME">ISO ZonedDateTime format</a>720 * to allow calling {@link ZonedDateTime#parse(CharSequence)} method.721 * <p>722 * <b>Breaking change</b>: since 3.15.0 the default comparator uses {@link ChronoZonedDateTime#timeLineOrder()} which only723 * compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.<br>724 * This behaviour can be overridden by {@link AbstractZonedDateTimeAssert#usingComparator(Comparator)}.725 * <p>726 * Example:727 * <pre><code class='java'> ZonedDateTime firstOfJanuary2000 = ZonedDateTime.parse("2000-01-01T00:00:00Z");728 *729 * // assertions succeed:730 * assertThat(firstOfJanuary2000).isBetween("1999-12-31T23:59:59Z", "2000-01-01T00:00:01Z")731 * .isBetween("2000-01-01T00:00:00Z", "2000-01-01T00:00:01Z")732 * .isBetween("1999-12-31T23:59:59Z", "2000-01-01T00:00:00Z")733 * .isBetween("2000-01-01T00:00:00Z", "2000-01-01T00:00:00Z")734 * // same instant as firstOfJanuary2000 but on a different offset735 * .isBetween("2000-01-01T01:00:00+01:00", "2000-01-01T01:00:00+01:00");736 *737 * // assertion fails:738 * assertThat(firstOfJanuary2000).isBetween("1999-01-01T00:00:01Z", "1999-12-31T23:59:59Z");</code></pre>739 *740 * @param startInclusive the start value (inclusive), expected not to be null.741 * @param endInclusive the end value (inclusive), expected not to be null.742 * @return this assertion object.743 *744 * @throws AssertionError if the actual value is {@code null}.745 * @throws NullPointerException if start value is {@code null}.746 * @throws NullPointerException if end value is {@code null}.747 * @throws DateTimeParseException if any of the given String can't be converted to a {@link ZonedDateTime}.748 * @throws AssertionError if the actual value is not in [start, end] period.749 *750 * @since 3.7.1751 */752 public SELF isBetween(String startInclusive, String endInclusive) {753 return isBetween(parse(startInclusive), parse(endInclusive));754 }755 /**756 * Verifies that the actual {@link ZonedDateTime} is in the ]start, end[ period (start and end excluded) according to757 * the comparator in use.758 * <p>759 * <b>Breaking change</b>: since 3.15.0 the default comparator uses {@link ChronoZonedDateTime#timeLineOrder()} which only760 * compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.<br>761 * This behaviour can be overridden by {@link AbstractZonedDateTimeAssert#usingComparator(Comparator)}.762 * <p>763 * Example:764 * <pre><code class='java'> ZonedDateTime zonedDateTime = ZonedDateTime.now();765 *766 * // assertions succeed:767 * assertThat(zonedDateTime).isStrictlyBetween(zonedDateTime.minusSeconds(1), zonedDateTime.plusSeconds(1));768 * // succeeds with a different comparator even though the end value refers to the same instant as the actual769 * assertThat(parse("2010-01-01T12:00:00Z")).usingComparator(ZonedDateTime::compareTo)770 * .isStrictlyBetween(parse("2010-01-01T12:59:59+01:00"),771 * parse("2010-01-01T13:00:00+01:00"));772 *773 * // assertions fail:774 * assertThat(zonedDateTime).isStrictlyBetween(zonedDateTime.minusSeconds(10), zonedDateTime.minusSeconds(1));775 * assertThat(zonedDateTime).isStrictlyBetween(zonedDateTime.plusSeconds(1), zonedDateTime.plusSeconds(10));776 * assertThat(zonedDateTime).isStrictlyBetween(zonedDateTime, zonedDateTime.plusSeconds(1));777 * assertThat(zonedDateTime).isStrictlyBetween(zonedDateTime.minusSeconds(1), zonedDateTime);778 * // fails with default comparator since the end value refers to the same instant as the actual779 * assertThat(parse("2010-01-01T12:00:00Z")).isStrictlyBetween(parse("2010-01-01T12:59:59+01:00"),780 * parse("2010-01-01T13:00:00+01:00"));</code></pre>781 *782 * @param startExclusive the start value (exclusive), expected not to be null.783 * @param endExclusive the end value (exclusive), expected not to be null.784 * @return this assertion object.785 * @throws AssertionError if the actual value is {@code null}.786 * @throws NullPointerException if start value is {@code null}.787 * @throws NullPointerException if end value is {@code null}.788 * @throws AssertionError if the actual value is not in ]start, end[ period.789 *790 * @since 3.7.1791 */792 public SELF isStrictlyBetween(ZonedDateTime startExclusive, ZonedDateTime endExclusive) {793 comparables.assertIsBetween(info, actual, startExclusive, endExclusive, false, false);794 return myself;795 }796 /**797 * Same assertion as {@link #isStrictlyBetween(ZonedDateTime, ZonedDateTime)} but here you pass {@link ZonedDateTime} String representations798 * which must follow <a href="http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_ZONED_DATE_TIME">ISO ZonedDateTime format</a>799 * to allow calling {@link ZonedDateTime#parse(CharSequence)} method.800 * <p>801 * <b>Breaking change</b>: since 3.15.0 the default comparator uses {@link ChronoZonedDateTime#timeLineOrder()} which only802 * compares the underlying instant and not the chronology. The underlying comparison is equivalent to comparing the epoch-second and nano-of-second.<br>803 * This behaviour can be overridden by {@link AbstractZonedDateTimeAssert#usingComparator(Comparator)}.804 * <p>805 * Example:806 * <pre><code class='java'> ZonedDateTime firstOfJanuary2000 = ZonedDateTime.parse("2000-01-01T00:00:00Z");807 *808 * // assertions succeed:809 * assertThat(firstOfJanuary2000).isStrictlyBetween("1999-12-31T23:59:59Z", "2000-01-01T00:00:01Z")810 * // succeeds with a different comparator even though the end value refers to the same instant as the actual811 * .usingComparator(ZonedDateTime::compareTo)812 * .isStrictlyBetween("1999-12-31T23:59:59Z", "2000-01-01T01:00:00+01:00");813 *814 * // assertions fail:815 * assertThat(firstOfJanuary2000).isStrictlyBetween("1999-01-01T00:00:01Z", "1999-12-31T23:59:59Z");816 * assertThat(firstOfJanuary2000).isStrictlyBetween("2000-01-01T00:00:00Z", "2000-01-01T00:00:01Z");817 * assertThat(firstOfJanuary2000).isStrictlyBetween("1999-12-31T23:59:59Z", "2000-01-01T00:00:00Z");818 * // fails with default comparator since the end value refers to the same instant as the actual819 * assertThat(parse("2010-01-01T12:00:00Z")).isStrictlyBetween("2010-01-01T12:59:59+01:00", "2010-01-01T13:00:00+01:00");</code></pre>820 *821 * @param startExclusive the start value (exclusive), expected not to be null.822 * @param endExclusive the end value (exclusive), expected not to be null.823 * @return this assertion object.824 *825 * @throws AssertionError if the actual value is {@code null}.826 * @throws NullPointerException if start value is {@code null}.827 * @throws NullPointerException if end value is {@code null}.828 * @throws DateTimeParseException if any of the given String can't be converted to a {@link ZonedDateTime}.829 * @throws AssertionError if the actual value is not in ]start, end[ period.830 *831 * @since 3.7.1832 */833 public SELF isStrictlyBetween(String startExclusive, String endExclusive) {834 return isStrictlyBetween(parse(startExclusive), parse(endExclusive));835 }836 /** {@inheritDoc} */837 @Override838 @CheckReturnValue839 public SELF usingDefaultComparator() {840 SELF self = super.usingDefaultComparator();841 self.comparables = buildDefaultComparables();842 return self;843 }844 private Comparables buildDefaultComparables() {845 ChronoZonedDateTimeByInstantComparator defaultComparator = ChronoZonedDateTimeByInstantComparator.getInstance();846 return new Comparables(new ComparatorBasedComparisonStrategy(defaultComparator, defaultComparator.description()));847 }848 private ZonedDateTime[] convertToDateTimeArray(String... dateTimesAsString) {849 ZonedDateTime[] dates = new ZonedDateTime[dateTimesAsString.length];850 for (int i = 0; i < dateTimesAsString.length; i++) {851 dates[i] = parse(dateTimesAsString[i]);852 }853 return dates;854 }855 private ZonedDateTime[] changeToActualTimeZone(ZonedDateTime... dateTimes) {856 ZonedDateTime[] dates = new ZonedDateTime[dateTimes.length];857 for (int i = 0; i < dateTimes.length; i++) {858 dates[i] = sameInstantInActualTimeZone(dateTimes[i]);859 }860 return dates;861 }862 private void checkIsNotNullAndNotEmpty(Object[] values) {863 checkArgument(values != null, "The given ZonedDateTime array should not be null");864 checkArgument(values.length > 0, "The given ZonedDateTime array should not be empty");865 }866 /**867 * Obtains an instance of {@link ZonedDateTime} from a string representation in ISO date format.868 *869 * @param dateTimeAsString the string to parse870 * @return the parsed {@link ZonedDateTime}871 */872 @Override873 protected ZonedDateTime parse(String dateTimeAsString) {874 return ZonedDateTime.parse(dateTimeAsString, DateTimeFormatter.ISO_DATE_TIME);875 }876 private ZonedDateTime sameInstantInActualTimeZone(ZonedDateTime zonedDateTime) {877 if (zonedDateTime == null) return null; // nothing to convert in actual's TZ878 if (actual == null) return zonedDateTime; // no actual => let's keep zonedDateTime as it is.879 return zonedDateTime.withZoneSameInstant(actual.getZone());880 }881 /**882 * Check that the {@link ZonedDateTime} string representation to compare actual {@link ZonedDateTime} to is not null,883 * otherwise throws a {@link IllegalArgumentException} with an explicit message884 *885 * @param dateTimeAsString String representing the ZonedDateTime to compare actual with886 * @throws IllegalArgumentException with an explicit message if the given {@link String} is null887 */888 private static void assertDateTimeAsStringParameterIsNotNull(String dateTimeAsString) {889 checkArgument(dateTimeAsString != null,890 "The String representing the ZonedDateTime to compare actual with should not be null");891 }892 /**893 * Returns true if both datetime are in the same year, month and day of month, hour, minute and second, false894 * otherwise.895 *896 * @param actual the actual datetime. expected not be null897 * @param other the other datetime. expected not be null898 * @return true if both datetime are in the same year, month and day of month, hour, minute and second, false899 * otherwise.900 */901 private static boolean areEqualIgnoringNanos(ZonedDateTime actual, ZonedDateTime other) {902 return areEqualIgnoringSeconds(actual, other) && actual.getSecond() == other.getSecond();...

Full Screen

Full Screen

assertDateTimeAsStringParameterIsNotNull

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.assertThat;2import static org.assertj.core.api.Assertions.assertThatExceptionOfType;3import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;4import static org.assertj.core.api.Assertions.assertThatNullPointerException;5import static org.assertj.core.api.Assertions.catchThrowable;6import static org.assertj.core.api.Assertions.assertThatThrownBy;7import static org.assertj.core.api.Assertions.assertThatCode;8import static org.assertj.core.api.Assertions.assertThatNoException;9import org.junit.jupiter.api.Test;10import java.time.ZonedDateTime;11import java.time.format.DateTimeParseException;12public class ZonedDateTimeAssert_isEqualTo_Test {13 public void test_isEqualTo_assertion() {14 final ZonedDateTime refZonedDateTime = ZonedDateTime.parse("2000-01-05T03:30:00+01:00[Europe/Paris]");15 assertThat(refZonedDateTime).isEqualTo("2000-01-05T03:30:00+01:00[Europe/Paris]");16 }17 public void test_isEqualTo_assertion_error_message() {18 final ZonedDateTime refZonedDateTime = ZonedDateTime.parse("2000-01-05T03:30:00+01:00[Europe/Paris]");19 assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> assertThat(refZonedDateTime).isEqualTo("2000-01-05T03:30:00+01:00[Europe/Brussels]"))20 .withMessageContaining("expected: \"2000-01-05T03:30:00+01:00[Europe/Brussels]\"");21 }22 public void test_isEqualTo_assertion_error_message_with_custom_comparison_strategy() {23 final ZonedDateTime refZonedDateTime = ZonedDateTime.parse("2000-01-05T03:30:00+01:00[Europe/Paris]");24 assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> assertThat(refZonedDateTime).usingComparatorForType(ZonedDateTime::compareTo, ZonedDateTime.class).isEqualTo("2000-01-05T03:30:00+01:00[Europe/Brussels]"))25 .withMessageContaining("expected: \"2000-01-05T03:30:00+01:00[Europe/Brussels]\"");26 }

Full Screen

Full Screen

assertDateTimeAsStringParameterIsNotNull

Using AI Code Generation

copy

Full Screen

1assertThat(ZonedDateTime.now()).assertDateTimeAsStringParameterIsNotNull("2011-12-03T10:15:30+01:00[Europe/Paris]");2assertThat(ZonedDateTime.now()).assertDateTimeAsStringParameterIsNotNull("2011-12-03T10:15:30+01:00[Europe/Paris]");3assertThat(ZonedDateTime.now()).assertDateTimeAsStringParameterIsNotNull("2011-12-03T10:15:30+01:00[Europe/Paris]");4assertThat(ZonedDateTime.now()).assertDateTimeAsStringParameterIsNotNull("2011-12-03T10:15:30+01:00[Europe/Paris]");5assertThat(ZonedDateTime.now()).assertDateTimeAsStringParameterIsNotNull("2011-12-03T10:15:30+01:00[Europe/Paris]");6assertThat(ZonedDateTime.now()).assertDateTimeAsStringParameterIsNotNull("2011-12-03T10:15:30+01:00[Europe/Paris]");

Full Screen

Full Screen

assertDateTimeAsStringParameterIsNotNull

Using AI Code Generation

copy

Full Screen

1import org.junit.Test;2import org.junit.runner.RunWith;3import org.mockito.junit.MockitoJUnitRunner;4import java.time.ZonedDateTime;5import static org.assertj.core.api.Assertions.assertThat;6@RunWith(MockitoJUnitRunner.class)7public class AbstractZonedDateTimeAssert_assertDateTimeAsStringParameterIsNotNull_Test {8 public void test_assertDateTimeAsStringParameterIsNotNull() {9 ZonedDateTime zonedDateTime = ZonedDateTime.now();10 assertThat(zonedDateTime).isNotNull();11 }12}13 at org.junit.Assert.assertEquals(Assert.java:115)14 at org.junit.Assert.assertEquals(Assert.java:144)15 at org.assertj.core.api.AbstractZonedDateTimeAssert_assertDateTimeAsStringParameterIsNotNull_Test.test_assertDateTimeAsStringParameterIsNotNull(AbstractZonedDateTimeAssert_assertDateTimeAsStringParameterIsNotNull_Test.java:17)

Full Screen

Full Screen

assertDateTimeAsStringParameterIsNotNull

Using AI Code Generation

copy

Full Screen

1ZonedDateTime zonedDateTime = ZonedDateTime.now();2assertThat(zonedDateTime).assertDateTimeAsStringParameterIsNotNull();3ZonedDateTime zonedDateTime = ZonedDateTime.now();4assertThat(zonedDateTime).assertDateTimeAsStringParameterIsNotNull();5ZonedDateTime zonedDateTime = ZonedDateTime.now();6assertThat(zonedDateTime).assertDateTimeAsStringParameterIsNotNull();7ZonedDateTime zonedDateTime = ZonedDateTime.now();8assertThat(zonedDateTime).assertDateTimeAsStringParameterIsNotNull();

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