Best Assertj code snippet using org.assertj.core.internal.Dates.dateParameterIsNotNull
Source:Dates.java  
...97   * @throws AssertionError if the actual {@code Date} is not strictly before the given one.98   */99  public void assertIsBefore(AssertionInfo info, Date actual, Date other) {100    assertNotNull(info, actual);101    dateParameterIsNotNull(other);102    if (!isBefore(actual, other))103      throw failures.failure(info, shouldBeBefore(actual, other, comparisonStrategy));104  }105  /**106   * Verifies that the actual {@code Date} is before or equal to the given one.107   * @param info contains information about the assertion.108   * @param actual the "actual" {@code Date}.109   * @param other the other date to compare actual with.110   * @throws AssertionError if {@code actual} is {@code null}.111   * @throws NullPointerException if other {@code Date} is {@code null}.112   * @throws AssertionError if the actual {@code Date} is not before or equal to the given one.113   */114  public void assertIsBeforeOrEqualTo(AssertionInfo info, Date actual, Date other) {115    assertNotNull(info, actual);116    dateParameterIsNotNull(other);117    if (!isBeforeOrEqualTo(actual, other))118      throw failures.failure(info, shouldBeBeforeOrEqualTo(actual, other, comparisonStrategy));119  }120  /**121   * Verifies that the actual {@code Date} is strictly after the given one.122   * @param info contains information about the assertion.123   * @param actual the "actual" {@code Date}.124   * @param other the given Date.125   * @throws AssertionError if {@code actual} is {@code null}.126   * @throws NullPointerException if other {@code Date} is {@code null}.127   * @throws AssertionError if the actual {@code Date} is not strictly after the given one.128   */129  public void assertIsAfter(AssertionInfo info, Date actual, Date other) {130    assertNotNull(info, actual);131    dateParameterIsNotNull(other);132    if (!isAfter(actual, other))133      throw failures.failure(info, shouldBeAfter(actual, other, comparisonStrategy));134  }135  /**136   * Verifies that the actual {@code Date} is after or equal to the given one.137   * @param info contains information about the assertion.138   * @param actual the "actual" {@code Date}.139   * @param other the given Date.140   * @throws AssertionError if {@code actual} is {@code null}.141   * @throws NullPointerException if other {@code Date} is {@code null}.142   * @throws AssertionError if the actual {@code Date} is not after or equal to the given one.143   */144  public void assertIsAfterOrEqualTo(AssertionInfo info, Date actual, Date other) {145    assertNotNull(info, actual);146    dateParameterIsNotNull(other);147    if (!isAfterOrEqualTo(actual, other))148      throw failures.failure(info, shouldBeAfterOrEqualTo(actual, other, comparisonStrategy));149  }150  /**151   * Verifies that the actual {@code Date} is equal to the given one with precision.152   * @param info contains information about the assertion.153   * @param actual the "actual" {@code Date}.154   * @param other the given Date.155   * @param precision maximum precision for the comparison.156   * @throws AssertionError if {@code actual} is {@code null}.157   * @throws NullPointerException if other {@code Date} is {@code null}.158   * @throws AssertionError if the actual {@code Date} is not equal to the given one.159   */160  public void assertIsEqualWithPrecision(AssertionInfo info, Date actual, Date other, TimeUnit precision) {161    assertNotNull(info, actual);162    Calendar calendarActual = Calendar.getInstance();163    calendarActual.setTime(actual);164    Calendar calendarOther = Calendar.getInstance();165    calendarOther.setTime(other);166    switch (precision) {167    case DAYS:168      calendarActual.set(Calendar.DAY_OF_WEEK, 0);169      calendarOther.set(Calendar.DAY_OF_WEEK, 0);170    case HOURS:171      calendarActual.set(Calendar.HOUR_OF_DAY, 0);172      calendarOther.set(Calendar.HOUR_OF_DAY, 0);173    case MINUTES:174      calendarActual.set(Calendar.MINUTE, 0);175      calendarOther.set(Calendar.MINUTE, 0);176    case SECONDS:177      calendarActual.set(Calendar.SECOND, 0);178      calendarOther.set(Calendar.SECOND, 0);179    case MILLISECONDS:180      calendarActual.set(Calendar.MILLISECOND, 0);181      calendarOther.set(Calendar.MILLISECOND, 0);182    case MICROSECONDS:183      break;184    default:185      break;186    }187    if (calendarActual.compareTo(calendarOther) != 0)188      throw failures.failure(info, ShouldBeEqualWithTimePrecision.shouldBeEqual(actual, other, precision));189  }190  /**191   * Verifies that the actual {@code Date} is in <i>start:end</i> period.<br>192   * start date belongs to the period if inclusiveStart is true.<br>193   * end date belongs to the period if inclusiveEnd is true.<br>194   * @param info contains information about the assertion.195   * @param actual the "actual" {@code Date}.196   * @param start the period start, expected not to be null.197   * @param end the period end, expected not to be null.198   * @param inclusiveStart whether to include start date in period.199   * @param inclusiveEnd whether to include end date in period.200   * @throws AssertionError if {@code actual} is {@code null}.201   * @throws NullPointerException if start {@code Date} is {@code null}.202   * @throws NullPointerException if end {@code Date} is {@code null}.203   * @throws AssertionError if the actual {@code Date} is not in <i>start:end</i> period.204   */205  public void assertIsBetween(AssertionInfo info, Date actual, Date start, Date end, boolean inclusiveStart,206                              boolean inclusiveEnd) {207    if (!actualIsBetweenGivenPeriod(info, actual, start, end, inclusiveStart, inclusiveEnd))208      throw failures.failure(info, shouldBeBetween(actual, start, end, inclusiveStart, inclusiveEnd, comparisonStrategy));209  }210  private boolean actualIsBetweenGivenPeriod(AssertionInfo info, Date actual, Date start, Date end, boolean inclusiveStart,211                                             boolean inclusiveEnd) {212    assertNotNull(info, actual);213    startDateParameterIsNotNull(start);214    endDateParameterIsNotNull(end);215    boolean checkLowerBoundaryPeriod = inclusiveStart ? isAfterOrEqualTo(actual, start) : isAfter(actual, start);216    boolean checkUpperBoundaryPeriod = inclusiveEnd ? isBeforeOrEqualTo(actual, end) : isBefore(actual, end);217    boolean isBetweenGivenPeriod = checkLowerBoundaryPeriod && checkUpperBoundaryPeriod;218    return isBetweenGivenPeriod;219  }220  /**221   * Verifies that the actual {@code Date} is not in <i>start:end</i> period..<br>222   * start date belongs to the period if inclusiveStart is true.<br>223   * end date belongs to the period if inclusiveEnd is true.<br>224   * @param info contains information about the assertion.225   * @param actual the "actual" {@code Date}.226   * @param start the period start, expected not to be null.227   * @param end the period end, expected not to be null.228   * @param inclusiveStart whether to include start date in period.229   * @param inclusiveEnd whether to include end date in period.230   * @throws AssertionError if {@code actual} is {@code null}.231   * @throws NullPointerException if start {@code Date} is {@code null}.232   * @throws NullPointerException if end {@code Date} is {@code null}.233   * @throws AssertionError if the actual {@code Date} is in <i>start:end</i> period.234   */235  public void assertIsNotBetween(AssertionInfo info, Date actual, Date start, Date end, boolean inclusiveStart,236                                 boolean inclusiveEnd) {237    if (actualIsBetweenGivenPeriod(info, actual, start, end, inclusiveStart, inclusiveEnd))238      throw failures.failure(info, shouldNotBeBetween(actual, start, end, inclusiveStart, inclusiveEnd, comparisonStrategy));239  }240  /**241   * Verifies that the actual {@code Date} is strictly in the past.242   * @param info contains information about the assertion.243   * @param actual the "actual" {@code Date}.244   * @throws AssertionError if {@code actual} is {@code null}.245   * @throws AssertionError if the actual {@code Date} is not in the past.246   */247  public void assertIsInThePast(AssertionInfo info, Date actual) {248    assertNotNull(info, actual);249    if (!isBefore(actual, now())) throw failures.failure(info, shouldBeInThePast(actual, comparisonStrategy));250  }251  /**252   * Verifies that the actual {@code Date} is today, by comparing only year, month and day of actual to today (ie. we don't check253   * hours).254   * @param info contains information about the assertion.255   * @param actual the "actual" {@code Date}.256   * @throws AssertionError if {@code actual} is {@code null}.257   * @throws AssertionError if the actual {@code Date} is not today.258   */259  public void assertIsToday(AssertionInfo info, Date actual) {260    assertNotNull(info, actual);261    Date todayWithoutTime = truncateTime(now());262    Date actualWithoutTime = truncateTime(actual);263    if (!areEqual(actualWithoutTime, todayWithoutTime)) throw failures.failure(info, shouldBeToday(actual, comparisonStrategy));264  }265  /**266   * Verifies that the actual {@code Date} is strictly in the future.267   * @param info contains information about the assertion.268   * @param actual the "actual" {@code Date}.269   * @throws AssertionError if {@code actual} is {@code null}.270   * @throws AssertionError if the actual {@code Date} is not in the future.271   */272  public void assertIsInTheFuture(AssertionInfo info, Date actual) {273    assertNotNull(info, actual);274    if (!isAfter(actual, now())) throw failures.failure(info, shouldBeInTheFuture(actual, comparisonStrategy));275  }276  /**277   * Verifies that the actual {@code Date} is strictly before the given year.278   * @param info contains information about the assertion.279   * @param actual the "actual" {@code Date}.280   * @param year the year to compare actual year to281   * @throws AssertionError if {@code actual} is {@code null}.282   * @throws AssertionError if the actual {@code Date} year is after or equal to the given year.283   */284  public void assertIsBeforeYear(AssertionInfo info, Date actual, int year) {285    assertNotNull(info, actual);286    if (yearOf(actual) >= year) throw failures.failure(info, shouldBeBeforeYear(actual, year));287  }288  /**289   * Verifies that the actual {@code Date} is strictly after the given year.290   * @param info contains information about the assertion.291   * @param actual the "actual" {@code Date}.292   * @param year the year to compare actual year to293   * @throws AssertionError if {@code actual} is {@code null}.294   * @throws AssertionError if the actual {@code Date} year is before or equal to the given year.295   */296  public void assertIsAfterYear(AssertionInfo info, Date actual, int year) {297    assertNotNull(info, actual);298    if (yearOf(actual) <= year) throw failures.failure(info, shouldBeAfterYear(actual, year));299  }300  /**301   * Verifies that the actual {@code Date} year is equal to the given year.302   * @param year the year to compare actual year to303   * @param info contains information about the assertion.304   * @param actual the "actual" {@code Date}.305   * @throws AssertionError if {@code actual} is {@code null}.306   * @throws AssertionError if the actual {@code Date} year is not equal to the given year.307   */308  public void assertHasYear(AssertionInfo info, Date actual, int year) {309    assertNotNull(info, actual);310    if (yearOf(actual) != year) throw failures.failure(info, shouldHaveDateField(actual, "year", year));311  }312  /**313   * Verifies that the actual {@code Date} month is equal to the given month, <b>month value starting at 1</b> (January=1,314   * February=2, ...).315   * @param info contains information about the assertion.316   * @param actual the "actual" {@code Date}.317   * @param month the month to compare actual month to, see {@link Calendar#MONTH} for valid values318   * @throws AssertionError if {@code actual} is {@code null}.319   * @throws AssertionError if the actual {@code Date} month is not equal to the given month.320   */321  public void assertHasMonth(AssertionInfo info, Date actual, int month) {322    assertNotNull(info, actual);323    if (monthOf(actual) != month)324      throw failures.failure(info, shouldHaveDateField(actual, "month", month));325  }326  /**327   * Verifies that the actual {@code Date} day of month is equal to the given day of month.328   * @param info contains information about the assertion.329   * @param actual the "actual" {@code Date}.330   * @param dayOfMonth the day of month to compare actual day of month to331   * @throws AssertionError if {@code actual} is {@code null}.332   * @throws AssertionError if the actual {@code Date} month is not equal to the given day of month.333   */334  public void assertHasDayOfMonth(AssertionInfo info, Date actual, int dayOfMonth) {335    assertNotNull(info, actual);336    if (dayOfMonthOf(actual) != dayOfMonth) throw failures.failure(info, shouldHaveDateField(actual, "day of month", dayOfMonth));337  }338  /**339   * Verifies that the actual {@code Date} day of week is equal to the given day of week.340   * @param info contains information about the assertion.341   * @param actual the "actual" {@code Date}.342   * @param dayOfWeek the day of week to compare actual day of week to, see {@link Calendar#DAY_OF_WEEK} for valid values343   * @throws AssertionError if {@code actual} is {@code null}.344   * @throws AssertionError if the actual {@code Date} week is not equal to the given day of week.345   */346  public void assertHasDayOfWeek(AssertionInfo info, Date actual, int dayOfWeek) {347    assertNotNull(info, actual);348    if (dayOfWeekOf(actual) != dayOfWeek) throw failures.failure(info, shouldHaveDateField(actual, "day of week", dayOfWeek));349  }350  /**351   * Verifies that the actual {@code Date} hour od day is equal to the given hour of day (24-hour clock).352   * @param info contains information about the assertion.353   * @param actual the "actual" {@code Date}.354   * @param hourOfDay the hour of day to compare actual hour of day to (24-hour clock)355   * @throws AssertionError if {@code actual} is {@code null}.356   * @throws AssertionError if the actual {@code Date} hour is not equal to the given hour.357   */358  public void assertHasHourOfDay(AssertionInfo info, Date actual, int hourOfDay) {359    assertNotNull(info, actual);360    if (hourOfDayOf(actual) != hourOfDay)361      throw failures.failure(info, shouldHaveDateField(actual, "hour", hourOfDay));362  }363  /**364   * Verifies that the actual {@code Date} minute is equal to the given minute.365   * @param info contains information about the assertion.366   * @param actual the "actual" {@code Date}.367   * @param minute the minute to compare actual minute to368   * @throws AssertionError if {@code actual} is {@code null}.369   * @throws AssertionError if the actual {@code Date} minute is not equal to the given minute.370   */371  public void assertHasMinute(AssertionInfo info, Date actual, int minute) {372    assertNotNull(info, actual);373    if (minuteOf(actual) != minute) throw failures.failure(info, shouldHaveDateField(actual, "minute", minute));374  }375  /**376   * Verifies that the actual {@code Date} second is equal to the given second.377   * @param info contains information about the assertion.378   * @param actual the "actual" {@code Date}.379   * @param second the second to compare actual second to380   * @throws AssertionError if {@code actual} is {@code null}.381   * @throws AssertionError if the actual {@code Date} second is not equal to the given second.382   */383  public void assertHasSecond(AssertionInfo info, Date actual, int second) {384    assertNotNull(info, actual);385    if (secondOf(actual) != second) throw failures.failure(info, shouldHaveDateField(actual, "second", second));386  }387  /**388   * Verifies that the actual {@code Date} millisecond is equal to the given millisecond.389   * @param info contains information about the assertion.390   * @param actual the "actual" {@code Date}.391   * @param millisecond the millisecond to compare actual millisecond to392   * @throws AssertionError if {@code actual} is {@code null}.393   * @throws AssertionError if the actual {@code Date} millisecond is not equal to the given millisecond.394   */395  public void assertHasMillisecond(AssertionInfo info, Date actual, int millisecond) {396    assertNotNull(info, actual);397    if (millisecondOf(actual) != millisecond)398      throw failures.failure(info, shouldHaveDateField(actual, "millisecond", millisecond));399  }400  /**401   * Verifies that actual and given {@code Date} are in the same year.402   * @param info contains information about the assertion.403   * @param actual the "actual" {@code Date}.404   * @param other the given {@code Date} to compare actual {@code Date} to.405   * @throws AssertionError if {@code actual} is {@code null}.406   * @throws NullPointerException if other {@code Date} is {@code null}.407   * @throws AssertionError if actual and given {@code Date} are not in the same year.408   */409  public void assertIsInSameYearAs(AssertionInfo info, Date actual, Date other) {410    assertNotNull(info, actual);411    dateParameterIsNotNull(other);412    if (!areInSameYear(actual, other)) throw failures.failure(info, shouldBeInSameYear(actual, other));413  }414  /**415   * Returns true if both date are in the same year, false otherwise.416   * @param actual the actual date. expected not be null417   * @param other the other date. expected not be null418   * @return true if both date are in the same year, false otherwise419   */420  private static boolean areInSameYear(Date actual, Date other) {421    return yearOf(actual) == yearOf(other);422  }423  /**424   * Verifies that actual and given {@code Date} are chronologically in the same month (and thus in the same year).425   * @param info contains information about the assertion.426   * @param actual the "actual" {@code Date}.427   * @param other the given {@code Date} to compare actual {@code Date} to.428   * @throws AssertionError if {@code actual} is {@code null}.429   * @throws NullPointerException if other {@code Date} is {@code null}.430   * @throws AssertionError if actual and given {@code Date} are not chronologically speaking in the same month.431   */432  public void assertIsInSameMonthAs(AssertionInfo info, Date actual, Date other) {433    assertNotNull(info, actual);434    dateParameterIsNotNull(other);435    if (!areInSameMonth(actual, other)) throw failures.failure(info, shouldBeInSameMonth(actual, other));436  }437  /**438   * Returns true if both date are in the same year and month, false otherwise.439   * @param actual the actual date. expected not be null440   * @param other the other date. expected not be null441   * @return true if both date are in the same year and month, false otherwise442   */443  private static boolean areInSameMonth(Date actual, Date other) {444    return areInSameYear(actual, other) && monthOf(actual) == monthOf(other);445  }446  /**447   * Verifies that actual and given {@code Date} are chronologically in the same day of month (and thus in the same month and448   * year).449   * @param info contains information about the assertion.450   * @param actual the "actual" {@code Date}.451   * @param other the given {@code Date} to compare actual {@code Date} to.452   * @throws AssertionError if {@code actual} is {@code null}.453   * @throws NullPointerException if other {@code Date} is {@code null}.454   * @throws AssertionError if actual and given {@code Date} are not chronologically speaking in the same day of month.455   */456  public void assertIsInSameDayAs(AssertionInfo info, Date actual, Date other) {457    assertNotNull(info, actual);458    dateParameterIsNotNull(other);459    if (!areInSameDayOfMonth(actual, other)) throw failures.failure(info, shouldBeInSameDay(actual, other));460  }461  /**462   * Returns true if both date are in the same year, month and day of month, false otherwise.463   * @param actual the actual date. expected not be null464   * @param other the other date. expected not be null465   * @return true if both date are in the same year, month and day of month, false otherwise466   */467  private static boolean areInSameDayOfMonth(Date actual, Date other) {468    return areInSameMonth(actual, other) && dayOfMonthOf(actual) == dayOfMonthOf(other);469  }470  /**471   * Verifies that actual and given {@code Date} are in the same hour (and thus in the same day of month, month472   * and year).473   * @param info contains information about the assertion.474   * @param actual the "actual" {@code Date}.475   * @param other the given {@code Date} to compare actual {@code Date} to.476   * @throws AssertionError if {@code actual} is {@code null}.477   * @throws NullPointerException if other {@code Date} is {@code null}.478   * @throws AssertionError if actual and given {@code Date} are not chronologically speaking in the same hour.479   */480  public void assertIsInSameHourAs(AssertionInfo info, Date actual, Date other) {481    assertNotNull(info, actual);482    dateParameterIsNotNull(other);483    if (!areInSameHour(actual, other)) throw failures.failure(info, shouldBeInSameHour(actual, other));484  }485  /**486   * Verifies that actual and given {@code Date} are chronologically in the same hour, day of month, month and year.487   *488   * @param info contains information about the assertion.489   * @param actual the "actual" {@code Date}.490   * @param other the given {@code Date} to compare actual {@code Date} to.491   * @throws AssertionError if {@code actual} is {@code null}.492   * @throws NullPointerException if other {@code Date} is {@code null}.493   * @throws AssertionError if actual and given {@code Date} are not chronologically speaking in the same hour.494   */495  public void assertIsInSameHourWindowAs(AssertionInfo info, Date actual, Date other) {496    assertNotNull(info, actual);497    dateParameterIsNotNull(other);498    if (!areInSameHourWindow(actual, other)) throw failures.failure(info, shouldBeInSameHourWindow(actual, other));499  }500  /**501   * Returns true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.502   * @param actual the actual date. expected not be null503   * @param other the other date. expected not be null504   * @return true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.505   */506  private static boolean areInSameHourWindow(Date actual, Date other) {507    return timeDifference(actual, other) < TimeUnit.HOURS.toMillis(1);508  }509  /**510   * Returns true if both date are in the same year, month, day of month and hour, false otherwise.511   * @param actual the actual date. expected not be null512   * @param other the other date. expected not be null513   * @return true if both date are in the same year, month, day of month and hour, false otherwise.514   */515  private static boolean areInSameHour(Date actual, Date other) {516    return areInSameDayOfMonth(actual, other) && hourOfDayOf(actual) == hourOfDayOf(other);517  }518  /**519   * Verifies that actual and given {@code Date} are in the same minute, hour, day of month, month and year.520   * @param info contains information about the assertion.521   * @param actual the "actual" {@code Date}.522   * @param other the given {@code Date} to compare actual {@code Date} to.523   * @throws AssertionError if {@code actual} is {@code null}.524   * @throws NullPointerException if other {@code Date} is {@code null}.525   * @throws AssertionError if actual and given {@code Date} are not chronologically speaking in the same minute.526   */527  public void assertIsInSameMinuteAs(AssertionInfo info, Date actual, Date other) {528    assertNotNull(info, actual);529    dateParameterIsNotNull(other);530    if (!areInSameMinute(actual, other)) throw failures.failure(info, shouldBeInSameMinute(actual, other));531  }532  /**533   * Verifies that actual and given {@code Date} are chronologically in the same minute.534   * @param info contains information about the assertion.535   * @param actual the "actual" {@code Date}.536   * @param other the given {@code Date} to compare actual {@code Date} to.537   * @throws AssertionError if {@code actual} is {@code null}.538   * @throws NullPointerException if other {@code Date} is {@code null}.539   * @throws AssertionError if actual and given {@code Date} are not chronologically speaking in the same minute.540   */541  public void assertIsInSameMinuteWindowAs(AssertionInfo info, Date actual, Date other) {542    assertNotNull(info, actual);543    dateParameterIsNotNull(other);544    if (!areInSameMinuteWindow(actual, other)) throw failures.failure(info, shouldBeInSameMinuteWindow(actual, other));545  }546  /**547   * Returns true if both date are in the same year, month, day of month, hour and minute, false otherwise.548   * @param actual the actual date. expected not be null549   * @param other the other date. expected not be null550   * @return true if both date are in the same year, month, day of month, hour and minute, false otherwise.551   */552  private static boolean areInSameMinute(Date actual, Date other) {553    return areInSameHour(actual, other) && minuteOf(actual) == minuteOf(other);554  }555  private static boolean areInSameMinuteWindow(Date actual, Date other) {556    return timeDifference(actual, other) < TimeUnit.MINUTES.toMillis(1);557  }558  /**559   * Verifies that actual and given {@code Date} are in the same second, minute, hour, day of month, month and year.560   * @param info contains information about the assertion.561   * @param actual the "actual" {@code Date}.562   * @param other the given {@code Date} to compare actual {@code Date} to.563   * @throws AssertionError if {@code actual} is {@code null}.564   * @throws NullPointerException if other {@code Date} is {@code null}.565   * @throws AssertionError if actual and given {@code Date} are not chronologically speaking in the same second.566   */567  public void assertIsInSameSecondAs(AssertionInfo info, Date actual, Date other) {568    assertNotNull(info, actual);569    dateParameterIsNotNull(other);570    if (!areInSameSecond(actual, other)) throw failures.failure(info, shouldBeInSameSecond(actual, other));571  }572  /**573   * Verifies that actual and given {@code Date} are chronologically in the same second.574   * @param info contains information about the assertion.575   * @param actual the "actual" {@code Date}.576   * @param other the given {@code Date} to compare actual {@code Date} to.577   * @throws AssertionError if {@code actual} is {@code null}.578   * @throws NullPointerException if other {@code Date} is {@code null}.579   * @throws AssertionError if actual and given {@code Date} are not chronologically speaking in the same second.580   */581  public void assertIsInSameSecondWindowAs(AssertionInfo info, Date actual, Date other) {582    assertNotNull(info, actual);583    dateParameterIsNotNull(other);584    if (!areInSameSecondWindow(actual, other)) throw failures.failure(info, shouldBeInSameSecondWindow(actual, other));585  }586  /**587   * Returns true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.588   * @param actual the actual date. expected not be null589   * @param other the other date. expected not be null590   * @return true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.591   */592  private static boolean areInSameSecondWindow(Date actual, Date other) {593    return timeDifference(actual, other) < TimeUnit.SECONDS.toMillis(1);594  }595  /**596   * Returns true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.597   * @param actual the actual date. expected not be null598   * @param other the other date. expected not be null599   * @return true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.600   */601  private static boolean areInSameSecond(Date actual, Date other) {602    return areInSameMinute(actual, other) && secondOf(actual) == secondOf(other);603  }604  /**605   * Verifies that the actual {@code Date} is close to the other date by less than delta, if difference is equals to delta it is606   * ok.<br>607   * Note that delta expressed in milliseconds.<br>608   * Use handy TimeUnit to convert a duration in milliseconds, for example you can express a delta of 5 seconds with609   * <code>TimeUnit.SECONDS.toMillis(5)</code>.610   * @param info contains information about the assertion.611   * @param actual the "actual" {@code Date}.612   * @param other the given {@code Date} to compare actual {@code Date} to.613   * @param deltaInMilliseconds the delta used for date comparison, expressed in milliseconds614   * @throws AssertionError if {@code actual} is {@code null}.615   * @throws NullPointerException if other {@code Date} is {@code null}.616   * @throws AssertionError if the actual {@code Date} week is not close to the given date by less than delta.617   */618  public void assertIsCloseTo(AssertionInfo info, Date actual, Date other, long deltaInMilliseconds) {619    assertNotNull(info, actual);620    dateParameterIsNotNull(other);621    long difference = Math.abs(actual.getTime() - other.getTime());622    if (difference > deltaInMilliseconds)623      throw failures.failure(info, shouldBeCloseTo(actual, other, deltaInMilliseconds, difference));624  }625  /**626   * Verifies that the actual {@code Date} time is equal to the given timestamp.627   * @param info contains information about the assertion.628   * @param actual the "actual" {@code Date}.629   * @param timestamp the timestamp to compare actual time to630   * @throws AssertionError if {@code actual} is {@code null}.631   * @throws AssertionError if the actual {@code Date} time is not equal to the given timestamp.632   */633  public void assertHasTime(AssertionInfo info, Date actual, long timestamp) {634    assertNotNull(info, actual);635    if (actual.getTime() != timestamp) throw failures.failure(info, shouldHaveTime(actual, timestamp));636  }637  /**638   * Verifies that the actual {@code Date} has same time as the given {@code Date}.639   * @param info contains information about the assertion.640   * @param actual the "actual" {@code Date}.641   * @param expected the "expected" {@code Date} to compare actual time to642   * @throws AssertionError if {@code actual} is {@code null}.643   * @throws AssertionError if {@code expected} is {@code null}.644   * @throws AssertionError if the actual {@code Date} time is not equal to the given {@code Date}.645   */646  public void assertHasSameTime(AssertionInfo info, Date actual, Date expected) {647    assertNotNull(info, actual);648    dateParameterIsNotNull(expected);649    if (actual.getTime() != expected.getTime()) throw failures.failure(info, shouldHaveSameTime(actual, expected));650  }651  /**652   * Verifies that the actual {@code Date} is equal to the given date by comparing their time.653   * @param info contains information about the assertion.654   * @param actual the "actual" {@code Date}.655   * @param date the date to compare actual time to656   * @throws AssertionError if {@code actual} is {@code null}.657   * @throws AssertionError if the actual {@code Date} time is not equal to the given date time.658   * @throws NullPointerException if other {@code Date} is {@code null}.659   */660  public void hasSameTimeAs(AssertionInfo info, Date actual, Date date) {661    assertNotNull(info, actual);662    dateParameterIsNotNull(date);663    assertHasSameTime(info, actual, date);664  }665  /**666   * used to check that the date to compare actual date to is not null, in that case throws a {@link NullPointerException} with an667   * explicit message668   * @param date the date to check669   * @throws NullPointerException with an explicit message if the given date is null670   */671  private static void dateParameterIsNotNull(Date date) {672    requireNonNull(date, "The date to compare actual with should not be null");673  }674  /**675   * used to check that the start of period date to compare actual date to is not null, in that case throws a676   * {@link NullPointerException} with an explicit message677   * @param start the start date to check678   * @throws NullPointerException with an explicit message if the given start date is null679   */680  private static void startDateParameterIsNotNull(Date start) {681    requireNonNull(start, "The start date of period to compare actual with should not be null");682  }683  /**684   * used to check that the end of period date to compare actual date to is not null, in that case throws a685   * {@link NullPointerException} with an explicit message...dateParameterIsNotNull
Using AI Code Generation
1public class Dates_assertIsNotEqualTo_Test extends DatesBaseTest {2  public void should_pass_if_actual_is_not_equal_to_given_date() {3    dates.assertIsNotEqualTo(parseDatetime("2011-01-01"), parseDatetime("2011-01-02"));4  }5  public void should_fail_if_actual_is_equal_to_given_date() {6    AssertionInfo info = someInfo();7    Date other = parseDatetime("2011-01-01");8    Throwable error = catchThrowable(() -> dates.assertIsNotEqualTo(info, actual, other));9    assertThat(error).isInstanceOf(AssertionError.class);10    verify(failures).failure(info, shouldBeNotEqual(actual, other));11  }12  public void should_fail_if_actual_is_equal_to_given_date_by_comparison() {13    AssertionInfo info = someInfo();14    Date other = parseDatetime("2011-01-01");15    Throwable error = catchThrowable(() -> datesWithCustomComparisonStrategy.assertIsNotEqualTo(info, actual, other));16    assertThat(error).isInstanceOf(AssertionError.class);17    verify(failures).failure(info, shouldBeNotEqual(actual, other, customComparisonStrategy));18  }19  public void should_throw_error_if_given_date_is_null() {20    assertThatIllegalArgumentException().isThrownBy(() -> dates.assertIsNotEqualTo(someInfo(), actual, null))21                                        .withMessage("The Date to compare actual with should not be null");22  }23  public void should_fail_if_actual_is_null() {24    assertThatNullPointerException().isThrownBy(() -> dates.assertIsNotEqualTo(someInfo(), null, parseDatetime("2011-01-01")))25                                    .withMessage(actualIsNull());26  }27  public void should_pass_if_actual_is_not_equal_to_given_date_according_to_custom_comparison_strategy() {28    datesWithCustomComparisonStrategy.assertIsNotEqualTo(parseDatetime("2011-01-01"), parseDatetime("2011-01-02"));29  }30  public void should_fail_if_actual_is_equal_to_given_date_according_to_custom_comparison_strategy() {31    AssertionInfo info = someInfo();32    Date other = parseDatetime("2011-01-01");33    Throwable error = catchThrowable(() -> datesWithCustomComparisonStrategy.assertIsNotEqualTo(info, actual, other));34    assertThat(error).isInstanceOf(AssertionError.class);35    verify(failures).failure(info, shouldBeNotEqualdateParameterIsNotNull
Using AI Code Generation
1import static org.assertj.core.api.Assertions.assertThat;2import static org.assertj.core.api.Assertions.catchThrowable;3import static org.assertj.core.error.ShouldNotBeNull.shouldNotBeNull;4import static org.assertj.core.util.FailureMessages.actualIsNull;5import java.util.Date;6import org.assertj.core.api.AbstractDateAssert;7import org.assertj.core.internal.Dates;8import org.assertj.core.internal.Objects;9import org.assertj.core.util.VisibleForTesting;10public class DateAssert extends AbstractDateAssert<DateAssert, Date> {11  Dates dates = Dates.instance();12  public DateAssert(Date actual) {13    super(actual, DateAssert.class);14  }15  protected void invokeApiMethod() {16  }17  protected void verify_internal_effects() {18  }19  public DateAssert isNotNull() {20    objects.assertNotNull(info, actual);21    return this;22  }23  public DateAssert isNull() {24    objects.assertNull(info, actual);25    return this;26  }27  public DateAssert isAfter(Date other) {28    dates.assertIsAfter(info, actual, other);29    return this;30  }31  public DateAssert isAfterOrEqualsTo(Date other) {32    dates.assertIsAfterOrEqualsTo(info, actual, other);33    return this;34  }35  public DateAssert isBefore(Date other) {36    dates.assertIsBefore(info, actual, other);37    return this;38  }39  public DateAssert isBeforeOrEqualsTo(Date other) {40    dates.assertIsBeforeOrEqualsTo(info, actual, other);41    return this;42  }43  public DateAssert isEqualTo(Date other) {44    dates.assertEqual(info, actual, other);45    return this;46  }47  public DateAssert isNotEqualTo(Date other) {48    dates.assertNotEqual(info, actual, other);49    return this;50  }51  public DateAssert isNotAfter(Date other) {52    dates.assertIsNotAfter(info, actual, other);53    return this;54  }55  public DateAssert isNotAfterOrEqualsTo(Date other) {56    dates.assertIsNotAfterOrEqualsTo(info, actual, other);57    return this;58  }59  public DateAssert isNotBefore(Date other) {dateParameterIsNotNull
Using AI Code Generation
1assertThat(date).isNotNull();2assertThat(date).isNotNull();3assertThat(date).isNotNull();4assertThat(date).isNotNull();5assertThat(date).isNotNull();6assertThat(date).isNotNull();7assertThat(date).isNotNull();8assertThat(date).isNotNull();9assertThat(date).isNotNull();10assertThat(date).isNotNull();11assertThat(date).isNotNull();12assertThat(date).isNotNull();13assertThat(date).isNotNull();14assertThat(date).isNotNull();15assertThat(date).isNotNull();dateParameterIsNotNull
Using AI Code Generation
1public void should_pass_if_actual_is_not_null() {2  Date actual = new Date();3  dates.assertIsNotNull(someInfo(), actual);4}5public void should_pass_if_actual_is_null() {6  Date actual = null;7  dates.assertIsNull(someInfo(), actual);8}9public void should_pass_if_actual_is_not_null() {10  Date actual = new Date();11  dates.assertIsNotNull(someInfo(), actual);12}13public void should_pass_if_actual_is_null() {14  Date actual = null;15  dates.assertIsNull(someInfo(), actual);16}17public void should_pass_if_actual_is_not_null() {18  Date actual = new Date();19  dates.assertIsNotNull(someInfo(), actual);20}21public void should_pass_if_actual_is_null() {22  Date actual = null;23  dates.assertIsNull(someInfo(), actual);24}25public void should_pass_if_actual_is_not_null() {26  Date actual = new Date();27  dates.assertIsNotNull(someInfo(), actual);28}29public void should_pass_if_actual_is_null() {30  Date actual = null;31  dates.assertIsNull(someInfo(), actual);32}33public void should_pass_if_actual_is_not_null() {34  Date actual = new Date();35  dates.assertIsNotNull(someInfo(), actual);36}dateParameterIsNotNull
Using AI Code Generation
1[1] = new Date();2[2] = new Date();3[3] = new Date();4[4] = null;5[5] = null;6[6] = null;7[7] = null;8[8] = null;9[9] = null;10[10] = null;11[11] = null;12[12] = null;13[13] = null;14[14] = null;15[15] = null;16[16] = null;17[17] = null;18[18] = null;19[19] = null;20[20] = null;21[21] = null;22[22] = null;23[23] = null;24[24] = null;25[25] = null;26[26] = null;27[27] = null;28[28] = null;29[29] = null;30[30] = null;31[31] = null;32[32] = null;33[33] = null;34[34] = null;35[35] = null;36[36] = null;37[37] = null;38[38] = null;39[39] = null;40[40] = null;41[41] = null;42[42] = null;43[43] = null;44[44] = null;45[45] = null;46[46] = null;47[47] = null;48[48] = null;49[49] = null;50[50] = null;51[51] = null;52[52] = null;53[53] = null;54[54] = null;55[55] = null;56[56] = null;57[57] = null;58[58] = null;59[59] = null;60[60] = null;61[61] = null;62[62] = null;63[63] = null;64[64] = null;65[65] = null;66[66] = null;67[67] = null;68[68] = null;69[69] = null;70[70] = null;71[71] = null;72[72] = null;73[73] = null;74[74] = null;75[75] = null;76[76] = null;77[77] = null;78[78] = null;79[79] = null;80[80] = null;81[81] = null;82[82] = null;dateParameterIsNotNull
Using AI Code Generation
1  public void should_pass_if_actual_is_not_null() {2    Date date = new Date();3    dates.assertIsNotNull(someInfo(), date);4  }5  public void should_fail_if_actual_is_null() {6    thrown.expectAssertionError(actualIsNull());7    dates.assertIsNotNull(someInfo(), null);8  }9  public void should_pass_if_actual_is_not_null_whatever_custom_comparison_strategy_is() {10    Date date = new Date();11    datesWithCustomComparisonStrategy.assertIsNotNull(someInfo(), date);12  }13  public void should_fail_if_actual_is_null_whatever_custom_comparison_strategy_is() {14    thrown.expectAssertionError(actualIsNull());15    datesWithCustomComparisonStrategy.assertIsNotNull(someInfo(), null);16  }17}18package org.assertj.core.internal.dates;19import static org.assertj.core.api.Assertions.assertThat;20import static org.assertj.core.error.ShouldBeBefore.shouldBeBefore;21import static org.assertj.core.test.ExpectedException.none;22import static org.assertj.core.test.TestData.someInfo;23import static org.assertj.core.util.FailureMessages.actualIsNull;24import java.util.Date;25import org.assertj.core.api.AssertionInfo;26import org.assertj.core.internal.Dates;27import org.assertj.core.internal.DatesBaseTest;28import org.assertj.core.test.ExpectedException;29import org.junit.Before;30import org.junit.Rule;31import org.junitdateParameterIsNotNull
Using AI Code Generation
1I am trying to write a query that will return the number of bytes of data that is stored in a table. I have a table that stores data in a column called data. The data is stored in a varbinary(max) data type. I need to return the number of bytes of data that is stored in the table. I am using SQL Server 2008 R2. I have tried the following query:2SELECT SUM(DATALENGTH(data)) FROM myTable3SELECT SUM(DATALENGTH(data)), MONTH(date) FROM myTable GROUP BY MONTH(date)4SELECT SUM(DATALENGTH(data)), MONTH(date), YEAR(date) FROM myTable GROUP BY MONTH(date), YEAR(date)5SELECT SUM(DATALENGTH(data)), DAY(date), MONTH(date), YEAR(date) FROM myTable GROUP BY DAY(date), MONTH(date), YEAR(date)6SELECT SUM(DATALENGTH(data)), DAY(date), MONTH(date), YEAR(date), HOUR(date) FROM myTable GROUP BY DAY(date), MONTH(date), YEAR(date), HOUR(date)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!!
