Best Assertj code snippet using org.assertj.core.internal.Dates.assertNotNull
Source:Dates.java
...94 * @throws NullPointerException if other {@code Date} is {@code null}.95 * @throws AssertionError if the actual {@code Date} is not strictly before the given one.96 */97 public void assertIsBefore(AssertionInfo info, Date actual, Date other) {98 assertNotNull(info, actual);99 dateParameterIsNotNull(other);100 if (!isBefore(actual, other))101 throw failures.failure(info, shouldBeBefore(actual, other, comparisonStrategy));102 }103 /**104 * Verifies that the actual {@code Date} is before or equal to the given one.105 * @param info contains information about the assertion.106 * @param actual the "actual" {@code Date}.107 * @param other the other date to compare actual with.108 * @throws AssertionError if {@code actual} is {@code null}.109 * @throws NullPointerException if other {@code Date} is {@code null}.110 * @throws AssertionError if the actual {@code Date} is not before or equal to the given one.111 */112 public void assertIsBeforeOrEqualsTo(AssertionInfo info, Date actual, Date other) {113 assertNotNull(info, actual);114 dateParameterIsNotNull(other);115 if (!isBeforeOrEqualTo(actual, other))116 throw failures.failure(info, shouldBeBeforeOrEqualsTo(actual, other, comparisonStrategy));117 }118 /**119 * Verifies that the actual {@code Date} is strictly after the given one.120 * @param info contains information about the assertion.121 * @param actual the "actual" {@code Date}.122 * @param other the given Date.123 * @throws AssertionError if {@code actual} is {@code null}.124 * @throws NullPointerException if other {@code Date} is {@code null}.125 * @throws AssertionError if the actual {@code Date} is not strictly after the given one.126 */127 public void assertIsAfter(AssertionInfo info, Date actual, Date other) {128 assertNotNull(info, actual);129 dateParameterIsNotNull(other);130 if (!isAfter(actual, other))131 throw failures.failure(info, shouldBeAfter(actual, other, comparisonStrategy));132 }133 /**134 * Verifies that the actual {@code Date} is after or equal to the given one.135 * @param info contains information about the assertion.136 * @param actual the "actual" {@code Date}.137 * @param other the given Date.138 * @throws AssertionError if {@code actual} is {@code null}.139 * @throws NullPointerException if other {@code Date} is {@code null}.140 * @throws AssertionError if the actual {@code Date} is not after or equal to the given one.141 */142 public void assertIsAfterOrEqualsTo(AssertionInfo info, Date actual, Date other) {143 assertNotNull(info, actual);144 dateParameterIsNotNull(other);145 if (!isAfterOrEqualTo(actual, other))146 throw failures.failure(info, shouldBeAfterOrEqualsTo(actual, other, comparisonStrategy));147 }148 /**149 * Verifies that the actual {@code Date} is equal to the given one with precision.150 * @param info contains information about the assertion.151 * @param actual the "actual" {@code Date}.152 * @param other the given Date.153 * @param precision maximum precision for the comparison.154 * @throws AssertionError if {@code actual} is {@code null}.155 * @throws NullPointerException if other {@code Date} is {@code null}.156 * @throws AssertionError if the actual {@code Date} is not equal to the given one.157 */158 public void assertIsEqualWithPrecision(AssertionInfo info, Date actual, Date other, TimeUnit precision) {159 assertNotNull(info, actual);160 Calendar calendarActual = Calendar.getInstance();161 calendarActual.setTime(actual);162 Calendar calendarOther = Calendar.getInstance();163 calendarOther.setTime(other);164 switch (precision) {165 case DAYS:166 calendarActual.set(Calendar.DAY_OF_WEEK, 0);167 calendarOther.set(Calendar.DAY_OF_WEEK, 0);168 case HOURS:169 calendarActual.set(Calendar.HOUR_OF_DAY, 0);170 calendarOther.set(Calendar.HOUR_OF_DAY, 0);171 case MINUTES:172 calendarActual.set(Calendar.MINUTE, 0);173 calendarOther.set(Calendar.MINUTE, 0);174 case SECONDS:175 calendarActual.set(Calendar.SECOND, 0);176 calendarOther.set(Calendar.SECOND, 0);177 case MILLISECONDS:178 calendarActual.set(Calendar.MILLISECOND, 0);179 calendarOther.set(Calendar.MILLISECOND, 0);180 case MICROSECONDS:181 break;182 default:183 break;184 }185 if (calendarActual.compareTo(calendarOther) != 0)186 throw failures.failure(info, ShouldBeEqualWithTimePrecision.shouldBeEqual(actual, other, precision));187 }188 /**189 * Verifies that the actual {@code Date} is in <i>start:end</i> period.<br>190 * start date belongs to the period if inclusiveStart is true.<br>191 * end date belongs to the period if inclusiveEnd is true.<br>192 * @param info contains information about the assertion.193 * @param actual the "actual" {@code Date}.194 * @param start the period start, expected not to be null.195 * @param end the period end, expected not to be null.196 * @param inclusiveStart whether to include start date in period.197 * @param inclusiveEnd whether to include end date in period.198 * @throws AssertionError if {@code actual} is {@code null}.199 * @throws NullPointerException if start {@code Date} is {@code null}.200 * @throws NullPointerException if end {@code Date} is {@code null}.201 * @throws AssertionError if the actual {@code Date} is not in <i>start:end</i> period.202 */203 public void assertIsBetween(AssertionInfo info, Date actual, Date start, Date end, boolean inclusiveStart, boolean inclusiveEnd) {204 if (!actualIsBetweenGivenPeriod(info, actual, start, end, inclusiveStart, inclusiveEnd))205 throw failures.failure(info, shouldBeBetween(actual, start, end, inclusiveStart, inclusiveEnd, comparisonStrategy));206 }207 private boolean actualIsBetweenGivenPeriod(AssertionInfo info, Date actual, Date start, Date end, boolean inclusiveStart, boolean inclusiveEnd) {208 assertNotNull(info, actual);209 startDateParameterIsNotNull(start);210 endDateParameterIsNotNull(end);211 boolean checkLowerBoundaryPeriod = inclusiveStart ? isAfterOrEqualTo(actual, start) : isAfter(actual, start);212 boolean checkUpperBoundaryPeriod = inclusiveEnd ? isBeforeOrEqualTo(actual, end) : isBefore(actual, end);213 boolean isBetweenGivenPeriod = checkLowerBoundaryPeriod && checkUpperBoundaryPeriod;214 return isBetweenGivenPeriod;215 }216 /**217 * Verifies that the actual {@code Date} is not in <i>start:end</i> period..<br>218 * start date belongs to the period if inclusiveStart is true.<br>219 * end date belongs to the period if inclusiveEnd is true.<br>220 * @param info contains information about the assertion.221 * @param actual the "actual" {@code Date}.222 * @param start the period start, expected not to be null.223 * @param end the period end, expected not to be null.224 * @param inclusiveStart whether to include start date in period.225 * @param inclusiveEnd whether to include end date in period.226 * @throws AssertionError if {@code actual} is {@code null}.227 * @throws NullPointerException if start {@code Date} is {@code null}.228 * @throws NullPointerException if end {@code Date} is {@code null}.229 * @throws AssertionError if the actual {@code Date} is in <i>start:end</i> period.230 */231 public void assertIsNotBetween(AssertionInfo info, Date actual, Date start, Date end, boolean inclusiveStart,232 boolean inclusiveEnd) {233 if (actualIsBetweenGivenPeriod(info, actual, start, end, inclusiveStart, inclusiveEnd))234 throw failures.failure(info, shouldNotBeBetween(actual, start, end, inclusiveStart, inclusiveEnd, comparisonStrategy));235 }236 /**237 * Verifies that the actual {@code Date} is strictly in the past.238 * @param info contains information about the assertion.239 * @param actual the "actual" {@code Date}.240 * @throws AssertionError if {@code actual} is {@code null}.241 * @throws AssertionError if the actual {@code Date} is not in the past.242 */243 public void assertIsInThePast(AssertionInfo info, Date actual) {244 assertNotNull(info, actual);245 if (!isBefore(actual, now()))246 throw failures.failure(info, shouldBeInThePast(actual, comparisonStrategy));247 }248 /**249 * Verifies that the actual {@code Date} is today, by comparing only year, month and day of actual to today (ie. we don't check250 * hours).251 * @param info contains information about the assertion.252 * @param actual the "actual" {@code Date}.253 * @throws AssertionError if {@code actual} is {@code null}.254 * @throws AssertionError if the actual {@code Date} is not today.255 */256 public void assertIsToday(AssertionInfo info, Date actual) {257 assertNotNull(info, actual);258 Date todayWithoutTime = truncateTime(now());259 Date actualWithoutTime = truncateTime(actual);260 if (!areEqual(actualWithoutTime, todayWithoutTime))261 throw failures.failure(info, shouldBeToday(actual, comparisonStrategy));262 }263 /**264 * Verifies that the actual {@code Date} is strictly in the future.265 * @param info contains information about the assertion.266 * @param actual the "actual" {@code Date}.267 * @throws AssertionError if {@code actual} is {@code null}.268 * @throws AssertionError if the actual {@code Date} is not in the future.269 */270 public void assertIsInTheFuture(AssertionInfo info, Date actual) {271 assertNotNull(info, actual);272 if (!isAfter(actual, now()))273 throw failures.failure(info, shouldBeInTheFuture(actual, comparisonStrategy));274 }275 /**276 * Verifies that the actual {@code Date} is strictly before the given year.277 * @param info contains information about the assertion.278 * @param actual the "actual" {@code Date}.279 * @param year the year to compare actual year to280 * @throws AssertionError if {@code actual} is {@code null}.281 * @throws AssertionError if the actual {@code Date} year is after or equal to the given year.282 */283 public void assertIsBeforeYear(AssertionInfo info, Date actual, int year) {284 assertNotNull(info, actual);285 if (yearOf(actual) >= year)286 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)299 throw failures.failure(info, shouldBeAfterYear(actual, year));300 }301 /**302 * Verifies that the actual {@code Date} year is equal to the given year.303 * @param year the year to compare actual year to304 * @param info contains information about the assertion.305 * @param actual the "actual" {@code Date}.306 * @throws AssertionError if {@code actual} is {@code null}.307 * @throws AssertionError if the actual {@code Date} year is not equal to the given year.308 */309 public void assertHasYear(AssertionInfo info, Date actual, int year) {310 assertNotNull(info, actual);311 if (yearOf(actual) != year)312 throw failures.failure(info, shouldHaveDateField(actual, "year", year));313 }314 /**315 * Verifies that the actual {@code Date} month is equal to the given month, <b>month value starting at 1</b> (January=1,316 * February=2, ...).317 * @param info contains information about the assertion.318 * @param actual the "actual" {@code Date}.319 * @param month the month to compare actual month to, see {@link Calendar#MONTH} for valid values320 * @throws AssertionError if {@code actual} is {@code null}.321 * @throws AssertionError if the actual {@code Date} month is not equal to the given month.322 */323 public void assertHasMonth(AssertionInfo info, Date actual, int month) {324 assertNotNull(info, actual);325 if (monthOf(actual) != month)326 throw failures.failure(info, shouldHaveDateField(actual, "month", month));327 }328 /**329 * Verifies that the actual {@code Date} day of month is equal to the given day of month.330 * @param info contains information about the assertion.331 * @param actual the "actual" {@code Date}.332 * @param dayOfMonth the day of month to compare actual day of month to333 * @throws AssertionError if {@code actual} is {@code null}.334 * @throws AssertionError if the actual {@code Date} month is not equal to the given day of month.335 */336 public void assertHasDayOfMonth(AssertionInfo info, Date actual, int dayOfMonth) {337 assertNotNull(info, actual);338 if (dayOfMonthOf(actual) != dayOfMonth)339 throw failures.failure(info, shouldHaveDateField(actual, "day of month", dayOfMonth));340 }341 /**342 * Verifies that the actual {@code Date} day of week is equal to the given day of week.343 * @param info contains information about the assertion.344 * @param actual the "actual" {@code Date}.345 * @param dayOfWeek the day of week to compare actual day of week to, see {@link Calendar#DAY_OF_WEEK} for valid values346 * @throws AssertionError if {@code actual} is {@code null}.347 * @throws AssertionError if the actual {@code Date} week is not equal to the given day of week.348 */349 public void assertHasDayOfWeek(AssertionInfo info, Date actual, int dayOfWeek) {350 assertNotNull(info, actual);351 if (dayOfWeekOf(actual) != dayOfWeek)352 throw failures.failure(info, shouldHaveDateField(actual, "day of week", dayOfWeek));353 }354 /**355 * Verifies that the actual {@code Date} hour od day is equal to the given hour of day (24-hour clock).356 * @param info contains information about the assertion.357 * @param actual the "actual" {@code Date}.358 * @param hourOfDay the hour of day to compare actual hour of day to (24-hour clock)359 * @throws AssertionError if {@code actual} is {@code null}.360 * @throws AssertionError if the actual {@code Date} hour is not equal to the given hour.361 */362 public void assertHasHourOfDay(AssertionInfo info, Date actual, int hourOfDay) {363 assertNotNull(info, actual);364 if (hourOfDayOf(actual) != hourOfDay)365 throw failures.failure(info, shouldHaveDateField(actual, "hour", hourOfDay));366 }367 /**368 * Verifies that the actual {@code Date} minute is equal to the given minute.369 * @param info contains information about the assertion.370 * @param actual the "actual" {@code Date}.371 * @param minute the minute to compare actual minute to372 * @throws AssertionError if {@code actual} is {@code null}.373 * @throws AssertionError if the actual {@code Date} minute is not equal to the given minute.374 */375 public void assertHasMinute(AssertionInfo info, Date actual, int minute) {376 assertNotNull(info, actual);377 if (minuteOf(actual) != minute)378 throw failures.failure(info, shouldHaveDateField(actual, "minute", minute));379 }380 /**381 * Verifies that the actual {@code Date} second is equal to the given second.382 * @param info contains information about the assertion.383 * @param actual the "actual" {@code Date}.384 * @param second the second to compare actual second to385 * @throws AssertionError if {@code actual} is {@code null}.386 * @throws AssertionError if the actual {@code Date} second is not equal to the given second.387 */388 public void assertHasSecond(AssertionInfo info, Date actual, int second) {389 assertNotNull(info, actual);390 if (secondOf(actual) != second)391 throw failures.failure(info, shouldHaveDateField(actual, "second", second));392 }393 /**394 * Verifies that the actual {@code Date} millisecond is equal to the given millisecond.395 * @param info contains information about the assertion.396 * @param actual the "actual" {@code Date}.397 * @param millisecond the millisecond to compare actual millisecond to398 * @throws AssertionError if {@code actual} is {@code null}.399 * @throws AssertionError if the actual {@code Date} millisecond is not equal to the given millisecond.400 */401 public void assertHasMillisecond(AssertionInfo info, Date actual, int millisecond) {402 assertNotNull(info, actual);403 if (millisecondOf(actual) != millisecond)404 throw failures.failure(info, shouldHaveDateField(actual, "millisecond", millisecond));405 }406 /**407 * Verifies that actual and given {@code Date} are in the same year.408 * @param info contains information about the assertion.409 * @param actual the "actual" {@code Date}.410 * @param other the given {@code Date} to compare actual {@code Date} to.411 * @throws AssertionError if {@code actual} is {@code null}.412 * @throws NullPointerException if other {@code Date} is {@code null}.413 * @throws AssertionError if actual and given {@code Date} are not in the same year.414 */415 public void assertIsInSameYearAs(AssertionInfo info, Date actual, Date other) {416 assertNotNull(info, actual);417 dateParameterIsNotNull(other);418 if (!areInSameYear(actual, other))419 throw failures.failure(info, shouldBeInSameYear(actual, other));420 }421 /**422 * Returns true if both date are in the same year, false otherwise.423 * @param actual the actual date. expected not be null424 * @param other the other date. expected not be null425 * @return true if both date are in the same year, false otherwise426 */427 private static boolean areInSameYear(Date actual, Date other) {428 return yearOf(actual) == yearOf(other);429 }430 /**431 * Verifies that actual and given {@code Date} are chronologically in the same month (and thus in the same year).432 * @param info contains information about the assertion.433 * @param actual the "actual" {@code Date}.434 * @param other the given {@code Date} to compare actual {@code Date} to.435 * @throws AssertionError if {@code actual} is {@code null}.436 * @throws NullPointerException if other {@code Date} is {@code null}.437 * @throws AssertionError if actual and given {@code Date} are not chronologically speaking in the same month.438 */439 public void assertIsInSameMonthAs(AssertionInfo info, Date actual, Date other) {440 assertNotNull(info, actual);441 dateParameterIsNotNull(other);442 if (!areInSameMonth(actual, other))443 throw failures.failure(info, shouldBeInSameMonth(actual, other));444 }445 /**446 * Returns true if both date are in the same year and month, false otherwise.447 * @param actual the actual date. expected not be null448 * @param other the other date. expected not be null449 * @return true if both date are in the same year and month, false otherwise450 */451 private static boolean areInSameMonth(Date actual, Date other) {452 return areInSameYear(actual, other) && monthOf(actual) == monthOf(other);453 }454 /**455 * Verifies that actual and given {@code Date} are chronologically in the same day of month (and thus in the same month and456 * year).457 * @param info contains information about the assertion.458 * @param actual the "actual" {@code Date}.459 * @param other the given {@code Date} to compare actual {@code Date} to.460 * @throws AssertionError if {@code actual} is {@code null}.461 * @throws NullPointerException if other {@code Date} is {@code null}.462 * @throws AssertionError if actual and given {@code Date} are not chronologically speaking in the same day of month.463 */464 public void assertIsInSameDayAs(AssertionInfo info, Date actual, Date other) {465 assertNotNull(info, actual);466 dateParameterIsNotNull(other);467 if (!areInSameDayOfMonth(actual, other))468 throw failures.failure(info, shouldBeInSameDay(actual, other));469 }470 /**471 * Returns true if both date are in the same year, month and day of month, false otherwise.472 * @param actual the actual date. expected not be null473 * @param other the other date. expected not be null474 * @return true if both date are in the same year, month and day of month, false otherwise475 */476 private static boolean areInSameDayOfMonth(Date actual, Date other) {477 return areInSameMonth(actual, other) && dayOfMonthOf(actual) == dayOfMonthOf(other);478 }479 /**480 * Verifies that actual and given {@code Date} are in the same hour (and thus in the same day of month, month481 * and year).482 * @param info contains information about the assertion.483 * @param actual the "actual" {@code Date}.484 * @param other the given {@code Date} to compare actual {@code Date} to.485 * @throws AssertionError if {@code actual} is {@code null}.486 * @throws NullPointerException if other {@code Date} is {@code null}.487 * @throws AssertionError if actual and given {@code Date} are not chronologically speaking in the same hour.488 */489 public void assertIsInSameHourAs(AssertionInfo info, Date actual, Date other) {490 assertNotNull(info, actual);491 dateParameterIsNotNull(other);492 if (!areInSameHour(actual, other))493 throw failures.failure(info, shouldBeInSameHour(actual, other));494 }495 /**496 * Verifies that actual and given {@code Date} are chronologically in the same hour, day of month, month and year.497 *498 * @param info contains information about the assertion.499 * @param actual the "actual" {@code Date}.500 * @param other the given {@code Date} to compare actual {@code Date} to.501 * @throws AssertionError if {@code actual} is {@code null}.502 * @throws NullPointerException if other {@code Date} is {@code null}.503 * @throws AssertionError if actual and given {@code Date} are not chronologically speaking in the same hour.504 */505 public void assertIsInSameHourWindowAs(AssertionInfo info, Date actual, Date other) {506 assertNotNull(info, actual);507 dateParameterIsNotNull(other);508 if (!areInSameHourWindow(actual, other))509 throw failures.failure(info, shouldBeInSameHourWindow(actual, other));510 }511 /**512 * Returns true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.513 * @param actual the actual date. expected not be null514 * @param other the other date. expected not be null515 * @return true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.516 */517 private static boolean areInSameHourWindow(Date actual, Date other) {518 return timeDifference(actual, other) < TimeUnit.HOURS.toMillis(1);519 }520 /**521 * Returns true if both date are in the same year, month, day of month and hour, false otherwise.522 * @param actual the actual date. expected not be null523 * @param other the other date. expected not be null524 * @return true if both date are in the same year, month, day of month and hour, false otherwise.525 */526 private static boolean areInSameHour(Date actual, Date other) {527 return areInSameDayOfMonth(actual, other) && hourOfDayOf(actual) == hourOfDayOf(other);528 }529 /**530 * Verifies that actual and given {@code Date} are in the same minute, hour, day of month, month and year.531 * @param info contains information about the assertion.532 * @param actual the "actual" {@code Date}.533 * @param other the given {@code Date} to compare actual {@code Date} to.534 * @throws AssertionError if {@code actual} is {@code null}.535 * @throws NullPointerException if other {@code Date} is {@code null}.536 * @throws AssertionError if actual and given {@code Date} are not chronologically speaking in the same minute.537 */538 public void assertIsInSameMinuteAs(AssertionInfo info, Date actual, Date other) {539 assertNotNull(info, actual);540 dateParameterIsNotNull(other);541 if (!areInSameMinute(actual, other))542 throw failures.failure(info, shouldBeInSameMinute(actual, other));543 }544 /**545 * Verifies that actual and given {@code Date} are chronologically in the same minute.546 * @param info contains information about the assertion.547 * @param actual the "actual" {@code Date}.548 * @param other the given {@code Date} to compare actual {@code Date} to.549 * @throws AssertionError if {@code actual} is {@code null}.550 * @throws NullPointerException if other {@code Date} is {@code null}.551 * @throws AssertionError if actual and given {@code Date} are not chronologically speaking in the same minute.552 */553 public void assertIsInSameMinuteWindowAs(AssertionInfo info, Date actual, Date other) {554 assertNotNull(info, actual);555 dateParameterIsNotNull(other);556 if (!areInSameMinuteWindow(actual, other))557 throw failures.failure(info, shouldBeInSameMinuteWindow(actual, other));558 }559 /**560 * Returns true if both date are in the same year, month, day of month, hour and minute, false otherwise.561 * @param actual the actual date. expected not be null562 * @param other the other date. expected not be null563 * @return true if both date are in the same year, month, day of month, hour and minute, false otherwise.564 */565 private static boolean areInSameMinute(Date actual, Date other) {566 return areInSameHour(actual, other) && minuteOf(actual) == minuteOf(other);567 }568 private static boolean areInSameMinuteWindow(Date actual, Date other) {569 return timeDifference(actual, other) < TimeUnit.MINUTES.toMillis(1);570 }571 /**572 * Verifies that actual and given {@code Date} are in the same second, minute, hour, day of month, month and year.573 * @param info contains information about the assertion.574 * @param actual the "actual" {@code Date}.575 * @param other the given {@code Date} to compare actual {@code Date} to.576 * @throws AssertionError if {@code actual} is {@code null}.577 * @throws NullPointerException if other {@code Date} is {@code null}.578 * @throws AssertionError if actual and given {@code Date} are not chronologically speaking in the same second.579 */580 public void assertIsInSameSecondAs(AssertionInfo info, Date actual, Date other) {581 assertNotNull(info, actual);582 dateParameterIsNotNull(other);583 if (!areInSameSecond(actual, other))584 throw failures.failure(info, shouldBeInSameSecond(actual, other));585 }586 /**587 * Verifies that actual and given {@code Date} are chronologically in the same second.588 * @param info contains information about the assertion.589 * @param actual the "actual" {@code Date}.590 * @param other the given {@code Date} to compare actual {@code Date} to.591 * @throws AssertionError if {@code actual} is {@code null}.592 * @throws NullPointerException if other {@code Date} is {@code null}.593 * @throws AssertionError if actual and given {@code Date} are not chronologically speaking in the same second.594 */595 public void assertIsInSameSecondWindowAs(AssertionInfo info, Date actual, Date other) {596 assertNotNull(info, actual);597 dateParameterIsNotNull(other);598 if (!areInSameSecondWindow(actual, other))599 throw failures.failure(info, shouldBeInSameSecondWindow(actual, other));600 }601 /**602 * Returns true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.603 * @param actual the actual date. expected not be null604 * @param other the other date. expected not be null605 * @return true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.606 */607 private static boolean areInSameSecondWindow(Date actual, Date other) {608 return timeDifference(actual, other) < TimeUnit.SECONDS.toMillis(1);609 }610 /**611 * Returns true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.612 * @param actual the actual date. expected not be null613 * @param other the other date. expected not be null614 * @return true if both date are in the same year, month and day of month, hour, minute and second, false otherwise.615 */616 private static boolean areInSameSecond(Date actual, Date other) {617 return areInSameMinute(actual, other) && secondOf(actual) == secondOf(other);618 }619 /**620 * Verifies that the actual {@code Date} is close to the other date by less than delta, if difference is equals to delta it is621 * ok.<br>622 * Note that delta expressed in milliseconds.<br>623 * Use handy TimeUnit to convert a duration in milliseconds, for example you can express a delta of 5 seconds with624 * <code>TimeUnit.SECONDS.toMillis(5)</code>.625 * @param info contains information about the assertion.626 * @param actual the "actual" {@code Date}.627 * @param other the given {@code Date} to compare actual {@code Date} to.628 * @param deltaInMilliseconds the delta used for date comparison, expressed in milliseconds629 * @throws AssertionError if {@code actual} is {@code null}.630 * @throws NullPointerException if other {@code Date} is {@code null}.631 * @throws AssertionError if the actual {@code Date} week is not close to the given date by less than delta.632 */633 public void assertIsCloseTo(AssertionInfo info, Date actual, Date other, long deltaInMilliseconds) {634 assertNotNull(info, actual);635 dateParameterIsNotNull(other);636 long difference = Math.abs(actual.getTime() - other.getTime());637 if (difference > deltaInMilliseconds)638 throw failures.failure(info, shouldBeCloseTo(actual, other, deltaInMilliseconds, difference));639 }640 /**641 * Verifies that the actual {@code Date} time is equal to the given timestamp.642 * @param info contains information about the assertion.643 * @param actual the "actual" {@code Date}.644 * @param timestamp the timestamp to compare actual time to645 * @throws AssertionError if {@code actual} is {@code null}.646 * @throws AssertionError if the actual {@code Date} time is not equal to the given timestamp.647 */648 public void assertHasTime(AssertionInfo info, Date actual, long timestamp) {649 assertNotNull(info, actual);650 if (actual.getTime() != timestamp)651 throw failures.failure(info, shouldHaveTime(actual, timestamp));652 }653 /**654 * Verifies that the actual {@code Date} has same time as the given {@code Date}.655 * @param info contains information about the assertion.656 * @param actual the "actual" {@code Date}.657 * @param expected the "expected" {@code Date} to compare actual time to658 * @throws AssertionError if {@code actual} is {@code null}.659 * @throws AssertionError if {@code expected} is {@code null}.660 * @throws AssertionError if the actual {@code Date} time is not equal to the given {@code Date}.661 */662 public void assertHasSameTime(AssertionInfo info, Date actual, Date expected) {663 assertNotNull(info, actual);664 assertNotNull(info, expected);665 if (actual.getTime() != expected.getTime())666 throw failures.failure(info, shouldHaveSameTime(actual, expected));667 }668 /**669 * Verifies that the actual {@code Date} is equal to the given date by comparing their time.670 * @param info contains information about the assertion.671 * @param actual the "actual" {@code Date}.672 * @param date the date to compare actual time to673 * @throws AssertionError if {@code actual} is {@code null}.674 * @throws AssertionError if the actual {@code Date} time is not equal to the given date time.675 * @throws NullPointerException if other {@code Date} is {@code null}.676 */677 public void hasSameTimeAs(AssertionInfo info, Date actual, Date date) {678 assertNotNull(info, actual);679 dateParameterIsNotNull(date);680 assertHasSameTime(info, actual, date);681 }682 /**683 * used to check that the date to compare actual date to is not null, in that case throws a {@link NullPointerException} with an684 * explicit message685 * @param date the date to check686 * @throws NullPointerException with an explicit message if the given date is null687 */688 private static void dateParameterIsNotNull(Date date) {689 checkNotNull(date, "The date to compare actual with should not be null");690 }691 /**692 * used to check that the start of period date to compare actual date to is not null, in that case throws a693 * {@link NullPointerException} with an explicit message694 * @param start the start date to check695 * @throws NullPointerException with an explicit message if the given start date is null696 */697 private static void startDateParameterIsNotNull(Date start) {698 checkNotNull(start, "The start date of period to compare actual with should not be null");699 }700 /**701 * used to check that the end of period date to compare actual date to is not null, in that case throws a702 * {@link NullPointerException} with an explicit message703 * @param end the end date to check704 * @throws NullPointerException with an explicit message if the given end date is null705 */706 private static void endDateParameterIsNotNull(Date end) {707 checkNotNull(end, "The end date of period to compare actual with should not be null");708 }709 private void assertNotNull(AssertionInfo info, Date actual) {710 Objects.instance().assertNotNull(info, actual);711 }712 /**713 * Returns <code>true</code> if the actual {@code Date} is before or equal to the given one according to underlying714 * {@link #comparisonStrategy}, false otherwise.715 * @param actual the actual date - must not be null.716 * @param other the given Date.717 * @return <code>true</code> if the actual {@code Date} is before or equal to the given one according to underlying718 * {@link #comparisonStrategy}, false otherwise.719 * @throws NullPointerException if {@code actual} is {@code null}.720 */721 private boolean isBeforeOrEqualTo(Date actual, Date other) {722 return comparisonStrategy.isLessThanOrEqualTo(actual, other);723 }724 /**...
assertNotNull
Using AI Code Generation
1assertThat(date).isNotNull();2assertThat(date).isEqualTo(date);3assertThat(date).isNotEqualTo(date);4assertThat(date).isSameAs(date);5assertThat(date).isNotSameAs(date);6assertThat(date).isToday();7assertThat(date).isNotToday();8assertThat(date).isIn(date);9assertThat(date).isNotIn(date);10assertThat(date).isBefore(date);11assertThat(date).isBeforeOrEqualsTo(date);12assertThat(date).isAfter(date);13assertThat(date).isAfterOrEqualsTo(date);14assertThat(date).isInSameHourWindowAs(date);15assertThat(date).isInSameMinuteWindowAs(date);16assertThat(date).isInSameSecondWindowAs(date);17assertThat(date).isInSameHourAs(date);18assertThat(date).isInSameMinuteAs(date);
assertNotNull
Using AI Code Generation
1import static org.assertj.core.api.Assertions.*;2import static org.assertj.core.util.FailureMessages.*;3import static org.assertj.core.internal.Dates.*;4import static org.assertj.core.test.TestData.someInfo;5import static org.assertj.core.util.DateUtil.*;6import static org.mockito.Mockito.verify;7import org.assertj.core.api.AssertionInfo;8import org.assertj.core.internal.Dates;9import org.assertj.core.internal.DatesBaseTest;10import org.junit.Test;11public class Dates_assertIsNotNull_Test extends DatesBaseTest {12 public void should_fail_if_actual_is_null() {13 thrown.expectAssertionError(actualIsNull());14 Date actual = null;
assertNotNull
Using AI Code Generation
1import static org.assertj.core.api.Assertions.*;2import static org.assertj.core.util.DateUtil.parse;3import static org.assertj.core.util.FailureMessages.actualIsNull;4import java.util.Date;5import org.assertj.core.api.AbstractAssert;6import org.assertj.core.internal.Dates;7import org.assertj.core.internal.Failures;8import org.assertj.core.internal.Objects;9public class MyDateAssert extends AbstractAssert<MyDateAssert, Date> {10 private static final String DATE_FORMAT = "yyyy-MM-dd";11 private final Dates dates = Dates.instance();12 private final Objects objects = Objects.instance();13 public MyDateAssert(Date actual) {14 super(actual, MyDateAssert.class);15 }16 public static MyDateAssert assertThat(Date actual) {17 return new MyDateAssert(actual);18 }19 public MyDateAssert isBefore(String dateAsString) {20 return isBefore(parse(dateAsString));21 }22 public MyDateAssert isBefore(Date other) {23 objects.assertNotNull(info, actual);24 if (!dates.isBefore(info, actual, other)) {25 throw Failures.instance().failure(info, shouldBeBefore(actual, other, DATE_FORMAT));26 }27 return this;28 }29 public MyDateAssert isAfter(String dateAsString) {30 return isAfter(parse(dateAsString));31 }32 public MyDateAssert isAfter(Date other) {33 objects.assertNotNull(info, actual);34 if (!dates.isAfter(info, actual, other)) {35 throw Failures.instance().failure(info, shouldBeAfter(actual, other, DATE_FORMAT));36 }37 return this;38 }39}40public class MyDateAssertTest {41 public void test() {42 Date date = new Date();43 assertThat(date).isNotNull();44 assertThat(date).isBefore("2014-05-10");45 assertThat(date).isAfter("2014-05-01");46 }47}
assertNotNull
Using AI Code Generation
1import static org.assertj.core.api.Assertions.*;2import static org.assertj.core.util.FailureMessages.*;3import static org.assertj.core.internal.Dates.*;4import static org.assertj.core.test.TestData.someInfo;5import static org.assertj.core.util.DateUtil.*;6import static org.mockito.Mockito.verify;7import org.assertj.core.api.AssertionInfo;8import org.assertj.core.internal.Dates;9import org.assertj.core.internal.DatesBaseTest;10import org.junit.Test;11public class Dates_assertIsNotNull_Test extends DatesBaseTest {12 public void should_fail_if_actual_is_null() {13 thrown.expectAssertionError(actualIsNull());14 Date actual = null;
assertNotNull
Using AI Code Generation
1import static org.assertj.core.api.Assertions.*;2import static org.assertj.core.util.DateUtil.parse;3import static org.assertj.core.util.FailureMessages.actualIsNull;4import java.util.Date;5import org.assertj.core.api.AbstractAssert;6import org.assertj.core.internal.Dates;7import org.assertj.core.internal.Failures;8import org.assertj.core.internal.Objects;9public class MyDateAssert extends AbstractAssert<MyDateAssert, Date> {10 private static final String DATE_FORMAT = "yyyy-MM-dd";11 private final Dates dates = Dates.instance();12 private final Objects objects = Objects.instance();13 public MyDateAssert(Date actual) {14 super(actual, MyDateAssert.class);15 }16 public static MyDateAssert assertThat(Date actual) {17 return new MyDateAssert(actual);18 }19 public MyDateAssert isBefore(String dateAsString) {20 return isBefore(parse(dateAsString));21 }22 public MyDateAssert isBefore(Date other) {23 objects.assertNotNull(info, actual);24 if (!dates.isBefore(info, actual, other)) {25 throw Failures.instance().failure(info, shouldBeBefore(actual, other, DATE_FORMAT));26 }27 return this;28 }29 public MyDateAssert isAfter(String dateAsString) {30 return isAfter(parse(dateAsString));31 }32 public MyDateAssert isAfter(Date other) {33 objects.assertNotNull(info, actual);34 if (!dates.isAfter(info, actual, other)) {35 throw Failures.instance().failure(info, shouldBeAfter(actual, other, DATE_FORMAT));36 }37 return this;38 }39}40public class MyDateAssertTest {41 public void test() {42 Date date = new Date();43 assertThat(date).isNotNull();44 assertThat(date).isBefore("2014-05-10");45 assertThat(date).isAfter("2014-05-01");46 }47}
assertNotNull
Using AI Code Generation
1 assertThat(date).isNotNull();2 assertThat(date).isNotNull().isAfterOrEqualTo("2011-01-01").isBeforeOrEqualTo("2011-12-31");3 assertThat(date).isNotNull().isAfterOrEqualTo("2011-01-01").isBeforeOrEqualTo("2011-12-31").isIn("2011-01-01", "2011-01-02");4 assertThat(date).isNotNull().isAfterOrEqualTo("2011-01-01").isBeforeOrEqualTo("2011-12-31").isIn("2011-01-01", "2011-01-02").isIn("2011-01-01", "2011-01-02");5 assertThat(date).isNotNull().isAfterOrEqualTo("2011-01-01").isBeforeOrEqualTo("2011-12-31").isIn("2011-01-01", "2011-01-02").isIn("2011-01-01", "2011-01-02").isIn("2011-01-01", "2011-01-02");6 assertThat(object).isNotNull();7 assertThat(object).isNotNull().isInstanceOf(String.class).isNotInstanceOf(Integer.class);8 assertThat(object).isNotNull().isInstanceOf(String.class).isNotInstanceOf(Integer.class).isNotSameAs(new String());9 assertThat(object).isNotNull().isInstanceOf(String.class).isNotInstanceOf(Integer.class).isNotSameAs(new String()).isSameAs(new String());10 assertThat(string).isNotNull();11 assertThat(string).isNotNull().contains("foo").containsOnlyOnce("foo");12 assertThat(string).isNotNull().contains("foo").containsOnlyOnce("foo").containsIgnoringCase("foo");13 assertThat(string).isNotNull().contains("foo").containsOnlyOnce("foo").containsIgnoringCase("foo").containsPattern("foo");14 assertThat(array).isNotNull();15 assertThat(array).isNotNull().contains("foo").containsOnlyOnce("foo");16 assertThat(array).isNotNull().contains("foo").containsOnlyOnce("foo").containsExactly("foo");17 assertThat(array).isNotNull().contains("foo").containsOnlyOnce("
assertNotNull
Using AI Code Generation
1import org.assertj.core.api.Assertions;2import org.assertj.core.api.DateAssert;3import org.assertj.core.internal.Dates;4import org.junit.Test;5import java.util.Date;6public class AssertjTest {7 public void testAssertNotNull() {8 Date date = new Date();9 DateAssert dateAssert = Assertions.assertThat(date);10 dateAssert.isNotNull();11 }12}13import org.assertj.core.api.Assertions;14import org.assertj.core.api.DateAssert;15import org.assertj.core.internal.Dates;16import org.junit.Test;17import java.util.Date;18public class AssertjTest {19 public void testAssertNotNull() {20 Date date = new Date();21 DateAssert dateAssert = Assertions.assertThat(date);22 dateAssert.isNotNull();23 }24}25import org.assertj.core.api.Assertions;26import org.assertj.core.api.DateAssert;27import org.assertj.core.internal.Dates;28import org.junit.Test;29import java.util.Date;30public class AssertjTest {31 public void testAssertNotNull() {32 Date date = new Date();33 DateAssert dateAssert = Assertions.assertThat(date);34 dateAssert.isNotNull();35 }36}
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!!