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

Best Kotest code snippet using io.kotest.matchers.date.localtime.LocalTime.shouldBeBetween

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

localtime.kt

Source:localtime.kt Github

copy

Full Screen

1package io.kotest.matchers.date2import io.kotest.matchers.Matcher3import io.kotest.matchers.MatcherResult4import io.kotest.matchers.should5import io.kotest.matchers.shouldBe6import io.kotest.matchers.shouldNot7import io.kotest.matchers.shouldNotBe8import java.time.LocalTime9/**10 * Asserts that hours in this time are the same as [time]'s hours11 *12 * Verifies that hours in this time are the same as [time]'s hours, ignoring any other fields.13 * For example, 16:59:59:7777 has the same hours as 16:01:02:0001, and this assertion should pass for this comparison14 *15 * Opposite of [LocalTime.shouldNotHaveSameHoursAs]16 *17 * ```18 * val firstTime = LocalTime.of(23, 59, 30, 1000)19 * val secondTime = LocalTime.of(23, 1, 2, 3333)20 *21 * firstTime shouldHaveSameHoursAs secondTime // Assertion passes22 *23 *24 * val firstTime = LocalTime.of(23, 59, 30, 1000)25 * val secondTime = LocalTime.of(16, 59, 30, 1000)26 *27 * firstTime shouldHaveSameHoursAs secondTime // Assertion fails, 23 != 1628```29 */30infix fun LocalTime.shouldHaveSameHoursAs(time: LocalTime) = this should haveSameHours(time)31/**32 * Asserts that hours in this time are NOT the same as [time]'s hours33 *34 * Verifies that hours in this time aren't the same as [time]'s hours, ignoring any other fields.35 * For example, 16:59:59:7777 doesn't have the same hours as 16:01:02:0001, and this assertion should pass for this comparison36 *37 * Opposite of [LocalTime.shouldNotHaveSameHoursAs]38 *39 * ```40 * val firstTime = LocalTime.of(23, 59, 30, 1000)41 * val secondTime = LocalTime.of(20, 59, 30, 1000)42 *43 * firstTime shouldNotHaveSameHoursAs secondTime // Assertion passes44 *45 *46 * val firstTime = LocalTime.of(23, 59, 30, 1000)47 * val secondTime = LocalTime.of(23, 30, 25, 2222)48 *49 * firstTime shouldNotHaveSameHoursAs secondTime // Assertion fails, 23 == 2350```51 */52infix fun LocalTime.shouldNotHaveSameHoursAs(time: LocalTime) = this shouldNot haveSameHours(time)53/**54 * Matcher that compares hours of LocalTimes55 *56 * Verifies that two times have exactly the same hours, ignoring any other fields.57 * For example, 23:59:30:9999 has the same hours as 23:01:02:3333, and the matcher will have a positive result for this comparison58 *59 * ```60 * val firstTime = LocalTime.of(23, 59, 30, 1000)61 * val secondTime = LocalTime.of(23, 1, 2, 3333)62 *63 * firstTime should haveSameHours(secondTime) // Assertion passes64 *65 *66 * val firstTime = LocalTime.of(23, 59, 30, 1000)67 * val secondTime = LocalTime.of(16, 59, 30, 1000)68 *69 * firstTime shouldNot haveSameHours(secondTime) // Assertion passes70 * ```71 *72 * @see [LocalTime.shouldHaveSameHoursAs]73 * @see [LocalTime.shouldNotHaveSameHoursAs]74 */75fun haveSameHours(time: LocalTime): Matcher<LocalTime> = object : Matcher<LocalTime> {76 override fun test(value: LocalTime): MatcherResult =77 MatcherResult(78 value.hour == time.hour,79 { "$value should have hours ${time.hour}" },80 { "$value should not have hours ${time.hour}" }81 )82}83/**84 * Asserts that minutes in this time are the same as [time]'s minutes85 *86 * Verifies that minutes in this time are the same as [time]'s minutes, ignoring any other fields.87 * For example, 1:59:03:7777 has the same minutes as 2:59:22:3333, and this assertion should pass for this comparison88 *89 * Opposite of [LocalTime.shouldNotHaveSameMinutesAs]90 *91 * ```92 * val firstTime = LocalTime.of(13, 59, 30, 1000)93 * val secondTime = LocalTime.of(17, 59, 22, 3333)94 *95 * firstTime shouldHaveSameMinutesAs secondTime // Assertion passes96 *97 *98 * val firstTime = LocalTime.of(23, 59, 30, 1000)99 * val secondTime = LocalTime.of(23, 1, 30, 1000)100 *101 * firstTime shouldHaveSameMinutesAs secondTime // Assertion fails, 59 != 1102```103 */104infix fun LocalTime.shouldHaveSameMinutesAs(time: LocalTime) = this should haveSameMinutes(time)105/**106 * Asserts that minutes in this time are NOT the same as [time]'s minutes107 *108 * Verifies that minutes in this time aren't the same as [time]'s minutes, ignoring any other fields.109 * For example, 16:59:02:1111 doesn't have the same minutes as 16:01:02:1111, and this assertion should pass for this comparison110 *111 * Opposite of [LocalTime.shouldHaveSameMinutesAs]112 *113 * ```114 * val firstTime = LocalTime.of(22, 59, 30, 1000)115 * val secondTime = LocalTime.of(11, 59, 22, 3333)116 *117 * firstTime shouldNotHaveSameMinutesAs secondTime // Assertion passes118 *119 *120 * val firstTime = LocalTime.of(23, 59, 30, 1000)121 * val secondTime = LocalTime.of(22, 59, 35, 2222)122 *123 * firstTime shouldNotHaveSameMinutesAs secondTime // Assertion fails, 59 == 59124```125 */126infix fun LocalTime.shouldNotHaveSameMinutesAs(time: LocalTime) = this shouldNot haveSameMinutes(time)127/**128 * Matcher that compares minutes of LocalTimes129 *130 * Verifies that two times have exactly the same minutes, ignoring any other fields.131 * For example, 23:59:30:9999 has the same minutes as 12:59:02:3333, and the matcher will have a positive result for this comparison132 *133 * ```134 * val firstTime = LocalTime.of(23, 59, 30, 1000)135 * val secondTime = LocalTime.of(12, 59, 2, 3333)136 *137 * firstTime should haveSameMinutes(secondTime) // Assertion passes138 *139 *140 * val firstTime = LocalTime.of(23, 59, 30, 1000)141 * val secondTime = LocalTime.of(23, 20, 30, 1000)142 *143 * firstTime shouldNot haveSameMinutes(secondTime) // Assertion passes144 * ```145 *146 * @see [LocalTime.shouldHaveSameMinutesAs]147 * @see [LocalTime.shouldNotHaveSameMinutesAs]148 */149fun haveSameMinutes(time: LocalTime): Matcher<LocalTime> = object : Matcher<LocalTime> {150 override fun test(value: LocalTime): MatcherResult =151 MatcherResult(value.minute == time.minute,152 { "$value should have minutes ${time.minute}" },153 { "$value should not have minutes ${time.minute}" }154 )155}156/**157 * Asserts that seconds in this time are the same as [time]'s seconds158 *159 * Verifies that seconds in this time are the same as [time]'s seconds, ignoring any other fields.160 * For example, 1:59:03:7777 has the same seconds as 2:33:03:3333, and this assertion should pass for this comparison161 *162 * Opposite of [LocalTime.shouldNotHaveSameSecondsAs]163 *164 * ```165 * val firstTime = LocalTime.of(13, 59, 30, 1000)166 * val secondTime = LocalTime.of(17, 22, 30, 3333)167 *168 * firstTime shouldHaveSameSecondsAs secondTime // Assertion passes169 *170 *171 * val firstTime = LocalTime.of(23, 59, 30, 1000)172 * val secondTime = LocalTime.of(23, 59, 25, 1000)173 *174 * firstTime shouldHaveSameSecondsAs secondTime // Assertion fails, 30 != 25175```176 */177infix fun LocalTime.shouldHaveSameSecondsAs(time: LocalTime) = this should haveSameSeconds(time)178/**179 * Asserts that seconds in this time are NOT the same as [time]'s seconds180 *181 * Verifies that seconds in this time aren't the same as [time]'s seconds, ignoring any other fields.182 * For example, 16:59:05:1111 doesn't have the same seconds as 16:59:02:1111, and this assertion should pass for this comparison183 *184 * Opposite of [LocalTime.shouldHaveSameSecondsAs]185 *186 * ```187 * val firstTime = LocalTime.of(22, 59, 30, 1000)188 * val secondTime = LocalTime.of(22, 59, 21, 1000)189 *190 * firstTime shouldNotHaveSameSecondsAs secondTime // Assertion passes191 *192 *193 * val firstTime = LocalTime.of(23, 40, 30, 1000)194 * val secondTime = LocalTime.of(11, 45, 30, 2222)195 *196 * firstTime shouldNotHaveSameSecondsAs secondTime // Assertion fails, 30 == 30197```198 */199infix fun LocalTime.shouldNotHaveSameSecondsAs(time: LocalTime) = this shouldNot haveSameSeconds(time)200/**201 * Matcher that compares seconds of LocalTimes202 *203 * Verifies that two times have exactly the same seconds, ignoring any other fields.204 * For example, 23:17:30:9999 has the same seconds as 12:59:30:3333, and the matcher will have a positive result for this comparison205 *206 * ```207 * val firstTime = LocalTime.of(23, 59, 30, 1000)208 * val secondTime = LocalTime.of(12, 27, 30, 3333)209 *210 * firstTime should haveSameSeconds(secondTime) // Assertion passes211 *212 *213 * val firstTime = LocalTime.of(23, 59, 30, 1000)214 * val secondTime = LocalTime.of(23, 59, 45, 1000)215 *216 * firstTime shouldNot haveSameSeconds(secondTime) // Assertion passes217 * ```218 *219 * @see [LocalTime.shouldHaveSameSecondsAs]220 * @see [LocalTime.shouldNotHaveSameSecondsAs]221 */222fun haveSameSeconds(time: LocalTime): Matcher<LocalTime> = object : Matcher<LocalTime> {223 override fun test(value: LocalTime): MatcherResult =224 MatcherResult(value.second == time.second,225 { "$value should have seconds ${time.second}" },226 { "$value should not have seconds ${time.second}" }227 )228}229/**230 * Asserts that nanos in this time are the same as [time]'s nanos231 *232 * Verifies that nanos in this time are the same as [time]'s nanos, ignoring any other fields.233 * For example, 1:59:15:7777 has the same nanos as 2:33:03:7777, and this assertion should pass for this comparison234 *235 * Opposite of [LocalTime.shouldNotHaveSameNanosAs]236 *237 * ```238 * val firstTime = LocalTime.of(13, 59, 45, 1000)239 * val nanoTime = LocalTime.of(17, 22, 30, 1000)240 *241 * firstTime shouldHaveSameNanosAs nanoTime // Assertion passes242 *243 *244 * val firstTime = LocalTime.of(23, 59, 30, 1000)245 * val nanoTime = LocalTime.of(23, 59, 30, 3333)246 *247 * firstTime shouldHaveSameNanosAs nanoTime // Assertion fails, 1000 != 3333248```249 */250infix fun LocalTime.shouldHaveSameNanosAs(time: LocalTime) = this should haveSameNanos(time)251/**252 * Asserts that nanos in this time are NOT the same as [time]'s nanos253 *254 * Verifies that nanos in this time aren't the same as [time]'s nanos, ignoring any other fields.255 * For example, 16:59:05:2222 doesn't have the same nanos as 16:59:05:1111, and this assertion should pass for this comparison256 *257 * Opposite of [LocalTime.shouldHaveSameNanosAs]258 *259 * ```260 * val firstTime = LocalTime.of(22, 59, 30, 1000)261 * val secondTime = LocalTime.of(22, 59, 30, 3333)262 *263 * firstTime shouldNotHaveSameNanosAs secondTime // Assertion passes264 *265 *266 * val firstTime = LocalTime.of(23, 40, 30, 1000)267 * val secondTime = LocalTime.of(12, 17, 59, 1000)268 *269 * firstTime shouldNotHaveSameNanosAs secondTime // Assertion fails, 1000 == 1000270```271 */272infix fun LocalTime.shouldNotHaveSameNanosAs(time: LocalTime) = this shouldNot haveSameNanos(time)273/**274 * Matcher that compares nanos of LocalTimes275 *276 * Verifies that two times have exactly the same nanos, ignoring any other fields.277 * For example, 23:17:30:9999 has the same nanos as 12:59:30:3333, and the matcher will have a positive result for this comparison278 *279 * ```280 * val firstTime = LocalTime.of(23, 59, 30, 1000)281 * val secondTime = LocalTime.of(12, 27, 05, 1000)282 *283 * firstTime should haveSameNanos(secondTime) // Assertion passes284 *285 *286 * val firstTime = LocalTime.of(23, 59, 30, 1000)287 * val secondTime = LocalTime.of(23, 59, 30, 2222)288 *289 * firstTime shouldNot haveSameNanos(secondTime) // Assertion passes290 * ```291 *292 * @see [LocalTime.shouldHaveSameNanosAs]293 * @see [LocalTime.shouldNotHaveSameNanosAs]294 */295fun haveSameNanos(time: LocalTime): Matcher<LocalTime> = object : Matcher<LocalTime> {296 override fun test(value: LocalTime): MatcherResult =297 MatcherResult(298 value.nano == time.nano,299 { "$value should have nanos ${time.nano}" },300 { "$value should not have nanos ${time.nano}" }301 )302}303/**304 * Asserts that this is before [time]305 *306 * Verifies that this is before [time], comparing hours, minutes, seconds, nanos.307 * For example, 12:30:59:2222 is before 12:30:59:3333, and this assertion should pass for this comparison.308 *309 * Opposite of [LocalTime.shouldNotBeBefore]310 *311 * ```312 * val firstTime = LocalTime.of(12:30:59:2222)313 * val secondTime = LocalTime.of(12:30:59:3333)314 *315 * firstTime shouldBeBefore secondTime // Assertion passes316 *317 *318 * val firstTime = LocalTime.of(14:30:59:2222)319 * val secondTime = LocalTime.of(12:30:59:2222)320 *321 * firstTime shouldBeBefore secondTime // Assertion fails, 14:30:59:2222 is not before 12:30:59:2222 as expected.322 * ```323 *324 * @see LocalTime.shouldNotBeAfter325 */326infix fun LocalTime.shouldBeBefore(time: LocalTime) = this should before(time)327/**328 * Asserts that this is NOT before [time]329 *330 * Verifies that this is not before [time], comparing hours, minutes, seconds, nanos.331 * For example, 12:30:59:2222 is not before 12:30:59:1111, and this assertion should pass for this comparison.332 *333 * Opposite of [LocalTime.shouldBeBefore]334 *335 * ```336 * val firstTime = LocalTime.of(12:30:59:2222)337 * val secondTime = LocalTime.of(12:30:59:1111)338 *339 * firstTime shouldNotBeBefore secondTime // Assertion passes340 *341 *342 * val firstTime = LocalTime.of(12:30:59:2222)343 * val secondTime = LocalTime.of(12:30:59:3333)344 *345 * firstTime shouldNotBeBefore secondTime // Assertion fails, 12:30:59:2222 is before 12:30:59:3333, and we expected the opposite.346 * ```347 *348 * @see LocalTime.shouldBeAfter349 */350infix fun LocalTime.shouldNotBeBefore(time: LocalTime) = this shouldNot before(time)351/**352 * Matcher that compares two LocalTimes and checks whether one is before the other353 *354 * Verifies that two LocalTimes occurs in a certain order, checking that one happened before the other.355 * For example, 12:30:59:2222 is before 12:30:59:3333, and the matcher will have a positive result for this comparison356 *357 * ```358 * val firstTime = LocalTime.of(12:30:59:2222)359 * val secondTime = LocalTime.of(12:30:59:3333)360 *361 * firstTime shouldBe before(secondTime) // Assertion passes362 *363 *364 * val firstTime = LocalTime.of(12:30:59:2222)365 * val secondTime = LocalTime.of(12:30:59:1111)366 *367 * firstTime shouldNotBe before(secondTime) // Assertion passes368 * ```369 *370 * @see LocalTime.shouldBeBefore371 * @see LocalTime.shouldNotBeBefore372 */373fun before(time: LocalTime): Matcher<LocalTime> = object : Matcher<LocalTime> {374 override fun test(value: LocalTime): MatcherResult =375 MatcherResult(376 value.isBefore(time),377 { "$value should be before $time" },378 { "$value should not be before $time" }379 )380}381/**382 * Asserts that this is after [time]383 *384 * Verifies that this is after [time], comparing hours, minutes, seconds, nanos.385 * For example, 12:30:59:2222 is after 10:22:59:2222, and this assertion should pass for this comparison.386 *387 * Opposite of [LocalTime.shouldNotBeAfter]388 *389 * ```390 * val firstTime = LocalTime.of(12, 30, 59, 1111)391 * val secondTime = LocalTime.of(11, 30, 59, 1111)392 *393 * firstTime shouldBeAfter secondTime // Assertion passes394 *395 *396 * val firstTime = LocalTime.of(12, 30, 59, 1111)397 * val secondTime = LocalTime.of(12, 50, 59, 1111)398 *399 * firstTime shouldBeAfter secondTime // Assertion fails, firstTime is NOT after secondTime400 * ```401 *402 * @see LocalTime.shouldNotBeBefore403 */404infix fun LocalTime.shouldBeAfter(time: LocalTime) = this should after(time)405/**406 * Asserts that this is NOT after [time]407 *408 * Verifies that this is not after [time], comparing hours, minutes, seconds, nanos.409 * For example, 12:30:59:2222 is not after 12:30:59:3333, and this assertion should pass for this comparison.410 *411 * Opposite of [LocalTime.shouldBeAfter]412 *413 * ```414 * val firstTime = LocalTime.of(12:30:59:2222)415 * val secondTime = LocalTime.of(12:30:59:3333)416 *417 * firstTime shouldNotBeAfter secondTime // Assertion passes418 *419 *420 * val firstTime = LocalTime.of(12:30:59:2222)421 * val secondTime = LocalTime.of(12:30:59:1111)422 *423 * firstTime shouldNotBeAfter secondTime // Assertion fails, first time IS after secondTime424 * ```425 *426 * @see LocalTime.shouldBeBefore427 */428infix fun LocalTime.shouldNotBeAfter(time: LocalTime) = this shouldNot after(time)429/**430 * Matcher that compares two LocalTimes and checks whether one is after the other431 *432 * Verifies that two LocalTimes occurs in a certain order, checking that one happened after the other.433 * For example, 12:30:59:2222 is after 12:30:59:1111, and the matcher will have a positive result for this comparison434 *435 * ```436 * val firstTime = LocalTime.of(12:30:59:2222)437 * val secondTime = LocalTime.of(09:30:59:2222)438 *439 * firstTime shouldBe after(secondTime ) // Assertion passes440 *441 *442 * val firstTime = LocalTime.of(12:30:59:2222)443 * val secondTime = LocalTime.of(16:30:59:2222)444 *445 * firstTime shouldNotBe after(secondTime) // Assertion passes446 * ```447 *448 * @see LocalTime.shouldBeAfter449 * @see LocalTime.shouldNotBeAfter450 */451fun after(time: LocalTime): Matcher<LocalTime> = object : Matcher<LocalTime> {452 override fun test(value: LocalTime): MatcherResult =453 MatcherResult(454 value.isAfter(time),455 { "$value should be after $time" },456 { "$value should not be after $time" }457 )458}459/**460 * Asserts that this is between [a] and [b]461 *462 * Verifies that this is after [a] and before [b], comparing hours, minutes, seconds, nanos.463 *464 * Opposite of [LocalTime.shouldNotBeBetween]465 *466 * ```467 * val time = LocalTime.of(12, 30, 59, 1111)468 * val firstTime = LocalTime.of(11, 0, 0, 0)469 * val secondTime = LocalTime.of(12, 31, 0, 0)470 *471 * date.shouldBeBetween(firstTime, secondTime) // Assertion passes472 *473 *474 * val time = LocalTime.of(12, 30, 59, 1111)475 * val firstTime = LocalTime.of(12, 30, 59, 2222)476 * val secondTime = LocalTime.of(12, 30, 59, 3333)477 *478 * date.shouldBeBetween(firstTime, secondTime) // Assertion fails, time is NOT between firstTime and secondTime479 * ```480 *481 * @see LocalTime.shouldNotBeBetween482 */483fun LocalTime.shouldBeBetween(a: LocalTime, b: LocalTime) = this shouldBe between(a, b)484/**485 * Asserts that this is NOT between [a] and [b]486 *487 * Verifies that this is not after [a] and before [b], comparing hours, minutes, seconds, nanos.488 *489 * Opposite of [LocalTime.shouldBeBetween]490 *491 * ```492 * val time = LocalTime.of(12, 30, 59, 1111)493 * val firstTime = LocalTime.of(12, 30, 59, 2222)494 * val secondTime = LocalTime.of(12, 30, 59, 3333)495 *496 * time.shouldNotBeBetween(firstTime, secondTime) // Assertion passes497 *498 *499 * val time = LocalTime.of(12, 30, 59, 1111)500 * val firstTime = LocalTime.of(11, 0, 0, 0)501 * val secondTime = LocalTime.of(12, 31, 0, 0)502 *503 * time.shouldNotBeBetween(firstTime, secondTime) // Assertion fails, time IS between firstTime and secondTime504 * ```505 *506 * @see LocalTime.shouldBeBetween507 */508fun LocalTime.shouldNotBeBetween(a: LocalTime, b: LocalTime) = this shouldNotBe between(a, b)509/**510 * Matcher that checks if LocalTime is between two other LocalTimes511 *512 * Verifies that LocalTime is after the first LocalTime and before the second LocalTime513 * For example, 12:30:59:2222 is between 12:30:59:1111 and 12:30:59:3333, and the matcher will have a positive result for this comparison514 *515 * ```516 * val time = LocalTime.of(12, 30, 59, 1111)517 * val firstTime = LocalTime.of(11, 0, 0, 0)518 * val secondTime = LocalTime.of(12, 31, 0, 0)519 *520 * time shouldBe after(firstTime, secondTime) // Assertion passes521 *522 *523 * val time = LocalTime.of(12, 30, 59, 1111)524 * val firstTime = LocalTime.of(12, 30, 59, 2222)525 * val secondTime = LocalTime.of(12, 30, 59, 3333)526 *527 * time shouldNotBe between(firstTime, secondTime) // Assertion passes528 * ```529 *530 * @see LocalTime.shouldBeBetween531 * @see LocalTime.shouldNotBeBetween532 */533fun between(a: LocalTime, b: LocalTime): Matcher<LocalTime> = object : Matcher<LocalTime> {534 override fun test(value: LocalTime): MatcherResult {535 val passed = value.isAfter(a) && value.isBefore(b)536 return MatcherResult(537 passed,538 { "$value should be after $a and before $b" },539 { "$value should not be be after $a and before $b" }540 )541 }542}...

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

LocalTime.shouldBeBetween

Using AI Code Generation

copy

Full Screen

1LocalTime.now().shouldBeBetween(LocalTime.of(9, 0), LocalTime.of(17, 0))2LocalTime.now().shouldBeBetween(LocalTime.of(9, 0), LocalTime.of(17, 0), true)3LocalTime.now().shouldBeBetween(LocalTime.of(9, 0), LocalTime.of(17, 0), false)4LocalTime.now().shouldBeBetween(LocalTime.of(9, 0), LocalTime.of(17, 0), true, true)5LocalTime.now().shouldBeBetween(LocalTime.of(9, 0), LocalTime.of(17, 0), true, false)6LocalTime.now().shouldBeBetween(LocalTime.of(9, 0), LocalTime.of(17, 0), false, true)7LocalTime.now().shouldBeBetween(LocalTime.of(9, 0), LocalTime.of(17, 0), false, false)8LocalTime.now().shouldBeBetween(LocalTime.of(9, 0), LocalTime.of(17, 0), inclusiveStart = true, inclusiveEnd = true)9LocalTime.now().shouldBeBetween(LocalTime.of(9, 0), LocalTime.of(17, 0), inclusiveStart = true, inclusiveEnd = false)10LocalTime.now().shouldBeBetween(LocalTime.of(9, 0), LocalTime.of(17, 0), inclusiveStart = false, inclusiveEnd = true)11LocalTime.now().shouldBeBetween(LocalTime.of(9, 0), LocalTime.of(17, 0), inclusiveStart = false, inclusiveEnd = false)12LocalTime.now().shouldBeBetween(LocalTime.of(9, 0), LocalTime.of(17, 0), inclusiveStart = true)13LocalTime.now().shouldBeBetween(LocalTime.of(9, 0), LocalTime.of(17, 0), inclusiveStart = false)14LocalTime.now().shouldBeBetween(LocalTime.of(9, 0), LocalTime.of(17, 0), inclusiveEnd = true)15LocalTime.now().shouldBeBetween(LocalTime.of(9, 0), LocalTime.of(17, 0), inclusiveEnd = false)16LocalTime.now().shouldBeBetween(LocalTime.of(9, 0), LocalTime.of(17, 0), inclusiveStart = true, inclusiveEnd = true)17LocalTime.now().shouldBeBetween(LocalTime.of(9, 0), LocalTime.of(17, 0),

Full Screen

Full Screen

LocalTime.shouldBeBetween

Using AI Code Generation

copy

Full Screen

1LocalTime.now().shouldBeBetween(LocalTime.of(9, 0, 0), LocalTime.of(18, 0, 0))2LocalDate.now().shouldBeBetween(LocalDate.of(2018, 1, 1), LocalDate.of(2020, 12, 31))3LocalDateTime.now().shouldBeBetween(LocalDateTime.of(2018, 1, 1, 0, 0, 0), LocalDateTime.of(2020, 12, 31, 0, 0, 0))4OffsetTime.now().shouldBeBetween(OffsetTime.of(9, 0, 0, 0, ZoneOffset.UTC), OffsetTime.of(18, 0, 0, 0, ZoneOffset.UTC))5OffsetDateTime.now().shouldBeBetween(OffsetDateTime.of(2018, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC), OffsetDateTime.of(2020, 12, 31, 0, 0, 0, 0, ZoneOffset.UTC))6ZonedDateTime.now().shouldBeBetween(ZonedDateTime.of(2018, 1, 1, 0, 0, 0, 0, ZoneId.of("America/Los_Angeles")), ZonedDateTime.of(2020, 12, 31, 0, 0, 0, 0, ZoneId.of("America/Los_Angeles")))7Instant.now().shouldBeBetween(Instant.ofEpochSecond(1514764800), Instant.ofEpochSecond(1609459200))8Instant.now().shouldBeBetween(Instant.ofEpochSecond(1514764800), Instant.ofEpochSecond(1609459200

Full Screen

Full Screen

LocalTime.shouldBeBetween

Using AI Code Generation

copy

Full Screen

1 LocalTime.now().shouldBeBetween(LocalTime.of(11, 0), LocalTime.of(12, 0))2 LocalDateTime.now().shouldBeBetween(LocalDateTime.of(2020, 1, 1, 11, 0), LocalDateTime.of(2020, 1, 1, 12, 0))3 ZonedDateTime.now().shouldBeBetween(ZonedDateTime.of(2020, 1, 1, 11, 0, 0, 0, ZoneId.systemDefault()), ZonedDateTime.of(2020, 1, 1, 12, 0, 0, 0, ZoneId.systemDefault()))4 OffsetDateTime.now().shouldBeBetween(OffsetDateTime.of(2020, 1, 1, 11, 0, 0, 0, ZoneOffset.UTC), OffsetDateTime.of(2020, 1, 1, 12, 0, 0, 0, ZoneOffset.UTC))5 Instant.now().shouldBeBetween(Instant.ofEpochSecond(0), Instant.ofEpochSecond(100))6 OffsetTime.now().shouldBeBetween(OffsetTime.of(11, 0, 0, 0, ZoneOffset.UTC), OffsetTime.of(12, 0, 0, 0, ZoneOffset.UTC))7}

Full Screen

Full Screen

LocalTime.shouldBeBetween

Using AI Code Generation

copy

Full Screen

1LocalTime.now().shouldBeBetween(LocalTime.of(23, 0, 0), LocalTime.of(23, 59, 59))2LocalDateTime.now().shouldBeBetween(LocalDateTime.of(2020, 1, 1, 0, 0, 0), LocalDateTime.of(2020, 12, 31, 23, 59, 59))3LocalDate.now().shouldBeBetween(LocalDate.of(2020, 1, 1), LocalDate.of(2020, 12, 31))4Instant.now().shouldBeBetween(Instant.ofEpochMilli(0), Instant.now())5OffsetDateTime.now().shouldBeBetween(OffsetDateTime.of(2020, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC), OffsetDateTime.of(2020, 12, 31, 23, 59, 59, 0, ZoneOffset.UTC))6ZonedDateTime.now().shouldBeBetween(ZonedDateTime.of(2020, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC")), ZonedDateTime.of(2020, 12, 31, 23, 59, 59, 0, ZoneId.of("UTC")))7OffsetTime.now().shouldBeBetween(OffsetTime.of(23, 0, 0, 0, ZoneOffset.UTC), OffsetTime.of(23, 59, 59, 0, ZoneOffset.UTC))8YearMonth.now().shouldBeBetween(YearMonth.of(2020, 1), YearMonth.of(2020, 12))

Full Screen

Full Screen

LocalTime.shouldBeBetween

Using AI Code Generation

copy

Full Screen

1LocalTime.now().shouldBeBetween(LocalTime.of(8, 0), LocalTime.of(20, 0))2LocalTime.now().shouldBeBetween(LocalTime.of(8, 0), LocalTime.of(20, 0), true)3LocalTime.now().shouldBeBetween(LocalTime.of(8, 0), LocalTime.of(20, 0), false)4LocalTime.now().shouldBeBetween(LocalTime.of(8, 0), LocalTime.of(20, 0), true, true)5LocalTime.now().shouldBeBetween(LocalTime.of(8, 0), LocalTime.of(20, 0), true, false)6LocalTime.now().shouldBeBetween(LocalTime.of(8, 0), LocalTime.of(20, 0), false, true)7LocalTime.now().shouldBeBetween(LocalTime.of(8, 0), LocalTime.of(20, 0), false, false)8LocalTime.now().shouldBeBetween(LocalTime.of(8, 0), LocalTime.of(20, 0), true, true, false)9LocalTime.now().shouldBeBetween(LocalTime.of(8, 0), LocalTime.of(20, 0), true, false, false)10LocalTime.now().shouldBeBetween(LocalTime.of(8, 0), LocalTime.of(20, 0), false, true, false)11LocalTime.now().shouldBeBetween(LocalTime.of(

Full Screen

Full Screen

LocalTime.shouldBeBetween

Using AI Code Generation

copy

Full Screen

1val time = LocalTime.now()2time.shouldBeBetween(LocalTime.of(9, 0), LocalTime.of(17, 0))3val date = LocalDate.now()4date.shouldBeBetween(LocalDate.of(2020, 1, 1), LocalDate.of(2020, 12, 31))5val dateTime = LocalDateTime.now()6dateTime.shouldBeBetween(LocalDateTime.of(2020, 1, 1, 10, 0), LocalDateTime.of(2020, 12, 31, 17, 0))7val zonedDateTime = ZonedDateTime.now()8zonedDateTime.shouldBeBetween(ZonedDateTime.of(2020, 1, 1, 10, 0, 0, 0, ZoneId.of("Europe/London")), ZonedDateTime.of(2020, 12, 31, 17, 0, 0, 0, ZoneId.of("Europe/London")))9val offsetDateTime = OffsetDateTime.now()10offsetDateTime.shouldBeBetween(OffsetDateTime.of(2020, 1, 1, 10, 0, 0, 0, ZoneOffset.UTC), OffsetDateTime.of(2020, 12, 31, 17, 0, 0, 0, ZoneOffset.UTC))11val instant = Instant.now()12instant.shouldBeBetween(Instant.ofEpochMilli(1577836800000), Instant.ofEpochMilli(1609459200000))13val year = Year.now()14year.shouldBeBetween(Year.of(2020), Year.of(2021))15val yearMonth = YearMonth.now()16yearMonth.shouldBeBetween(YearMonth.of(2020, 1), YearMonth.of(202

Full Screen

Full Screen

LocalTime.shouldBeBetween

Using AI Code Generation

copy

Full Screen

1LocalTime.now().shouldBeBetween( LocalTime.of( 9 , 0 ), LocalTime.of( 17 , 0 ))2LocalTime.now().shouldBeBetween( LocalTime.of( 9 , 0 ), LocalTime.of( 17 , 0 ))3LocalTime.now().shouldBeBetween( LocalTime.of( 9 , 0 ), LocalTime.of( 17 , 0 ))4LocalTime.now().shouldBeBetween( LocalTime.of( 9 , 0 ), LocalTime.of( 17 , 0 ))5LocalTime.now().shouldBeBetween( LocalTime.of( 9 , 0 ), LocalTime.of( 17 , 0 ))6LocalTime.now().shouldBeBetween( LocalTime.of( 9 , 0 ), LocalTime.of( 17 , 0 ))7LocalTime.now().shouldBeBetween( LocalTime.of( 9 , 0 ), LocalTime.of( 17 , 0 ))8LocalTime.now().shouldBeBetween( LocalTime.of( 9 , 0 ), LocalTime.of( 17 , 0 ))9LocalTime.now().shouldBeBetween( LocalTime.of( 9 , 0 ), LocalTime.of( 17 , 0 ))10LocalTime.now().shouldBeBetween( LocalTime.of( 9 , 0 ), LocalTime.of( 17 , 0 ))11LocalTime.now().shouldBeBetween( LocalTime.of( 9 , 0 ), Local

Full Screen

Full Screen

LocalTime.shouldBeBetween

Using AI Code Generation

copy

Full Screen

1LocalTime . shouldBeBetween ( LocalTime . of ( 9 , 0 ), LocalTime . of ( 12 , 0 ))2LocalTime . shouldBeBetweenInclusive ( LocalTime . of ( 9 , 0 ), LocalTime . of ( 12 , 0 ))3LocalTime . shouldBeBetweenInclusive ( LocalTime . of ( 9 , 0 ), LocalTime . of ( 12 , 0 ))4LocalTime . shouldBeBetweenInclusive ( LocalTime . of ( 9 , 0 ), LocalTime . of ( 12 , 0 ))5LocalTime . shouldBeBetweenInclusive ( LocalTime . of ( 9 , 0 ), LocalTime . of ( 12 , 0 ))6LocalTime . shouldBeBetweenInclusive ( LocalTime . of ( 9 , 0 ), LocalTime . of ( 12 , 0 ))7LocalTime . shouldBeBetweenInclusive ( LocalTime . of ( 9 , 0 ), LocalTime . of ( 12 , 0 ))8LocalTime . shouldBeBetweenInclusive ( LocalTime . of ( 9 , 0 ), LocalTime . of ( 12 , 0 ))9LocalTime . shouldBeBetweenInclusive ( LocalTime . of ( 9 , 0 ), LocalTime . of ( 12 , 0 ))10LocalTime . shouldBeBetweenInclusive ( LocalTime . of ( 9 , 0 ), LocalTime . of

Full Screen

Full Screen

LocalTime.shouldBeBetween

Using AI Code Generation

copy

Full Screen

1"LocalTime should be between" {2val localTime = LocalTime.of(11, 10, 9)3localTime.shouldBeBetween(LocalTime.of(11, 10, 8), LocalTime.of(11, 10, 10))4}5"LocalTime should not be between" {6val localTime = LocalTime.of(11, 10, 9)7localTime.shouldNotBeBetween(LocalTime.of(11, 10, 10), LocalTime.of(11, 10, 12))8}9"LocalTime should be after" {10val localTime = LocalTime.of(11, 10, 9)11localTime.shouldBeAfter(LocalTime.of(11, 10, 8))12}13"LocalTime should not be after" {14val localTime = LocalTime.of(11, 10, 9)15localTime.shouldNotBeAfter(LocalTime.of(11, 10, 10))16}17"LocalTime should be before" {18val localTime = LocalTime.of(11, 10, 9)19localTime.shouldBeBefore(LocalTime.of(11, 10, 10))20}21"LocalTime should not be before" {22val localTime = LocalTime.of(11, 10, 9)23localTime.shouldNotBeBefore(LocalTime.of(11, 10, 8))24}25"LocalTime should be between" {26val localTime = LocalTime.of(11, 10, 9)27localTime.shouldBeBetween(LocalTime.of(11, 10, 8), LocalTime.of(11, 10, 10))28}29"LocalTime should not be between" {

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.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful