How to use assertLocalDateTimeParameterIsNotNull method of org.assertj.core.api.AbstractLocalDateTimeAssert class

Best Assertj code snippet using org.assertj.core.api.AbstractLocalDateTimeAssert.assertLocalDateTimeParameterIsNotNull

Source:AbstractLocalDateTimeAssert.java Github

copy

Full Screen

...71 * @throws IllegalArgumentException if other {@code LocalDateTime} is {@code null}.72 * @throws AssertionError if the actual {@code LocalDateTime} is not strictly before the given one.73 */74 public SELF isBefore(LocalDateTime other) {75 assertLocalDateTimeParameterIsNotNull(other);76 comparables.assertIsBefore(info, actual, other);77 return myself;78 }79 /**80 * Same assertion as {@link #isBefore(LocalDateTime)} but the {@link LocalDateTime} is built from given String, which81 * must follow <a href=82 * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_LOCAL_DATE_TIME"83 * >ISO LocalDateTime format</a> to allow calling {@link LocalDateTime#parse(CharSequence)} method.84 * <p>85 * Example :86 * <pre><code class='java'> // use String in comparison to avoid writing the code to perform the conversion87 * assertThat(parse("2000-01-01T23:59:59")).isBefore("2000-01-02T00:00:00");</code></pre>88 *89 * @param localDateTimeAsString String representing a {@link LocalDateTime}.90 * @return this assertion object.91 * @throws AssertionError if the actual {@code LocalDateTime} is {@code null}.92 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link LocalDateTime}.93 * @throws AssertionError if the actual {@code LocalDateTime} is not strictly before the {@link LocalDateTime} built94 * from given String.95 */96 public SELF isBefore(String localDateTimeAsString) {97 assertLocalDateTimeAsStringParameterIsNotNull(localDateTimeAsString);98 return isBefore(parse(localDateTimeAsString));99 }100 /**101 * Verifies that the actual {@code LocalDateTime} is before or equals to the given one according to the {@link ChronoLocalDateTime#timeLineOrder()} comparator102 * which is consistent with {@link LocalDateTime#isBefore(ChronoLocalDateTime)}.103 * <p>104 * {@link ChronoLocalDateTime#timeLineOrder()} compares {@code LocalDateTime} in time-line order <b>ignoring the chronology</b>, this is equivalent to comparing the epoch-day and nano-of-day.105 * <p>106 * This behaviour can be overridden by {@link AbstractLocalDateTimeAssert#usingComparator(Comparator)}.107 * <p>108 * Example :109 * <pre><code class='java'> assertThat(parse("2000-01-01T23:59:59")).isBeforeOrEqualTo(parse("2000-01-01T23:59:59"))110 * .isBeforeOrEqualTo(parse("2000-01-02T00:00:00"));</code></pre>111 *112 * @param other the given {@link LocalDateTime}.113 * @return this assertion object.114 * @throws AssertionError if the actual {@code LocalDateTime} is {@code null}.115 * @throws IllegalArgumentException if other {@code LocalDateTime} is {@code null}.116 * @throws AssertionError if the actual {@code LocalDateTime} is not before or equals to the given one.117 */118 public SELF isBeforeOrEqualTo(LocalDateTime other) {119 assertLocalDateTimeParameterIsNotNull(other);120 comparables.assertIsBeforeOrEqualTo(info, actual, other);121 return myself;122 }123 /**124 * Same assertion as {@link #isBeforeOrEqualTo(LocalDateTime)} but the {@link LocalDateTime} is built from given125 * String, which must follow <a href=126 * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_LOCAL_DATE_TIME"127 * >ISO LocalDateTime format</a> to allow calling {@link LocalDateTime#parse(CharSequence)} method.128 * <p>129 * Example :130 * <pre><code class='java'> // use String in comparison to avoid conversion131 * assertThat(parse("2000-01-01T23:59:59")).isBeforeOrEqualTo("2000-01-01T23:59:59")132 * .isBeforeOrEqualTo("2000-01-02T00:00:00");</code></pre>133 *134 * @param localDateTimeAsString String representing a {@link LocalDateTime}.135 * @return this assertion object.136 * @throws AssertionError if the actual {@code LocalDateTime} is {@code null}.137 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link LocalDateTime}.138 * @throws AssertionError if the actual {@code LocalDateTime} is not before or equals to the {@link LocalDateTime}139 * built from given String.140 */141 public SELF isBeforeOrEqualTo(String localDateTimeAsString) {142 assertLocalDateTimeAsStringParameterIsNotNull(localDateTimeAsString);143 return isBeforeOrEqualTo(parse(localDateTimeAsString));144 }145 /**146 * Verifies that the actual {@code LocalDateTime} is after or equals to the given one according to the {@link ChronoLocalDateTime#timeLineOrder()} comparator147 * which is consistent with {@link LocalDateTime#isAfter(ChronoLocalDateTime)}.148 * <p>149 * {@link ChronoLocalDateTime#timeLineOrder()} compares {@code LocalDateTime} in time-line order <b>ignoring the chronology</b>, this is equivalent to comparing the epoch-day and nano-of-day.150 * <p>151 * This behaviour can be overridden by {@link AbstractLocalDateTimeAssert#usingComparator(Comparator)}.152 * <p>153 * Example :154 * <pre><code class='java'> assertThat(parse("2000-01-01T00:00:00")).isAfterOrEqualTo(parse("2000-01-01T00:00:00"))155 * .isAfterOrEqualTo(parse("1999-12-31T23:59:59"));</code></pre>156 *157 * @param other the given {@link LocalDateTime}.158 * @return this assertion object.159 * @throws AssertionError if the actual {@code LocalDateTime} is {@code null}.160 * @throws IllegalArgumentException if other {@code LocalDateTime} is {@code null}.161 * @throws AssertionError if the actual {@code LocalDateTime} is not after or equals to the given one.162 */163 public SELF isAfterOrEqualTo(LocalDateTime other) {164 assertLocalDateTimeParameterIsNotNull(other);165 comparables.assertIsAfterOrEqualTo(info, actual, other);166 return myself;167 }168 /**169 * Same assertion as {@link #isAfterOrEqualTo(LocalDateTime)} but the {@link LocalDateTime} is built from given170 * String, which must follow <a href=171 * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_LOCAL_DATE_TIME"172 * >ISO LocalDateTime format</a> to allow calling {@link LocalDateTime#parse(CharSequence)} method.173 * <p>174 * Example :175 * <pre><code class='java'> // use String in comparison to avoid conversion176 * assertThat(parse("2000-01-01T00:00:00")).isAfterOrEqualTo("2000-01-01T00:00:00")177 * .isAfterOrEqualTo("1999-12-31T23:59:59");</code></pre>178 *179 * @param localDateTimeAsString String representing a {@link LocalDateTime}.180 * @return this assertion object.181 * @throws AssertionError if the actual {@code LocalDateTime} is {@code null}.182 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link LocalDateTime}.183 * @throws AssertionError if the actual {@code LocalDateTime} is not after or equals to the {@link LocalDateTime}184 * built from given String.185 */186 public SELF isAfterOrEqualTo(String localDateTimeAsString) {187 assertLocalDateTimeAsStringParameterIsNotNull(localDateTimeAsString);188 return isAfterOrEqualTo(parse(localDateTimeAsString));189 }190 /**191 * Verifies that the actual {@code LocalDateTime} is <b>strictly</b> after the given one according to the {@link ChronoLocalDateTime#timeLineOrder()} comparator192 * which is consistent with {@link LocalDateTime#isAfter(ChronoLocalDateTime)}.193 * <p>194 * {@link ChronoLocalDateTime#timeLineOrder()} compares {@code LocalDateTime} in time-line order <b>ignoring the chronology</b>, this is equivalent to comparing the epoch-day and nano-of-day.195 * <p>196 * This behaviour can be overridden by {@link AbstractLocalDateTimeAssert#usingComparator(Comparator)}.197 * <p>198 * Example :199 * <pre><code class='java'> assertThat(parse("2000-01-01T00:00:00")).isAfter(parse("1999-12-31T23:59:59"));</code></pre>200 *201 * @param other the given {@link LocalDateTime}.202 * @return this assertion object.203 * @throws AssertionError if the actual {@code LocalDateTime} is {@code null}.204 * @throws IllegalArgumentException if other {@code LocalDateTime} is {@code null}.205 * @throws AssertionError if the actual {@code LocalDateTime} is not strictly after the given one.206 */207 public SELF isAfter(LocalDateTime other) {208 assertLocalDateTimeParameterIsNotNull(other);209 comparables.assertIsAfter(info, actual, other);210 return myself;211 }212 /**213 * Same assertion as {@link #isAfter(LocalDateTime)} but the {@link LocalDateTime} is built from given a String that214 * must follow <a href=215 * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_LOCAL_DATE_TIME"216 * >ISO LocalDateTime format</a> to allow calling {@link LocalDateTime#parse(CharSequence)} method.217 * <p>218 * Example :219 * <pre><code class='java'> // use String in comparison to avoid conversion220 * assertThat(parse("2000-01-01T00:00:00")).isAfter("1999-12-31T23:59:59");</code></pre>221 *222 * @param localDateTimeAsString String representing a {@link LocalDateTime}.223 * @return this assertion object.224 * @throws AssertionError if the actual {@code LocalDateTime} is {@code null}.225 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link LocalDateTime}.226 * @throws AssertionError if the actual {@code LocalDateTime} is not strictly after the {@link LocalDateTime} built227 * from given String.228 */229 public SELF isAfter(String localDateTimeAsString) {230 assertLocalDateTimeAsStringParameterIsNotNull(localDateTimeAsString);231 return isAfter(parse(localDateTimeAsString));232 }233 /**234 * Verifies that the actual {@code LocalDateTime} is equal to the given one according to the {@link ChronoLocalDateTime#timeLineOrder()} comparator235 * which is consistent with {@link LocalDateTime#isEqual(ChronoLocalDateTime)}.236 * <p>237 * {@link ChronoLocalDateTime#timeLineOrder()} compares {@code LocalDateTime} in time-line order <b>ignoring the chronology</b>, this is equivalent to comparing the epoch-day and nano-of-day.238 * <p>239 * This behaviour can be overridden by {@link AbstractLocalDateTimeAssert#usingComparator(Comparator)}.240 * <p>241 * Example :242 * <pre><code class='java'> assertThat(parse("2000-01-01T00:00:00")).isEqualTo(parse("2000-01-01T00:00:00"));</code></pre>243 *244 * @param other the given {@link LocalDateTime}.245 * @return this assertion object.246 * @throws AssertionError if the actual {@code LocalDateTime} is {@code null}.247 * @throws AssertionError if the actual {@code LocalDateTime} differs from the given {@code LocalDateTime}248 * according to the comparator in use.249 */250 @Override251 public SELF isEqualTo(Object other) {252 if (actual == null || other == null) {253 super.isEqualTo(other);254 } else {255 comparables.assertEqual(info, actual, other);256 }257 return myself;258 }259 /**260 * Same assertion as {@link #isEqualTo(Object)} (where Object is expected to be {@link LocalDateTime}) but here you261 * pass {@link LocalDateTime} String representation that must follow <a href=262 * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_LOCAL_DATE_TIME"263 * >ISO LocalDateTime format</a> to allow calling {@link LocalDateTime#parse(CharSequence)} method.264 * <p>265 * Example :266 * <pre><code class='java'> // use String in comparison to avoid writing the code to perform the conversion267 * assertThat(parse("2000-01-01T00:00:00")).isEqualTo("2000-01-01T00:00:00");</code></pre>268 *269 * @param dateTimeAsString String representing a {@link LocalDateTime}.270 * @return this assertion object.271 * @throws AssertionError if the actual {@code LocalDateTime} is {@code null}.272 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link LocalDateTime}.273 * @throws AssertionError if the actual {@code LocalDateTime} is not equal to the {@link LocalDateTime} built from274 * given String.275 */276 public SELF isEqualTo(String dateTimeAsString) {277 assertLocalDateTimeAsStringParameterIsNotNull(dateTimeAsString);278 return isEqualTo(parse(dateTimeAsString));279 }280 /**281 * Verifies that the actual {@code LocalDateTime} is not equal to the given one according to the {@link ChronoLocalDateTime#timeLineOrder()} comparator282 * which is consistent with {@link LocalDateTime#isEqual(ChronoLocalDateTime)}.283 * <p>284 * {@link ChronoLocalDateTime#timeLineOrder()} compares {@code LocalDateTime} in time-line order <b>ignoring the chronology</b>, this is equivalent to comparing the epoch-day and nano-of-day.285 * <p>286 * This behaviour can be overridden by {@link AbstractLocalDateTimeAssert#usingComparator(Comparator)}.287 * <p>288 * Example :289 * <pre><code class='java'> assertThat(parse("2000-01-01T00:00:00")).isEqualTo(parse("2000-01-01T00:00:00"));</code></pre>290 *291 * @param other the given value to compare the actual value to.292 * @return this assertion object.293 * @throws AssertionError if the actual {@code LocalDateTime} is {@code null}.294 * @throws AssertionError if the actual {@code LocalDateTime} equals to the given {@code LocalDateTime}295 * according to the comparator in use.296 */297 @Override298 public SELF isNotEqualTo(Object other) {299 if (actual == null || other == null) {300 super.isNotEqualTo(other);301 } else {302 comparables.assertNotEqual(info, actual, other);303 }304 return myself;305 }306 /**307 * Same assertion as {@link #isNotEqualTo(Object)} (where Object is expected to be {@link LocalDateTime}) but here you308 * pass {@link LocalDateTime} String representation that must follow <a href=309 * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_LOCAL_DATE_TIME"310 * >ISO LocalDateTime format</a> to allow calling {@link LocalDateTime#parse(CharSequence)} method.311 * <p>312 * Example :313 * <pre><code class='java'> // use String in comparison to avoid writing the code to perform the conversion314 * assertThat(parse("2000-01-01T00:00:00")).isNotEqualTo("2000-01-15T00:00:00");</code></pre>315 *316 * @param dateTimeAsString String representing a {@link LocalDateTime}.317 * @return this assertion object.318 * @throws AssertionError if the actual {@code LocalDateTime} is {@code null}.319 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link LocalDateTime}.320 * @throws AssertionError if the actual {@code LocalDateTime} is equal to the {@link LocalDateTime} built from given321 * String.322 */323 public SELF isNotEqualTo(String dateTimeAsString) {324 assertLocalDateTimeAsStringParameterIsNotNull(dateTimeAsString);325 return isNotEqualTo(parse(dateTimeAsString));326 }327 /**328 * Same assertion as {@link #isIn(Object...)} (where Objects are expected to be {@link LocalDateTime}) but here you329 * pass {@link LocalDateTime} String representations that must follow <a href=330 * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_LOCAL_DATE_TIME"331 * >ISO LocalDateTime format</a> to allow calling {@link LocalDateTime#parse(CharSequence)} method.332 * <p>333 * Example :334 * <pre><code class='java'> // use String based representation of LocalDateTime335 * assertThat(parse("2000-01-01T00:00:00")).isIn("1999-12-31T00:00:00", "2000-01-01T00:00:00");</code></pre>336 *337 * @param dateTimesAsString String array representing {@link LocalDateTime}s.338 * @return this assertion object.339 * @throws AssertionError if the actual {@code LocalDateTime} is {@code null}.340 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link LocalDateTime}.341 * @throws AssertionError if the actual {@code LocalDateTime} is not in the {@link LocalDateTime}s built from given342 * Strings.343 */344 public SELF isIn(String... dateTimesAsString) {345 checkIsNotNullAndNotEmpty(dateTimesAsString);346 return isIn(convertToLocalDateTimeArray(dateTimesAsString));347 }348 /**349 * Same assertion as {@link #isNotIn(Object...)} (where Objects are expected to be {@link LocalDateTime}) but here you350 * pass {@link LocalDateTime} String representations that must follow <a href=351 * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_LOCAL_DATE_TIME"352 * >ISO LocalDateTime format</a> to allow calling {@link LocalDateTime#parse(CharSequence)} method.353 * <p>354 * Example :355 * <pre><code class='java'> // use String based representation of LocalDateTime356 * assertThat(parse("2000-01-01T00:00:00")).isNotIn("1999-12-31T00:00:00", "2000-01-02T00:00:00");</code></pre>357 *358 * @param dateTimesAsString Array of String representing a {@link LocalDateTime}.359 * @return this assertion object.360 * @throws AssertionError if the actual {@code LocalDateTime} is {@code null}.361 * @throws IllegalArgumentException if given String is null or can't be converted to a {@link LocalDateTime}.362 * @throws AssertionError if the actual {@code LocalDateTime} is in the {@link LocalDateTime}s built from given363 * Strings.364 */365 public SELF isNotIn(String... dateTimesAsString) {366 checkIsNotNullAndNotEmpty(dateTimesAsString);367 return isNotIn(convertToLocalDateTimeArray(dateTimesAsString));368 }369 /**370 * Verifies that the actual {@link LocalDateTime} 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'> LocalDateTime actual = LocalDateTime.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 LocalDateTime} is {@code null}.389 * @throws AssertionError if the actual {@code LocalDateTime} 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 /** {@inheritDoc} */395 @Override396 @CheckReturnValue397 public SELF usingDefaultComparator() {398 SELF self = super.usingDefaultComparator();399 self.comparables = buildDefaultComparables();400 return self;401 }402 private Comparables buildDefaultComparables() {403 ChronoLocalDateTimeComparator defaultComparator = ChronoLocalDateTimeComparator.getInstance();404 return new Comparables(new ComparatorBasedComparisonStrategy(defaultComparator, defaultComparator.description()));405 }406 private static Object[] convertToLocalDateTimeArray(String... dateTimesAsString) {407 return Arrays.stream(dateTimesAsString)408 .map(LocalDateTime::parse)409 .toArray();410 }411 private void checkIsNotNullAndNotEmpty(Object[] values) {412 checkArgument(values != null, "The given LocalDateTime array should not be null");413 checkArgument(values.length > 0, "The given LocalDateTime array should not be empty");414 }415 /**416 * Check that the {@link LocalDateTime} string representation to compare actual {@link LocalDateTime} to is not null,417 * otherwise throws a {@link IllegalArgumentException} with an explicit message418 *419 * @param localDateTimeAsString String representing the {@link LocalDateTime} to compare actual with420 * @throws IllegalArgumentException with an explicit message if the given {@link String} is null421 */422 private static void assertLocalDateTimeAsStringParameterIsNotNull(String localDateTimeAsString) {423 checkArgument(localDateTimeAsString != null,424 "The String representing the LocalDateTime to compare actual with should not be null");425 }426 /**427 * Check that the {@link LocalDateTime} to compare actual {@link LocalDateTime} to is not null, in that case throws a428 * {@link IllegalArgumentException} with an explicit message429 *430 * @param other the {@link LocalDateTime} to check431 * @throws IllegalArgumentException with an explicit message if the given {@link LocalDateTime} is null432 */433 private static void assertLocalDateTimeParameterIsNotNull(LocalDateTime other) {434 checkArgument(other != null, "The LocalDateTime to compare actual with should not be null");435 }436 /**437 * Verifies that actual and given {@code LocalDateTime} have same year, month, day, hour, minute and second fields,438 * (nanosecond fields are ignored in comparison).439 * <p>440 * Assertion can fail with localDateTimes in same chronological nanosecond time window, e.g :441 * <p>442 * 2000-01-01T00:00:<b>01.000000000</b> and 2000-01-01T00:00:<b>00.999999999</b>.443 * <p>444 * Assertion fails as second fields differ even if time difference is only 1ns.445 * <p>446 * Code example :447 * <pre><code class='java'> // successful assertions448 * LocalDateTime localDateTime1 = LocalDateTime.of(2000, 1, 1, 0, 0, 1, 0);449 * LocalDateTime localDateTime2 = LocalDateTime.of(2000, 1, 1, 0, 0, 1, 456);450 * assertThat(localDateTime1).isEqualToIgnoringNanos(localDateTime2);451 *452 * // failing assertions (even if time difference is only 1ms)453 * LocalDateTime localDateTimeA = LocalDateTime.of(2000, 1, 1, 0, 0, 1, 0);454 * LocalDateTime localDateTimeB = LocalDateTime.of(2000, 1, 1, 0, 0, 0, 999999999);455 * assertThat(localDateTimeA).isEqualToIgnoringNanos(localDateTimeB);</code></pre>456 *457 * @param other the given {@link LocalDateTime}.458 * @return this assertion object.459 * @throws AssertionError if the actual {@code LocalDateTime} is {@code null}.460 * @throws IllegalArgumentException if other {@code LocalDateTime} is {@code null}.461 * @throws AssertionError if the actual {@code LocalDateTime} is are not equal with nanoseconds ignored.462 */463 public SELF isEqualToIgnoringNanos(LocalDateTime other) {464 Objects.instance().assertNotNull(info, actual);465 assertLocalDateTimeParameterIsNotNull(other);466 if (!areEqualIgnoringNanos(actual, other)) {467 throw Failures.instance().failure(info, shouldBeEqualIgnoringNanos(actual, other));468 }469 return myself;470 }471 /**472 * Verifies that actual and given {@link LocalDateTime} have same year, month, day, hour and minute fields (second and473 * nanosecond fields are ignored in comparison).474 * <p>475 * Assertion can fail with LocalDateTimes in same chronological second time window, e.g :476 * <p>477 * 2000-01-01T00:<b>01:00</b>.000 and 2000-01-01T00:<b>00:59</b>.000.478 * <p>479 * Assertion fails as minute fields differ even if time difference is only 1s.480 * <p>481 * Code example :482 * <pre><code class='java'> // successful assertions483 * LocalDateTime localDateTime1 = LocalDateTime.of(2000, 1, 1, 23, 50, 0, 0);484 * LocalDateTime localDateTime2 = LocalDateTime.of(2000, 1, 1, 23, 50, 10, 456);485 * assertThat(localDateTime1).isEqualToIgnoringSeconds(localDateTime2);486 *487 * // failing assertions (even if time difference is only 1ms)488 * LocalDateTime localDateTimeA = LocalDateTime.of(2000, 1, 1, 23, 50, 00, 000);489 * LocalDateTime localDateTimeB = LocalDateTime.of(2000, 1, 1, 23, 49, 59, 999);490 * assertThat(localDateTimeA).isEqualToIgnoringSeconds(localDateTimeB);</code></pre>491 *492 * @param other the given {@link LocalDateTime}.493 * @return this assertion object.494 * @throws AssertionError if the actual {@code LocalDateTime} is {@code null}.495 * @throws IllegalArgumentException if other {@code LocalDateTime} is {@code null}.496 * @throws AssertionError if the actual {@code LocalDateTime} is are not equal with second and nanosecond fields497 * ignored.498 */499 public SELF isEqualToIgnoringSeconds(LocalDateTime other) {500 Objects.instance().assertNotNull(info, actual);501 assertLocalDateTimeParameterIsNotNull(other);502 if (!areEqualIgnoringSeconds(actual, other)) {503 throw Failures.instance().failure(info, shouldBeEqualIgnoringSeconds(actual, other));504 }505 return myself;506 }507 /**508 * Verifies that actual and given {@code LocalDateTime} have same year, month, day and hour fields (minute, second and509 * nanosecond fields are ignored in comparison).510 * <p>511 * Assertion can fail with localDateTimes in same chronological second time window, e.g :512 * <p>513 * 2000-01-01T<b>01:00</b>:00.000 and 2000-01-01T<b>00:59:59</b>.000.514 * <p>515 * Time difference is only 1s but hour fields differ.516 * <p>517 * Code example :518 * <pre><code class='java'> // successful assertions519 * LocalDateTime localDateTime1 = LocalDateTime.of(2000, 1, 1, 23, 50, 0, 0);520 * LocalDateTime localDateTime2 = LocalDateTime.of(2000, 1, 1, 23, 00, 2, 7);521 * assertThat(localDateTime1).isEqualToIgnoringMinutes(localDateTime2);522 *523 * // failing assertions (even if time difference is only 1ms)524 * LocalDateTime localDateTimeA = LocalDateTime.of(2000, 1, 1, 01, 00, 00, 000);525 * LocalDateTime localDateTimeB = LocalDateTime.of(2000, 1, 1, 00, 59, 59, 999);526 * assertThat(localDateTimeA).isEqualToIgnoringMinutes(localDateTimeB);</code></pre>527 *528 * @param other the given {@link LocalDateTime}.529 * @return this assertion object.530 * @throws AssertionError if the actual {@code LocalDateTime} is {@code null}.531 * @throws IllegalArgumentException if other {@code LocalDateTime} is {@code null}.532 * @throws AssertionError if the actual {@code LocalDateTime} is are not equal ignoring minute, second and nanosecond533 * fields.534 */535 public SELF isEqualToIgnoringMinutes(LocalDateTime other) {536 Objects.instance().assertNotNull(info, actual);537 assertLocalDateTimeParameterIsNotNull(other);538 if (!areEqualIgnoringMinutes(actual, other)) {539 throw Failures.instance().failure(info, shouldBeEqualIgnoringMinutes(actual, other));540 }541 return myself;542 }543 /**544 * Verifies that actual and given {@code LocalDateTime} have same year, month and day fields (hour, minute, second and545 * nanosecond fields are ignored in comparison).546 * <p>547 * Assertion can fail with localDateTimes in same chronological minute time window, e.g :548 * <p>549 * 2000-01-<b>01T23:59</b>:00.000 and 2000-01-02T<b>00:00</b>:00.000.550 * <p>551 * Time difference is only 1min but day fields differ.552 * <p>553 * Code example :554 * <pre><code class='java'> // successful assertions555 * LocalDateTime localDateTime1 = LocalDateTime.of(2000, 1, 1, 23, 59, 59, 999);556 * LocalDateTime localDateTime2 = LocalDateTime.of(2000, 1, 1, 00, 00, 00, 000);557 * assertThat(localDateTime1).isEqualToIgnoringHours(localDateTime2);558 *559 * // failing assertions (even if time difference is only 1ms)560 * LocalDateTime localDateTimeA = LocalDateTime.of(2000, 1, 2, 00, 00, 00, 000);561 * LocalDateTime localDateTimeB = LocalDateTime.of(2000, 1, 1, 23, 59, 59, 999);562 * assertThat(localDateTimeA).isEqualToIgnoringHours(localDateTimeB);</code></pre>563 *564 * @param other the given {@link LocalDateTime}.565 * @return this assertion object.566 * @throws AssertionError if the actual {@code LocalDateTime} is {@code null}.567 * @throws IllegalArgumentException if other {@code LocalDateTime} is {@code null}.568 * @throws AssertionError if the actual {@code LocalDateTime} is are not equal with second and nanosecond fields569 * ignored.570 */571 public SELF isEqualToIgnoringHours(LocalDateTime other) {572 Objects.instance().assertNotNull(info, actual);573 assertLocalDateTimeParameterIsNotNull(other);574 if (!haveSameYearMonthAndDayOfMonth(actual, other)) {575 throw Failures.instance().failure(info, shouldBeEqualIgnoringHours(actual, other));576 }577 return myself;578 }579 /**580 * Verifies that the actual {@link LocalDateTime} is in the [start, end] period (start and end included) according to the {@link ChronoLocalDateTime#timeLineOrder()} comparator.581 * <p>582 * {@link ChronoLocalDateTime#timeLineOrder()} compares {@code LocalDateTime} in time-line order <b>ignoring the chronology</b>, this is equivalent to comparing the epoch-day and nano-of-day.583 * <p>584 * This behaviour can be overridden by {@link AbstractLocalDateTimeAssert#usingComparator(Comparator)}.585 * <p>586 * Example:587 * <pre><code class='java'> LocalDateTime localDateTime = LocalDateTime.now();...

Full Screen

Full Screen

assertLocalDateTimeParameterIsNotNull

Using AI Code Generation

copy

Full Screen

1assertThat(localDateTime).assertLocalDateTimeParameterIsNotNull("localDateTime");2assertThat(localDateTime).assertLocalDateTimeParameterIsNotNull("localDateTime");3assertThat(localDateTime).assertLocalDateTimeParameterIsNotNull("localDateTime");4assertThat(localDateTime).assertLocalDateTimeParameterIsNotNull("localDateTime");5assertThat(localDateTime).assertLocalDateTimeParameterIsNotNull("localDateTime");6assertThat(localDateTime).assertLocalDateTimeParameterIsNotNull("localDateTime");7assertThat(localDateTime).assertLocalDateTimeParameterIsNotNull("localDateTime");8assertThat(localDateTime).assertLocalDateTimeParameterIsNotNull("localDateTime");9assertThat(localDateTime).assertLocalDateTimeParameterIsNotNull("localDateTime");10assertThat(localDateTime).assertLocalDateTimeParameterIsNotNull("localDateTime");11assertThat(localDateTime).assertLocalDateTimeParameterIsNotNull("localDateTime");12assertThat(localDateTime).assertLocalDateTimeParameterIsNotNull("localDateTime");13assertThat(localDateTime).assertLocalDateTimeParameterIsNotNull("localDateTime");14assertThat(localDateTime).assertLocalDateTimeParameterIsNotNull("localDateTime");

Full Screen

Full Screen

assertLocalDateTimeParameterIsNotNull

Using AI Code Generation

copy

Full Screen

1LocalDateTime localDateTime = LocalDateTime.now();2assertThat(localDateTime).assertLocalDateTimeParameterIsNotNull();3LocalDateTime localDateTime = null;4assertThat(localDateTime).assertLocalDateTimeParameterIsNotNull();5public SELF assertLocalDateParameterIsNotNull()6package com.javadevjournal;7import org.junit.Test;8import java.time.LocalDate;9import static org.assertj.core.api.Assertions.assertThat;10public class AssertLocalDateParameterIsNotNullExample {11 public void testLocalDate(){12 LocalDate localDate = LocalDate.now();13 assertThat(localDate).assertLocalDateParameterIsNotNull();14 LocalDate localDate = null;15 assertThat(localDate).assertLocalDateParameterIsNotNull();16 }17}18public SELF assertLocalTimeParameterIsNotNull()19package com.javadevjournal;20import org.junit.Test;21import java.time.LocalTime;22import static org.assertj.core.api.Assertions.assertThat;23public class AssertLocalTimeParameterIsNotNullExample {24 public void testLocalTime(){25 LocalTime localTime = LocalTime.now();

Full Screen

Full Screen

assertLocalDateTimeParameterIsNotNull

Using AI Code Generation

copy

Full Screen

1import static org.assertj.core.api.Assertions.assertThat;2import java.time.LocalDateTime;3import java.time.Month;4import org.junit.Test;5public class AbstractLocalDateTimeAssert_assertLocalDateTimeParameterIsNotNull_Test {6 public void should_pass_if_localDateTime_parameter_is_not_null() {7 assertThat(assertLocalDateTimeParameterIsNotNull(LocalDateTime.of(2010, Month.JANUARY, 5, 3, 0, 5))).isNotNull();8 }9 public void should_fail_if_localDateTime_parameter_is_null() {10 thrown.expectAssertionError("The LocalDateTime to compare actual with should not be null");11 assertThat(assertLocalDateTimeParameterIsNotNull(null)).isNotNull();12 }13 private static LocalDateTime assertLocalDateTimeParameterIsNotNull(LocalDateTime dateToCheck) {14 AbstractLocalDateTimeAssert<?> assertions = assertThat(LocalDateTime.of(2010, Month.JANUARY, 5, 3, 0, 5));15 assertions.assertLocalDateTimeParameterIsNotNull(dateToCheck);16 return dateToCheck;17 }18}19package org.assertj.core.api.localtimeassert;20import static org.assertj.core.api.Assertions.assertThat;21import java.time.LocalDateTime;22import java.time.Month;23import org.junit.Test;24public class AbstractLocalDateTimeAssert_assertLocalDateTimeParameterIsNotNull_Test {25 public void should_pass_if_localDateTime_parameter_is_not_null() {26 assertThat(assertLocalDateTimeParameterIsNotNull(LocalDateTime.of(2010, Month.JANUARY, 5, 3, 0, 5))).isNotNull();27 }28 public void should_fail_if_localDateTime_parameter_is_null() {29 thrown.expectAssertionError("The LocalDateTime to compare actual with should not be null");30 assertThat(assertLocalDateTimeParameterIsNotNull(null)).isNotNull();31 }32 private static LocalDateTime assertLocalDateTimeParameterIsNotNull(LocalDateTime dateToCheck) {33 AbstractLocalDateTimeAssert<?> assertions = assertThat(LocalDateTime.of(2010, Month.JANUARY, 5, 3, 0, 5));34 assertions.assertLocalDateTimeParameterIsNotNull(dateToCheck);35 return dateToCheck;36 }37}

Full Screen

Full Screen

assertLocalDateTimeParameterIsNotNull

Using AI Code Generation

copy

Full Screen

1import java.time.LocalDateTime;2import java.time.Month;3import org.junit.Test;4import static org.assertj.core.api.Assertions.assertThat;5public class AssertJAssertLocalDateTimeParameterIsNotNullTest {6 public void testAssertLocalDateTimeParameterIsNotNull() {7 LocalDateTime localDateTime = LocalDateTime.of(2017, Month.JANUARY, 1, 0, 0, 0);8 assertThat(localDateTime).isNotNull();9 }10}11OK (1 test)12assertLocalDateTimeParameterIsNotNull() method of AbstractLocalDateTimeAssert class13public AbstractLocalDateTimeAssert<?> assertLocalDateTimeParameterIsNotNull(LocalDateTime value) {14 assertNotNull(info, value);15 return myself;16}17assertNotNull() method of Objects class18public static void assertNotNull(AssertionInfo info, Object actual) {19 Objects.instance().assertNotNull(info, actual);20}21assertNotNull() method of Objects class22public void assertNotNull(AssertionInfo info, Object actual) {23 if (actual == null) throw failures.failure(info, shouldBeNotNull());24}25assertNotNull() method of Failures class26public AssertionError failure(AssertionInfo info, Description description) {27 return failure(info, description, newArrayList());28}29assertNotNull() method of Failures class30public AssertionError failure(AssertionInfo info, Description description, List<Representation> representations) {31 return new AssertionError(failureMessages.failure(info, description, representations));32}33assertNotNull() method of StandardRepresentation class34public String toStringOf(Object o) {35 return o == null ? NULL_STRING : o.toString();36}37assertNotNull() method of StandardRepresentation class38public String toStringOf(Object o) {39 return o == null ? NULL_STRING : o.toString();

Full Screen

Full Screen

assertLocalDateTimeParameterIsNotNull

Using AI Code Generation

copy

Full Screen

1 private static void assertLocalDateTimeParameterIsNotNull(LocalDateTime localDateTime) {2 if (localDateTime == null) {3 throw new IllegalArgumentException("The LocalDateTime to compare actual with should not be null");4 }5 }6assertLocalDateTimeParameterIsNotNull(localDateTime);7assertLocalDateTimeParameterIsNotNull(null);8assertLocalDateTimeParameterIsNotNull(localDateTime);

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