How to use localtime class of io.kotest.matchers.date package

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

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

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

DslTest.kt

Source:DslTest.kt Github

copy

Full Screen

1package com.github.cpickl.timesheet.builder2import com.github.cpickl.timesheet.DayOffEntry3import com.github.cpickl.timesheet.EntryDateRange4import com.github.cpickl.timesheet.OffReason5import com.github.cpickl.timesheet.Tag6import com.github.cpickl.timesheet.TestConstants7import com.github.cpickl.timesheet.TimeEntries8import com.github.cpickl.timesheet.TimeRange9import com.github.cpickl.timesheet.WorkDayEntry10import com.github.cpickl.timesheet.until11import com.github.cpickl.timesheet.any12import com.github.cpickl.timesheet.anyWorkingDay13import com.github.cpickl.timesheet.dayOff14import com.github.cpickl.timesheet.failingTimesheet15import com.github.cpickl.timesheet.shouldHaveSingleEntryWithDate16import com.github.cpickl.timesheet.someWorkEntry17import com.github.cpickl.timesheet.someDayOff18import com.github.cpickl.timesheet.someWorkingDay19import com.github.cpickl.timesheet.tag120import com.github.cpickl.timesheet.tag221import com.github.cpickl.timesheet.timesheet22import io.kotest.core.spec.style.DescribeSpec23import io.kotest.matchers.collections.shouldContain24import io.kotest.matchers.collections.shouldContainExactly25import io.kotest.matchers.collections.shouldHaveSize26import io.kotest.matchers.shouldBe27import io.kotest.matchers.string.shouldContain28import io.kotest.matchers.types.shouldBeInstanceOf29import java.time.LocalDate30import java.time.LocalTime31import java.time.Month32class BuilderTest : DescribeSpec({33 val someDate = TestConstants.someDate34 val date1 = TestConstants.date135 val date2 = TestConstants.date236 val someTimeRange = TestConstants.someTimeRange37 val someTimeRangeString = someTimeRange.toParseableString()38 val anyTimeRangeString = someTimeRange.toParseableString()39 val timeRange1 = TestConstants.timeRange140 val timeRange2 = TestConstants.timeRange241 val description = "test description"42 val anyDescription = "any description"43 val anyYear = 201044 val anyMonth = Month.JULY45 val someTag = Tag.any46 val tag1 = Tag.tag147 val tag2 = Tag.tag248 val someOffReason = OffReason.any49 describe("When sunshine case") {50 it("valid working day and entry Then sheet's start date is of work entry") {51 val sheet = timesheet {52 someWorkingDay(someDate) {53 someWorkEntry()54 }55 }56 sheet.startDate shouldBe someDate57 }58 it("two valid working days Then two entries returned") {59 val sheet = timesheet {60 someWorkingDay {61 someWorkEntry(timeRange = timeRange1.toParseableString())62 someWorkEntry(timeRange = timeRange2.toParseableString())63 }64 }65 sheet.entries.size shouldBe 266 }67 it("valid work day Then parsed entry returned") {68 val timeStart = LocalTime.of(9, 30)69 val timeEnd = LocalTime.of(10, 0)70 val sheet = timesheet {71 someWorkingDay(someDate) {72 "9:30-10" about description tag (someTag)73 }74 }75 sheet.entries shouldBe TimeEntries.newValidatedOrThrow(76 listOf(77 WorkDayEntry(78 dateRange = EntryDateRange(someDate, TimeRange(timeStart, timeEnd)),79 about = description,80 tags = setOf(someTag),81 )82 )83 )84 }85 it("two tags Then parsed tags returned") {86 val sheet = timesheet {87 someWorkingDay {88 anyTimeRangeString - anyDescription - listOf(tag1, tag2)89 // anyTimeRangeString.about(anyDescription).tags(tag1, tag2)90 }91 }92 sheet.entries.workEntries shouldHaveSize 193 sheet.entries.workEntries[0].tags shouldContainExactly setOf(tag1, tag2)94 }95 it("day off") {96 val sheet = timesheet {97 anyWorkingDay()98 dayOff(date2, someOffReason)99 }100 sheet.entries shouldContain DayOffEntry(101 day = date2,102 reason = someOffReason,103 )104 }105 }106 describe("When ... invalid Then fail") {107 it("no days") {108 failingTimesheet {}109 }110 it("starts with day-off day") {111 failingTimesheet {112 someDayOff()113 }114 }115 it("Given some work day When day-off without reason entry") {116 failingTimesheet {117 anyWorkingDay()118 year(anyYear) {119 month(anyMonth) {120 dayOff(1) // missing: becauseOf reason121 }122 }123 }124 }125 it("two work days with same date") {126 val conflictingDate = TestConstants.someDate127 failingTimesheet {128 someWorkingDay(date = conflictingDate)129 someWorkingDay(date = conflictingDate)130 }.message shouldContain conflictingDate.year.toString().substring(2) shouldContain conflictingDate.monthValue.toString() shouldContain conflictingDate.dayOfMonth.toString()131 }132 // TODO two day offs with same date133 // TODO 1 work day 1 day off; same date134 it("work entry without about") {135 failingTimesheet {136 someWorkingDay(someDate) {137 anyTimeRangeString about " "138 }139 }.message shouldContain someDate.toParsableDate()140 }141 // TODO test 2 days off at same date142 it("two work entries with same time") {143 failingTimesheet {144 someWorkingDay(someDate) {145 someWorkEntry(timeRange = someTimeRangeString)146 someWorkEntry(timeRange = someTimeRangeString)147 }148 }.message shouldContain someDate.toParsableDate() // someTimeRangeString ... unfortunately this info is lost due to dynamic time construction and lack of validation info149 }150 }151 describe("When ... year-month-day") {152 it("When add work-day Then set date correctly") {153 timesheet {154 year(2003) {155 month(Month.of(2)) {156 day(1) {157 someWorkEntry()158 }159 }160 }161 } shouldHaveSingleEntryWithDate LocalDate.of(2003, 2, 1)162 }163 it("Given work-day When add day-off Then set date correctly") {164 val day1 = 1165 val day2 = 2166 val sheet = timesheet {167 year(anyYear) {168 month(anyMonth) {169 day(day1) {170 someWorkEntry()171 }172 someDayOff(day2)173 }174 }175 }176 sheet.entries.size shouldBe 2177 sheet.entries.last().day.dayOfMonth shouldBe day2178 }179 }180 describe("When ... partial time range") {181 it("open end success") {182 val sheet = timesheet {183 someWorkingDay {184 "0-" - "open end entry"185 "1-2" - "last entry"186 }187 }188 sheet.entries.workEntries.size shouldBe 2189 sheet.entries.workEntries.first().dateRange.timeRange shouldBe (0 until 1)190 }191 it("open begin success") {192 val sheet = timesheet {193 someWorkingDay {194 "0-1" - "first entry"195 "-2" - "open begin entry"196 }197 }198 sheet.entries.workEntries.size shouldBe 2199 sheet.entries.workEntries.last().dateRange.timeRange shouldBe (1 until 2)200 }201 it("single open end fail") {202 val exception = failingTimesheet {203 someWorkingDay(LocalDate.of(2003, 2, 1)) {204 "0-" - "open end entry"205 }206 }207 exception.message shouldContain "00:00-"208 exception.message shouldContain "1.2.03"209 }210 it("single end end fail") {211 val exception = failingTimesheet {212 someWorkingDay(LocalDate.of(2003, 2, 1)) {213 "-1" - "open begin entry"214 }215 }216 exception.message shouldContain "1:00"217 exception.message shouldContain "1.2.03"218 }219 // TODO test overlaps220 }221 describe("days off") {222 it("range") {223 val sheet = timesheet {224 year(2000) {225 month(Month.JULY) {226 someWorkingDay(1)227 daysOff(2..3) becauseOf OffReason.any228 }229 }230 }231 sheet.entries shouldHaveSize 3232 sheet.entries[1].shouldBeInstanceOf<DayOffEntry>()233 sheet.entries[2].shouldBeInstanceOf<DayOffEntry>()234 sheet.entries[1].day shouldBe LocalDate.of(2000, Month.JULY, 2)235 sheet.entries[2].day shouldBe LocalDate.of(2000, Month.JULY, 3)236 }237 }238})...

Full Screen

Full Screen

CaPluginTest.kt

Source:CaPluginTest.kt Github

copy

Full Screen

1package family.haschka.wolkenschloss.gradle.ca2import family.haschka.wolkenschloss.testing.Template3import family.haschka.wolkenschloss.testing.createRunner4import io.kotest.assertions.assertSoftly5import io.kotest.core.spec.IsolationMode6import io.kotest.core.spec.style.FunSpec7import io.kotest.engine.spec.tempdir8import io.kotest.matchers.file.shouldBeReadable9import io.kotest.matchers.file.shouldContainFile10import io.kotest.matchers.file.shouldExist11import io.kotest.matchers.file.shouldNotBeWriteable12import io.kotest.matchers.ints.shouldBeGreaterThan13import io.kotest.matchers.shouldBe14import org.bouncycastle.asn1.x500.X500Name15import org.bouncycastle.asn1.x509.KeyUsage16import org.gradle.testkit.runner.TaskOutcome17import java.time.LocalDate18import java.time.LocalTime19import java.time.ZoneOffset20import java.time.ZonedDateTime21import java.util.*22class CaPluginTest : FunSpec({23 autoClose(Template("ca")).withClone {24 context("A project using com.github.wolkenschloss.ca gradle plugin") {25 val xdgDataHome = tempdir()26 val environment = mapOf("XDG_DATA_HOME" to xdgDataHome.absolutePath)27 context("executing ca task") {28 val result = createRunner()29 .withArguments(CaPlugin.CREATE_TASK_NAME)30 .withEnvironment(environment)31 .build()32 test("should be successful") {33 result.task(":${CaPlugin.CREATE_TASK_NAME}")!!.outcome shouldBe TaskOutcome.SUCCESS34 }35 test("should create self signed root certificate") {36 assertSoftly(CertificateWrapper.read(xdgDataHome.resolve("wolkenschloss/ca/ca.crt"))) {37 x509Certificate.basicConstraints shouldBeGreaterThan -138 x509Certificate.basicConstraints shouldBe Int.MAX_VALUE39 keyUsage.hasUsages(KeyUsage.keyCertSign) shouldBe true40 issuer shouldBe X500Name(CaPlugin.TRUST_ANCHOR_DEFAULT_SUBJECT)41 subject shouldBe X500Name(CaPlugin.TRUST_ANCHOR_DEFAULT_SUBJECT)42 }43 }44 test("should create read only certificate") {45 assertSoftly(xdgDataHome.resolve("wolkenschloss/ca/ca.crt")) {46 shouldBeReadable()47 shouldNotBeWriteable()48 }49 }50 test("should create readonly private key") {51 assertSoftly(xdgDataHome.resolve("wolkenschloss/ca/ca.key")) {52 shouldNotBeWriteable()53 shouldBeReadable()54 readPrivateKey().algorithm shouldBe "RSA"55 }56 }57 }58 context("executing truststore task") {59 val result = createRunner()60 .withArguments(CaPlugin.TRUSTSTORE_TASK_NAME)61 .withEnvironment(environment)62 .build()63 test("should execute successfully") {64 result.task(":${CaPlugin.TRUSTSTORE_TASK_NAME}")!!.outcome shouldBe TaskOutcome.SUCCESS65 }66 test("should create truststore file") {67 xdgDataHome.resolve("wolkenschloss/ca/ca.jks").shouldExist()68 }69 }70 test("should customize validity") {71 val start = ZonedDateTime.of(72 LocalDate.of(2022, 2, 4),73 LocalTime.MIDNIGHT,74 ZoneOffset.UTC75 )76 val end = ZonedDateTime.of(77 LocalDate.of(2027, 2, 4),78 LocalTime.MIDNIGHT,79 ZoneOffset.UTC80 )81 val result = createRunner()82 .withArguments(CaPlugin.CREATE_TASK_NAME, "-DnotBefore=$start", "-DnotAfter=$end")83 .withEnvironment(environment)84 .build()85 result.task(":${CaPlugin.CREATE_TASK_NAME}")!!.outcome shouldBe TaskOutcome.SUCCESS86 val certificate = xdgDataHome.resolve("wolkenschloss/ca/ca.crt")87 .readX509Certificate()88 assertSoftly(certificate) {89 notBefore.toUtc() shouldBe start90 notAfter.toUtc() shouldBe end91 }92 }93 test("should create output in user defined location") {94 val result = createRunner()95 .withArguments("createInUserDefinedLocation")96 .withEnvironment(environment)97 .build()98 result.task(":createInUserDefinedLocation")!!.outcome shouldBe TaskOutcome.SUCCESS99 assertSoftly(workingDirectory.resolve("build/ca")) {100 shouldContainFile("ca.crt")101 shouldContainFile("ca.key")102 }103 }104 }105 }106}) {107 override fun isolationMode(): IsolationMode = IsolationMode.InstancePerLeaf108}109private fun Date.toUtc(): ZonedDateTime {110 return ZonedDateTime.ofInstant(this.toInstant(), ZoneOffset.UTC)111}...

Full Screen

Full Screen

FinishRideUseCaseTest.kt

Source:FinishRideUseCaseTest.kt Github

copy

Full Screen

1package com.stringconcat.kirillov.carsharing.ride.usecase.ride2import com.stringconcat.kirillov.carsharing.fixtures.commons.types.valueObjects.randomDistance3import com.stringconcat.kirillov.carsharing.fixtures.ride.domain.finishedRide4import com.stringconcat.kirillov.carsharing.fixtures.ride.domain.randomRideId5import com.stringconcat.kirillov.carsharing.fixtures.ride.domain.startedRide6import com.stringconcat.kirillov.carsharing.fixtures.ride.usecase.InMemoryRideRepository7import com.stringconcat.kirillov.carsharing.ride.domain.RideFinishedEvent8import com.stringconcat.kirillov.carsharing.ride.domain.RideStatus.FINISHED9import com.stringconcat.kirillov.carsharing.ride.usecase.ride.FinishRideUseCaseError.RideAlreadyFinishedError10import com.stringconcat.kirillov.carsharing.ride.usecase.ride.FinishRideUseCaseError.RideNotFound11import io.kotest.assertions.arrow.either.shouldBeLeft12import io.kotest.assertions.arrow.either.shouldBeRight13import io.kotest.matchers.collections.shouldContainExactly14import io.kotest.matchers.nulls.shouldBeNull15import io.kotest.matchers.nulls.shouldNotBeNull16import io.kotest.matchers.should17import io.kotest.matchers.shouldBe18import java.time.LocalDate.EPOCH19import java.time.LocalTime.MIDNIGHT20import java.time.OffsetDateTime21import java.time.ZoneOffset.UTC22import org.junit.jupiter.api.Test23internal class FinishRideUseCaseTest {24 private val coveredDistance = randomDistance()25 private val finishedDateTime = OffsetDateTime.of(EPOCH, MIDNIGHT, UTC)26 @Test27 fun `should finish started ride`() {28 val startedRide = startedRide()29 val persister = InMemoryRideRepository()30 val usecase = FinishRideUseCase(31 extractor = InMemoryRideRepository().apply {32 put(startedRide.id, startedRide)33 },34 persister = persister35 )36 val result = usecase.execute(FinishRideRequest(startedRide.id, finishedDateTime, coveredDistance))37 result.shouldBeRight()38 persister[startedRide.id] should {39 it.shouldNotBeNull()40 it.status shouldBe FINISHED41 it.finishDateTime shouldBe finishedDateTime42 it.coveredDistance shouldBe coveredDistance43 it.popEvents().shouldContainExactly(RideFinishedEvent(rideId = startedRide.id))44 }45 }46 @Test47 fun `shouldn't finish ride if ride not found`() {48 val persister = InMemoryRideRepository()49 val usecase = FinishRideUseCase(50 extractor = InMemoryRideRepository(),51 persister = persister52 )53 val rideId = randomRideId()54 val result = usecase.execute(FinishRideRequest(rideId = rideId, finishedDateTime, coveredDistance))55 result shouldBeLeft RideNotFound56 persister[rideId].shouldBeNull()57 }58 @Test59 fun `shouldn't finish ride if ride already finished`() {60 val finishedRide = finishedRide()61 val persister = InMemoryRideRepository()62 val usecase = FinishRideUseCase(63 extractor = InMemoryRideRepository().apply {64 put(finishedRide.id, finishedRide)65 },66 persister = persister67 )68 val result = usecase.execute(FinishRideRequest(rideId = finishedRide.id, finishedDateTime, coveredDistance))69 result shouldBeLeft RideAlreadyFinishedError70 persister[finishedRide.id].shouldBeNull()71 }72}...

Full Screen

Full Screen

TimeRangeTest.kt

Source:TimeRangeTest.kt Github

copy

Full Screen

1package com.github.cpickl.timesheet2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.core.spec.style.DescribeSpec4import io.kotest.matchers.shouldBe5import java.time.LocalDate6import java.time.LocalTime7class TimeRangeTest : DescribeSpec({8 val time1 = LocalTime.of(1, 0)9 val time2 = LocalTime.of(2, 0)10 val time3 = LocalTime.of(3, 0)11 val time4 = LocalTime.of(4, 0)12 describe("start before-equals end") {13 it("success") {14 TimeRange(time1, time2)15 }16 it("bigger fail") {17 shouldThrow<IllegalArgumentException> {18 TimeRange(time2, time1)19 }20 }21 it("same fail") {22 shouldThrow<IllegalArgumentException> {23 TimeRange(time1, time1)24 }25 }26 }27 describe("not overlaps") {28 it("range A before range B") {29 TimeRange(time1, time2).overlaps(TimeRange(time3, time4))shouldBe false30 }31 it("range A after range B") {32 TimeRange(time3, time4).overlaps(TimeRange(time1, time2)) shouldBe false33 }34 }35 describe("overlaps") {36 it("range A equals range B") {37 TimeRange(time1, time2).overlaps(TimeRange(time1, time2)) shouldBe true38 }39 it("range A before range B") {40 TimeRange(time1, time3).overlaps(TimeRange(time2, time4)) shouldBe true41 }42 it("range A after range B") {43 TimeRange(time2, time4).overlaps(TimeRange(time1, time3)) shouldBe true44 }45 it("range A bigger range B") {46 TimeRange(time1, time4).overlaps(TimeRange(time2, time3)) shouldBe true47 }48 it("range A smaller range B") {49 TimeRange(time2, time3).overlaps(TimeRange(time1, time4)) shouldBe true50 }51 }52})...

Full Screen

Full Screen

DayScheduleTest.kt

Source:DayScheduleTest.kt Github

copy

Full Screen

1package eu.kowalcze.michal.arch.clean.example.domain.model2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.matchers.shouldBe4import org.junit.jupiter.api.Test5import java.time.LocalDate6import java.time.LocalTime7internal class DayScheduleTest {8 @Test9 fun `Should reserve a slot`() {10 // given11 val today = LocalDate.now()12 val givenSchedule =13 DaySchedule(today, listOf(Slot(reserved = false, start = LocalTime.MIN, end = LocalTime.MAX)))14 // when15 val daySchedule = givenSchedule.reserveSlot(0)16 // then17 daySchedule.slots[0].reserved shouldBe true18 }19 @Test20 fun `Should fail when slot is already reserved`() {21 // given22 val today = LocalDate.now()23 val givenSchedule =24 DaySchedule(today, listOf(Slot(reserved = true, start = LocalTime.MIN, end = LocalTime.MAX)))25 // expect26 val exception =27 shouldThrow<SlotAlreadyReservedException> { givenSchedule.reserveSlot(0) }28 exception.message shouldBe "Slot[0] is already reserved"29 }30 @Test31 fun `Should fail when slot index is out of `() {32 // given33 val today = LocalDate.now()34 val givenSchedule =35 DaySchedule(today, listOf(Slot(reserved = true, start = LocalTime.MIN, end = LocalTime.MAX)))36 // expect37 val exception =38 shouldThrow<InvalidSlotIndexException> { givenSchedule.reserveSlot(1) }39 exception.message shouldBe "Slot[1] is not available. Slots count is: 1"40 }41}...

Full Screen

Full Screen

DateTest.kt

Source:DateTest.kt Github

copy

Full Screen

1package com.github.cpickl.timesheet.builder2import io.kotest.core.spec.style.DescribeSpec3import io.kotest.matchers.shouldBe4import java.time.LocalDate5import java.time.LocalTime6class DateTest : DescribeSpec() {7 init {8 describe("LocalDate.toParseableString") {9 it("sunshine") {10 val date = LocalDate.of(2003, 2, 1)11 date.toParsableDate() shouldBe "1.2.03"12 }13 }14 describe("LocalTime.toParseableString()") {15 LocalTime.of(1, 2).toParseableString() shouldBe "01:02"16 LocalTime.of(21, 42).toParseableString() shouldBe "21:42"17 }18 }19}...

Full Screen

Full Screen

localtime

Using AI Code Generation

copy

Full Screen

1val date = Date()2val localDate = date.toLocalDate()3val localTime = date.toLocalTime()4val localDateTime = date.toLocalDateTime()5val localDate = LocalDate.now()6val date = localDate.toDate()7val localDateTime = localDate.toLocalDateTime()8val localTime = LocalTime.now()9val date = localTime.toDate()10val localDateTime = localTime.toLocalDateTime()11val localDateTime = LocalDateTime.now()12val date = localDateTime.toDate()13val localDate = localDateTime.toLocalDate()14val localTime = localDateTime.toLocalTime()15val period = Period.ofDays(3)16val date = Date()17val datePlus3Days = date.plus(period)18val dateMinus3Days = date.minus(period)19val duration = Duration.ofHours(3)20val date = Date()21val datePlus3Hours = date.plus(duration)22val dateMinus3Hours = date.minus(duration)23val date = Date()24val datePlus3Days = date.plus(3, ChronoUnit.DAYS)25val dateMinus3Days = date.minus(3, ChronoUnit.DAYS)26val datePlus3Hours = date.plus(3, ChronoUnit.HOURS)27val dateMinus3Hours = date.minus(3, ChronoUnit.HOURS)28val date = Date()29val datePlus3Days = date.plus(3, Days)30val dateMinus3Days = date.minus(3, Days)31val datePlus3Hours = date.plus(3, Hours)32val dateMinus3Hours = date.minus(3, Hours)33val date = Date()34val period = Period.ofDays(3)35val datePlus3Days = date.plus(period)36val dateMinus3Days = date.minus(period)

Full Screen

Full Screen

localtime

Using AI Code Generation

copy

Full Screen

1val date = Date(2020, 1, 1, 0, 0, 0)2date should beToday()3date should beYesterday()4date should beTomorrow()5date should beDayBeforeYesterday()6date should beDayAfterTomorrow()7date should beLastWeek()8date should beNextWeek()9date should beLastMonth()10date should beNextMonth()11date should beLastYear()12date should beNextYear()13date should beThisYear()14date should beThisMonth()15date should beThisWeek()16date should beThisDay()17date should beThisHour()18date should beThisMinute()19date should beThisSecond()20date should beThisMillisecond()21date should beInThisYear()22date should beInThisMonth()23date should beInThisWeek()24date should beInThisDay()25date should beInThisHour()26date should beInThisMinute()27date should beInThisSecond()28date should beInThisMillisecond()29val dateTime = LocalDateTime(2020, 1, 1, 0, 0, 0)30dateTime should beToday()31dateTime should beYesterday()32dateTime should beTomorrow()33dateTime should beDayBeforeYesterday()34dateTime should beDayAfterTomorrow()35dateTime should beLastWeek()36dateTime should beNextWeek()37dateTime should beLastMonth()38dateTime should beNextMonth()39dateTime should beLastYear()40dateTime should beNextYear()41dateTime should beThisYear()42dateTime should beThisMonth()43dateTime should beThisWeek()44dateTime should beThisDay()45dateTime should beThisHour()46dateTime should beThisMinute()47dateTime should beThisSecond()48dateTime should beThisMillisecond()49dateTime should beInThisYear()50dateTime should beInThisMonth()51dateTime should beInThisWeek()52dateTime should beInThisDay()53dateTime should beInThisHour()54dateTime should beInThisMinute()55dateTime should beInThisSecond()56dateTime should beInThisMillisecond()57val offsetDateTime = OffsetDateTime(2020, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC)58offsetDateTime should beToday()59offsetDateTime should beYesterday()60offsetDateTime should beTomorrow()61offsetDateTime should beDayBeforeYesterday()62offsetDateTime should beDayAfterTomorrow()63offsetDateTime should beLastWeek()

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