How to use LocalDate.shouldBeBetween method of io.kotest.matchers.date.matchers class

Best Kotest code snippet using io.kotest.matchers.date.matchers.LocalDate.shouldBeBetween

datetime.kt

Source:datetime.kt Github

copy

Full Screen

1package io.kotest.matchers.kotlinx.datetime2import io.kotest.matchers.Matcher3import io.kotest.matchers.MatcherResult4import io.kotest.matchers.should5import io.kotest.matchers.shouldBe6import io.kotest.matchers.shouldNot7import io.kotest.matchers.shouldNotBe8import kotlinx.datetime.DayOfWeek9import kotlinx.datetime.LocalDate10import kotlinx.datetime.LocalDateTime11import kotlinx.datetime.Month12import kotlinx.datetime.isoDayNumber13import kotlinx.datetime.number14/**15 * Asserts that this year is the same as [date]'s year16 *17 * Verifies that this year is the same as [date]'s year, ignoring any other fields.18 * For example, 09/02/1998 has the same year as 10/03/1998, and this assertion should pass for this comparison19 *20 * Opposite of [LocalDate.shouldNotHaveSameYearAs]21 *22 * ```23 * val firstDate = LocalDate(1998, 2, 9)24 * val secondDate = LocalDate(1998, 3, 10)25 *26 * firstDate shouldHaveSameYearAs secondDate // Assertion passes27 *28 *29 * val firstDate = LocalDate(2018, 2, 9)30 * val secondDate = LocalDate(1998, 2, 9)31 *32 * firstDate shouldHaveSameYearAs secondDate // Assertion fails, 2018 != 199833 ```34 */35infix fun LocalDate.shouldHaveSameYearAs(date: LocalDate) = this should haveSameYear(date)36/**37 * Asserts that this year is NOT the same as [date]'s year38 *39 * Verifies that this year isn't the same as [date]'s year, ignoring any other fields.40 * For example, 09/02/1998 doesn't have the same year as 09/02/2018, and this assertion should pass for this comparison41 *42 * Opposite of [LocalDate.shouldHaveSameYearAs]43 *44 * ```45 * val firstDate = LocalDate(2018, 2, 9)46 * val secondDate = LocalDate(1998, 2, 9)47 *48 * firstDate shouldNotHaveSameYearAs secondDate // Assertion passes49 *50 *51 * val firstDate = LocalDate(1998, 2, 9)52 * val secondDate = LocalDate(1998, 3, 10)53 *54 * firstDate shouldNotHaveSameYearAs secondDate // Assertion fails, 1998 == 1998, and we expected a difference55 * ```56 */57infix fun LocalDate.shouldNotHaveSameYearAs(date: LocalDate) = this shouldNot haveSameYear(date)58/**59 * Matcher that compares years of LocalDates60 *61 * Verifies that two dates have exactly the same year, ignoring any other fields.62 * For example, 09/02/1998 has the same year as 10/03/1998, and the matcher will have a positive result for this comparison63 *64 * ```65 * val firstDate = LocalDate(1998, 2, 9)66 * val secondDate = LocalDate(1998, 3, 10)67 *68 * firstDate should haveSameYear(secondDate) // Assertion passes69 *70 *71 * val firstDate = LocalDate(1998, 2, 9)72 * val secondDate = LocalDate(2018, 2, 9)73 *74 * firstDate shouldNot haveSameYear(secondDate) // Assertion passes75 * ```76 *77 * @see [LocalDate.shouldHaveSameYearAs]78 * @see [LocalDate.shouldNotHaveSameYearAs]79 */80fun haveSameYear(date: LocalDate): Matcher<LocalDate> = object : Matcher<LocalDate> {81 override fun test(value: LocalDate): MatcherResult =82 MatcherResult(value.year == date.year, "$value should have year ${date.year}", "$value should not have year ${date.year}")83}84/**85 * Asserts that this year is the same as [date]'s year86 *87 * Verifies that this year is the same as [date]'s year, ignoring any other fields.88 * For example, 09/02/1998 10:00:00 has the same year as 10/03/1998 11:30:30, and this assertion should pass for this comparison89 *90 * Opposite of [LocalDateTime.shouldNotHaveSameYearAs]91 *92 * ```93 * val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)94 * val secondDate = LocalDateTime(1998, 3, 10, 11, 30, 30)95 *96 * firstDate shouldHaveSameYearAs secondDate // Assertion passes97 *98 *99 * val firstDate = LocalDateTime(2018, 2, 9, 10, 0, 0)100 * val secondDate = LocalDateTime(1998, 2, 9, 10, 0, 0)101 *102 * firstDate shouldHaveSameYearAs secondDate // Assertion fails, 2018 != 1998103 * ```104 */105infix fun LocalDateTime.shouldHaveSameYearAs(date: LocalDateTime) = this should haveSameYear(date)106/**107 * Asserts that this year is NOT the same as [date]'s year108 *109 * Verifies that this year isn't the same as [date]'s year, ignoring any other fields.110 * For example, 09/02/1998 10:00:00 doesn't have the same year as 09/02/2018 10:00:00, and this assertion should pass for this comparison111 *112 * Opposite of [LocalDateTime.shouldHaveSameYearAs]113 *114 * ```115 * val firstDate = LocalDateTime(2018, 2, 9, 10, 0, 0)116 * val secondDate = LocalDateTime(1998, 3, 10, 11, 30, 30)117 *118 * firstDate shouldNotHaveSameYearAs secondDate // Assertion passes119 *120 *121 * val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)122 * val secondDate = LocalDateTime(1998, 3, 10, 1, 30, 30)123 *124 * firstDate shouldNotHaveSameYearAs secondDate // Assertion fails, 1998 == 1998, and we expected a difference125 * ```126 */127infix fun LocalDateTime.shouldNotHaveSameYearAs(date: LocalDateTime) = this shouldNot haveSameYear(date)128/**129 * Matcher that compares years of LocalDateTimes130 *131 * Verifies that two DateTimes have exactly the same year, ignoring any other fields.132 * For example, 09/02/1998 10:00:00 has the same year as 10/03/1998 11:30:30, and the matcher will have a positive result for this comparison133 *134 * ```135 * val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)136 * val secondDate = LocalDateTime(1998, 3, 10, 11, 30, 30)137 *138 * firstDate should haveSameYear(secondDate) // Assertion passes139 *140 *141 * val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)142 * val secondDate = LocalDateTime(2018, 2, 9, 10, 0, 0)143 *144 * firstDate shouldNot haveSameYear(secondDate) // Assertion passes145 * ```146 *147 * @see [LocalDateTime.shouldHaveSameYearAs]148 * @see [LocalDateTime.shouldNotHaveSameYearAs]149 */150fun haveSameYear(date: LocalDateTime): Matcher<LocalDateTime> = object : Matcher<LocalDateTime> {151 override fun test(value: LocalDateTime): MatcherResult =152 MatcherResult(value.year == date.year, "$value should have year ${date.year}", "$value should not have year ${date.year}")153}154/**155 * Asserts that this month is the same as [date]'s month156 *157 * Verifies that month year is the same as [date]'s month, ignoring any other fields.158 * For example, 09/02/1998 has the same month as 10/02/2018, and this assertion should pass for this comparison159 *160 * Opposite of [LocalDate.shouldNotHaveSameMonthAs]161 *162 * ```163 * val firstDate = LocalDate(1998, 2, 9)164 * val secondDate = LocalDate(1998, 3, 10)165 *166 * firstDate should haveSameYear(secondDate) // Assertion passes167 *168 *169 * val firstDate = LocalDate(1998, 2, 9)170 * val secondDate = LocalDate(2018, 2, 9)171 *172 * firstDate shouldNot haveSameYear(secondDate) // Assertion passes173 * ```174 */175infix fun LocalDate.shouldHaveSameMonthAs(date: LocalDate) = this should haveSameMonth(date)176/**177 * Asserts that this month is NOT the same as [date]'s month178 *179 * Verifies that this month isn't the same as [date]'s month, ignoring any other fields.180 * For example, 09/02/1998 doesn't have the same month as 09/03/1998, and this assertion should pass for this comparison181 *182 * Opposite of [LocalDate.shouldHaveSameMonthAs]183 *184 * ```185 * val firstDate = LocalDate(1998, 2, 9)186 * val secondDate = LocalDate(2018, 2, 10)187 *188 * firstDate shouldHaveSameMonthAs secondDate // Assertion passes189 *190 *191 * val firstDate = LocalDate(1998, 2, 9)192 * val secondDate = LocalDate(1998, 3, 9)193 *194 * firstDate shouldHaveSameMonthAs secondDate // Assertion fails, 2 != 3195 * ```196 */197infix fun LocalDate.shouldNotHaveSameMonthAs(date: LocalDate) = this shouldNot haveSameMonth(date)198/**199 * Matcher that compares months of LocalDates200 *201 * Verifies that two dates have exactly the same month, ignoring any other fields.202 * For example, 09/02/1998 has the same month as 10/02/2018, and the matcher will have a positive result for this comparison203 *204 * ```205 * val firstDate = LocalDate(1998, 2, 9)206 * val secondDate = LocalDate(1998, 3, 9)207 *208 * firstDate shouldNotHaveSameMonthAs secondDate // Assertion passes209 *210 *211 * val firstDate = LocalDate(1998, 2, 9)212 * val secondDate = LocalDate(2018, 2, 10)213 *214 * firstDate shouldNotHaveSameMonthAs secondDate // Assertion fails, 2 == 2, and we expected a difference215 * ```216 *217 * @see [LocalDate.shouldHaveSameMonthAs]218 * @see [LocalDate.shouldNotHaveSameMonthAs]219 */220fun haveSameMonth(date: LocalDate): Matcher<LocalDate> = object : Matcher<LocalDate> {221 override fun test(value: LocalDate): MatcherResult =222 MatcherResult(value.month == date.month, "$value should have month ${date.month}", "$value should not have month ${date.month}")223}224/**225 * Asserts that this month is the same as [date]'s month226 *227 * Verifies that this month is the same as [date]'s month, ignoring any other fields.228 * For example, 09/02/1998 10:00:00 has the same month as 10/02/2018 11:30:30, and this assertion should pass for this comparison229 *230 * Opposite of [LocalDateTime.shouldNotHaveSameMonthAs]231 *232 * ```233 * val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)234 * val secondDate = LocalDateTime(2018, 2, 10, 10, 0, 0)235 *236 * firstDate should haveSameMonth(secondDate) // Assertion passes237 *238 *239 * val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)240 * val secondDate = LocalDateTime(1998, 3, 9, 10, 0, 0)241 *242 * firstDate shouldNot haveSameMonth(secondDate) // Assertion passes243 * ```244 */245infix fun LocalDateTime.shouldHaveSameMonthAs(date: LocalDateTime) = this should haveSameMonth(date)246/**247 * Asserts that this month is NOT the same as [date]'s month248 *249 * Verifies that this month isn't the same as [date]'s month, ignoring any other fields.250 * For example, 09/02/1998 10:00:00 doesn't have the same month as 09/03/1998 10:00:00, and this assertion should pass for this comparison251 *252 * Opposite of [LocalDateTime.shouldHaveSameMonthAs]253 *254 * ```255 * val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)256 * val secondDate = LocalDateTime(2018, 2, 10, 11, 30, 30)257 *258 * firstDate shouldHaveSameMonthAs secondDate // Assertion passes259 *260 *261 * val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)262 * val secondDate = LocalDateTime(1998, 3, 9, 10, 0, 0)263 *264 * firstDate shouldHaveSameMonthAs secondDate // Assertion fails, 2 != 3265 * ```266 */267infix fun LocalDateTime.shouldNotHaveSameMonthAs(date: LocalDateTime) = this shouldNot haveSameMonth(date)268/**269 * Matcher that compares months of LocalDateTimes270 *271 * Verifies that two DateTimes have exactly the same month, ignoring any other fields.272 * For example, 09/02/1998 10:00:00 has the same month as 10/02/2018 11:30:30, and the matcher will have a positive result for this comparison273 *274 * ```275 * val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)276 * val secondDate = LocalDateTime(1998, 3, 10, 11, 30, 30)277 *278 * firstDate shouldNotHaveSameMonthAs secondDate // Assertion passes279 *280 *281 * val firstDate = LocalDateTime(2018, 2, 9, 10, 0, 0)282 * val secondDate = LocalDateTime(1998, 2, 10, 1, 30, 30)283 *284 * firstDate shouldNotHaveSameMonthAs secondDate // Assertion fails, 2 == 2, and we expected a difference285 * ```286 *287 * @see [LocalDateTime.shouldHaveSameMonthAs]288 * @see [LocalDateTime.shouldNotHaveSameMonthAs]289 */290fun haveSameMonth(date: LocalDateTime): Matcher<LocalDateTime> = object : Matcher<LocalDateTime> {291 override fun test(value: LocalDateTime): MatcherResult =292 MatcherResult(value.month == date.month, "$value should have month ${date.month}", "$value should not have month ${date.month}")293}294/**295 * Asserts that this day is the same as [date]'s day296 *297 * Verifies that this day is the same as [date]'s day, ignoring any other fields.298 * For example, 09/02/1998 has the same day as 09/03/2018, and this assertion should pass for this comparison299 *300 * Opposite of [LocalDate.shouldNotHaveSameDayAs]301 *302 * ```303 * val firstDate = LocalDate(1998, 2, 9)304 * val secondDate = LocalDate(2018, 3, 9)305 *306 * firstDate shouldHaveSameDayAs secondDate // Assertion passes307 *308 *309 * val firstDate = LocalDate(1998, 2, 9)310 * val secondDate = LocalDate(1998, 2, 10)311 *312 * firstDate shouldHaveSameDayAs secondDate // Assertion fails, 9 != 10313 * ```314 */315infix fun LocalDate.shouldHaveSameDayAs(date: LocalDate) = this should haveSameDay(date)316/**317 * Asserts that this day is NOT the same as [date]'s day318 *319 * Verifies that this day isn't the same as [date]'s day, ignoring any other fields.320 * For example, 09/02/1998 doesn't have the same day as 10/02/1998, and this assertion should pass for this comparison321 *322 * Opposite of [LocalDate.shouldHaveSameDayAs]323 *324 * ```325 * val firstDate = LocalDate(1998, 2, 9)326 * val secondDate = LocalDate(1998, 2, 10)327 *328 * firstDate shouldNotHaveSameDayAs secondDate // Assertion passes329 *330 *331 * val firstDate = LocalDate(1998, 2, 9)332 * val secondDate = LocalDate(2018, 3, 9)333 *334 * firstDate shouldNotHaveSameDayAs secondDate // Assertion fails, 9 == 9, and we expected a difference335 * ```336 */337infix fun LocalDate.shouldNotHaveSameDayAs(date: LocalDate) = this shouldNot haveSameDay(date)338/**339 * Matcher that compares days of LocalDates340 *341 * Verifies that two dates have exactly the same day, ignoring any other fields.342 * For example, 09/02/1998 has the same day as 09/03/2018, and the matcher will have a positive result for this comparison343 *344 * ```345 * val firstDate = LocalDate(1998, 2, 9)346 * val secondDate = LocalDate(2018, 3, 9)347 *348 * firstDate should haveSameDay(secondDate) // Assertion passes349 *350 *351 * val firstDate = LocalDate(1998, 2, 9)352 * val secondDate = LocalDate(1998, 2, 10)353 *354 * firstDate shouldNot haveSameDay(secondDate) // Assertion passes355 * ```356 *357 * @see [LocalDate.shouldHaveSameDayAs]358 * @see [LocalDate.shouldNotHaveSameDayAs]359 */360fun haveSameDay(date: LocalDate): Matcher<LocalDate> = object : Matcher<LocalDate> {361 override fun test(value: LocalDate): MatcherResult =362 MatcherResult(value.dayOfMonth == date.dayOfMonth, "$value should have day ${date.dayOfMonth} but had ${value.dayOfMonth}", "$value should not have day ${date.dayOfMonth}")363}364/**365 * Asserts that this day is the same as [date]'s day366 *367 * Verifies that this day is the same as [date]'s day, ignoring any other fields.368 * For example, 09/02/1998 10:00:00 has the same day as 09/03/2018 11:30:30, and this assertion should pass for this comparison369 *370 * Opposite of [LocalDateTime.shouldNotHaveSameDayAs]371 *372 * ```373 * val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)374 * val secondDate = LocalDateTime(1998, 3, 9, 11, 30, 30)375 *376 * firstDate shouldHaveSameDayAs secondDate // Assertion passes377 *378 *379 * val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)380 * val secondDate = LocalDateTime(1998, 2, 10, 10, 0, 0)381 *382 * firstDate shouldHaveSameDayAs secondDate // Assertion fails, 9 != 10383 * ```384 */385infix fun LocalDateTime.shouldHaveSameDayAs(date: LocalDateTime) = this should haveSameDay(date)386/**387 * Asserts that this day is NOT the same as [date]'s day388 *389 * Verifies that this year isn't the same as [date]'s day, ignoring any other fields.390 * For example, 09/02/1998 10:00:00 doesn't have the same day as 10/02/1998 10:00:00, and this assertion should pass for this comparison391 *392 * Opposite of [LocalDateTime.shouldHaveSameDayAs]393 *394 * ```395 * val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)396 * val secondDate = LocalDateTime(1998, 2, 10, 10, 0, 0)397 *398 * firstDate shouldNotHaveSameDayAs secondDate // Assertion passes399 *400 *401 * val firstDate = LocalDateTime(2018, 2, 9, 10, 0, 0)402 * val secondDate = LocalDateTime(1998, 3, 9, 11, 30, 30)403 *404 * firstDate shouldNotHaveSameDayAs secondDate // Assertion fails, 9 == 9, and we expected a difference405 * ```406 */407infix fun LocalDateTime.shouldNotHaveSameDayAs(date: LocalDateTime) = this shouldNot haveSameDay(date)408/**409 * Matcher that compares days of LocalDateTimes410 *411 * Verifies that two DateTimes have exactly the same day, ignoring any other fields.412 * For example, 09/02/1998 10:00:00 has the same day as 09/03/2018 11:30:30, and the matcher will have a positive result for this comparison413 *414 * ```415 * val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)416 * val secondDate = LocalDateTime(2018, 3, 9, 11, 30, 30)417 *418 * firstDate should haveSameDay(secondDate) // Assertion passes419 *420 *421 * val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)422 * val secondDate = LocalDateTime(1998, 2, 10, 10, 0, 0)423 *424 * firstDate shouldNot haveSameDay(secondDate) // Assertion passes425 * ```426 *427 * @see [LocalDateTime.shouldHaveSameDayAs]428 * @see [LocalDateTime.shouldNotHaveSameDayAs]429 */430fun haveSameDay(date: LocalDateTime): Matcher<LocalDateTime> = object : Matcher<LocalDateTime> {431 override fun test(value: LocalDateTime): MatcherResult =432 MatcherResult(value.dayOfMonth == date.dayOfMonth, "$value should have day ${date.dayOfMonth} but had ${value.dayOfMonth}", "$value should not have day ${date.dayOfMonth}")433}434/**435 * Asserts that this is before [date]436 *437 * Verifies that this is before [date], comparing year, month and day.438 * For example, 09/02/1998 is before 10/02/1998, and this assertion should pass for this comparison.439 *440 * Opposite of [LocalDate.shouldNotBeBefore]441 *442 * ```443 * val firstDate = LocalDate(1998, 2, 9)444 * val secondDate = LocalDate(1998, 2, 10)445 *446 * firstDate shouldBeBefore secondDate // Assertion passes447 *448 *449 * val firstDate = LocalDate(1998, 2, 10)450 * val secondDate = LocalDate(1998, 2, 9)451 *452 * firstDate shouldBeBefore secondDate // Assertion fails, 10/02/1998 is not before 09/02/1998 as expected.453 * ```454 *455 * @see LocalDate.shouldNotBeAfter456 */457infix fun LocalDate.shouldBeBefore(date: LocalDate) = this should before(date)458/**459 * Asserts that this is NOT before [date]460 *461 * Verifies that this is not before [date], comparing year, month and day.462 * For example, 10/02/1998 is not before 09/02/1998, and this assertion should pass for this comparison.463 *464 * Opposite of [LocalDate.shouldBeBefore]465 *466 * ```467 * val firstDate = LocalDate(1998, 2, 10)468 * val secondDate = LocalDate(1998, 2, 9)469 *470 * firstDate shouldNotBeBefore secondDate // Assertion passes471 * val firstDate = LocalDate(1998, 2, 9)472 * val secondDate = LocalDate(1998, 2, 10)473 *474 * firstDate shouldNotBeBefore secondDate // Assertion fails, 09/02/1998 is before 10/02/1998, and we expected the opposite.475 * ```476 *477 * @see LocalDate.shouldBeAfter478 */479infix fun LocalDate.shouldNotBeBefore(date: LocalDate) = this shouldNot before(date)480/**481 * Matcher that compares two LocalDates and checks whether one is before the other482 *483 * Verifies that two LocalDates occurs in a certain order, checking that one happened before the other.484 * For example, 09/02/1998 is before 10/02/1998, and the matcher will have a positive result for this comparison485 *486 * ```487 * val firstDate = LocalDate(1998, 2, 9)488 * val secondDate = LocalDate(1998, 2, 10)489 *490 * firstDate shouldBe before(secondDate) // Assertion passes491 *492 *493 * val firstDate = LocalDate(1998, 2, 10)494 * val secondDate = LocalDate(1998, 2, 9)495 *496 * firstDate shouldNotBe before(secondDate) // Assertion passes497 * ```498 *499 * @see LocalDate.shouldBeBefore500 * @see LocalDate.shouldNotBeBefore501 */502fun before(date: LocalDate): Matcher<LocalDate> = object : Matcher<LocalDate> {503 override fun test(value: LocalDate): MatcherResult =504 MatcherResult(value < date, "$value should be before $date", "$value should not be before $date")505}506/**507 * Asserts that this is before [date]508 *509 * Verifies that this is before [date], comparing every field in the LocalDateTime.510 * For example, 09/02/1998 00:00:00 is before 09/02/1998 00:00:01, and this assertion should pass for this comparison.511 *512 * Opposite of [LocalDateTime.shouldNotBeBefore]513 *514 * ```515 * val firstDate = LocalDateTime(1998, 2, 9, 0, 0, 0)516 * val secondDate = LocalDateTime(1998, 2, 9, 0, 0, 1)517 *518 * firstDate shouldBeBefore secondDate // Assertion passes519 *520 *521 * val firstDate = LocalDateTime(1998, 2, 9, 0, 0, 1)522 * val secondDate = LocalDateTime(1998, 2, 9, 0, 0, 0)523 *524 * firstDate shouldBeBefore secondDate // Assertion fails, firstDate is one second after secondDate525 * ```526 *527 * @see LocalDateTime.shouldNotBeAfter528 */529infix fun LocalDateTime.shouldBeBefore(date: LocalDateTime) = this should before(date)530/**531 * Asserts that this is NOT before [date]532 *533 * Verifies that this is not before [date], comparing every field in the LocalDateTime.534 * For example, 09/02/1998 00:00:01 is not before 09/02/1998 00:00:00, and this assertion should pass for this comparison.535 *536 * Opposite of [LocalDateTime.shouldBeBefore]537 *538 * ```539 * val firstDate = LocalDateTime(1998, 2, 9, 0, 0, 1)540 * val secondDate = LocalDateTime(1998, 2, 9, 0, 0, 0)541 *542 * firstDate shouldNotBeBefore secondDate // Assertion passes543 *544 *545 * val firstDate = LocalDateTime(1998, 2, 9, 0, 0, 0)546 * val secondDate = LocalDateTime(1998, 2, 9, 0, 0, 1)547 *548 * firstDate shouldNotBeBefore secondDate // Assertion fails, firstDate is one second before secondDate and we didn't expect it549 * ```550 *551 * @see LocalDateTime.shouldBeAfter552 */553infix fun LocalDateTime.shouldNotBeBefore(date: LocalDateTime) = this shouldNot before(date)554/**555 * Matcher that compares two LocalDateTimes and checks whether one is before the other556 *557 * Verifies that two LocalDateTimes occurs in a certain order, checking that one happened before the other.558 * For example, 09/02/1998 00:00:00 is before 09/02/1998 00:00:01, and the matcher will have a positive result for this comparison559 *560 * ```561 * val firstDate = LocalDateTime(1998, 2, 9, 0, 0, 0)562 * val secondDate = LocalDateTime(1998, 2, 9, 0, 0, 1)563 *564 * firstDate shouldBe before(secondDate) // Assertion passes565 *566 *567 * val firstDate = LocalDateTime(1998, 2, 9, 0, 0, 1)568 * val secondDate = LocalDateTime(1998, 2, 9, 0, 0, 0)569 *570 * firstDate shouldNotBe before(secondDate) // Assertion passes571 * ```572 *573 * @see LocalDateTime.shouldBeBefore574 * @see LocalDateTime.shouldNotBeBefore575 */576fun before(date: LocalDateTime): Matcher<LocalDateTime> = object : Matcher<LocalDateTime> {577 override fun test(value: LocalDateTime): MatcherResult =578 MatcherResult(value < date, "$value should be before $date", "$value should not be before $date")579}580/**581 * Asserts that this is after [date]582 *583 * Verifies that this is after [date], comparing year, month and day.584 * For example, 09/02/1998 is after 08/02/1998, and this assertion should pass for this comparison.585 *586 * Opposite of [LocalDate.shouldNotBeAfter]587 *588 * ```589 * val firstDate = LocalDate(1998, 2, 9)590 * val secondDate = LocalDate(1998, 2, 8)591 *592 * firstDate shouldBeAfter secondDate // Assertion passes593 *594 *595 * val firstDate = LocalDate(1998, 2, 9)596 * val secondDate = LocalDate(1998, 2, 10)597 *598 * firstDate shouldBeAfter secondDate // Assertion fails, firstDate is NOT after secondDate599 * ```600 *601 * @see LocalDate.shouldNotBeBefore602 */603infix fun LocalDate.shouldBeAfter(date: LocalDate) = this should after(date)604/**605 * Asserts that this is NOT after [date]606 *607 * Verifies that this is not after [date], comparing year, month and day.608 * For example, 09/02/1998 is not after 10/02/1998, and this assertion should pass for this comparison.609 *610 * Opposite of [LocalDate.shouldBeAfter]611 *612 * ```613 * val firstDate = LocalDate(1998, 2, 9)614 * val secondDate = LocalDate(1998, 2, 10)615 *616 * firstDate shouldNotBeAfter secondDate // Assertion passes617 *618 *619 * val firstDate = LocalDate(1998, 2, 10)620 * val secondDate = LocalDate(1998, 2, 9)621 *622 * firstDate shouldNotBeAfter secondDate // Assertion fails, first date IS after secondDate623 * ```624 *625 * @see LocalDate.shouldBeBefore626 */627infix fun LocalDate.shouldNotBeAfter(date: LocalDate) = this shouldNot after(date)628/**629 * Matcher that compares two LocalDates and checks whether one is after the other630 *631 * Verifies that two LocalDates occurs in a certain order, checking that one happened after the other.632 * For example, 10/02/1998 is after 09/02/1998, and the matcher will have a positive result for this comparison633 *634 * ```635 * val firstDate = LocalDate(1998, 2, 9)636 * val secondDate = LocalDate(1998, 2, 8)637 *638 * firstDate shouldBe after(secondDate ) // Assertion passes639 *640 *641 * val firstDate = LocalDate(1998, 2, 9)642 * val secondDate = LocalDate(1998, 2, 10)643 *644 * firstDate shouldNotBe after(secondDate) // Assertion passes645 * ```646 *647 * @see LocalDate.shouldBeAfter648 * @see LocalDate.shouldNotBeAfter649 */650fun after(date: LocalDate): Matcher<LocalDate> = object : Matcher<LocalDate> {651 override fun test(value: LocalDate): MatcherResult =652 MatcherResult(value > date, "$value should be after $date", "$value should not be after $date")653}654/**655 * Asserts that this is after [date]656 *657 * Verifies that this is after [date], comparing all fields in LocalDateTime.658 * For example, 09/02/1998 10:00:00 is after 09/02/1998 09:00:00, and this assertion should pass for this comparison.659 *660 * Opposite of [LocalDateTime.shouldNotBeAfter]661 *662 * ```663 * val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)664 * val secondDate = LocalDateTime(1998, 2, 8, 10, 0, 0)665 *666 * firstDate shouldBeAfter secondDate // Assertion passes667 *668 *669 * val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)670 * val secondDate = LocalDateTime(1998, 2, 10, 10, 0, 0)671 *672 * firstDate shouldBeAfter secondDate // Assertion fails, firstDate is NOT after secondDate673 * ```674 *675 * @see LocalDateTime.shouldNotBeBefore676 */677infix fun LocalDateTime.shouldBeAfter(date: LocalDateTime) = this should after(date)678/**679 * Asserts that this is NOT after [date]680 *681 * Verifies that this is not after [date], comparing all fields in LocalDateTime.682 * For example, 09/02/1998 09:00:00 is not after 09/02/1998 10:00:00, and this assertion should pass for this comparison.683 *684 * Opposite of [LocalDateTime.shouldBeAfter]685 *686 * ```687 * val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)688 * val secondDate = LocalDateTime(1998, 2, 10, 10, 0, 0)689 *690 * firstDate shouldNotBeAfter secondDate // Assertion passes691 *692 *693 * val firstDate = LocalDateTime(1998, 2, 10, 10, 0, 0)694 * val secondDate = LocalDateTime(1998, 2, 9, 10, 0, 0)695 *696 * firstDate shouldNotBeAfter secondDate // Assertion fails, first date IS after secondDate697 * ```698 *699 * @see LocalDateTime.shouldBeBefore700 */701infix fun LocalDateTime.shouldNotBeAfter(date: LocalDateTime) = this shouldNot after(date)702/**703 * Matcher that compares two LocalDateTimes and checks whether one is after the other704 *705 * Verifies that two LocalDateTimes occurs in a certain order, checking that one happened after the other.706 * For example, 09/02/1998 10:00:00 is after 09/02/1998 09:00:00, and the matcher will have a positive result for this comparison707 *708 * ```709 * val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)710 * val secondDate = LocalDateTime(1998, 2, 8, 10, 0, 0)711 *712 * firstDate shouldBe after(secondDate ) // Assertion passes713 *714 *715 * val firstDate = LocalDateTime(1998, 2, 9, 10, 0, 0)716 * val secondDate = LocalDateTime(1998, 2, 10, 10, 0, 0)717 *718 * firstDate shouldNotBe after(secondDate) // Assertion passes719 * ```720 *721 * @see LocalDateTime.shouldBeAfter722 * @see LocalDateTime.shouldNotBeAfter723 */724fun after(date: LocalDateTime): Matcher<LocalDateTime> = object : Matcher<LocalDateTime> {725 override fun test(value: LocalDateTime): MatcherResult =726 MatcherResult(value > date, "$value should be after $date", "$value should not be after $date")727}728/**729 * Asserts that this is between [a] and [b]730 *731 * Verifies that this is after [a] and before [b], comparing year, month and day.732 *733 * Opposite of [LocalDate.shouldNotBeBetween]734 *735 * ```736 * val date = LocalDate(2019, 2, 16)737 * val firstDate = LocalDate(2019, 2, 15)738 * val secondDate = LocalDate(2019, 2, 17)739 *740 * date.shouldBeBetween(firstDate, secondDate) // Assertion passes741 *742 *743 * val date = LocalDate(2019, 2, 15)744 * val firstDate = LocalDate(2019, 2, 16)745 * val secondDate = LocalDate(2019, 2, 17)746 *747 * date.shouldBeBetween(firstDate, secondDate) // Assertion fails, date is NOT between firstDate and secondDate748 * ```749 *750 * @see LocalDate.shouldNotBeBetween751 */752fun LocalDate.shouldBeBetween(a: LocalDate, b: LocalDate) = this shouldBe between(a, b)753/**754 * Asserts that this is NOT between [a] and [b]755 *756 * Verifies that this is not after [a] and before [b], comparing year, month and day.757 *758 * Opposite of [LocalDate.shouldBeBetween]759 *760 * ```761 * val date = LocalDate(2019, 2, 15)762 * val firstDate = LocalDate(2019, 2, 16)763 * val secondDate = LocalDate(2019, 2, 17)764 *765 * date.shouldNotBeBetween(firstDate, secondDate) // Assertion passes766 *767 *768 * val date = LocalDate(2019, 2, 16)769 * val firstDate = LocalDate(2019, 2, 15)770 * val secondDate = LocalDate(2019, 2, 17)771 *772 * date.shouldNotBeBetween(firstDate, secondDate) // Assertion fails, date IS between firstDate and secondDate773 * ```774 *775 * @see LocalDate.shouldBeBetween776 */777fun LocalDate.shouldNotBeBetween(a: LocalDate, b: LocalDate) = this shouldNotBe between(a, b)778/**779 * Matcher that checks if LocalDate is between two other LocalDates780 *781 * Verifies that LocalDate is after the first LocalDate and before the second LocalDate782 * For example, 20/03/2019 is between 19/03/2019 and 21/03/2019, and the matcher will have a positive result for this comparison783 *784 * ```785 * val date = LocalDate(2019, 2, 16)786 * val firstDate = LocalDate(2019, 2, 15)787 * val secondDate = LocalDate(2019, 2, 17)788 *789 * date shouldBe after(firstDate, secondDate) // Assertion passes790 *791 *792 * val date = LocalDate(2019, 2, 15)793 * val firstDate = LocalDate(2019, 2, 16)794 * val secondDate = LocalDate(2019, 2, 17)795 *796 * date shouldNotBe between(firstDate, secondDate) // Assertion passes797 * ```798 *799 * @see LocalDate.shouldBeBetween800 * @see LocalDate.shouldNotBeBetween801 */802fun between(a: LocalDate, b: LocalDate): Matcher<LocalDate> = object : Matcher<LocalDate> {803 override fun test(value: LocalDate): MatcherResult {804 val passed = value > a && value < b805 return MatcherResult(passed, "$value should be after $a and before $b", "$value should not be be after $a and before $b")806 }807}808/**809 * Asserts that this is between [a] and [b]810 *811 * Verifies that this is after [a] and before [b], comparing all fields in LocalDateTime.812 *813 * Opposite of [LocalDateTime.shouldNotBeBetween]814 *815 * ```816 * val date = LocalDateTime(2019, 2, 16, 12, 0, 0)817 * val firstDate = LocalDateTime(2019, 2, 15, 12, 0, 0)818 * val secondDate = LocalDateTime(2019, 2, 17, 12, 0, 0)819 *820 * date.shouldBeBetween(firstDate, secondDate) // Assertion passes821 *822 *823 * val date = LocalDateTime(2019, 2, 15, 12, 0, 0)824 * val firstDate = LocalDateTime(2019, 2, 16, 12, 0, 0)825 * val secondDate = LocalDateTime(2019, 2, 17, 12, 0, 0)826 *827 * date.shouldBeBetween(firstDate, secondDate) // Assertion fails, date is NOT between firstDate and secondDate828 * ```829 *830 * @see LocalDateTime.shouldNotBeBetween831 */832fun LocalDateTime.shouldBeBetween(a: LocalDateTime, b: LocalDateTime) = this shouldBe between(a, b)833/**834 * Asserts that this is NOT between [a] and [b]835 *836 * Verifies that this is not after [a] and before [b], comparing all fields in LocalDateTime.837 *838 * Opposite of [LocalDateTime.shouldBeBetween]839 *840 * ```841 * val date = LocalDateTime(2019, 2, 15, 12, 0, 0)842 * val firstDate = LocalDateTime(2019, 2, 16, 12, 0, 0)843 * val secondDate = LocalDateTime(2019, 2, 17, 12, 0, 0)844 *845 * date.shouldNotBeBetween(firstDate, secondDate) // Assertion passes846 *847 *848 * val date = LocalDateTime(2019, 2, 16, 12, 0, 0)849 * val firstDate = LocalDateTime(2019, 2, 15, 12, 0, 0)850 * val secondDate = LocalDateTime(2019, 2, 17, 12, 0, 0)851 *852 * date.shouldNotBeBetween(firstDate, secondDate) // Assertion fails, date IS between firstDate and secondDate853 * ```854 *855 * @see LocalDateTime.shouldBeBetween856 */857fun LocalDateTime.shouldNotBeBetween(a: LocalDateTime, b: LocalDateTime) = this shouldNotBe between(a, b)858/**859 * Matcher that checks if LocalDateTime is between two other LocalDateTimes860 *861 * Verifies that LocalDateTime is after the first LocalDateTime and before the second LocalDateTime862 * For example, 20/03/2019 10:00:00 is between 19/03/2019 10:00:00 and 21/03/2019 10:00:00, and the matcher will have a positive result for this comparison863 *864 * ```865 * val date = LocalDateTime(2019, 2, 16, 12, 0, 0)866 * val firstDate = LocalDateTime(2019, 2, 15, 12, 0, 0)867 * val secondDate = LocalDateTime(2019, 2, 17, 12, 0, 0)868 *869 * date shouldBe after(firstDate, secondDate) // Assertion passes870 *871 *872 * val date = LocalDateTime(2019, 2, 15, 12, 0, 0)873 * val firstDate = LocalDateTime(2019, 2, 16, 12, 0, 0)874 * val secondDate = LocalDateTime(2019, 2, 17, 12, 0, 0)875 *876 * date shouldNotBe between(firstDate, secondDate) // Assertion passes877 * ```878 *879 * @see LocalDateTime.shouldBeBetween880 * @see LocalDateTime.shouldNotBeBetween881 */882fun between(a: LocalDateTime, b: LocalDateTime): Matcher<LocalDateTime> = object : Matcher<LocalDateTime> {883 override fun test(value: LocalDateTime): MatcherResult {884 val passed = value > a && value < b885 return MatcherResult(passed, "$value should be after $a and before $b", "$value should not be be after $a and before $b")886 }887}888/**889 * Asserts that the day of month inputted is equaled the date day890 *891 * ```892 * val date = LocalDateTime(2019, 2, 15, 12, 0, 0, 0)893 *894 * date.shouldHaveDayOfMonth(15) // Assertion passes895 * ```896 */897infix fun LocalDateTime.shouldHaveDayOfMonth(day: Int) = this.dayOfMonth shouldBe day898/**899 * Asserts that the day of year inputted is equaled the date day900 *901 * ```902 * val date = LocalDateTime(2019, 2, 15, 12, 0, 0, 0)903 *904 * date.shouldHaveDayOfYear(46) // Assertion passes905 * ```906 */907infix fun LocalDateTime.shouldHaveDayOfYear(day: Int) = this.dayOfYear shouldBe day908/**909 * Asserts that the day of year inputted is equaled the date day910 *911 * ```912 * val date = LocalDateTime(2019, 2, 15, 12, 0, 0, 0)913 *914 * date.shouldHaveDayOfWeek(FRIDAY) // Assertion passes915 * date.shouldHaveDayOfWeek(5) // Assertion passes916 * ```917 */918infix fun LocalDateTime.shouldHaveDayOfWeek(day: Int) = this.dayOfWeek.isoDayNumber shouldBe day919infix fun LocalDateTime.shouldHaveDayOfWeek(day: DayOfWeek) = this.dayOfWeek shouldBe day920/**921 * Asserts that the month inputted is equaled the date month922 *923 * ```924 * val date = LocalDateTime(2019, 2, 15, 12, 0, 0, 0)925 *926 * date.shouldHaveMonth(2) // Assertion passes927 * date.shouldHaveMonth(FEBRUARY) // Assertion passes928 * ```929 */930infix fun LocalDateTime.shouldHaveMonth(month: Int) = this.month.number shouldBe month931infix fun LocalDateTime.shouldHaveMonth(month: Month) = this.month shouldBe month932/**933 * Asserts that the hour inputted is equaled the date time hour934 *935 * ```936 * val date = LocalDateTime(2019, 2, 15, 12, 10, 0, 0)937 *938 * date.shouldHaveHour(12) // Assertion passes939 * ```940 */941infix fun LocalDateTime.shouldHaveHour(hour: Int) = this.hour shouldBe hour942/**943 * Asserts that the minute inputted is equaled the date time minute944 *945 * ```946 * val date = LocalDateTime(2019, 2, 15, 12, 10, 0, 0)947 *948 * date.shouldHaveMinute(10) // Assertion passes949 * ```950 */951infix fun LocalDateTime.shouldHaveMinute(minute: Int) = this.minute shouldBe minute952/**953 * Asserts that the second inputted is equaled the date time second954 *955 * ```956 * val date = LocalDateTime(2019, 2, 15, 12, 10, 11, 0)957 *958 * date.shouldHaveSecond(11) // Assertion passes959 * ```960 */961infix fun LocalDateTime.shouldHaveSecond(second: Int) = this.second shouldBe second962/**963 * Asserts that the nano inputted is equaled the date time nano964 *965 * ```966 * val date = LocalDateTime(2019, 2, 15, 12, 10, 0, 12)967 *968 * date.shouldHaveNano(10) // Assertion passes969 * ```970 */971infix fun LocalDateTime.shouldHaveNano(nano: Int) = this.nanosecond shouldBe nano...

