Best Assertj code snippet using org.assertj.core.api.AbstractOffsetDateTimeAssert.buildDefaultComparables
Source:AbstractOffsetDateTimeAssert.java
...51 * @param actual the actual value to verify52 */53 protected AbstractOffsetDateTimeAssert(OffsetDateTime actual, Class<?> selfType) {54 super(actual, selfType);55 comparables = buildDefaultComparables();56 }57 /**58 * Verifies that the actual {@code OffsetDateTime} is <b>strictly</b> before the given one according to the comparator in use.59 * <p>60 * <b>Breaking change</b> since 3.15.0 The default comparator uses {@link OffsetDateTime#timeLineOrder()}61 * which only compares the underlying instant and ignores different timezones / offsets / chronologies.<br>62 * This behaviour can be overridden by {@link AbstractOffsetDateTimeAssert#usingComparator(Comparator)}.63 * <p>64 * Example :65 * <pre><code class='java'> // assertion succeeds66 * assertThat(parse("2000-01-01T01:00:00Z")).isBefore(parse("2020-01-01T01:00:00Z"));67 *68 * // assertions fail69 * assertThat(parse("2000-01-01T01:00:00Z")).isBefore(parse("1999-01-01T01:00:00Z"));70 * assertThat(parse("2000-01-01T01:00:00Z")).isBefore(parse("2000-01-01T01:00:00Z"));71 * // fails because both OffsetDateTime refer to the same instant (on different offsets)72 * assertThat(parse("2000-01-01T01:00:00Z")).isBefore(parse("2000-01-01T00:00:00-01:00"));73 *74 * // succeeds because both OffsetDateTime refer to the same instant and OffsetDateTime natural comparator is used.75 * assertThat(parse("2000-01-02T00:00:00Z")).usingComparator(OffsetDateTime::compareTo)76 * .isBefore(parse("2000-01-02T01:00:00+01:00")); </code></pre>77 *78 * @param other the given {@link java.time.OffsetDateTime}.79 * @return this assertion object.80 * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.81 * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.82 * @throws AssertionError if the actual {@code OffsetDateTime} is not strictly before the given one according to83 * the comparator in use.84 */85 public SELF isBefore(OffsetDateTime other) {86 assertOffsetDateTimeParameterIsNotNull(other);87 comparables.assertIsBefore(info, actual, other);88 return myself;89 }90 /**91 * Same assertion as {@link #isBefore(java.time.OffsetDateTime)} but the {@link java.time.OffsetDateTime} is built92 * from given String, which93 * must follow <a href=94 * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_OFFSET_DATE_TIME"95 * >ISO OffsetDateTime format</a> to allow calling {@link java.time.OffsetDateTime#parse(CharSequence)} method.96 * <p>97 * <b>Breaking change</b> since 3.15.0 The default comparator uses {@link OffsetDateTime#timeLineOrder()}98 * which only compares the underlying instant and ignores different timezones / offsets / chronologies.<br>99 * This behaviour can be overridden by {@link AbstractOffsetDateTimeAssert#usingComparator(Comparator)}.100 * <p>101 * Example :102 * <pre><code class='java'> // assertion succeeds103 * assertThat(parse("2000-01-01T01:00:00Z")).isBefore("2020-01-01T01:00:00Z");104 *105 * // assertions fail106 * assertThat(parse("2000-01-01T01:00:00Z")).isBefore("1999-01-01T01:00:00Z");107 * assertThat(parse("2000-01-01T01:00:00Z")).isBefore("2000-01-01T01:00:00Z");108 * // fails because both OffsetDateTime refer to the same instant (on different offsets)109 * assertThat(parse("2000-01-01T01:00:00Z")).isBefore("2000-01-01T00:00:00-01:00");110 *111 * // succeeds because both OffsetDateTime refer to the same instant and OffsetDateTime natural comparator is used.112 * assertThat(parse("2000-01-02T00:00:00Z")).usingComparator(OffsetDateTime::compareTo)113 * .isBefore("2000-01-02T01:00:00+01:00"); </code></pre>114 *115 * @param offsetDateTimeAsString String representing a {@link java.time.OffsetDateTime}.116 * @return this assertion object.117 * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.118 * @throws IllegalArgumentException if given String is null or can't be converted to a119 * {@link java.time.OffsetDateTime}.120 * @throws AssertionError if the actual {@code OffsetDateTime} is not strictly before the121 * {@link java.time.OffsetDateTime} built122 * from given String.123 */124 public SELF isBefore(String offsetDateTimeAsString) {125 assertOffsetDateTimeAsStringParameterIsNotNull(offsetDateTimeAsString);126 return isBefore(parse(offsetDateTimeAsString));127 }128 /**129 * Verifies that the actual {@code OffsetDateTime} is before or equals to the given one according to the comparator in use.130 * <p>131 * <b>Breaking change</b> since 3.15.0 The default comparator uses {@link OffsetDateTime#timeLineOrder()}132 * which only compares the underlying instant and ignores different timezones / offsets / chronologies.<br>133 * This behaviour can be overridden by {@link AbstractOffsetDateTimeAssert#usingComparator(Comparator)}.134 * <p>135 * Example :136 * <pre><code class='java'> // assertions succeed137 * assertThat(parse("2000-01-01T01:00:00Z")).isBeforeOrEqualTo(parse("2020-01-01T01:00:00Z"))138 * .isBeforeOrEqualTo(parse("2000-01-01T01:00:00Z"))139 * // same instant (on different offsets)140 * .isBeforeOrEqualTo(parse("2000-01-01T00:00:00-01:00"));141 *142 * // assertions fail143 * assertThat(parse("2000-01-01T01:00:00Z")).isBeforeOrEqualTo(parse("1999-01-01T01:00:00Z"));144 * // even though the same instant, fails because of OffsetDateTime natural comparator is used and OffsetDateTime are on different offsets145 * assertThat(parse("2000-01-01T01:00:00Z")).usingComparator(OffsetDateTime::compareTo)146 * .isBeforeOrEqualTo(parse("2000-01-01T00:00:00-01:00")); </code></pre>147 *148 * @param other the given {@link java.time.OffsetDateTime}.149 * @return this assertion object.150 * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.151 * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.152 * @throws AssertionError if the actual {@code OffsetDateTime} is not before or equals to the given one according to153 * the comparator in use.154 */155 public SELF isBeforeOrEqualTo(OffsetDateTime other) {156 assertOffsetDateTimeParameterIsNotNull(other);157 comparables.assertIsBeforeOrEqualTo(info, actual, other);158 return myself;159 }160 /**161 * Same assertion as {@link #isBeforeOrEqualTo(java.time.OffsetDateTime)} but the {@link java.time.OffsetDateTime} is162 * built from given163 * String, which must follow <a href=164 * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_OFFSET_DATE_TIME"165 * >ISO OffsetDateTime format</a> to allow calling {@link java.time.OffsetDateTime#parse(CharSequence)} method.166 * <p>167 * <b>Breaking change</b> since 3.15.0 The default comparator uses {@link OffsetDateTime#timeLineOrder()}168 * which only compares the underlying instant and ignores different timezones / offsets / chronologies.<br>169 * This behaviour can be overridden by {@link AbstractOffsetDateTimeAssert#usingComparator(Comparator)}.170 * <p>171 * Example :172 * <pre><code class='java'> // assertions succeed173 * assertThat(parse("2000-01-01T01:00:00Z")).isBeforeOrEqualTo("2020-01-01T01:00:00Z")174 * .isBeforeOrEqualTo("2000-01-01T01:00:00Z")175 * // same instant (on different offsets)176 * .isBeforeOrEqualTo("2000-01-01T00:00:00-01:00");177 *178 * // assertions fail179 * assertThat(parse("2000-01-01T01:00:00Z")).isBeforeOrEqualTo("1999-01-01T01:00:00Z");180 * // even though the same instant, fails because of OffsetDateTime natural comparator is used and OffsetDateTime are on different offsets181 * assertThat(parse("2000-01-01T01:00:00Z")).usingComparator(OffsetDateTime::compareTo)182 * .isBeforeOrEqualTo("2000-01-01T00:00:00-01:00"); </code></pre>183 *184 * @param offsetDateTimeAsString String representing a {@link java.time.OffsetDateTime}.185 * @return this assertion object.186 * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.187 * @throws IllegalArgumentException if given String is null or can't be converted to a188 * {@link java.time.OffsetDateTime}.189 * @throws AssertionError if the actual {@code OffsetDateTime} is not before or equals to the190 * {@link java.time.OffsetDateTime} built from given String.191 */192 public SELF isBeforeOrEqualTo(String offsetDateTimeAsString) {193 assertOffsetDateTimeAsStringParameterIsNotNull(offsetDateTimeAsString);194 return isBeforeOrEqualTo(parse(offsetDateTimeAsString));195 }196 /**197 * Verifies that the actual {@code OffsetDateTime} is after or equals to the given one according to the comparator in use.198 * <p>199 * <b>Breaking change</b> since 3.15.0 The default comparator uses {@link OffsetDateTime#timeLineOrder()}200 * which only compares the underlying instant and ignores different timezones / offsets / chronologies.<br>201 * This behaviour can be overridden by {@link AbstractOffsetDateTimeAssert#usingComparator(Comparator)}.202 * <p>203 * Example :204 * <pre><code class='java'> // assertions succeed205 * assertThat(parse("2000-01-01T00:00:00Z")).isAfterOrEqualTo(parse("2000-01-01T00:00:00Z"))206 * .isAfterOrEqualTo(parse("1999-12-31T23:59:59Z"))207 * // same instant in different offset208 * .isAfterOrEqualTo(parse("2000-01-01T00:00:00-01:00"));209 *210 * // assertions fail211 * assertThat(parse("2000-01-01T00:00:00Z")).isAfterOrEqualTo(parse("2001-01-01T00:00:00Z"));212 * // fails even though they refer to the same instant due to OffsetDateTime natural comparator213 * assertThat(parse("2000-01-01T00:00:00Z")).usingComparator(OffsetDateTime::compareTo)214 * .isAfterOrEqualTo(parse("2000-01-01T01:00:00+01:00"));</code></pre>215 *216 * @param other the given {@link java.time.OffsetDateTime}.217 * @return this assertion object.218 * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.219 * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.220 * @throws AssertionError if the actual {@code OffsetDateTime} is not after or equals to the given one according to221 * the comparator in use.222 */223 public SELF isAfterOrEqualTo(OffsetDateTime other) {224 assertOffsetDateTimeParameterIsNotNull(other);225 comparables.assertIsAfterOrEqualTo(info, actual, other);226 return myself;227 }228 /**229 * Same assertion as {@link #isAfterOrEqualTo(java.time.OffsetDateTime)} but the {@link java.time.OffsetDateTime} is230 * built from given231 * String, which must follow <a href=232 * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_OFFSET_DATE_TIME"233 * >ISO OffsetDateTime format</a> to allow calling {@link java.time.OffsetDateTime#parse(CharSequence)} method.234 * <p>235 * <b>Breaking change</b> since 3.15.0 The default comparator uses {@link OffsetDateTime#timeLineOrder()}236 * which only compares the underlying instant and ignores different timezones / offsets / chronologies.<br>237 * This behaviour can be overridden by {@link AbstractOffsetDateTimeAssert#usingComparator(Comparator)}.238 * <p>239 * Example :240 * <pre><code class='java'> // assertions succeed241 * assertThat(parse("2000-01-01T00:00:00Z")).isAfterOrEqualTo("2000-01-01T00:00:00Z")242 * .isAfterOrEqualTo("1999-12-31T23:59:59Z")243 * // same instant in different offset244 * .isAfterOrEqualTo("2000-01-01T00:00:00-01:00");245 *246 * // assertions fail247 * assertThat(parse("2000-01-01T00:00:00Z")).isAfterOrEqualTo("2001-01-01T00:00:00Z");248 * // fails even though they refer to the same instant due to OffsetDateTime natural comparator249 * assertThat(parse("2000-01-01T00:00:00Z")).usingComparator(OffsetDateTime::compareTo)250 * .isAfterOrEqualTo("2000-01-01T01:00:00+01:00");</code></pre>251 *252 * @param offsetDateTimeAsString String representing a {@link java.time.OffsetDateTime}.253 * @return this assertion object.254 * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.255 * @throws IllegalArgumentException if given String is null or can't be converted to a256 * {@link java.time.OffsetDateTime}.257 * @throws AssertionError if the actual {@code OffsetDateTime} is not after or equals to the258 * {@link java.time.OffsetDateTime} built from given String.259 */260 public SELF isAfterOrEqualTo(String offsetDateTimeAsString) {261 assertOffsetDateTimeAsStringParameterIsNotNull(offsetDateTimeAsString);262 return isAfterOrEqualTo(parse(offsetDateTimeAsString));263 }264 /**265 * Verifies that the actual {@code OffsetDateTime} is <b>strictly</b> after the given one according to the comparator in use.266 * <p>267 * <b>Breaking change</b> since 3.15.0 The default comparator uses {@link OffsetDateTime#timeLineOrder()}268 * which only compares the underlying instant and ignores different timezones / offsets / chronologies.<br>269 * This behaviour can be overridden by {@link AbstractOffsetDateTimeAssert#usingComparator(Comparator)}.270 * <p>271 * Example :272 * <pre><code class='java'> // assertions succeed:273 * assertThat(parse("2000-01-01T00:00:00Z")).isAfter(parse("1999-12-31T23:59:59Z"));274 *275 * // assertions fail276 * assertThat(parse("2000-01-01T01:00:00Z")).isAfter(parse("2001-01-01T01:00:00Z"));277 * assertThat(parse("2000-01-01T01:00:00Z")).isAfter(parse("2000-01-01T01:00:00Z"));278 * // fails because both OffsetDateTime refer to the same instant (on different offsets)279 * assertThat(parse("2000-01-01T01:00:00Z")).isAfter(parse("2000-01-01T00:00:00-01:00"));280 *281 * // even though they refer to the same instant assertion succeeds because of different offset282 * assertThat(parse("2000-01-01T01:00:00Z")).usingComparator(OffsetDateTime::compareTo)283 * .isAfter(parse("2000-01-01T00:00:00-01:00"));</code></pre>284 *285 * @param other the given {@link java.time.OffsetDateTime}.286 * @return this assertion object.287 * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.288 * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.289 * @throws AssertionError if the actual {@code OffsetDateTime} is not strictly after the given one according to290 * the comparator in use.291 */292 public SELF isAfter(OffsetDateTime other) {293 assertOffsetDateTimeParameterIsNotNull(other);294 comparables.assertIsAfter(info, actual, other);295 return myself;296 }297 /**298 * Same assertion as {@link #isAfter(java.time.OffsetDateTime)} but the {@link java.time.OffsetDateTime} is built from299 * given a String that300 * must follow <a href=301 * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_OFFSET_DATE_TIME"302 * >ISO OffsetDateTime format</a> to allow calling {@link java.time.OffsetDateTime#parse(CharSequence)} method.303 * <p>304 * <b>Breaking change</b> since 3.15.0 The default comparator uses {@link OffsetDateTime#timeLineOrder()}305 * which only compares the underlying instant and ignores different timezones / offsets / chronologies.<br>306 * This behaviour can be overridden by {@link AbstractOffsetDateTimeAssert#usingComparator(Comparator)}.307 * <p>308 * Example :309 * <pre><code class='java'> // assertion succeeds310 * assertThat(parse("2000-01-01T01:00:00Z")).isAfter("1999-01-01T00:00:00Z");311 *312 * // assertions fail313 * assertThat(parse("2000-01-01T01:00:00Z")).isAfter("2001-01-01T01:00:00Z");314 * assertThat(parse("2000-01-01T01:00:00Z")).isAfter("2000-01-01T01:00:00Z");315 * // fails because both OffsetDateTime refer to the same instant (on different offsets)316 * assertThat(parse("2000-01-01T01:00:00Z")).isAfter("2000-01-01T00:00:00-01:00");317 *318 * // even though they refer to the same instant assertion succeeds because of different offset319 * assertThat(parse("2000-01-01T01:00:00Z")).usingComparator(OffsetDateTime::compareTo)320 * .isAfter("2000-01-01T00:00:00-01:00");</code></pre>321 *322 * @param offsetDateTimeAsString String representing a {@link java.time.OffsetDateTime}.323 * @return this assertion object.324 * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.325 * @throws IllegalArgumentException if given String is null or can't be converted to a326 * {@link java.time.OffsetDateTime}.327 * @throws AssertionError if the actual {@code OffsetDateTime} is not strictly after the328 * {@link java.time.OffsetDateTime} built from given String.329 */330 public SELF isAfter(String offsetDateTimeAsString) {331 assertOffsetDateTimeAsStringParameterIsNotNull(offsetDateTimeAsString);332 return isAfter(parse(offsetDateTimeAsString));333 }334 /**335 * Verifies that the actual {@code OffsetDateTime} is equal to the given one according to the comparator in use.336 * <p>337 * <b>Breaking change</b> since 3.15.0 The default comparator uses {@link OffsetDateTime#timeLineOrder()}338 * which only compares the underlying instant and ignores different timezones / offsets / chronologies.<br>339 * This behaviour can be overridden by {@link AbstractOffsetDateTimeAssert#usingComparator(Comparator)}.340 * <p>341 * Example :342 * <pre><code class='java'> OffsetDateTime firstOfJanuary2000InUTC = OffsetDateTime.parse("2000-01-01T00:00:00Z");343 *344 * // both assertions succeed, the second one because the comparison based on the instant they are referring to345 * // 2000-01-01T01:00:00+01:00 = 2000-01-01T00:00:00 in UTC346 * assertThat(firstOfJanuary2000InUTC).isEqualTo(parse("2000-01-01T00:00:00Z"))347 * .isEqualTo(parse("2000-01-01T01:00:00+01:00"));348 *349 * // assertions fail350 * assertThat(firstOfJanuary2000InUTC).isEqualTo(parse("1999-01-01T01:00:00Z"));351 * // fails as the comparator compares the offsets352 * assertThat(firstOfJanuary2000InUTC).usingComparator(OffsetDateTime::compareTo)353 * .isEqualTo(parse("2000-01-01T01:00:00+01:00"));</code></pre>354 *355 * @param other the given value to compare the actual value to.356 * @return this assertion object.357 * @throws AssertionError if the actual {@code OffsetDateTime} is not equal to the given one according to358 * the comparator in use.359 */360 @Override361 public SELF isEqualTo(Object other) {362 if (actual == null || other == null) {363 super.isEqualTo(other);364 } else {365 comparables.assertEqual(info, actual, other);366 }367 return myself;368 }369 /**370 * Verifies that the actual {@link OffsetDateTime} is close to the current date and time on the UTC timezone,371 * according to the given {@link TemporalUnitOffset}.372 * You can build the offset parameter using {@link Assertions#within(long, TemporalUnit)} or {@link Assertions#byLessThan(long, TemporalUnit)}.373 * <p>374 * If the difference is equal to the offset, the assertion succeeds.375 * <p>376 * Example:377 * <pre><code class='java'> OffsetDateTime actual = OffsetDateTime.now(Clock.systemUTC());378 *379 * // assertion will pass as if executed less than one second after actual was built380 * assertThat(actual).isCloseToUtcNow(within(1, ChronoUnit.SECONDS));381 *382 * // assertion will fail383 * assertThat(actual.plusSeconds(2)).isCloseToUtcNow(within(1, ChronoUnit.SECONDS));</code></pre>384 *385 * @param offset The offset used for comparison386 * @return this assertion object387 * @throws NullPointerException if {@code offset} parameter is {@code null}.388 * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.389 * @throws AssertionError if the actual {@code OffsetDateTime} is not close to the current time by less than the given offset.390 */391 public SELF isCloseToUtcNow(TemporalUnitOffset offset) {392 return isCloseTo(now(systemUTC()), offset);393 }394 /**395 * Same assertion as {@link #isEqualTo(Object)} (where Object is expected to be {@link java.time.OffsetDateTime}) but396 * here you397 * pass {@link java.time.OffsetDateTime} String representation that must follow <a href=398 * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_OFFSET_DATE_TIME"399 * >ISO OffsetDateTime format</a> to allow calling {@link java.time.OffsetDateTime#parse(CharSequence)} method.400 * <p>401 * <b>Breaking change</b> since 3.15.0 The default comparator uses {@link OffsetDateTime#timeLineOrder()}402 * which only compares the underlying instant and ignores different timezones / offsets / chronologies.<br>403 * This behaviour can be overridden by {@link AbstractOffsetDateTimeAssert#usingComparator(Comparator)}.404 * <p>405 * Example :406 * <pre><code class='java'> OffsetDateTime firstOfJanuary2000InUTC = OffsetDateTime.parse("2000-01-01T00:00:00Z");407 *408 * // both assertions succeed, the second one because the comparison based on the instant they are referring to409 * // 2000-01-01T01:00:00+01:00 = 2000-01-01T00:00:00 in UTC410 * assertThat(firstOfJanuary2000InUTC).isEqualTo("2000-01-01T00:00:00Z")411 * .isEqualTo("2000-01-01T01:00:00+01:00");412 *413 * // assertions fail414 * assertThat(firstOfJanuary2000InUTC).isEqualTo("1999-01-01T01:00:00Z");415 * // fails as the comparator compares the offsets416 * assertThat(firstOfJanuary2000InUTC).usingComparator(OffsetDateTime::compareTo)417 * .isEqualTo("2000-01-01T01:00:00+01:00");</code></pre>418 *419 * @param dateTimeAsString String representing a {@link java.time.OffsetDateTime}.420 * @return this assertion object.421 * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.422 * @throws IllegalArgumentException if given String is null or can't be converted to a423 * {@link java.time.OffsetDateTime}.424 * @throws AssertionError if the actual {@code OffsetDateTime} is not equal to the {@link java.time.OffsetDateTime}425 * built from given String.426 */427 public SELF isEqualTo(String dateTimeAsString) {428 assertOffsetDateTimeAsStringParameterIsNotNull(dateTimeAsString);429 return isEqualTo(parse(dateTimeAsString));430 }431 /**432 * Verifies that the actual {@code OffsetDateTime} is not equal to the given value according to the comparator in use.433 * <p>434 * <b>Breaking change</b> since 3.15.0 The default comparator uses {@link OffsetDateTime#timeLineOrder()}435 * which only compares the underlying instant and ignores different timezones / offsets / chronologies.<br>436 * This behaviour can be overridden by {@link AbstractOffsetDateTimeAssert#usingComparator(Comparator)}.437 * <p>438 * Example :439 * <pre><code class='java'> // assertions succeed440 * assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo(parse("2020-01-01T00:00:00Z"));441 * // even though they refer to the same instant, succeeds as the OffsetDateTime comparator checks the offsets442 * assertThat(parse("2000-01-01T00:00:00Z")).usingComparator(OffsetDateTime::compareTo)443 * .isNotEqualTo(parse("2000-01-01T02:00:00+02:00"));444 *445 * // assertions fail446 * assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo(parse("2000-01-01T00:00:00Z"));447 * // fails because the default comparator only checks the instant and they refer to the same448 * assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo(parse("2000-01-01T02:00:00+02:00"));</code></pre>449 *450 * @param other the given value to compare the actual value to.451 * @return this assertion object.452 * @throws AssertionError if the actual {@code OffsetDateTime} is equal to the given one according to453 * the comparator in use.454 */455 @Override456 public SELF isNotEqualTo(Object other) {457 if (actual == null || other == null) {458 super.isNotEqualTo(other);459 } else {460 comparables.assertNotEqual(info, actual, other);461 }462 return myself;463 }464 /**465 * Same assertion as {@link #isNotEqualTo(Object)} (where Object is expected to be {@link java.time.OffsetDateTime})466 * but here you467 * pass {@link java.time.OffsetDateTime} String representation that must follow <a href=468 * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_OFFSET_DATE_TIME"469 * >ISO OffsetDateTime format</a> to allow calling {@link java.time.OffsetDateTime#parse(CharSequence)} method.470 * <p>471 * <b>Breaking change</b> since 3.15.0 The default comparator uses {@link OffsetDateTime#timeLineOrder()}472 * which only compares the underlying instant and ignores different timezones / offsets / chronologies.<br>473 * This behaviour can be overridden by {@link AbstractOffsetDateTimeAssert#usingComparator(Comparator)}.474 * <p>475 * Example :476 * <pre><code class='java'> // assertions succeed477 * assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo("2020-01-01T00:00:00Z");478 * // even though they refer to the same instant, succeeds as the OffsetDateTime comparator checks the offsets479 * assertThat(parse("2000-01-01T00:00:00Z")).usingComparator(OffsetDateTime::compareTo)480 * .isNotEqualTo("2000-01-01T02:00:00+02:00");481 *482 * // assertions fail483 * assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo("2000-01-01T00:00:00Z");484 * // fails because the default comparator only checks the instant and they refer to the same485 * assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo("2000-01-01T02:00:00+02:00");</code></pre>486 *487 * @param dateTimeAsString String representing a {@link java.time.OffsetDateTime}.488 * @return this assertion object.489 * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.490 * @throws IllegalArgumentException if given String is null or can't be converted to a491 * {@link java.time.OffsetDateTime}.492 * @throws AssertionError if the actual {@code OffsetDateTime} is equal to the {@link java.time.OffsetDateTime} built493 * from given String.494 */495 public SELF isNotEqualTo(String dateTimeAsString) {496 assertOffsetDateTimeAsStringParameterIsNotNull(dateTimeAsString);497 return isNotEqualTo(parse(dateTimeAsString));498 }499 /**500 * Same assertion as {@link #isIn(Object...)} (where Objects are expected to be {@link java.time.OffsetDateTime}) but501 * here you502 * pass {@link java.time.OffsetDateTime} String representations that must follow <a href=503 * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_OFFSET_DATE_TIME"504 * >ISO OffsetDateTime format</a> to allow calling {@link java.time.OffsetDateTime#parse(CharSequence)} method.505 * <p>506 * Example :507 * <pre><code class='java'> // use String based representation of OffsetDateTime508 * assertThat(parse("2000-01-01T00:00:00Z")).isIn("1999-12-31T00:00:00Z",509 * "2000-01-01T00:00:00Z");</code></pre>510 *511 * @param dateTimesAsString String array representing {@link java.time.OffsetDateTime}s.512 * @return this assertion object.513 * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.514 * @throws IllegalArgumentException if given String is null or can't be converted to a515 * {@link java.time.OffsetDateTime}.516 * @throws AssertionError if the actual {@code OffsetDateTime} is not in the {@link java.time.OffsetDateTime}s built517 * from given Strings.518 */519 public SELF isIn(String... dateTimesAsString) {520 checkIsNotNullAndNotEmpty(dateTimesAsString);521 return isIn(convertToOffsetDateTimeArray(dateTimesAsString));522 }523 /**524 * Same assertion as {@link #isNotIn(Object...)} (where Objects are expected to be {@link java.time.OffsetDateTime})525 * but here you526 * pass {@link java.time.OffsetDateTime} String representations that must follow <a href=527 * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_OFFSET_DATE_TIME"528 * >ISO OffsetDateTime format</a> to allow calling {@link java.time.OffsetDateTime#parse(CharSequence)} method.529 * <p>530 * Example :531 * <pre><code class='java'> // use String based representation of OffsetDateTime532 * assertThat(parse("2000-01-01T00:00:00Z")).isNotIn("1999-12-31T00:00:00Z",533 * "2000-01-02T00:00:00Z");</code></pre>534 *535 * @param dateTimesAsString Array of String representing a {@link java.time.OffsetDateTime}.536 * @return this assertion object.537 * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.538 * @throws IllegalArgumentException if given String is null or can't be converted to a539 * {@link java.time.OffsetDateTime}.540 * @throws AssertionError if the actual {@code OffsetDateTime} is in the {@link java.time.OffsetDateTime}s built from541 * given Strings.542 */543 public SELF isNotIn(String... dateTimesAsString) {544 checkIsNotNullAndNotEmpty(dateTimesAsString);545 return isNotIn(convertToOffsetDateTimeArray(dateTimesAsString));546 }547 /**548 * Verifies that actual and given {@code OffsetDateTime} have same year, month, day, hour, minute and second fields,549 * (nanosecond fields are ignored in comparison).550 * <p>551 * Assertion can fail with OffsetDateTimes in same chronological nanosecond time window, e.g :552 * <p>553 * 2000-01-01T00:00:<b>01.000000000</b>+01:00 and 2000-01-01T00:00:<b>00.999999999</b>+01:00.554 * <p>555 * Assertion fails as second fields differ even if time difference is only 1ns.556 * <p>557 * Code example :558 * <pre><code class='java'> // successful assertions559 * OffsetDateTime OffsetDateTime1 = OffsetDateTime.of(2000, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC);560 * OffsetDateTime OffsetDateTime2 = OffsetDateTime.of(2000, 1, 1, 0, 0, 1, 456, ZoneOffset.UTC);561 * assertThat(OffsetDateTime1).isEqualToIgnoringNanos(OffsetDateTime2);</code></pre>562 *563 * <pre><code class='java'> // failing assertions (even if time difference is only 1ns)564 * OffsetDateTime OffsetDateTimeA = OffsetDateTime.of(2000, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC);565 * OffsetDateTime OffsetDateTimeB = OffsetDateTime.of(2000, 1, 1, 0, 0, 0, 999999999, ZoneOffset.UTC);566 * assertThat(OffsetDateTimeA).isEqualToIgnoringNanos(OffsetDateTimeB);</code></pre>567 *568 * @param other the given {@link java.time.OffsetDateTime}.569 * @return this assertion object.570 * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.571 * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.572 * @throws AssertionError if the actual {@code OffsetDateTime} is are not equal with nanoseconds ignored.573 */574 public SELF isEqualToIgnoringNanos(OffsetDateTime other) {575 Objects.instance().assertNotNull(info, actual);576 assertOffsetDateTimeParameterIsNotNull(other);577 if (!areEqualIgnoringNanos(actual, other)) {578 throw Failures.instance().failure(info, shouldBeEqualIgnoringNanos(actual, other));579 }580 return myself;581 }582 /**583 * Verifies that actual and given {@code OffsetDateTime} have same year, month, day, hour, minute, second and584 * nanosecond fields,585 * (timezone fields are ignored in comparison).586 * <p>587 * Code example :588 * <pre><code class='java'> // successful assertions589 * OffsetDateTime OffsetDateTime1 = OffsetDateTime.of(2000, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC);590 * OffsetDateTime OffsetDateTime2 = OffsetDateTime.of(2000, 1, 1, 0, 0, 1, 0, ZoneOffset.MAX);591 * assertThat(OffsetDateTime1).isEqualToIgnoringTimezone(OffsetDateTime2);592 *593 * // failing assertions594 * OffsetDateTime OffsetDateTimeA = OffsetDateTime.of(2000, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC);595 * OffsetDateTime OffsetDateTimeB = OffsetDateTime.of(2000, 1, 1, 0, 0, 0, 999999999, ZoneOffset.UTC);596 * assertThat(OffsetDateTimeA).isEqualToIgnoringTimezone(OffsetDateTimeB);</code></pre>597 *598 * @param other the given {@link java.time.OffsetDateTime}.599 * @return this assertion object.600 * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.601 * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.602 * @throws AssertionError if the actual {@code OffsetDateTime} is are not equal with timezone ignored.603 */604 public SELF isEqualToIgnoringTimezone(OffsetDateTime other) {605 Objects.instance().assertNotNull(info, actual);606 assertOffsetDateTimeParameterIsNotNull(other);607 if (!areEqualIgnoringTimezone(actual, other)) {608 throw Failures.instance().failure(info, shouldBeEqualIgnoringTimezone(actual, other));609 }610 return myself;611 }612 /**613 * Verifies that actual and given {@link java.time.OffsetDateTime} have same year, month, day, hour and minute fields614 * (second and615 * nanosecond fields are ignored in comparison).616 * <p>617 * Assertion can fail with OffsetDateTimes in same chronological second time window, e.g :618 * <p>619 * 2000-01-01T00:<b>01:00</b>.000+01:00 and 2000-01-01T00:<b>00:59</b>.000+01:00.620 * <p>621 * Assertion fails as minute fields differ even if time difference is only 1s.622 * <p>623 * Code example :624 * <pre><code class='java'> // successful assertions625 * OffsetDateTime OffsetDateTime1 = OffsetDateTime.of(2000, 1, 1, 23, 50, 0, 0, ZoneOffset.UTC);626 * OffsetDateTime OffsetDateTime2 = OffsetDateTime.of(2000, 1, 1, 23, 50, 10, 456, ZoneOffset.UTC);627 * assertThat(OffsetDateTime1).isEqualToIgnoringSeconds(OffsetDateTime2);628 *629 * // failing assertions (even if time difference is only 1ms)630 * OffsetDateTime OffsetDateTimeA = OffsetDateTime.of(2000, 1, 1, 23, 50, 00, 000, ZoneOffset.UTC);631 * OffsetDateTime OffsetDateTimeB = OffsetDateTime.of(2000, 1, 1, 23, 49, 59, 999, ZoneOffset.UTC);632 * assertThat(OffsetDateTimeA).isEqualToIgnoringSeconds(OffsetDateTimeB);</code></pre>633 *634 * @param other the given {@link java.time.OffsetDateTime}.635 * @return this assertion object.636 * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.637 * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.638 * @throws AssertionError if the actual {@code OffsetDateTime} is are not equal with second and nanosecond fields639 * ignored.640 */641 public SELF isEqualToIgnoringSeconds(OffsetDateTime other) {642 Objects.instance().assertNotNull(info, actual);643 assertOffsetDateTimeParameterIsNotNull(other);644 if (!areEqualIgnoringSeconds(actual, other)) {645 throw Failures.instance().failure(info, shouldBeEqualIgnoringSeconds(actual, other));646 }647 return myself;648 }649 /**650 * Verifies that actual and given {@code OffsetDateTime} have same year, month, day and hour fields (minute, second651 * and652 * nanosecond fields are ignored in comparison).653 * <p>654 * Assertion can fail with OffsetDateTimes in same chronological second time window, e.g :655 * <p>656 * 2000-01-01T<b>01:00</b>:00.000+01:00 and 2000-01-01T<b>00:59:59</b>.000+01:00.657 * <p>658 * Time difference is only 1s but hour fields differ.659 * <p>660 * Code example :661 * <pre><code class='java'> // successful assertions662 * OffsetDateTime OffsetDateTime1 = OffsetDateTime.of(2000, 1, 1, 23, 50, 0, 0, ZoneOffset.UTC);663 * OffsetDateTime OffsetDateTime2 = OffsetDateTime.of(2000, 1, 1, 23, 00, 2, 7, ZoneOffset.UTC);664 * assertThat(OffsetDateTime1).isEqualToIgnoringMinutes(OffsetDateTime2);665 *666 * // failing assertions (even if time difference is only 1ms)667 * OffsetDateTime OffsetDateTimeA = OffsetDateTime.of(2000, 1, 1, 01, 00, 00, 000, ZoneOffset.UTC);668 * OffsetDateTime OffsetDateTimeB = OffsetDateTime.of(2000, 1, 1, 00, 59, 59, 999, ZoneOffset.UTC);669 * assertThat(OffsetDateTimeA).isEqualToIgnoringMinutes(OffsetDateTimeB);</code></pre>670 *671 * @param other the given {@link java.time.OffsetDateTime}.672 * @return this assertion object.673 * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.674 * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.675 * @throws AssertionError if the actual {@code OffsetDateTime} is are not equal ignoring minute, second and nanosecond676 * fields.677 */678 public SELF isEqualToIgnoringMinutes(OffsetDateTime other) {679 Objects.instance().assertNotNull(info, actual);680 assertOffsetDateTimeParameterIsNotNull(other);681 if (!areEqualIgnoringMinutes(actual, other)) {682 throw Failures.instance().failure(info, shouldBeEqualIgnoringMinutes(actual, other));683 }684 return myself;685 }686 /**687 * Verifies that actual and given {@code OffsetDateTime} have same year, month and day fields (hour, minute, second688 * and nanosecond fields are ignored in comparison).689 * <p>690 * Assertion can fail with OffsetDateTimes in same chronological minute time window, e.g :691 * <p>692 * 2000-01-<b>01T23:59</b>:00.000+01:00 and 2000-01-02T<b>00:00</b>:00.000+01:00.693 * <p>694 * Time difference is only 1min but day fields differ.695 * <p>696 * Code example :697 * <pre><code class='java'> // successful assertions698 * OffsetDateTime OffsetDateTime1 = OffsetDateTime.of(2000, 1, 1, 23, 59, 59, 999, ZoneOffset.UTC);699 * OffsetDateTime OffsetDateTime2 = OffsetDateTime.of(2000, 1, 1, 00, 00, 00, 000, ZoneOffset.UTC);700 * assertThat(OffsetDateTime1).isEqualToIgnoringHours(OffsetDateTime2);701 *702 * // failing assertions (even if time difference is only 1ms)703 * OffsetDateTime OffsetDateTimeA = OffsetDateTime.of(2000, 1, 2, 00, 00, 00, 000, ZoneOffset.UTC);704 * OffsetDateTime OffsetDateTimeB = OffsetDateTime.of(2000, 1, 1, 23, 59, 59, 999, ZoneOffset.UTC);705 * assertThat(OffsetDateTimeA).isEqualToIgnoringHours(OffsetDateTimeB);</code></pre>706 *707 * @param other the given {@link java.time.OffsetDateTime}.708 * @return this assertion object.709 * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.710 * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.711 * @throws AssertionError if the actual {@code OffsetDateTime} is are not equal with second and nanosecond fields712 * ignored.713 */714 public SELF isEqualToIgnoringHours(OffsetDateTime other) {715 Objects.instance().assertNotNull(info, actual);716 assertOffsetDateTimeParameterIsNotNull(other);717 if (!haveSameYearMonthAndDayOfMonth(actual, other)) {718 throw Failures.instance().failure(info, shouldBeEqualIgnoringHours(actual, other));719 }720 return myself;721 }722 /**723 * Verifies that the actual {@link OffsetDateTime} is in the [start, end] period (start and end included) according to the comparator in use.724 * <p>725 * <b>Breaking change</b> since 3.15.0 The default comparator uses {@link OffsetDateTime#timeLineOrder()}726 * which only compares the underlying instant and ignores different timezones / offsets / chronologies.<br>727 * This behaviour can be overridden by {@link AbstractOffsetDateTimeAssert#usingComparator(Comparator)}.728 * <p>729 * Example:730 * <pre><code class='java'> OffsetDateTime offsetDateTime = OffsetDateTime.now();731 *732 * // assertions succeed:733 * assertThat(offsetDateTime).isBetween(offsetDateTime.minusSeconds(1), offsetDateTime.plusSeconds(1))734 * .isBetween(offsetDateTime, offsetDateTime.plusSeconds(1))735 * .isBetween(offsetDateTime.minusSeconds(1), offsetDateTime)736 * .isBetween(offsetDateTime, offsetDateTime);737 * // succeeds with default comparator which compares the point in time738 * assertThat(parse("2010-01-01T00:00:00Z")).isBetween(parse("2010-01-01T01:00:00+01:00"),739 * parse("2010-01-01T01:00:00+01:00"));740 *741 * // assertions fail:742 * assertThat(offsetDateTime).isBetween(offsetDateTime.minusSeconds(10), offsetDateTime.minusSeconds(1));743 * assertThat(offsetDateTime).isBetween(offsetDateTime.plusSeconds(1), offsetDateTime.plusSeconds(10));744 *745 * // succeeds with default comparator746 * assertThat(parse("2010-01-01T00:00:00Z")).isBetween(parse("2010-01-01T01:00:00+01:00"),747 * parse("2010-01-01T01:00:00+01:00"));748 * // fails with a comparator which checks the offset, too749 * assertThat(parse("2010-01-01T00:00:00Z")).usingComparator(OffsetDateTime::compareTo)750 * .isBetween(parse("2010-01-01T01:00:00+01:00"),751 * parse("2010-01-01T01:00:00+01:00"));</code></pre>752 *753 * @param startExclusive the start value (exclusive), expected not to be null.754 * @param endExclusive the end value (exclusive), expected not to be null.755 * @return this assertion object.756 * @throws AssertionError if the actual value is {@code null}.757 * @throws NullPointerException if start value is {@code null}.758 * @throws NullPointerException if end value is {@code null}.759 * @throws AssertionError if the actual value is not in [start, end] period according to the comparator in use.760 *761 * @since 3.7.1762 */763 public SELF isBetween(OffsetDateTime startExclusive, OffsetDateTime endExclusive) {764 comparables.assertIsBetween(info, actual, startExclusive, endExclusive, true, true);765 return myself;766 }767 /**768 * Same assertion as {@link #isBetween(OffsetDateTime, OffsetDateTime)} but here you pass {@link OffsetDateTime} String representations769 * which must follow <a href="http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_OFFSET_DATE_TIME">ISO OffsetDateTime format</a>770 * to allow calling {@link OffsetDateTime#parse(CharSequence)} method.771 * <p>772 * <b>Breaking change</b> since 3.15.0 The default comparator uses {@link OffsetDateTime#timeLineOrder()}773 * which only compares the underlying instant and ignores different timezones / offsets / chronologies.<br>774 * This behaviour can be overridden by {@link AbstractOffsetDateTimeAssert#usingComparator(Comparator)}.775 * <p>776 * Example:777 * <pre><code class='java'> OffsetDateTime firstOfJanuary2000 = OffsetDateTime.parse("2000-01-01T00:00:00Z");778 *779 * // assertions succeed:780 * assertThat(firstOfJanuary2000).isBetween("1999-12-31T23:59:59Z", "2000-01-01T00:00:01Z")781 * .isBetween("2000-01-01T00:00:00Z", "2000-01-01T00:00:01Z")782 * .isBetween("1999-12-31T23:59:59Z", "2000-01-01T00:00:00Z")783 * .isBetween("2000-01-01T00:00:00Z", "2000-01-01T00:00:00Z")784 * // same instant as firstOfJanuary2000 but on a different offset785 * .isBetween("2000-01-01T01:00:00+01:00", "2000-01-01T01:00:00+01:00");786 *787 * // assertion fails:788 * assertThat(firstOfJanuary2000).isBetween("1999-01-01T00:00:01Z", "1999-12-31T23:59:59Z");</code></pre>789 *790 * @param startExclusive the start value (exclusive), expected not to be null.791 * @param endExclusive the end value (exclusive), expected not to be null.792 * @return this assertion object.793 *794 * @throws AssertionError if the actual value is {@code null}.795 * @throws NullPointerException if start value is {@code null}.796 * @throws NullPointerException if end value is {@code null}.797 * @throws DateTimeParseException if any of the given String can't be converted to a {@link OffsetDateTime}.798 * @throws AssertionError if the actual value is not in [start, end] period.799 *800 * @since 3.7.1801 */802 public SELF isBetween(String startExclusive, String endExclusive) {803 return isBetween(parse(startExclusive), parse(endExclusive));804 }805 /**806 * Verifies that the actual {@link OffsetDateTime} is in the ]start, end[ period (start and end excluded) according to807 * the comparator in use.808 * <p>809 * <b>Breaking change</b> since 3.15.0 The default comparator uses {@link OffsetDateTime#timeLineOrder()}810 * which only compares the underlying instant and ignores different timezones / offsets / chronologies.<br>811 * This behaviour can be overridden by {@link AbstractOffsetDateTimeAssert#usingComparator(Comparator)}.812 * <p>813 * Example:814 * <pre><code class='java'> OffsetDateTime offsetDateTime = OffsetDateTime.now();815 *816 * // assertions succeed:817 * assertThat(offsetDateTime).isStrictlyBetween(offsetDateTime.minusSeconds(1), offsetDateTime.plusSeconds(1));818 * // succeeds with a different comparator even though the end value refers to the same instant as the actual819 * assertThat(parse("2010-01-01T12:00:00Z")).usingComparator(OffsetDateTime::compareTo)820 * .isStrictlyBetween(parse("2010-01-01T12:59:59+01:00"),821 * parse("2010-01-01T13:00:00+01:00"));822 *823 * // assertions fail:824 * assertThat(offsetDateTime).isStrictlyBetween(offsetDateTime.minusSeconds(10), offsetDateTime.minusSeconds(1));825 * assertThat(offsetDateTime).isStrictlyBetween(offsetDateTime.plusSeconds(1), offsetDateTime.plusSeconds(10));826 * assertThat(offsetDateTime).isStrictlyBetween(offsetDateTime, offsetDateTime.plusSeconds(1));827 * assertThat(offsetDateTime).isStrictlyBetween(offsetDateTime.minusSeconds(1), offsetDateTime);828 *829 * // fails with default comparator since the end value refers to the same instant as the actual830 * assertThat(parse("2010-01-01T12:00:00Z")).isStrictlyBetween(parse("2010-01-01T12:59:59+01:00"),831 * parse("2010-01-01T13:00:00+01:00"));</code></pre>832 *833 * @param startExclusive the start value (exclusive), expected not to be null.834 * @param endExclusive the end value (exclusive), expected not to be null.835 * @return this assertion object.836 * @throws AssertionError if the actual value is {@code null}.837 * @throws NullPointerException if start value is {@code null}.838 * @throws NullPointerException if end value is {@code null}.839 * @throws AssertionError if the actual value is not in ]start, end[ period according to the comparator in use.840 *841 * @since 3.7.1842 */843 public SELF isStrictlyBetween(OffsetDateTime startExclusive, OffsetDateTime endExclusive) {844 comparables.assertIsBetween(info, actual, startExclusive, endExclusive, false, false);845 return myself;846 }847 /**848 * Same assertion as {@link #isStrictlyBetween(OffsetDateTime, OffsetDateTime)} but here you pass {@link OffsetDateTime} String representations849 * which must follow <a href="http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_OFFSET_DATE_TIME">ISO OffsetDateTime format</a>850 * to allow calling {@link OffsetDateTime#parse(CharSequence)} method.851 * <p>852 * <b>Breaking change</b> since 3.15.0 The default comparator uses {@link OffsetDateTime#timeLineOrder()}853 * which only compares the underlying instant and ignores different timezones / offsets / chronologies.<br>854 * This behaviour can be overridden by {@link AbstractOffsetDateTimeAssert#usingComparator(Comparator)}.855 * <p>856 * Example:857 * <pre><code class='java'> OffsetDateTime firstOfJanuary2000 = OffsetDateTime.parse("2000-01-01T00:00:00Z");858 *859 * // assertion succeeds:860 * assertThat(firstOfJanuary2000).isStrictlyBetween("1999-12-31T23:59:59Z", "2000-01-01T00:00:01Z")861 * // succeeds with a different comparator even though the end value refers to the same instant as the actual862 * .usingComparator(OffsetDateTime::compareTo)863 * .isStrictlyBetween("1999-12-31T23:59:59Z", "2000-01-01T01:00:00+01:00");864 *865 * // assertions fail:866 * assertThat(firstOfJanuary2000).isStrictlyBetween("1999-01-01T00:00:01Z", "1999-12-31T23:59:59Z");867 * assertThat(firstOfJanuary2000).isStrictlyBetween("2000-01-01T00:00:00Z", "2000-01-01T00:00:01Z");868 * assertThat(firstOfJanuary2000).isStrictlyBetween("1999-12-31T23:59:59Z", "2000-01-01T00:00:00Z");869 * // fails with default comparator since the end value refers to the same instant as the actual870 * assertThat(parse("2010-01-01T12:00:00Z")).isStrictlyBetween("2010-01-01T12:59:59+01:00", "2010-01-01T13:00:00+01:00");</code></pre>871 *872 * @param startExclusive the start value (exclusive), expected not to be null.873 * @param endExclusive the end value (exclusive), expected not to be null.874 * @return this assertion object.875 *876 * @throws AssertionError if the actual value is {@code null}.877 * @throws NullPointerException if start value is {@code null}.878 * @throws NullPointerException if end value is {@code null}.879 * @throws DateTimeParseException if any of the given String can't be converted to a {@link OffsetDateTime}.880 * @throws AssertionError if the actual value is not in ]start, end[ period.881 *882 * @since 3.7.1883 */884 public SELF isStrictlyBetween(String startExclusive, String endExclusive) {885 return isStrictlyBetween(parse(startExclusive), parse(endExclusive));886 }887 /** {@inheritDoc} */888 @Override889 @CheckReturnValue890 public SELF usingDefaultComparator() {891 SELF self = super.usingDefaultComparator();892 self.comparables = buildDefaultComparables();893 return self;894 }895 private Comparables buildDefaultComparables() {896 OffsetDateTimeByInstantComparator defaultComparator = OffsetDateTimeByInstantComparator.getInstance();897 return new Comparables(new ComparatorBasedComparisonStrategy(defaultComparator, defaultComparator.description()));898 }899 /**900 * Verifies that actual and given {@code OffsetDateTime} are at the same {@link java.time.Instant}.901 * <p>902 * Example:903 * <pre><code class='java'> OffsetDateTime offsetDateTime1 = OffsetDateTime.of(2000, 12, 12, 3, 0, 0, 0, ZoneOffset.ofHours(3));904 * OffsetDateTime offsetDateTime2 = OffsetDateTime.of(2000, 12, 12, 0, 0, 0, 0, ZoneOffset.ofHours(0));905 * // assertion succeeds906 * assertThat(offsetDateTime1).isAtSameInstantAs(offsetDateTime2);907 *908 * offsetDateTime2 = OffsetDateTime.of(2000, 12, 12, 2, 0, 0, 0, ZoneOffset.ofHours(0));909 * // assertion fails...
buildDefaultComparables
Using AI Code Generation
1public class OffsetDateTimeAssert_buildDefaultComparables_Test {2 public void should_build_default_comparables() {3 OffsetDateTime reference = OffsetDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);4 List<OffsetDateTime> comparables = buildDefaultComparables(reference);5 assertThat(comparables).containsExactly(6 reference.minusYears(1),7 reference.minusMonths(1),8 reference.minusDays(1),9 reference.minusHours(1),10 reference.minusMinutes(1),11 reference.minusSeconds(1),12 reference.minusNanos(1),13 reference.plusNanos(1),14 reference.plusSeconds(1),15 reference.plusMinutes(1),16 reference.plusHours(1),17 reference.plusDays(1),18 reference.plusMonths(1),19 reference.plusYears(1));20 }21}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!