Best Assertj code snippet using org.assertj.core.api.AbstractLocalDateAssert.checkIsNotNullAndNotEmpty
Source:AbstractLocalDateAssert.java  
...264   * @throws AssertionError if the actual {@code LocalDate} is not in the {@link LocalDate}s built from given265   *           Strings.266   */267  public SELF isIn(String... localDatesAsString) {268    checkIsNotNullAndNotEmpty(localDatesAsString);269    return isIn(convertToLocalDateArray(localDatesAsString));270  }271  /**272   * Same assertion as {@link #isNotIn(Object...)} (where Objects are expected to be {@link LocalDate}) but here you273   * pass {@link LocalDate} String representations that must follow <a href=274   * "http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_LOCAL_DATE"275   * >ISO LocalDate format</a> to allow calling {@link LocalDate#parse(CharSequence)} method.276   * <p>277   * Example :278   * <pre><code class='java'> // use String based representation of LocalDate279   * assertThat(parse("2000-01-01")).isNotIn("1999-12-31", "2000-01-02");</code></pre>280   * 281   * @param localDatesAsString Array of String representing a {@link LocalDate}.282   * @return this assertion object.283   * @throws AssertionError if the actual {@code LocalDate} is {@code null}.284   * @throws IllegalArgumentException if given String is null or can't be converted to a {@link LocalDate}.285   * @throws AssertionError if the actual {@code LocalDate} is in the {@link LocalDate}s built from given286   *           Strings.287   */288  public SELF isNotIn(String... localDatesAsString) {289    checkIsNotNullAndNotEmpty(localDatesAsString);290    return isNotIn(convertToLocalDateArray(localDatesAsString));291  }292  /**293   * Verifies that the actual {@code LocalDate} is today, that is matching current year, month and day.294   * <p>295   * Example:296   * <pre><code class='java'> // assertion will pass297   * assertThat(LocalDate.now()).isToday();298   *299   * // assertion will fail300   * assertThat(theFellowshipOfTheRing.getReleaseDate()).isToday();</code></pre>301   *302   * @return this assertion object.303   * @throws AssertionError if the actual {@code LocalDate} is {@code null}.304   * @throws AssertionError if the actual {@code LocalDate} is not today.305   */306  public SELF isToday() {307    Objects.instance().assertNotNull(info, actual);308    if (!actual.isEqual(LocalDate.now())) throw Failures.instance().failure(info, shouldBeToday(actual));309    return myself;310  }311  /**312   * Verifies that the actual {@link LocalDate} is in the [start, end] period (start and end included).313   * <p>314   * Example:315   * <pre><code class='java'> LocalDate localDate = LocalDate.now();316   * 317   * // assertions succeed:318   * assertThat(localDate).isBetween(localDate.minusDays(1), localDate.plusDays(1))319   *                      .isBetween(localDate, localDate.plusDays(1))320   *                      .isBetween(localDate.minusDays(1), localDate)321   *                      .isBetween(localDate, localDate);322   * 323   * // assertions fail:324   * assertThat(localDate).isBetween(localDate.minusDays(10), localDate.minusDays(1));325   * assertThat(localDate).isBetween(localDate.plusDays(1), localDate.plusDays(10));</code></pre>326   * 327   * @param startInclusive the start value (inclusive), expected not to be null.328   * @param endInclusive the end value (inclusive), expected not to be null.329   * @return this assertion object.330   * @throws AssertionError if the actual value is {@code null}.331   * @throws NullPointerException if start value is {@code null}.332   * @throws NullPointerException if end value is {@code null}.333   * @throws AssertionError if the actual value is not in [start, end] period.334   * 335   * @since 3.7.1336   */337  public SELF isBetween(LocalDate startInclusive, LocalDate endInclusive) {338    comparables.assertIsBetween(info, actual, startInclusive, endInclusive, true, true);339    return myself;340  }341  /**342   * Same assertion as {@link #isBetween(LocalDate, LocalDate)} but here you pass {@link LocalDate} String representations 343   * which must follow <a href="http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_LOCAL_DATE">ISO LocalDate format</a> 344   * to allow calling {@link LocalDate#parse(CharSequence)} method.345   * <p>346   * Example:347   * <pre><code class='java'> LocalDate firstOfJanuary2000 = LocalDate.parse("2000-01-01");348   * 349   * // assertions succeed:350   * assertThat(firstOfJanuary2000).isBetween("1999-01-01", "2001-01-01")351   *                               .isBetween("2000-01-01", "2001-01-01")352   *                               .isBetween("1999-01-01", "2000-01-01")353   *                               .isBetween("2000-01-01", "2000-01-01");354   * 355   * // assertion fails:356   * assertThat(firstOfJanuary2000).isBetween("1999-01-01", "1999-12-31");</code></pre>357   * 358   * @param startInclusive the start value (inclusive), expected not to be null.359   * @param endInclusive the end value (inclusive), expected not to be null.360   * @return this assertion object.361   * 362   * @throws AssertionError if the actual value is {@code null}.363   * @throws NullPointerException if start value is {@code null}.364   * @throws NullPointerException if end value is {@code null}.365   * @throws DateTimeParseException if any of the given String can't be converted to a {@link LocalDate}.366   * @throws AssertionError if the actual value is not in [start, end] period.367   * 368   * @since 3.7.1369   */370  public SELF isBetween(String startInclusive, String endInclusive) {371    return isBetween(parse(startInclusive), parse(endInclusive));372  }373  /**374   * Verifies that the actual {@link LocalDate} is in the ]start, end[ period (start and end excluded).375   * <p>376   * Example:377   * <pre><code class='java'> LocalDate localDate = LocalDate.now();378   * 379   * // assertion succeeds:380   * assertThat(localDate).isStrictlyBetween(localDate.minusDays(1), localDate.plusDays(1));381   * 382   * // assertions fail:383   * assertThat(localDate).isStrictlyBetween(localDate.minusDays(10), localDate.minusDays(1));384   * assertThat(localDate).isStrictlyBetween(localDate.plusDays(1), localDate.plusDays(10));385   * assertThat(localDate).isStrictlyBetween(localDate, localDate.plusDays(1));386   * assertThat(localDate).isStrictlyBetween(localDate.minusDays(1), localDate);</code></pre>387   * 388   * @param startInclusive the start value (inclusive), expected not to be null.389   * @param endInclusive the end value (inclusive), expected not to be null.390   * @return this assertion object.391   * @throws AssertionError if the actual value is {@code null}.392   * @throws NullPointerException if start value is {@code null}.393   * @throws NullPointerException if end value is {@code null}.394   * @throws AssertionError if the actual value is not in ]start, end[ period.395   * 396   * @since 3.7.1397   */398  public SELF isStrictlyBetween(LocalDate startInclusive, LocalDate endInclusive) {399    comparables.assertIsBetween(info, actual, startInclusive, endInclusive, false, false);400    return myself;401  }402  /**403   * Same assertion as {@link #isStrictlyBetween(LocalDate, LocalDate)} but here you pass {@link LocalDate} String representations 404   * which must follow <a href="http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#ISO_LOCAL_DATE">ISO LocalDate format</a> 405   * to allow calling {@link LocalDate#parse(CharSequence)} method.406   * <p>407   * Example:408   * <pre><code class='java'> LocalDate firstOfJanuary2000 = LocalDate.parse("2000-01-01");409   * 410   * // assertion succeeds:411   * assertThat(firstOfJanuary2000).isStrictlyBetween("1999-01-01", "2001-01-01");412   * 413   * // assertions fail:414   * assertThat(firstOfJanuary2000).isStrictlyBetween("1999-01-01", "1999-12-31");415   * assertThat(firstOfJanuary2000).isStrictlyBetween("2000-01-01", "2001-01-01");416   * assertThat(firstOfJanuary2000).isStrictlyBetween("1999-01-01", "2000-01-01");</code></pre>417   * 418   * @param startInclusive the start value (inclusive), expected not to be null.419   * @param endInclusive the end value (inclusive), expected not to be null.420   * @return this assertion object.421   * 422   * @throws AssertionError if the actual value is {@code null}.423   * @throws NullPointerException if start value is {@code null}.424   * @throws NullPointerException if end value is {@code null}.425   * @throws DateTimeParseException if any of the given String can't be converted to a {@link LocalDate}.426   * @throws AssertionError if the actual value is not in ]start, end[ period.427   * 428   * @since 3.7.1429   */430  public SELF isStrictlyBetween(String startInclusive, String endInclusive) {431    return isStrictlyBetween(parse(startInclusive), parse(endInclusive));432  }433  /**434   * {@inheritDoc}435   */436  @Override437  protected LocalDate parse(String localDateAsString) {438    return LocalDate.parse(localDateAsString);439  }440  private static Object[] convertToLocalDateArray(String... localDatesAsString) {441    return Arrays.stream(localDatesAsString).map(LocalDate::parse).toArray();442  }443  private void checkIsNotNullAndNotEmpty(Object[] values) {444    checkArgument(values != null, "The given LocalDate array should not be null");445    checkArgument(values.length > 0, "The given LocalDate array should not be empty");446  }447  /**448   * Check that the {@link LocalDate} string representation to compare actual {@link LocalDate} to is not null,449   * otherwise throws a {@link IllegalArgumentException} with an explicit message450   * 451   * @param localDateAsString String representing the {@link LocalDate} to compare actual with452   * @throws IllegalArgumentException with an explicit message if the given {@link String} is null453   */454  private static void assertLocalDateAsStringParameterIsNotNull(String localDateAsString) {455    checkArgument(localDateAsString != null,456                  "The String representing the LocalDate to compare actual with should not be null");457  }...checkIsNotNullAndNotEmpty
Using AI Code Generation
1assertThat(new LocalDate(2010, 1, 1)).isNotNullAndNotEmpty();2assertThat(new LocalTime(12, 0)).isNotNullAndNotEmpty();3assertThat(new LocalDateTime(2010, 1, 1, 12, 0)).isNotNullAndNotEmpty();4assertThat(new DateTime(2010, 1, 1, 12, 0)).isNotNullAndNotEmpty();5assertThat(new Duration(2010, 1, 1, 12, 0)).isNotNullAndNotEmpty();6assertThat(new Interval(2010, 1, 1, 12, 0)).isNotNullAndNotEmpty();7assertThat(new Period(2010, 1, 1, 12, 0)).isNotNullAndNotEmpty();8assertThat(new Instant(2010, 1, 1, 12, 0)).isNotNullAndNotEmpty();9assertThat(new YearMonthDay(2010, 1, 1)).isNotNullAndNotEmpty();10assertThat(new Years(2010)).isNotNullAndNotEmpty();11assertThat(new Interval(2010, 1, 1, 12, 0)).isNotNullAndNotEmpty();12assertThat(new Duration(2010, 1, 1, 12, 0)).isNotNullAndNotEmpty();checkIsNotNullAndNotEmpty
Using AI Code Generation
1LocalDate date = LocalDate.of(2018, 1, 1);2assertThat(date).checkIsNotNullAndNotEmpty();3LocalTime time = LocalTime.of(12, 0, 0);4assertThat(time).checkIsNotNullAndNotEmpty();5LocalDateTime dateTime = LocalDateTime.of(2018, 1, 1, 12, 0, 0);6assertThat(dateTime).checkIsNotNullAndNotEmpty();7OffsetTime offsetTime = OffsetTime.of(12, 0, 0, 0, ZoneOffset.UTC);8assertThat(offsetTime).checkIsNotNullAndNotEmpty();9OffsetDateTime offsetDateTime = OffsetDateTime.of(2018, 1, 1, 12, 0, 0, 0, ZoneOffset.UTC);10assertThat(offsetDateTime).checkIsNotNullAndNotEmpty();11ZonedDateTime zonedDateTime = ZonedDateTime.of(2018, 1, 1, 12, 0, 0, 0, ZoneId.systemDefault());12assertThat(zonedDateTime).checkIsNotNullAndNotEmpty();13Instant instant = Instant.now();14assertThat(instant).checkIsNotNullAndNotEmpty();15Duration duration = Duration.of(1, ChronoUnit.HOURS);16assertThat(duration).checkIsNotNullAndNotEmpty();17Period period = Period.of(1, 0, 0);18assertThat(period).checkIsNotNullAndNotEmpty();19ChronoLocalDate chronoLocalDate = LocalDate.of(2018, 1, 1);20assertThat(chronoLocalDate).checkIsNotNullAndNotEmptycheckIsNotNullAndNotEmpty
Using AI Code Generation
1assertThat(LocalDate.now()).checkIsNotNullAndNotEmpty();2assertThat(LocalDate.now()).checkIsNotNullAndNotEmpty();3assertThat(LocalTime.now()).checkIsNotNullAndNotEmpty();4assertThat(LocalDateTime.now()).checkIsNotNullAndNotEmpty();5assertThat(OffsetTime.now()).checkIsNotNullAndNotEmpty();6assertThat(OffsetDateTime.now()).checkIsNotNullAndNotEmpty();7assertThat(ZonedDateTime.now()).checkIsNotNullAndNotEmpty();8assertThat(Instant.now()).checkIsNotNullAndNotEmpty();9assertThat(Duration.ofHours(1)).checkIsNotNullAndNotEmpty();10assertThat(Period.ofDays(1)).checkIsNotNullAndNotEmpty();11assertThat(LocalDate.now()).checkIsNotNullAndNotEmpty();12assertThat(LocalTime.now()).checkIsNotNullAndNotEmpty();13assertThat(LocalDateTime.now()).checkIsNotNullAndNotEmpty();14assertThat(OffsetTime.now()).checkIsNotNullAndNotEmpty();15assertThat(OffsetDateTime.now()).checkIsNotNullAndNotEmpty();checkIsNotNullAndNotEmpty
Using AI Code Generation
1import static org.assertj.core.api.Assertions.assertThat;2import java.time.LocalDate;3import java.time.Month;4import org.junit.Test;5public class AssertJAssertThatLocalDateTest {6    public void testAssertThatLocalDate() {7        LocalDate localDate = LocalDate.of(2015, Month.NOVEMBER, 15);8        assertThat(localDate).isNotNull();9        assertThat(localDate).isNotNullAndNotEmpty();10        assertThat(localDate).isNotNullAndNotEmpty().hasYear(2015).hasMonth(11).hasDayOfMonth(15).hasDayOfYear(319);11        assertThat(localDate).isNotNullAndNotEmpty().hasYear(2015).hasMonth(11).hasDayOfMonth(15).hasDayOfYear(319).hasDayOfWeek(3);12    }13}14	at org.assertj.core.api.AbstractLocalDateAssert.isNotNull(AbstractLocalDateAssert.java:66)15	at org.assertj.core.api.AbstractLocalDateAssert.isNotNullAndNotEmpty(AbstractLocalDateAssert.java:72)16	at AssertJAssertThatLocalDateTest.testAssertThatLocalDate(AssertJAssertThatLocalDateTest.java:11)17	at org.assertj.core.api.AbstractLocalDateAssert.isNotNull(AbstractLocalDateAssert.java:66)18	at org.assertj.core.api.AbstractLocalDateAssert.isNotNullAndNotEmpty(AbstractLocalDateAssert.java:72)19	at AssertJAssertThatLocalDateTest.testAssertThatLocalDate(AssertJAssertThatLocalDateTest.java:11)20	at org.assertj.core.api.AbstractLocalDateAssert.hasYear(AbstractLocalDateAssert.java:224)21	at AssertJAssertThatLocalDateTest.testAssertThatLocalDate(AssertJAssertThatLocalDateTest.java:12)22	at org.assertj.core.api.AbstractLocalDateAssert.hasMonth(AbstractLocalDateAssert.java:237)23	at AssertJAssertThatLocalDateTest.testAssertThatLocalDate(AssertJAssertThatLocalDateTest.java:13)checkIsNotNullAndNotEmpty
Using AI Code Generation
1assertThat(LocalDate.parse("2011-01-01")).checkIsNotNullAndNotEmpty();2assertThat(LocalDate.parse("2011-01-01")).checkIsNotNullAndNotEmpty().isEqualTo("2011-01-01");3assertThat(LocalTime.parse("10:15:30")).checkIsNotNullAndNotEmpty();4assertThat(LocalTime.parse("10:15:30")).checkIsNotNullAndNotEmpty().isEqualTo("10:15:30");5assertThat(LocalDateTime.parse("2011-01-01T10:15:30")).checkIsNotNullAndNotEmpty();6assertThat(LocalDateTime.parse("2011-01-01T10:15:30")).checkIsNotNullAndNotEmpty().isEqualTo("2011-01-01T10:15:30");7assertThat(ZonedDateTime.parse("2011-01-01T10:15:30+01:00[Europe/Paris]")).checkIsNotNullAndNotEmpty();8assertThat(ZonedDateTime.parse("2011-01-01T10:15:30+01:00[Europe/Paris]")).checkIsNotNullAndNotEmpty().isEqualTo("2011-01-01T10:15:30+01:00[Europe/Paris]");9assertThat(OffsetTime.parse("10:15:30+01:00")).checkIsNotNullAndNotEmpty();10assertThat(OffsetTime.parse("10:15:30+01:00")).checkIsNotNullAndNotEmpty().isEqualTo("10:15:30+01:00");11assertThat(OffsetDateTime.parse("2011-01-01T10:15:30+01:00")).checkIsNotNullAndNotEmpty();12assertThat(OffsetDateTime.parse("2011-01-01T10:15:30+01:00")).checkIsNotNullAndNotEmpty().isEqualTo("2011-01-01T10:15:30+01:00");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!!