Full Screen

Full Screen

DateMatchersTest.kt

Source:DateMatchersTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.matchers.date2import io.kotest.assertions.shouldFail3import io.kotest.assertions.throwables.shouldThrow4import io.kotest.core.spec.style.StringSpec5import io.kotest.matchers.date.after6import io.kotest.matchers.date.atSameZone7import io.kotest.matchers.date.before8import io.kotest.matchers.date.haveSameDay9import io.kotest.matchers.date.haveSameHours10import io.kotest.matchers.date.haveSameInstantAs11import io.kotest.matchers.date.haveSameMinutes12import io.kotest.matchers.date.haveSameMonth13import io.kotest.matchers.date.haveSameNanos14import io.kotest.matchers.date.haveSameSeconds15import io.kotest.matchers.date.haveSameYear16import io.kotest.matchers.date.shouldBeAfter17import io.kotest.matchers.date.shouldBeBefore18import io.kotest.matchers.date.shouldBeBetween19import io.kotest.matchers.date.shouldBeToday20import io.kotest.matchers.date.shouldBeWithin21import io.kotest.matchers.date.shouldHaveDayOfMonth22import io.kotest.matchers.date.shouldHaveDayOfWeek23import io.kotest.matchers.date.shouldHaveDayOfYear24import io.kotest.matchers.date.shouldHaveHour25import io.kotest.matchers.date.shouldHaveMinute26import io.kotest.matchers.date.shouldHaveMonth27import io.kotest.matchers.date.shouldHaveNano28import io.kotest.matchers.date.shouldHaveSameDayAs29import io.kotest.matchers.date.shouldHaveSameHoursAs30import io.kotest.matchers.date.shouldHaveSameInstantAs31import io.kotest.matchers.date.shouldHaveSameMinutesAs32import io.kotest.matchers.date.shouldHaveSameMonthAs33import io.kotest.matchers.date.shouldHaveSameNanosAs34import io.kotest.matchers.date.shouldHaveSameSecondsAs35import io.kotest.matchers.date.shouldHaveSameYearAs36import io.kotest.matchers.date.shouldHaveSecond37import io.kotest.matchers.date.shouldNotBeAfter38import io.kotest.matchers.date.shouldNotBeBefore39import io.kotest.matchers.date.shouldNotBeBetween40import io.kotest.matchers.date.shouldNotBeToday41import io.kotest.matchers.date.shouldNotBeWithin42import io.kotest.matchers.date.shouldNotHaveSameDayAs43import io.kotest.matchers.date.shouldNotHaveSameHoursAs44import io.kotest.matchers.date.shouldNotHaveSameInstantAs45import io.kotest.matchers.date.shouldNotHaveSameMinutesAs46import io.kotest.matchers.date.shouldNotHaveSameMonthAs47import io.kotest.matchers.date.shouldNotHaveSameNanosAs48import io.kotest.matchers.date.shouldNotHaveSameSecondsAs49import io.kotest.matchers.date.shouldNotHaveSameYearAs50import io.kotest.matchers.date.within51import io.kotest.matchers.shouldBe52import io.kotest.matchers.should53import io.kotest.matchers.shouldNot54import io.kotest.matchers.shouldNotBe55import java.time.DayOfWeek.SATURDAY56import java.time.Duration57import java.time.LocalDate58import java.time.LocalDateTime59import java.time.LocalTime60import java.time.Month61import java.time.OffsetDateTime62import java.time.Period63import java.time.ZoneId64import java.time.ZoneOffset65import java.time.ZonedDateTime66class DateMatchersTest : StringSpec() {67 init {68 "LocalTime should have same nanos ignoring other fields" {69 LocalTime.of(1, 2, 3, 4) should haveSameNanos(LocalTime.of(5, 6, 7, 4))70 LocalTime.of(1, 2, 3, 4) shouldNot haveSameNanos(LocalTime.of(1, 2, 3, 8))71 LocalTime.of(1, 2, 3, 4).shouldHaveSameNanosAs(LocalTime.of(5, 6, 7, 4))72 LocalTime.of(1, 2, 3, 4).shouldNotHaveSameNanosAs(LocalTime.of(1, 2, 3, 8))73 }74 "LocalTime should have same seconds ignoring other fields" {75 LocalTime.of(1, 2, 3, 4) should haveSameSeconds(LocalTime.of(5, 6, 3, 4))76 LocalTime.of(1, 2, 3, 4) shouldNot haveSameSeconds(LocalTime.of(1, 2, 5, 4))77 LocalTime.of(1, 2, 3, 4).shouldHaveSameSecondsAs(LocalTime.of(5, 6, 3, 4))78 LocalTime.of(1, 2, 3, 4).shouldNotHaveSameSecondsAs(LocalTime.of(1, 2, 5, 4))79 }80 "LocalTime should have same minutes ignoring other fields" {81 LocalTime.of(1, 2, 3, 4) should haveSameMinutes(LocalTime.of(5, 2, 7, 8))82 LocalTime.of(1, 2, 3, 4) shouldNot haveSameMinutes(LocalTime.of(1, 5, 3, 4))83 LocalTime.of(1, 2, 3, 4).shouldHaveSameMinutesAs(LocalTime.of(5, 2, 7, 8))84 LocalTime.of(1, 2, 3, 4).shouldNotHaveSameMinutesAs(LocalTime.of(1, 5, 3, 4))85 }86 "LocalTime should have same hours ignoring other fields" {87 LocalTime.of(12, 1, 2, 7777) should haveSameHours(LocalTime.of(12, 59, 58, 9999))88 LocalTime.of(3, 59, 58, 9999) shouldNot haveSameHours(LocalTime.of(12, 59, 58, 9999))89 LocalTime.of(12, 1, 2, 7777).shouldHaveSameHoursAs(LocalTime.of(12, 59, 58, 9999))90 LocalTime.of(3, 59, 58, 9999).shouldNotHaveSameHoursAs(LocalTime.of(12, 59, 58, 9999))91 }92 "LocalDate should have same year ignoring other fields" {93 LocalDate.of(2014, 1, 2) should haveSameYear(LocalDate.of(2014, 5, 6))94 LocalDate.of(2014, 1, 2) shouldNot haveSameYear(LocalDate.of(2018, 5, 6))95 LocalDate.of(2014, 1, 2).shouldHaveSameYearAs(LocalDate.of(2014, 5, 6))96 LocalDate.of(2014, 1, 2).shouldNotHaveSameYearAs(LocalDate.of(2018, 5, 6))97 }98 "LocalDateTime should have same year ignoring other fields" {99 LocalDateTime.of(2014, 1, 2, 4, 3, 2) should haveSameYear(LocalDateTime.of(2014, 5, 6, 3, 2, 1))100 LocalDateTime.of(2014, 1, 2, 3, 2, 1) shouldNot haveSameYear(LocalDateTime.of(2018, 5, 6, 3, 2, 1))101 LocalDateTime.of(2014, 1, 2, 4, 3, 2).shouldHaveSameYearAs(LocalDateTime.of(2014, 5, 6, 3, 2, 1))102 LocalDateTime.of(2014, 1, 2, 3, 2, 1).shouldNotHaveSameYearAs(LocalDateTime.of(2018, 5, 6, 3, 2, 1))103 }104 "ZonedDateTime should have same year ignoring other fields" {105 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")) should haveSameYear(LocalDateTime.of(2014, 5, 6, 3, 2, 1).atZone(ZoneId.of("Z")))106 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")) shouldNot haveSameYear(LocalDateTime.of(2018, 5, 6, 3, 2, 1).atZone(ZoneId.of("Z")))107 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")).shouldHaveSameYearAs(LocalDateTime.of(2014, 5, 6, 3, 2, 1).atZone(ZoneId.of("Z")))108 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")).shouldNotHaveSameYearAs(LocalDateTime.of(2018, 5, 6, 3, 2, 1).atZone(ZoneId.of("Z")))109 }110 "OffsetDateTime should have same year ignoring other fields" {111 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC) should haveSameYear(LocalDateTime.of(2014, 5, 6, 3, 2, 1).atOffset(ZoneOffset.UTC))112 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC) shouldNot haveSameYear(LocalDateTime.of(2018, 5, 6, 3, 2, 1).atOffset(ZoneOffset.UTC))113 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC).shouldHaveSameYearAs(LocalDateTime.of(2014, 5, 6, 3, 2, 1).atOffset(ZoneOffset.UTC))114 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC).shouldNotHaveSameYearAs(LocalDateTime.of(2018, 5, 6, 3, 2, 1).atOffset(ZoneOffset.UTC))115 }116 "LocalDate should have same month ignoring other fields" {117 LocalDate.of(2014, 1, 2) should haveSameMonth(LocalDate.of(2016, 1, 6))118 LocalDate.of(2014, 1, 2) shouldNot haveSameMonth(LocalDate.of(2018, 4, 6))119 LocalDate.of(2014, 1, 2).shouldHaveSameMonthAs(LocalDate.of(2016, 1, 6))120 LocalDate.of(2014, 1, 2).shouldNotHaveSameMonthAs(LocalDate.of(2018, 4, 6))121 }122 "LocalDateTime should have same month ignoring other fields" {123 LocalDateTime.of(2014, 1, 2, 4, 3, 2) should haveSameMonth(LocalDateTime.of(2014, 1, 6, 3, 2, 1))124 LocalDateTime.of(2014, 1, 2, 3, 2, 1) shouldNot haveSameMonth(LocalDateTime.of(2018, 2, 6, 3, 2, 1))125 LocalDateTime.of(2014, 1, 2, 4, 3, 2).shouldHaveSameMonthAs(LocalDateTime.of(2014, 1, 6, 3, 2, 1))126 LocalDateTime.of(2014, 1, 2, 3, 2, 1).shouldNotHaveSameMonthAs(LocalDateTime.of(2018, 2, 6, 3, 2, 1))127 }128 "ZonedDateTime should have same month ignoring other fields" {129 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")) should haveSameMonth(LocalDateTime.of(2014, 1, 6, 3, 2, 1).atZone(ZoneId.of("Z")))130 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")) shouldNot haveSameMonth(LocalDateTime.of(2018, 2, 6, 3, 2, 1).atZone(ZoneId.of("Z")))131 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")).shouldHaveSameMonthAs(LocalDateTime.of(2014, 1, 6, 3, 2, 1).atZone(ZoneId.of("Z")))132 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")).shouldNotHaveSameMonthAs(LocalDateTime.of(2018, 2, 6, 3, 2, 1).atZone(ZoneId.of("Z")))133 }134 "OffsetDateTime should have same month ignoring other fields" {135 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC) should haveSameMonth(LocalDateTime.of(2014, 1, 6, 3, 2, 1).atOffset(ZoneOffset.UTC))136 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC) shouldNot haveSameMonth(LocalDateTime.of(2018, 2, 6, 3, 2, 1).atOffset(ZoneOffset.UTC))137 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC).shouldHaveSameMonthAs(LocalDateTime.of(2014, 1, 6, 3, 2, 1).atOffset(ZoneOffset.UTC))138 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC).shouldNotHaveSameMonthAs(LocalDateTime.of(2018, 2, 6, 3, 2, 1).atOffset(ZoneOffset.UTC))139 }140 "LocalDate should have same day ignoring other fields" {141 LocalDate.of(2014, 1, 2) should haveSameDay(LocalDate.of(2014, 1, 2))142 LocalDate.of(2014, 1, 2) shouldNot haveSameDay(LocalDate.of(2014, 4, 6))143 LocalDate.of(2014, 1, 2).shouldHaveSameDayAs(LocalDate.of(2014, 1, 2))144 LocalDate.of(2014, 1, 2).shouldNotHaveSameDayAs(LocalDate.of(2014, 4, 6))145 }146 "LocalDateTime should have same day ignoring other fields" {147 LocalDateTime.of(2014, 1, 2, 4, 3, 2) should haveSameDay(LocalDateTime.of(2014, 1, 2, 3, 2, 1))148 LocalDateTime.of(2014, 1, 2, 3, 2, 1) shouldNot haveSameDay(LocalDateTime.of(2014, 2, 6, 3, 2, 1))149 LocalDateTime.of(2014, 1, 2, 4, 3, 2).shouldHaveSameDayAs(LocalDateTime.of(2014, 1, 2, 3, 2, 1))150 LocalDateTime.of(2014, 1, 2, 3, 2, 1).shouldNotHaveSameDayAs(LocalDateTime.of(2014, 2, 6, 3, 2, 1))151 }152 "ZonedDateTime should have same day ignoring other fields" {153 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")) should haveSameDay(LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")))154 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")) shouldNot haveSameDay(LocalDateTime.of(2014, 2, 6, 3, 2, 1).atZone(ZoneId.of("Z")))155 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")).shouldHaveSameDayAs(LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")))156 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")).shouldNotHaveSameDayAs(LocalDateTime.of(2014, 2, 6, 3, 2, 1).atZone(ZoneId.of("Z")))157 }158 "OffsetDateTime should have same day ignoring other fields" {159 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC) should haveSameDay(LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC))160 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC) shouldNot haveSameDay(LocalDateTime.of(2014, 2, 6, 3, 2, 1).atOffset(ZoneOffset.UTC))161 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC).shouldHaveSameDayAs(LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC))162 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC).shouldNotHaveSameDayAs(LocalDateTime.of(2014, 2, 6, 3, 2, 1).atOffset(ZoneOffset.UTC))163 }164 "LocalTime shouldBe before" {165 LocalTime.of(1, 2, 3, 1000) shouldBe before(LocalTime.of(1, 10, 3, 1000))166 LocalTime.of(1, 2, 3, 1000) shouldNotBe before(LocalTime.of(1, 1, 3, 1000))167 LocalTime.of(1, 2, 3, 1000).shouldBeBefore(LocalTime.of(5, 2, 3, 1000))168 LocalTime.of(1, 2, 3, 1000).shouldNotBeBefore(LocalTime.of(0, 2, 3, 1000))169 }170 "LocalDate shouldBe before" {171 LocalDate.of(2014, 1, 2) shouldBe before(LocalDate.of(2014, 1, 3))172 LocalDate.of(2014, 1, 2) shouldNotBe before(LocalDate.of(2014, 1, 1))173 LocalDate.of(2014, 1, 2).shouldBeBefore(LocalDate.of(2014, 1, 3))174 LocalDate.of(2014, 1, 2).shouldNotBeBefore(LocalDate.of(2014, 1, 1))175 }176 "LocalDateTime shouldBe before" {177 LocalDateTime.of(2014, 1, 2, 4, 3, 2) shouldBe before(LocalDateTime.of(2014, 2, 2, 3, 2, 1))178 LocalDateTime.of(2014, 1, 2, 3, 2, 1) shouldNotBe before(LocalDateTime.of(2014, 1, 1, 3, 2, 1))179 LocalDateTime.of(2014, 1, 2, 4, 3, 2).shouldBeBefore(LocalDateTime.of(2014, 2, 2, 3, 2, 1))180 LocalDateTime.of(2014, 1, 2, 3, 2, 1).shouldNotBeBefore(LocalDateTime.of(2014, 1, 1, 3, 2, 1))181 }182 "ZonedDateTime shouldBe before" {183 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")) shouldBe before(LocalDateTime.of(2014, 1, 3, 3, 2, 1).atZone(ZoneId.of("Z")))184 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")) shouldNotBe before(LocalDateTime.of(2014, 1, 1, 3, 2, 1).atZone(ZoneId.of("Z")))185 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")).shouldBeBefore(LocalDateTime.of(2014, 1, 3, 3, 2, 1).atZone(ZoneId.of("Z")))186 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")).shouldNotBeBefore(LocalDateTime.of(2014, 1, 1, 3, 2, 1).atZone(ZoneId.of("Z")))187 }188 "ZonedDateTime shouldBe equal" {189 ZonedDateTime.of(2019, 12, 10, 10, 0, 0, 0, ZoneOffset.UTC) shouldBe190 ZonedDateTime.of(2019, 12, 10, 4, 0, 0, 0, ZoneId.of("America/Chicago")).atSameZone()191 shouldThrow<AssertionError> {192 ZonedDateTime.of(2019, 12, 10, 10, 0, 0, 0, ZoneOffset.UTC) shouldBe193 ZonedDateTime.of(2019, 12, 10, 4, 1, 0, 0, ZoneId.of("America/Chicago")).atSameZone()194 }.message shouldBe "expected:<2019-12-10T10:01Z> but was:<2019-12-10T10:00Z>"195 }196 "OffsetDateTime shouldBe before" {197 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC) shouldBe before(LocalDateTime.of(2016, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC))198 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC) shouldNotBe before(LocalDateTime.of(2012, 2, 6, 3, 2, 1).atOffset(ZoneOffset.UTC))199 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC).shouldBeBefore(LocalDateTime.of(2016, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC))200 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC).shouldNotBeBefore(LocalDateTime.of(2012, 2, 6, 3, 2, 1).atOffset(ZoneOffset.UTC))201 }202 "LocalTime shouldBe after" {203 LocalTime.of(1, 2, 3, 9999) shouldBe after(LocalTime.of(1, 2, 3, 1111))204 LocalTime.of(1, 2, 3, 1000) shouldNotBe after(LocalTime.of(1, 2, 10, 1000))205 LocalTime.of(1, 2, 3, 9999).shouldBeAfter(LocalTime.of(1, 2, 3, 1111))206 LocalTime.of(1, 2, 3, 1000).shouldNotBeAfter(LocalTime.of(1, 2, 10, 1000))207 }208 "LocalDate shouldBe after" {209 LocalDate.of(2014, 1, 2) shouldBe after(LocalDate.of(2013, 1, 3))210 LocalDate.of(2014, 1, 2) shouldNotBe after(LocalDate.of(2014, 1, 3))211 LocalDate.of(2014, 1, 2).shouldBeAfter(LocalDate.of(2013, 1, 3))212 LocalDate.of(2014, 1, 2).shouldNotBeAfter(LocalDate.of(2014, 1, 3))213 }214 "LocalDateTime shouldBe after" {215 LocalDateTime.of(2014, 1, 2, 4, 3, 2) shouldBe after(LocalDateTime.of(2014, 1, 1, 3, 2, 1))216 LocalDateTime.of(2014, 1, 2, 3, 2, 1) shouldNotBe after(LocalDateTime.of(2014, 1, 3, 3, 2, 1))217 LocalDateTime.of(2014, 1, 2, 4, 3, 2).shouldBeAfter(LocalDateTime.of(2014, 1, 1, 3, 2, 1))218 LocalDateTime.of(2014, 1, 2, 3, 2, 1).shouldNotBeAfter(LocalDateTime.of(2014, 1, 3, 3, 2, 1))219 }220 "ZonedDateTime shouldBe after" {221 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")) shouldBe after(LocalDateTime.of(2014, 1, 1, 3, 2, 1).atZone(ZoneId.of("Z")))222 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")) shouldNotBe after(LocalDateTime.of(2014, 1, 3, 3, 2, 1).atZone(ZoneId.of("Z")))223 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")).shouldBeAfter(LocalDateTime.of(2014, 1, 1, 3, 2, 1).atZone(ZoneId.of("Z")))224 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")).shouldNotBeAfter(LocalDateTime.of(2014, 1, 3, 3, 2, 1).atZone(ZoneId.of("Z")))225 }226 "OffsetDateTime shouldBe after" {227 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC) shouldBe after(LocalDateTime.of(2014, 1, 1, 3, 2, 1).atOffset(ZoneOffset.UTC))228 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC) shouldNotBe after(LocalDateTime.of(2014, 2, 1, 3, 2, 1).atOffset(ZoneOffset.UTC))229 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC).shouldBeAfter(LocalDateTime.of(2014, 1, 1, 3, 2, 1).atOffset(ZoneOffset.UTC))230 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC).shouldNotBeAfter(LocalDateTime.of(2014, 2, 1, 3, 2, 1).atOffset(ZoneOffset.UTC))231 }232 "LocalDate shouldBe within(period, date)" {233 LocalDate.of(2014, 1, 2) shouldBe within(Period.ofDays(3), LocalDate.of(2014, 1, 1))234 LocalDate.of(2014, 1, 2) shouldBe within(Period.ofDays(3), LocalDate.of(2014, 1, 5))235 LocalDate.of(2014, 1, 2) shouldNotBe within(Period.ofDays(3), LocalDate.of(2014, 1, 6))236 LocalDate.of(2014, 1, 2).shouldBeWithin(Period.ofDays(3), LocalDate.of(2014, 1, 5))237 LocalDate.of(2014, 1, 2).shouldNotBeWithin(Period.ofDays(3), LocalDate.of(2014, 1, 6))238 }239 "LocalDateTime shouldBe within(period, date)" {240 LocalDateTime.of(2014, 1, 2, 4, 3, 2) shouldBe within(Period.ofDays(1), LocalDateTime.of(2014, 1, 2, 9, 3, 2))241 LocalDateTime.of(2014, 1, 2, 3, 2, 1) shouldNotBe within(Period.ofDays(1), LocalDateTime.of(2014, 1, 3, 3, 2, 2))242 LocalDateTime.of(2014, 1, 2, 4, 3, 2).shouldBeWithin(Period.ofDays(1), LocalDateTime.of(2014, 1, 2, 9, 3, 2))243 LocalDateTime.of(2014, 1, 2, 3, 2, 1).shouldNotBeWithin(Period.ofDays(1), LocalDateTime.of(2014, 1, 3, 3, 2, 2))244 }245 "ZonedDateTime shouldBe within(period, date)" {246 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")) shouldBe within(Period.ofDays(1), LocalDateTime.of(2014, 1, 3, 4, 3, 2).atZone(ZoneId.of("Z")))247 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")) shouldBe within(Period.ofDays(1), LocalDateTime.of(2014, 1, 1, 4, 3, 2).atZone(ZoneId.of("Z")))248 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")) shouldBe within(Period.ofDays(1), LocalDateTime.of(2014, 1, 2, 9, 3, 2).atZone(ZoneId.of("Z")))249 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")) shouldNotBe within(Period.ofDays(1), LocalDateTime.of(2014, 1, 3, 3, 2, 2).atZone(ZoneId.of("Z")))250 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")) shouldNotBe within(Period.ofDays(1), LocalDateTime.of(2014, 1, 1, 3, 2, 0).atZone(ZoneId.of("Z")))251 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")).shouldBeWithin(Period.ofDays(1), LocalDateTime.of(2014, 1, 3, 4, 3, 2).atZone(ZoneId.of("Z")))252 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")).shouldBeWithin(Period.ofDays(1), LocalDateTime.of(2014, 1, 1, 4, 3, 2).atZone(ZoneId.of("Z")))253 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")).shouldBeWithin(Period.ofDays(1), LocalDateTime.of(2014, 1, 2, 9, 3, 2).atZone(ZoneId.of("Z")))254 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")).shouldNotBeWithin(Period.ofDays(1), LocalDateTime.of(2014, 1, 3, 3, 2, 2).atZone(ZoneId.of("Z")))255 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")).shouldNotBeWithin(Period.ofDays(1), LocalDateTime.of(2014, 1, 1, 3, 2, 0).atZone(ZoneId.of("Z")))256 }257 "ZonedDateTime shouldBe within(duration, date)" {258 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")) shouldBe within(Duration.ofDays(1), LocalDateTime.of(2014, 1, 3, 4, 3, 2).atZone(ZoneId.of("Z")))259 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")) shouldBe within(Duration.ofDays(1), LocalDateTime.of(2014, 1, 1, 4, 3, 2).atZone(ZoneId.of("Z")))260 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")) shouldBe within(Duration.ofDays(1), LocalDateTime.of(2014, 1, 2, 9, 3, 2).atZone(ZoneId.of("Z")))261 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")) shouldNotBe within(Duration.ofDays(1), LocalDateTime.of(2014, 1, 3, 3, 2, 2).atZone(ZoneId.of("Z")))262 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")) shouldNotBe within(Duration.ofDays(1), LocalDateTime.of(2014, 1, 1, 3, 2, 0).atZone(ZoneId.of("Z")))263 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")).shouldBeWithin(Duration.ofDays(1), LocalDateTime.of(2014, 1, 3, 4, 3, 2).atZone(ZoneId.of("Z")))264 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")).shouldBeWithin(Duration.ofDays(1), LocalDateTime.of(2014, 1, 1, 4, 3, 2).atZone(ZoneId.of("Z")))265 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atZone(ZoneId.of("Z")).shouldBeWithin(Duration.ofDays(1), LocalDateTime.of(2014, 1, 2, 9, 3, 2).atZone(ZoneId.of("Z")))266 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")).shouldNotBeWithin(Duration.ofDays(1), LocalDateTime.of(2014, 1, 3, 3, 2, 2).atZone(ZoneId.of("Z")))267 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atZone(ZoneId.of("Z")).shouldNotBeWithin(Duration.ofDays(1), LocalDateTime.of(2014, 1, 1, 3, 2, 0).atZone(ZoneId.of("Z")))268 }269 "OffsetDateTime shouldBe within(period, date)" {270 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC) shouldBe within(Period.ofDays(1), LocalDateTime.of(2014, 1, 3, 4, 3, 2).atOffset(ZoneOffset.UTC))271 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC) shouldNotBe within(Period.ofDays(1), LocalDateTime.of(2014, 2, 1, 3, 2, 1).atOffset(ZoneOffset.UTC))272 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC).shouldBeWithin(Period.ofDays(1), LocalDateTime.of(2014, 1, 3, 4, 3, 2).atOffset(ZoneOffset.UTC))273 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC).shouldNotBeWithin(Period.ofDays(1), LocalDateTime.of(2014, 2, 1, 3, 2, 1).atOffset(ZoneOffset.UTC))274 }275 "OffsetDateTime shouldBe within(duration, date)" {276 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC) shouldBe within(Duration.ofDays(1), LocalDateTime.of(2014, 1, 3, 4, 3, 2).atOffset(ZoneOffset.UTC))277 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC) shouldNotBe within(Duration.ofDays(1), LocalDateTime.of(2014, 2, 1, 3, 2, 1).atOffset(ZoneOffset.UTC))278 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC).shouldBeWithin(Duration.ofDays(1), LocalDateTime.of(2014, 1, 3, 4, 3, 2).atOffset(ZoneOffset.UTC))279 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC).shouldNotBeWithin(Duration.ofDays(1), LocalDateTime.of(2014, 2, 1, 3, 2, 1).atOffset(ZoneOffset.UTC))280 }281 "LocalTime shouldBe between" {282 LocalTime.of(14, 20, 50, 1000).shouldBeBetween(LocalTime.of(14, 20, 49), LocalTime.of(14, 20, 51))283 LocalTime.of(14, 20, 50, 1000).shouldNotBeBetween(LocalTime.of(14, 20, 51), LocalTime.of(14, 20, 52))284 }285 "LocalDate shouldBe between" {286 LocalDate.of(2019, 2, 16).shouldBeBetween(LocalDate.of(2019, 2, 15), LocalDate.of(2019, 2, 17))287 LocalDate.of(2019, 2, 16).shouldNotBeBetween(LocalDate.of(2019, 2, 17), LocalDate.of(2019, 2, 18))288 }289 "LocalDateTime shouldBe between" {290 LocalDateTime.of(2019, 2, 16, 12, 0, 0).shouldBeBetween(LocalDateTime.of(2019, 2, 15, 12, 0, 0), LocalDateTime.of(2019, 2, 17, 12, 0, 0))291 LocalDateTime.of(2019, 2, 16, 12, 0, 0).shouldBeBetween(LocalDateTime.of(2019, 2, 16, 10, 0, 0), LocalDateTime.of(2019, 2, 16, 14, 0, 0))292 LocalDateTime.of(2019, 2, 16, 12, 0, 0).shouldNotBeBetween(LocalDateTime.of(2019, 2, 17, 12, 0, 0), LocalDateTime.of(2019, 2, 18, 12, 0, 0))293 LocalDateTime.of(2019, 2, 16, 12, 0, 0).shouldNotBeBetween(LocalDateTime.of(2019, 2, 16, 18, 0, 0), LocalDateTime.of(2019, 2, 16, 20, 0, 0))294 }295 "ZonedDateTime shouldBe between" {296 ZonedDateTime.of(2019, 2, 16, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo")).shouldBeBetween(ZonedDateTime.of(2019, 2, 15, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo")), ZonedDateTime.of(2019, 2, 17, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo")))297 ZonedDateTime.of(2019, 2, 16, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo")).shouldNotBeBetween(ZonedDateTime.of(2019, 2, 17, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo")), ZonedDateTime.of(2019, 2, 18, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo")))298 }299 "OffsetDateTime shouldBe between" {300 OffsetDateTime.of(2019, 2, 16, 12, 0, 0, 0, ZoneOffset.ofHours(-3)).shouldBeBetween(OffsetDateTime.of(2019, 2, 15, 12, 0, 0, 0, ZoneOffset.ofHours(-3)), OffsetDateTime.of(2019, 2, 17, 12, 0, 0, 0, ZoneOffset.ofHours(-3)))301 OffsetDateTime.of(2019, 2, 15, 12, 0, 0, 0, ZoneOffset.ofHours(-3)).shouldNotBeBetween(OffsetDateTime.of(2019, 2, 16, 12, 0, 0, 0, ZoneOffset.ofHours(-3)), OffsetDateTime.of(2019, 2, 17, 12, 0, 0, 0, ZoneOffset.ofHours(-3)))302 }303 "LocalDate.shouldBeToday() should match today" {304 LocalDate.now().shouldBeToday()305 }306 "LocalDateTime.shouldBeToday() should match today" {307 LocalDateTime.now().shouldBeToday()308 }309 "LocalDate.shouldBeToday() should not match the past" {310 shouldFail {311 LocalDate.of(2002, Month.APRIL, 1).shouldBeToday()312 }313 }314 "LocalDateTime.shouldBeToday() should not match the past" {315 shouldFail {316 LocalDateTime.of(2002, Month.APRIL, 1, 5, 2).shouldBeToday()317 }318 shouldFail {319 LocalDateTime.now().minusDays(1).shouldBeToday()320 }321 }322 "LocalDateTime.shouldNotBeToday()" {323 LocalDateTime.of(2002, Month.APRIL, 1, 5, 2).shouldNotBeToday()324 shouldFail {325 LocalDateTime.now().shouldNotBeToday()326 }327 }328 "LocalDate.shouldNotBeToday()" {329 LocalDate.of(2002, Month.APRIL, 2).shouldNotBeToday()330 shouldFail {331 LocalDateTime.now().shouldNotBeToday()332 }333 }334 "LocalDateTime should have day of month (day)" {335 LocalDateTime.of(2019, 2, 16, 12, 0, 0, 0) shouldHaveDayOfMonth 16336 }337 "LocalDateTime should have day of week" {338 LocalDateTime.of(2019, 2, 16, 12, 0, 0, 0) shouldHaveDayOfWeek SATURDAY339 LocalDateTime.of(2019, 2, 16, 12, 0, 0, 0) shouldHaveDayOfWeek 6340 }341 "LocalDateTime should have day of year" {342 LocalDateTime.of(2019, 2, 16, 12, 0, 0, 0) shouldHaveDayOfYear 47343 }344 "LocalDateTime should have month" {345 LocalDateTime.of(2019, 2, 16, 12, 0, 0, 0) shouldHaveMonth 2346 LocalDateTime.of(2019, 2, 16, 12, 0, 0, 0) shouldHaveMonth Month.FEBRUARY347 }348 "LocalDateTime should have hour" {349 LocalDateTime.of(2019, 2, 16, 12, 10, 0, 0) shouldHaveHour 12350 }351 "LocalDateTime should have minute" {352 LocalDateTime.of(2019, 2, 16, 12, 10, 0, 0) shouldHaveMinute 10353 }354 "LocalDateTime should have second" {355 LocalDateTime.of(2019, 2, 16, 12, 10, 13, 0) shouldHaveSecond 13356 }357 "LocalDateTime should have nano" {358 LocalDateTime.of(2019, 2, 16, 12, 10, 0, 14) shouldHaveNano 14359 }360 "ZonedDateTime should be have same instant of the given ZonedDateTime irrespective of their timezone" {361 ZonedDateTime.of(2019, 2, 16, 11, 0, 0, 0, ZoneOffset.ofHours(-1)) should haveSameInstantAs(ZonedDateTime.of(2019, 2, 16, 9, 0, 0, 0, ZoneOffset.ofHours(-3)))362 ZonedDateTime.of(2019, 2, 16, 11, 0, 0, 0, ZoneOffset.ofHours(-1)) shouldHaveSameInstantAs ZonedDateTime.of(2019, 2, 16, 9, 0, 0, 0, ZoneOffset.ofHours(-3))363 ZonedDateTime.of(2019, 2, 16, 11, 0, 0, 0, ZoneOffset.ofHours(-1)) shouldNot haveSameInstantAs(ZonedDateTime.of(2019, 2, 16, 9, 0, 0, 0, ZoneOffset.ofHours(-2)))364 ZonedDateTime.of(2019, 2, 16, 11, 0, 0, 0, ZoneOffset.ofHours(-1)) shouldNotHaveSameInstantAs ZonedDateTime.of(2019, 2, 16, 9, 0, 0, 0, ZoneOffset.ofHours(-2))365 }366 }367}...

Full Screen

Full Screen

BehandlingTilstandTjenesteTest.kt

Source:BehandlingTilstandTjenesteTest.kt Github

copy

Full Screen

1package no.nav.familie.tilbake.datavarehus.saksstatistikk2import io.kotest.matchers.date.shouldBeBetween3import io.kotest.matchers.nulls.shouldBeNull4import io.kotest.matchers.nulls.shouldNotBeNull5import io.kotest.matchers.should6import io.kotest.matchers.shouldBe7import no.nav.familie.kontrakter.felles.Fagsystem8import no.nav.familie.kontrakter.felles.Språkkode9import no.nav.familie.kontrakter.felles.tilbakekreving.Faktainfo10import no.nav.familie.kontrakter.felles.tilbakekreving.OpprettTilbakekrevingRequest11import no.nav.familie.kontrakter.felles.tilbakekreving.Periode12import no.nav.familie.kontrakter.felles.tilbakekreving.Tilbakekrevingsvalg13import no.nav.familie.kontrakter.felles.tilbakekreving.Tilbakekrevingsvalg.OPPRETT_TILBAKEKREVING_MED_VARSEL14import no.nav.familie.kontrakter.felles.tilbakekreving.Tilbakekrevingsvalg.OPPRETT_TILBAKEKREVING_UTEN_VARSEL15import no.nav.familie.kontrakter.felles.tilbakekreving.Varsel16import no.nav.familie.kontrakter.felles.tilbakekreving.Ytelsestype17import no.nav.familie.prosessering.internal.TaskService18import no.nav.familie.tilbake.OppslagSpringRunnerTest19import no.nav.familie.tilbake.api.dto.BehandlingPåVentDto20import no.nav.familie.tilbake.behandling.BehandlingRepository21import no.nav.familie.tilbake.behandling.BehandlingService22import no.nav.familie.tilbake.behandling.FagsakRepository23import no.nav.familie.tilbake.behandling.domain.Behandling24import no.nav.familie.tilbake.behandling.domain.Behandlingsresultat25import no.nav.familie.tilbake.behandling.domain.Behandlingsresultatstype26import no.nav.familie.tilbake.behandling.domain.Behandlingsstatus27import no.nav.familie.tilbake.behandling.domain.Behandlingstype28import no.nav.familie.tilbake.behandlingskontroll.BehandlingsstegstilstandRepository29import no.nav.familie.tilbake.behandlingskontroll.domain.Behandlingssteg30import no.nav.familie.tilbake.behandlingskontroll.domain.Venteårsak31import no.nav.familie.tilbake.common.repository.findByIdOrThrow32import no.nav.familie.tilbake.data.Testdata33import no.nav.familie.tilbake.faktaomfeilutbetaling.FaktaFeilutbetalingService34import no.nav.familie.tilbake.kravgrunnlag.KravgrunnlagRepository35import org.junit.jupiter.api.BeforeEach36import org.junit.jupiter.api.Test37import org.springframework.beans.factory.annotation.Autowired38import java.math.BigDecimal39import java.time.LocalDate40import java.time.OffsetDateTime41import java.time.YearMonth42import java.util.UUID43class BehandlingTilstandServiceTest : OppslagSpringRunnerTest() {44 @Autowired45 private lateinit var behandlingRepository: BehandlingRepository46 @Autowired47 private lateinit var behandlingsstegstilstandRepository: BehandlingsstegstilstandRepository48 @Autowired49 private lateinit var fagsakRepository: FagsakRepository50 @Autowired51 private lateinit var taskService: TaskService52 @Autowired53 private lateinit var behandlingService: BehandlingService54 @Autowired55 private lateinit var faktaFeilutbetalingService: FaktaFeilutbetalingService56 @Autowired57 private lateinit var kravgrunnlagRepository: KravgrunnlagRepository58 private lateinit var service: BehandlingTilstandService59 private lateinit var behandling: Behandling60 @BeforeEach61 fun setup() {62 service = BehandlingTilstandService(behandlingRepository,63 behandlingsstegstilstandRepository,64 fagsakRepository,65 taskService,66 faktaFeilutbetalingService)67 fagsakRepository.insert(Testdata.fagsak)68 behandling = behandlingRepository.insert(Testdata.behandling)69 }70 @Test71 fun `hentBehandlingensTilstand skal utlede behandlingtilstand for nyopprettet behandling`() {72 val behandling = behandlingService.opprettBehandling(lagOpprettTilbakekrevingRequest(true,73 OPPRETT_TILBAKEKREVING_MED_VARSEL))74 val tilstand = service.hentBehandlingensTilstand(behandling.id)75 tilstand.ytelsestype shouldBe Ytelsestype.BARNETRYGD76 tilstand.saksnummer shouldBe "1234567"77 tilstand.behandlingUuid shouldBe behandling.eksternBrukId78 tilstand.referertFagsaksbehandling shouldBe behandling.aktivFagsystemsbehandling.eksternId79 tilstand.behandlingstype shouldBe Behandlingstype.TILBAKEKREVING80 tilstand.behandlingsstatus shouldBe Behandlingsstatus.UTREDES81 tilstand.behandlingsresultat shouldBe Behandlingsresultatstype.IKKE_FASTSATT82 tilstand.venterPåBruker shouldBe true83 tilstand.venterPåØkonomi shouldBe false84 tilstand.behandlingErManueltOpprettet shouldBe false85 tilstand.funksjoneltTidspunkt.shouldBeBetween(OffsetDateTime.now().minusMinutes(1), OffsetDateTime.now().plusSeconds(1))86 tilstand.tekniskTidspunkt shouldBe null87 tilstand.ansvarligBeslutter shouldBe behandling.ansvarligBeslutter88 tilstand.ansvarligSaksbehandler shouldBe behandling.ansvarligSaksbehandler89 tilstand.ansvarligEnhet shouldBe behandling.behandlendeEnhet90 tilstand.totalFeilutbetaltBeløp shouldBe BigDecimal("1500")91 tilstand.totalFeilutbetaltPeriode.shouldNotBeNull()92 tilstand.totalFeilutbetaltPeriode!!.should {93 it.fom == YearMonth.now().minusMonths(1).atDay(1) &&94 it.tom == YearMonth.now().atEndOfMonth()95 }96 }97 @Test98 fun `hentBehandlingensTilstand skal utlede behandlingtilstand for nyopprettet behandling uten varsel`() {99 val behandling = behandlingService.opprettBehandling(lagOpprettTilbakekrevingRequest(false,100 OPPRETT_TILBAKEKREVING_UTEN_VARSEL))101 val tilstand = service.hentBehandlingensTilstand(behandling.id)102 tilstand.ytelsestype shouldBe Ytelsestype.BARNETRYGD103 tilstand.saksnummer shouldBe "1234567"104 tilstand.behandlingUuid shouldBe behandling.eksternBrukId105 tilstand.referertFagsaksbehandling shouldBe behandling.aktivFagsystemsbehandling.eksternId106 tilstand.behandlingstype shouldBe Behandlingstype.TILBAKEKREVING107 tilstand.behandlingsstatus shouldBe Behandlingsstatus.UTREDES108 tilstand.behandlingsresultat shouldBe Behandlingsresultatstype.IKKE_FASTSATT109 tilstand.venterPåBruker shouldBe false110 tilstand.venterPåØkonomi shouldBe true111 tilstand.behandlingErManueltOpprettet shouldBe false112 tilstand.funksjoneltTidspunkt.shouldBeBetween(OffsetDateTime.now().minusMinutes(1), OffsetDateTime.now().plusSeconds(1))113 tilstand.tekniskTidspunkt shouldBe null114 tilstand.ansvarligBeslutter shouldBe behandling.ansvarligBeslutter115 tilstand.ansvarligSaksbehandler shouldBe behandling.ansvarligSaksbehandler116 tilstand.ansvarligEnhet shouldBe behandling.behandlendeEnhet117 tilstand.totalFeilutbetaltBeløp.shouldBeNull()118 tilstand.totalFeilutbetaltPeriode.shouldBeNull()119 }120 @Test121 fun `hentBehandlingensTilstand skal utlede behandlingtilstand for fattet behandling`() {122 val behandlingsresultat = Behandlingsresultat(type = Behandlingsresultatstype.FULL_TILBAKEBETALING)123 val fattetBehandling = behandling.copy(behandlendeEnhet = "1234", behandlendeEnhetsNavn = "foo bar",124 ansvarligSaksbehandler = "Z111111",125 ansvarligBeslutter = "Z111112",126 resultater = setOf(behandlingsresultat))127 behandlingRepository.update(fattetBehandling)128 behandlingsstegstilstandRepository.insert(Testdata.behandlingsstegstilstand.copy(behandlingssteg = Behandlingssteg.FATTE_VEDTAK))129 kravgrunnlagRepository.insert(Testdata.kravgrunnlag431)130 val tilstand = service.hentBehandlingensTilstand(behandling.id)131 tilstand.ytelsestype shouldBe Ytelsestype.BARNETRYGD132 tilstand.saksnummer shouldBe Testdata.fagsak.eksternFagsakId133 tilstand.behandlingUuid shouldBe behandling.eksternBrukId134 tilstand.referertFagsaksbehandling shouldBe behandling.aktivFagsystemsbehandling.eksternId135 tilstand.behandlingstype shouldBe behandling.type136 tilstand.behandlingsstatus shouldBe behandling.status137 tilstand.behandlingsresultat shouldBe behandlingsresultat.type138 tilstand.venterPåBruker shouldBe false139 tilstand.venterPåØkonomi shouldBe false140 tilstand.behandlingErManueltOpprettet shouldBe false141 tilstand.funksjoneltTidspunkt.shouldBeBetween(OffsetDateTime.now().minusMinutes(1), OffsetDateTime.now().plusSeconds(1))142 tilstand.tekniskTidspunkt shouldBe null143 tilstand.ansvarligBeslutter shouldBe "Z111112"144 tilstand.ansvarligSaksbehandler shouldBe "Z111111"145 tilstand.ansvarligEnhet shouldBe "1234"146 tilstand.totalFeilutbetaltBeløp shouldBe BigDecimal("10000.00")147 tilstand.totalFeilutbetaltPeriode.shouldNotBeNull()148 tilstand.totalFeilutbetaltPeriode!!.should {149 it.fom == YearMonth.now().minusMonths(1).atDay(1) &&150 it.tom == YearMonth.now().atEndOfMonth()151 }152 }153 @Test154 fun `hentBehandlingensTilstand skal utlede behandlingstilstand for behandling på vent`() {155 behandlingsstegstilstandRepository.insert(Testdata.behandlingsstegstilstand)156 kravgrunnlagRepository.insert(Testdata.kravgrunnlag431)157 behandlingService.settBehandlingPåVent(behandling.id,158 BehandlingPåVentDto(Venteårsak.VENT_PÅ_BRUKERTILBAKEMELDING,159 LocalDate.now().plusDays(1)))160 behandling = behandlingRepository.findByIdOrThrow(behandling.id)161 val tilstand = service.hentBehandlingensTilstand(behandling.id)162 tilstand.ytelsestype shouldBe Ytelsestype.BARNETRYGD163 tilstand.saksnummer shouldBe Testdata.fagsak.eksternFagsakId164 tilstand.behandlingUuid shouldBe behandling.eksternBrukId165 tilstand.referertFagsaksbehandling shouldBe behandling.aktivFagsystemsbehandling.eksternId166 tilstand.behandlingstype shouldBe behandling.type167 tilstand.behandlingsstatus shouldBe behandling.status168 tilstand.behandlingsresultat shouldBe Testdata.behandlingsresultat.type169 tilstand.venterPåBruker shouldBe true170 tilstand.venterPåØkonomi shouldBe false171 tilstand.funksjoneltTidspunkt.shouldBeBetween(OffsetDateTime.now().minusMinutes(1),172 OffsetDateTime.now().plusSeconds(1))173 tilstand.totalFeilutbetaltBeløp shouldBe BigDecimal("10000.00")174 tilstand.totalFeilutbetaltPeriode.shouldNotBeNull()175 tilstand.totalFeilutbetaltPeriode!!.should {176 it.fom == YearMonth.now().minusMonths(1).atDay(1) &&177 it.tom == YearMonth.now().atEndOfMonth()178 }179 }180 private fun lagOpprettTilbakekrevingRequest(finnesVarsel: Boolean,181 tilbakekrevingsvalg: Tilbakekrevingsvalg): OpprettTilbakekrevingRequest {182 val fom = YearMonth.now().minusMonths(1).atDay(1)183 val tom = YearMonth.now().atEndOfMonth()184 val varsel = if (finnesVarsel) Varsel(varseltekst = "testverdi",185 sumFeilutbetaling = BigDecimal.valueOf(1500L),186 perioder = listOf(Periode(fom, tom))) else null187 val faktainfo = Faktainfo(revurderingsårsak = "testverdi",188 revurderingsresultat = "testresultat",189 tilbakekrevingsvalg = tilbakekrevingsvalg)190 return OpprettTilbakekrevingRequest(ytelsestype = Ytelsestype.BARNETRYGD,191 fagsystem = Fagsystem.BA,192 eksternFagsakId = "1234567",193 personIdent = "321321322",194 eksternId = UUID.randomUUID().toString(),195 manueltOpprettet = false,196 språkkode = Språkkode.NN,197 enhetId = "8020",198 enhetsnavn = "Oslo",199 varsel = varsel,200 revurderingsvedtaksdato = fom,201 faktainfo = faktainfo,202 saksbehandlerIdent = "Z0000")203 }204}...

Full Screen

Full Screen

matchers.kt

Source:matchers.kt Github

copy

Full Screen

1package tutorial.kotest2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.assertions.throwables.shouldThrowAny4import io.kotest.assertions.throwables.shouldThrowExactly5import io.kotest.core.spec.style.DescribeSpec6import io.kotest.core.test.AssertionMode7import io.kotest.matchers.booleans.shouldBeTrue8import io.kotest.matchers.collections.shouldBeIn9import io.kotest.matchers.collections.shouldBeOneOf10import io.kotest.matchers.collections.shouldBeSameSizeAs11import io.kotest.matchers.collections.shouldBeSingleton12import io.kotest.matchers.collections.shouldBeSmallerThan13import io.kotest.matchers.collections.shouldBeSorted14import io.kotest.matchers.collections.shouldBeUnique15import io.kotest.matchers.collections.shouldContain16import io.kotest.matchers.collections.shouldContainAll17import io.kotest.matchers.collections.shouldContainAnyOf18import io.kotest.matchers.collections.shouldContainDuplicates19import io.kotest.matchers.collections.shouldContainExactly20import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder21import io.kotest.matchers.collections.shouldContainInOrder22import io.kotest.matchers.collections.shouldContainNull23import io.kotest.matchers.collections.shouldEndWith24import io.kotest.matchers.collections.shouldHaveAtLeastSize25import io.kotest.matchers.collections.shouldHaveLowerBound26import io.kotest.matchers.collections.shouldHaveSingleElement27import io.kotest.matchers.collections.shouldHaveSize28import io.kotest.matchers.collections.shouldHaveUpperBound29import io.kotest.matchers.collections.shouldNotContainAnyOf30import io.kotest.matchers.collections.shouldNotHaveElementAt31import io.kotest.matchers.collections.shouldStartWith32import io.kotest.matchers.comparables.shouldBeEqualComparingTo33import io.kotest.matchers.comparables.shouldBeLessThanOrEqualTo34import io.kotest.matchers.date.shouldBeToday35import io.kotest.matchers.date.shouldHaveSameHoursAs36import io.kotest.matchers.doubles.Percentage37import io.kotest.matchers.doubles.beNaN38import io.kotest.matchers.doubles.plusOrMinus39import io.kotest.matchers.doubles.shouldBeNaN40import io.kotest.matchers.doubles.shouldNotBeNaN41import io.kotest.matchers.equality.shouldBeEqualToComparingFields42import io.kotest.matchers.equality.shouldBeEqualToComparingFieldsExcept43import io.kotest.matchers.equality.shouldBeEqualToIgnoringFields44import io.kotest.matchers.equality.shouldBeEqualToUsingFields45import io.kotest.matchers.file.shouldBeADirectory46import io.kotest.matchers.file.shouldBeAbsolute47import io.kotest.matchers.file.shouldExist48import io.kotest.matchers.file.shouldNotBeEmpty49import io.kotest.matchers.ints.beOdd50import io.kotest.matchers.ints.shouldBeBetween51import io.kotest.matchers.ints.shouldBeInRange52import io.kotest.matchers.ints.shouldBeLessThan53import io.kotest.matchers.ints.shouldBeLessThanOrEqual54import io.kotest.matchers.ints.shouldBeOdd55import io.kotest.matchers.ints.shouldBePositive56import io.kotest.matchers.ints.shouldBeZero57import io.kotest.matchers.iterator.shouldBeEmpty58import io.kotest.matchers.iterator.shouldHaveNext59import io.kotest.matchers.maps.shouldBeEmpty60import io.kotest.matchers.maps.shouldContain61import io.kotest.matchers.maps.shouldContainAll62import io.kotest.matchers.maps.shouldContainExactly63import io.kotest.matchers.maps.shouldContainKey64import io.kotest.matchers.nulls.shouldBeNull65import io.kotest.matchers.nulls.shouldNotBeNull66import io.kotest.matchers.shouldBe67import io.kotest.matchers.shouldNot68import io.kotest.matchers.shouldNotBe69import io.kotest.matchers.string.beEmpty70import io.kotest.matchers.string.shouldBeBlank71import io.kotest.matchers.string.shouldBeEmpty72import io.kotest.matchers.string.shouldBeEqualIgnoringCase73import io.kotest.matchers.string.shouldBeInteger74import io.kotest.matchers.string.shouldBeLowerCase75import io.kotest.matchers.string.shouldBeUpperCase76import io.kotest.matchers.string.shouldContain77import io.kotest.matchers.string.shouldContainADigit78import io.kotest.matchers.string.shouldContainIgnoringCase79import io.kotest.matchers.string.shouldContainOnlyDigits80import io.kotest.matchers.string.shouldContainOnlyOnce81import io.kotest.matchers.string.shouldEndWith82import io.kotest.matchers.string.shouldHaveLength83import io.kotest.matchers.string.shouldHaveLineCount84import io.kotest.matchers.string.shouldHaveMaxLength85import io.kotest.matchers.string.shouldHaveMinLength86import io.kotest.matchers.string.shouldHaveSameLengthAs87import io.kotest.matchers.string.shouldMatch88import io.kotest.matchers.string.shouldNotBeEmpty89import io.kotest.matchers.string.shouldStartWith90import io.kotest.matchers.throwable.shouldHaveCause91import io.kotest.matchers.throwable.shouldHaveCauseInstanceOf92import io.kotest.matchers.throwable.shouldHaveCauseOfType93import io.kotest.matchers.throwable.shouldHaveMessage94import io.kotest.matchers.types.shouldBeInstanceOf95import io.kotest.matchers.types.shouldBeSameInstanceAs96import io.kotest.matchers.types.shouldBeTypeOf97import io.kotest.matchers.uri.shouldHaveHost98import io.kotest.matchers.uri.shouldHavePort99import io.kotest.matchers.uri.shouldHaveScheme100import java.io.File101import java.net.URI102import java.time.LocalDate103import java.time.LocalTime104// https://kotest.io/docs/assertions/core-matchers.html105class MatchersTest : DescribeSpec({106 describe("general") {107 it("basics") {108 (1 == 1).shouldBeTrue()109 (2 + 2) shouldBe 4110 val foo: Any = "foobar"111 foo.shouldBeTypeOf<String>() shouldContain "fo"112 "".shouldBeEmpty()113 "x".shouldNot(beEmpty()) // manually negate114 "x".shouldNotBeEmpty() // reusable115 URI("https://tba") shouldHaveHost "tba"116 URI("https://tba:81") shouldHavePort 81117 URI("https://tba") shouldHaveScheme "https"118 File("/").apply {119 shouldExist()120 shouldBeADirectory()121 shouldBeAbsolute()122 shouldNotBeEmpty()123 }124 // executable, hidden, readable, smaller, writeable, containFile, extension, path, ...125 LocalDate.now().shouldBeToday()126 // before/after, within, same, between, have year/month/day/hour/...127 LocalTime.now().shouldHaveSameHoursAs(LocalTime.now())128 // before/after/between, sameMinute/Seconds/Nanos129 }130 it("numbers") {131 1 shouldBeLessThan 2132 1 shouldBeLessThanOrEqual 1 // Int-based; returns this133 1 shouldBeLessThanOrEqualTo 1 // Comparble-based; void134 1 shouldBeEqualComparingTo 1 // Comparable-based135 1.shouldBeBetween(0, 2)136 1 shouldBeInRange 0..2137 0.shouldBeZero()138 1.shouldBePositive()139 1.shouldBeOdd()140 (1.2).shouldBe(1.20001.plusOrMinus(Percentage(20.0)))141 (1.2).shouldNotBeNaN()142 }143 it("strings") {144 // generic: "abc" shouldBe "abc"145 "aBc" shouldBeEqualIgnoringCase "abc"146 "".shouldBeEmpty()147 " ".shouldBeBlank() // empty or whitespace148 "abc" shouldContain ("b")149 "aBc" shouldContainIgnoringCase "bc"150 "x-a-x" shouldContain """\-[a-z]\-""".toRegex()151 "-a-" shouldMatch """\-[a-z]\-""".toRegex()152 "abc" shouldStartWith ("a")153 "abc" shouldEndWith ("c")154 "ab aa" shouldContainOnlyOnce "aa"155 "abc".shouldBeLowerCase()156 "ABC".shouldBeUpperCase()157 "abc" shouldHaveLength 3158 "a\nb" shouldHaveLineCount 2159 "ab" shouldHaveMinLength 1 shouldHaveMaxLength 3160 "abc" shouldHaveSameLengthAs "foo"161 "1".shouldBeInteger()162 "12".shouldContainOnlyDigits()163 "abc1".shouldContainADigit() // at least one164 }165 it("types") {166 @Connotation167 open class SuperType()168 class SubType : SuperType()169 val sameRef = SuperType()170 sameRef.shouldBeSameInstanceAs(sameRef)171 val superType: SuperType = SubType()172 superType.shouldBeTypeOf<SubType>() // exact runtime match (SuperType won't work!)173 superType.shouldBeInstanceOf<SuperType>() // T or below174// SubType().shouldHaveAnnotation(Connotation::class)175 val nullable: String? = null176 nullable.shouldBeNull()177 }178 it("collections") {179 emptyList<Int>().iterator().shouldBeEmpty()180 listOf(1).iterator().shouldHaveNext()181 listOf(1, 2) shouldContain 1 // at least182 listOf(1, 2) shouldContainExactly listOf(1, 2) // in-order; not more183 listOf(1, 2) shouldContainExactlyInAnyOrder listOf(2, 1) // out-order; not more184 listOf(0, 3, 0, 4, 0).shouldContainInOrder(3, 4) // possible items in between185 listOf(1) shouldNotContainAnyOf listOf(2, 3) // black list186 listOf(1, 2, 3) shouldContainAll listOf(3, 2) // out-order; more187 listOf(1, 2, 3).shouldBeUnique() // no duplicates188 listOf(1, 2, 2).shouldContainDuplicates() // at least one duplicate189 listOf(1, 2).shouldNotHaveElementAt(1, 3)190 listOf(1, 2) shouldStartWith 1191 listOf(1, 2) shouldEndWith 2192 listOf(1, 2) shouldContainAnyOf listOf(2, 3)193 val x = SomeType(1)194 x shouldBeOneOf listOf(x) // by reference/instance195 x shouldBeIn listOf(SomeType(1)) // by equality/structural196 listOf(1, 2, null).shouldContainNull()197 listOf(1) shouldHaveSize 1198 listOf(1).shouldBeSingleton() // size == 1199 listOf(1).shouldBeSingleton {200 it.shouldBeOdd()201 }202 listOf(1).shouldHaveSingleElement {203 beOdd().test(it).passed() // have to return a boolean here :-/204 }205 listOf(2, 3) shouldHaveLowerBound 1 shouldHaveUpperBound 4206 listOf(1) shouldBeSmallerThan listOf(1, 2)207 listOf(1) shouldBeSameSizeAs listOf(2)208 listOf(1, 2) shouldHaveAtLeastSize 1209 listOf(1, 2).shouldBeSorted()210 mapOf(1 to "a").shouldContain(1, "a") // at least this211 mapOf(1 to "a") shouldContainAll mapOf(1 to "a") // at least those212 mapOf(1 to "a") shouldContainExactly mapOf(1 to "a") // not more213 mapOf(1 to "a") shouldContainKey 1214 emptyMap<Any, Any>().shouldBeEmpty()215 }216 it("exceptions") {217 class SubException() : Exception()218 Exception("a") shouldHaveMessage "a" // same (not contains!)219 Exception("abc").message shouldContain "b"220 Exception("", Exception()).shouldHaveCause()221 Exception("symptom", Exception("cause")).shouldHaveCause {222 it.message shouldBe "cause"223 }224 Exception("", SubException()).shouldHaveCauseInstanceOf<Exception>() // T or subclass225 Exception("", SubException()).shouldHaveCauseOfType<SubException>() // exactly T226 shouldThrow<Exception> { // type or subtype227 throw SubException()228 }229 shouldThrowExactly<Exception> { // exactly that type (no subtype!)230 throw Exception()231 }232 shouldThrowAny { // don't care which233 throw Exception()234 }235 }236 }237 describe("advanced") {238 it("selective matcheres") {239 data class Foo(val p1: Int, val p2: Int)240 val foo1 = Foo(1, 1)241 val foo2 = Foo(1, 2)242 foo1.shouldBeEqualToUsingFields(foo2, Foo::p1)243 foo1.shouldBeEqualToIgnoringFields(foo2, Foo::p2)244 class Bar(val p1: Int, val p2: Int) // not a data class! no equals.245 val bar1a = Bar(1, 1)246 val bar1b = Bar(1, 1)247 bar1a shouldNotBe bar1b248 bar1a shouldBeEqualToComparingFields bar1b // "fake equals" (ignoring private properties)249 bar1a.shouldBeEqualToComparingFields(bar1b, false) // explicitly also check private props250 val bar2 = Bar(1, 2)251 bar1a.shouldBeEqualToComparingFieldsExcept(bar2, Bar::p2)252 }253 }254 // channels255 // concurrent, futures256 // result, optional257 // threads258 // reflection259 // statistic, regex260})261private data class SomeType(val value: Int = 1)262private annotation class Connotation...

Full Screen

Full Screen

LocalDateTimeTests.kt

Source:LocalDateTimeTests.kt Github

copy

Full Screen

1package io.kotest.matchers.kotlinx.datetime2import io.kotest.assertions.shouldFail3import io.kotest.core.spec.style.StringSpec4import io.kotest.matchers.should5import io.kotest.matchers.shouldBe6import io.kotest.matchers.shouldNot7import io.kotest.matchers.shouldNotBe8import kotlinx.datetime.Clock9import kotlinx.datetime.DayOfWeek10import kotlinx.datetime.LocalDate11import kotlinx.datetime.LocalDateTime12import kotlinx.datetime.Month13import kotlinx.datetime.TimeZone14import kotlinx.datetime.toLocalDateTime15import kotlinx.datetime.todayAt16import kotlin.time.days17class LocalDateTimeTests : StringSpec({18 "LocalDateTime should have same year ignoring other fields" {19 LocalDateTime(2014, 1, 2, 4, 3, 2) should haveSameYear(LocalDateTime(2014, 5, 6, 3, 2, 1))20 LocalDateTime(2014, 1, 2, 3, 2, 1) shouldNot haveSameYear(LocalDateTime(2018, 5, 6, 3, 2, 1))21 LocalDateTime(2014, 1, 2, 4, 3, 2).shouldHaveSameYearAs(LocalDateTime(2014, 5, 6, 3, 2, 1))22 LocalDateTime(2014, 1, 2, 3, 2, 1).shouldNotHaveSameYearAs(LocalDateTime(2018, 5, 6, 3, 2, 1))23 }24 "LocalDate should have same month ignoring other fields" {25 LocalDate(2014, 1, 2) should haveSameMonth(LocalDate(2016, 1, 6))26 LocalDate(2014, 1, 2) shouldNot haveSameMonth(LocalDate(2018, 4, 6))27 LocalDate(2014, 1, 2).shouldHaveSameMonthAs(LocalDate(2016, 1, 6))28 LocalDate(2014, 1, 2).shouldNotHaveSameMonthAs(LocalDate(2018, 4, 6))29 }30 "LocalDateTime should have same month ignoring other fields" {31 LocalDateTime(2014, 1, 2, 4, 3, 2) should haveSameMonth(LocalDateTime(2014, 1, 6, 3, 2, 1))32 LocalDateTime(2014, 1, 2, 3, 2, 1) shouldNot haveSameMonth(LocalDateTime(2018, 2, 6, 3, 2, 1))33 LocalDateTime(2014, 1, 2, 4, 3, 2).shouldHaveSameMonthAs(LocalDateTime(2014, 1, 6, 3, 2, 1))34 LocalDateTime(2014, 1, 2, 3, 2, 1).shouldNotHaveSameMonthAs(LocalDateTime(2018, 2, 6, 3, 2, 1))35 }36 "LocalDate should have same day ignoring other fields" {37 LocalDate(2014, 1, 2) should haveSameDay(LocalDate(2014, 1, 2))38 LocalDate(2014, 1, 2) shouldNot haveSameDay(LocalDate(2014, 4, 6))39 LocalDate(2014, 1, 2).shouldHaveSameDayAs(LocalDate(2014, 1, 2))40 LocalDate(2014, 1, 2).shouldNotHaveSameDayAs(LocalDate(2014, 4, 6))41 }42 "LocalDateTime should have same day ignoring other fields" {43 LocalDateTime(2014, 1, 2, 4, 3, 2) should haveSameDay(LocalDateTime(2014, 1, 2, 3, 2, 1))44 LocalDateTime(2014, 1, 2, 3, 2, 1) shouldNot haveSameDay(LocalDateTime(2014, 2, 6, 3, 2, 1))45 LocalDateTime(2014, 1, 2, 4, 3, 2).shouldHaveSameDayAs(LocalDateTime(2014, 1, 2, 3, 2, 1))46 LocalDateTime(2014, 1, 2, 3, 2, 1).shouldNotHaveSameDayAs(LocalDateTime(2014, 2, 6, 3, 2, 1))47 }48 "LocalDate shouldBe before" {49 LocalDate(2014, 1, 2) shouldBe before(LocalDate(2014, 1, 3))50 LocalDate(2014, 1, 2) shouldNotBe before(LocalDate(2014, 1, 1))51 LocalDate(2014, 1, 2).shouldBeBefore(LocalDate(2014, 1, 3))52 LocalDate(2014, 1, 2).shouldNotBeBefore(LocalDate(2014, 1, 1))53 }54 "LocalDateTime shouldBe before" {55 LocalDateTime(2014, 1, 2, 4, 3, 2) shouldBe before(LocalDateTime(2014, 2, 2, 3, 2, 1))56 LocalDateTime(2014, 1, 2, 3, 2, 1) shouldNotBe before(LocalDateTime(2014, 1, 1, 3, 2, 1))57 LocalDateTime(2014, 1, 2, 4, 3, 2).shouldBeBefore(LocalDateTime(2014, 2, 2, 3, 2, 1))58 LocalDateTime(2014, 1, 2, 3, 2, 1).shouldNotBeBefore(LocalDateTime(2014, 1, 1, 3, 2, 1))59 }60 "LocalDate shouldBe after" {61 LocalDate(2014, 1, 2) shouldBe after(LocalDate(2013, 1, 3))62 LocalDate(2014, 1, 2) shouldNotBe after(LocalDate(2014, 1, 3))63 LocalDate(2014, 1, 2).shouldBeAfter(LocalDate(2013, 1, 3))64 LocalDate(2014, 1, 2).shouldNotBeAfter(LocalDate(2014, 1, 3))65 }66 "LocalDateTime shouldBe after" {67 LocalDateTime(2014, 1, 2, 4, 3, 2) shouldBe after(LocalDateTime(2014, 1, 1, 3, 2, 1))68 LocalDateTime(2014, 1, 2, 3, 2, 1) shouldNotBe after(LocalDateTime(2014, 1, 3, 3, 2, 1))69 LocalDateTime(2014, 1, 2, 4, 3, 2).shouldBeAfter(LocalDateTime(2014, 1, 1, 3, 2, 1))70 LocalDateTime(2014, 1, 2, 3, 2, 1).shouldNotBeAfter(LocalDateTime(2014, 1, 3, 3, 2, 1))71 }72 "LocalDateTime shouldBe between" {73 LocalDateTime(2019, 2, 16, 12, 0, 0).shouldBeBetween(LocalDateTime(2019, 2, 15, 12, 0, 0), LocalDateTime(2019, 2, 17, 12, 0, 0))74 LocalDateTime(2019, 2, 16, 12, 0, 0).shouldBeBetween(LocalDateTime(2019, 2, 16, 10, 0, 0), LocalDateTime(2019, 2, 16, 14, 0, 0))75 LocalDateTime(2019, 2, 16, 12, 0, 0).shouldNotBeBetween(LocalDateTime(2019, 2, 17, 12, 0, 0), LocalDateTime(2019, 2, 18, 12, 0, 0))76 LocalDateTime(2019, 2, 16, 12, 0, 0).shouldNotBeBetween(LocalDateTime(2019, 2, 16, 18, 0, 0), LocalDateTime(2019, 2, 16, 20, 0, 0))77 }78 "LocalDate.shouldBeToday() should match today" {79 Clock.System.todayAt(TimeZone.UTC).shouldBeToday(TimeZone.UTC)80 }81 "LocalDateTime.shouldBeToday() should match today" {82 Clock.System.todayAt(TimeZone.UTC).shouldBeToday(TimeZone.UTC)83 }84 "LocalDate.shouldBeToday() should not match the past" {85 shouldFail {86 LocalDate(2002, Month.APRIL, 1).shouldBeToday(TimeZone.UTC)87 }88 }89 "LocalDateTime.shouldBeToday() should not match the past" {90 shouldFail {91 LocalDateTime(2002, Month.APRIL, 1, 5, 2).shouldBeToday(TimeZone.UTC)92 }93 shouldFail {94 Clock.System.now().minus(1.days).toLocalDateTime(TimeZone.UTC).shouldBeToday(TimeZone.UTC)95 }96 }97 "LocalDateTime.shouldNotBeToday()" {98 LocalDateTime(2002, Month.APRIL, 1, 5, 2).shouldNotBeToday(TimeZone.UTC)99 shouldFail {100 Clock.System.todayAt(TimeZone.UTC).shouldNotBeToday(TimeZone.UTC)101 }102 }103 "LocalDate.shouldNotBeToday()" {104 LocalDate(2002, Month.APRIL, 2).shouldNotBeToday()105 shouldFail {106 Clock.System.todayAt(TimeZone.UTC).shouldNotBeToday(TimeZone.UTC)107 }108 }109 "LocalDateTime should have day of month (day)" {110 LocalDateTime(2019, 2, 16, 12, 0, 0, 0) shouldHaveDayOfMonth 16111 }112 "LocalDateTime should have day of week" {113 LocalDateTime(2019, 2, 16, 12, 0, 0, 0) shouldHaveDayOfWeek DayOfWeek.SATURDAY114 LocalDateTime(2019, 2, 16, 12, 0, 0, 0) shouldHaveDayOfWeek 6115 }116 "LocalDateTime should have day of year" {117 LocalDateTime(2019, 2, 16, 12, 0, 0, 0) shouldHaveDayOfYear 47118 }119 "LocalDateTime should have month" {120 LocalDateTime(2019, 2, 16, 12, 0, 0, 0) shouldHaveMonth 2121 LocalDateTime(2019, 2, 16, 12, 0, 0, 0) shouldHaveMonth Month.FEBRUARY122 }123 "LocalDateTime should have hour" {124 LocalDateTime(2019, 2, 16, 12, 10, 0, 0) shouldHaveHour 12125 }126 "LocalDateTime should have minute" {127 LocalDateTime(2019, 2, 16, 12, 10, 0, 0) shouldHaveMinute 10128 }129 "LocalDateTime should have second" {130 LocalDateTime(2019, 2, 16, 12, 10, 13, 0) shouldHaveSecond 13131 }132 "LocalDateTime should have nano" {133 LocalDateTime(2019, 2, 16, 12, 10, 0, 14) shouldHaveNano 14134 }135})...

Full Screen

Full Screen

TidspunktTest.kt

Source:TidspunktTest.kt Github

copy

Full Screen

1package no.nav.su.se.bakover.common2import io.kotest.matchers.comparables.shouldBeGreaterThan3import io.kotest.matchers.comparables.shouldBeLessThan4import io.kotest.matchers.comparables.shouldNotBeLessThan5import io.kotest.matchers.ints.shouldBeBetween6import io.kotest.matchers.shouldBe7import io.kotest.matchers.shouldNotBe8import io.kotest.matchers.types.shouldNotBeSameInstanceAs9import org.junit.jupiter.api.Test10import java.time.Clock11import java.time.Instant12import java.time.LocalDate13import java.time.Month14import java.time.ZoneOffset15import java.time.temporal.ChronoUnit16internal class TidspunktTest {17 private val instant = Instant.parse("1970-01-01T01:01:01.123456789Z")18 @Test19 fun `truncate instant to same format as repo, precision in micros`() {20 val tidspunkt = instant.toTidspunkt()21 ChronoUnit.MICROS.between(instant, tidspunkt) shouldBe 022 instant.toString().length.shouldNotBeLessThan(tidspunkt.toString().length)23 tidspunkt.nano % 1000 shouldBe 024 val addedMicrosInstant = instant.plus(251, ChronoUnit.MICROS)25 val addedMicrosTidspunkt = addedMicrosInstant.toTidspunkt()26 ChronoUnit.MICROS.between(addedMicrosInstant, addedMicrosTidspunkt) shouldBe 027 addedMicrosInstant.toString().length.shouldNotBeLessThan(addedMicrosTidspunkt.toString().length)28 addedMicrosTidspunkt.nano % 1000 shouldBe 029 val addedNanosInstant = instant.plusNanos(378)30 val addedNanosTidspunkt = addedNanosInstant.toTidspunkt()31 (addedNanosInstant.nano - addedNanosTidspunkt.nano).shouldBeBetween(1, 1000)32 addedNanosInstant shouldNotBe addedNanosTidspunkt.instant33 addedNanosTidspunkt shouldBe addedNanosInstant34 ChronoUnit.MICROS.between(addedNanosInstant, addedNanosTidspunkt) shouldBe 035 addedNanosInstant.toString().length.shouldNotBeLessThan(addedNanosTidspunkt.toString().length)36 addedNanosTidspunkt.nano % 1000 shouldBe 037 }38 @Test39 fun `should equal instant truncated to same precision`() {40 val instant = instant.plusNanos(515)41 val tidspunkt = instant.toTidspunkt()42 instant shouldNotBe tidspunkt.instant43 instant.truncatedTo(Tidspunkt.unit) shouldBe tidspunkt.instant44 tidspunkt shouldBe instant45 tidspunkt shouldBe instant.truncatedTo(Tidspunkt.unit)46 val othertidspunkt = instant.toTidspunkt()47 tidspunkt shouldBe othertidspunkt48 tidspunkt shouldBe tidspunkt49 }50 @Test51 fun comparison() {52 val startOfDayInstant = 1.januar(2020).atStartOfDay().toInstant(ZoneOffset.UTC)53 val endOfDayInstant = 1.januar(2020).plusDays(1).atStartOfDay().minusNanos(1).toInstant(ZoneOffset.UTC)54 val startOfDaytidspunkt = startOfDayInstant.toTidspunkt()55 val endOfDaytidspunkt = endOfDayInstant.toTidspunkt()56 startOfDayInstant shouldBeLessThan endOfDayInstant57 startOfDaytidspunkt.instant shouldBeLessThan endOfDaytidspunkt.instant58 startOfDayInstant shouldBeLessThan endOfDaytidspunkt.instant59 endOfDayInstant shouldBeGreaterThan startOfDaytidspunkt.instant60 }61 @Test62 fun `new instances for companions`() {63 val firstEpoch = Tidspunkt.EPOCH64 val secondEpoch = Tidspunkt.EPOCH65 firstEpoch shouldNotBeSameInstanceAs secondEpoch66 val firstMin = Tidspunkt.MIN67 val secondMin = Tidspunkt.MIN68 firstMin shouldNotBeSameInstanceAs secondMin69 }70 @Test71 fun `should serialize as instant`() {72 val start = 1.oktober(2020).endOfDay()73 val serialized = objectMapper.writeValueAsString(start)74 serialized shouldBe "\"2020-10-01T21:59:59.999999Z\"" // Denne serialiseres til json-streng istedenfor objekt75 val deserialized = objectMapper.readValue(serialized, Tidspunkt::class.java)76 deserialized shouldBe start77 val objSerialized = objectMapper.writeValueAsString(NestedSerialization(start))78 objSerialized shouldBe """{"tidspunkt":"2020-10-01T21:59:59.999999Z","other":"other values"}"""79 val objDeserialized = objectMapper.readValue(objSerialized, NestedSerialization::class.java)80 objDeserialized shouldBe NestedSerialization(start, "other values")81 }82 @Test83 fun now() {84 val fixedUTC = Clock.fixed(1.januar(2020).endOfDay(ZoneOffset.UTC).instant, ZoneOffset.UTC)85 val nowUTC = Tidspunkt.now(fixedUTC)86 nowUTC.toString() shouldBe "2020-01-01T23:59:59.999999Z"87 val fixedOslo = Clock.fixed(1.januar(2020).endOfDay(zoneIdOslo).instant, zoneIdOslo)88 val nowOslo = Tidspunkt.now(fixedOslo)89 nowOslo.toString() shouldBe "2020-01-01T22:59:59.999999Z"90 }91 @Test92 fun `konverterer tidspunkt til localDate`() {93 1.januar(2020).startOfDay(ZoneOffset.UTC).toLocalDate(ZoneOffset.UTC) shouldBe LocalDate.of(94 2020,95 Month.JANUARY,96 197 )98 1.januar(2020).endOfDay(ZoneOffset.UTC).toLocalDate(ZoneOffset.UTC) shouldBe LocalDate.of(99 2020,100 Month.JANUARY,101 1102 )103 1.januar(2020).startOfDay(zoneIdOslo).toLocalDate(zoneIdOslo) shouldBe LocalDate.of(2020, Month.JANUARY, 1)104 1.januar(2020).endOfDay(zoneIdOslo).toLocalDate(zoneIdOslo) shouldBe LocalDate.of(2020, Month.JANUARY, 1)105 }106 @Test107 fun `plusser på tid`() {108 Tidspunkt(instant).plus(1, ChronoUnit.DAYS).toString() shouldBe "1970-01-02T01:01:01.123456Z"109 }110 data class NestedSerialization(111 val tidspunkt: Tidspunkt,112 val other: String = "other values"113 )114}...

Full Screen

Full Screen

LocalDate.shouldBeBetween

Using AI Code Generation

copy

Full Screen

1val date = LocalDate.now()2date.shouldBeBetween(LocalDate.now().minusDays(1), LocalDate.now().plusDays(1))3val date = LocalDate.now()4date.shouldBeBetween(LocalDate.now().minusDays(1), LocalDate.now().plusDays(1))5val date = LocalDate.now()6date.shouldBeBetween(LocalDate.now().minusDays(1), LocalDate.now().plusDays(1))7val date = LocalDate.now()8date.shouldBeBetween(LocalDate.now().minusDays(1), LocalDate.now().plusDays(1))9val date = LocalDate.now()10date.shouldBeBetween(LocalDate.now().minusDays(1), LocalDate.now().plusDays(1))11val date = LocalDate.now()12date.shouldBeBetween(LocalDate.now().minusDays(1), LocalDate.now().plusDays(1))13val date = LocalDate.now()14date.shouldBeBetween(LocalDate.now().minusDays(1), LocalDate.now().plusDays(1))15val date = LocalDate.now()16date.shouldBeBetween(LocalDate.now().minusDays(1), LocalDate.now().plusDays(1))17val date = LocalDate.now()18date.shouldBeBetween(LocalDate.now().minusDays(1), LocalDate.now().plusDays(1))19val date = LocalDate.now()20date.shouldBeBetween(LocalDate.now().minusDays(1), LocalDate.now().plusDays(1))21val date = LocalDate.now()22date.shouldBeBetween(LocalDate.now().minusDays(1), LocalDate.now().plusDays(1))

Full Screen

Full Screen

LocalDate.shouldBeBetween

Using AI Code Generation

copy

Full Screen

1val date = LocalDate.of(2020, 12, 25)2date.shouldBeBetween(LocalDate.of(2020, 12, 24), LocalDate.of(2020, 12, 26))3val date = LocalDate.of(2020, 12, 25)4date.shouldNotBeBetween(LocalDate.of(2020, 12, 24), LocalDate.of(2020, 12, 26))5val date = LocalDate.of(2020, 12, 25)6date.shouldBeBefore(LocalDate.of(2020, 12, 26))7val date = LocalDate.of(2020, 12, 25)8date.shouldNotBeBefore(LocalDate.of(2020, 12, 24))9val date = LocalDate.of(2020, 12, 25)10date.shouldBeAfter(LocalDate.of(2020, 12, 24))11val date = LocalDate.of(2020, 12, 25)12date.shouldNotBeAfter(LocalDate.of(2020, 12, 26))13val date = LocalDate.of(2020, 12, 25)14date.shouldBeBetween(LocalDate.of(2020, 12, 24), LocalDate.of(2020, 12, 26))15val date = LocalDate.of(2020, 12, 25)16date.shouldNotBeBetween(LocalDate.of(2020, 12, 24), LocalDate.of(2020, 12, 26))17val date = LocalDate.of(2020, 12, 25)18date.shouldBeBefore(LocalDate.of(2020,

Full Screen

Full Screen

LocalDate.shouldBeBetween

Using AI Code Generation

copy

Full Screen

1val date = LocalDate.of(year, month, day)2date.shouldBeBetween(LocalDate.of(2020, 10, 19), LocalDate.of(2020, 10, 21))3val date = LocalDate.of(year, month, day)4date.shouldBeBetween(LocalDate.of(2020, 10, 19), LocalDate.of(2020, 10, 21))5val date = LocalDate.of(year, month, day)6date.shouldBeBetween(LocalDate.of(2020, 10, 19), LocalDate.of(2020, 10, 21))7val date = LocalDate.of(year, month, day)8date.shouldBeBetween(LocalDate.of(2020, 10, 19), LocalDate.of(2020, 10, 21))9val date = LocalDate.of(year, month, day)10date.shouldBeBetween(LocalDate.of(2020, 10, 19), LocalDate.of(2020, 10, 21))11val date = LocalDate.of(year, month, day)12date.shouldBeBetween(LocalDate.of(2020, 10, 19), LocalDate.of(2020, 10, 21))

Full Screen

Full Screen

LocalDate.shouldBeBetween

Using AI Code Generation

copy

Full Screen

1import io.kotest.matchers.date.shouldBeBetween2import java.time.LocalDate3import java.time.Month4import java.time.Month.*5import kotlin.test.Test6class DateMatchersTest {7fun testLocalDateIsBetween() {8val localDate = LocalDate.of(2019, JULY, 22)9localDate.shouldBeBetween(LocalDate.of(2019, JULY, 21), LocalDate.of(2019, JULY, 23))10}11}12import io.kotest.matchers.date.shouldBeBetween13import java.time.LocalDate14import java.time.Month15import java.time.Month.*16import kotlin.test.Test17class DateMatchersTest {18fun testLocalDateIsBetween() {19val localDate = LocalDate.of(2019, JULY, 22)20localDate.shouldBeBetween(LocalDate.of(2019, JULY, 21), LocalDate.of(2019, JULY, 23))21}22}23import io.kotest.matchers.date.shouldBeBetween24import java.time.LocalDate25import java.time.Month26import java.time.Month.*27import kotlin.test.Test28class DateMatchersTest {29fun testLocalDateIsBetween() {30val localDate = LocalDate.of(2019, JULY, 22)31localDate.shouldBeBetween(LocalDate.of(2019, JULY, 21), LocalDate.of(2019, JULY, 23))32}33}34import io.kotest.matchers.date.shouldBeBetween35import java.time.LocalDate36import java.time.Month37import java.time.Month.*38import kotlin.test.Test39class DateMatchersTest {40fun testLocalDateIsBetween() {41val localDate = LocalDate.of(2019, JULY, 22)42localDate.shouldBeBetween(LocalDate.of(2019, JULY, 21), LocalDate.of(2019, JULY, 23))43}44}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful