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

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

CreateTaskSpec.kt

Source:CreateTaskSpec.kt Github

copy

Full Screen

1package family.haschka.wolkenschloss.gradle.ca2import family.haschka.wolkenschloss.gradle.ca.CaPlugin3import family.haschka.wolkenschloss.gradle.ca.TrustStore4import family.haschka.wolkenschloss.gradle.testbed.Directories5import io.kotest.assertions.throwables.shouldNotThrowAny6import io.kotest.assertions.throwables.shouldThrow7import io.kotest.core.spec.style.FunSpec8import io.kotest.engine.spec.tempdir9import io.kotest.engine.spec.tempfile10import io.kotest.extensions.system.withEnvironment11import io.kotest.matchers.date.shouldBeWithin12import io.kotest.matchers.file.shouldStartWithPath13import io.kotest.matchers.shouldBe14import org.bouncycastle.asn1.x500.X500Name15import org.bouncycastle.asn1.x500.style.BCStyle16import org.gradle.api.tasks.StopExecutionException17import org.gradle.kotlin.dsl.*18import org.gradle.testfixtures.ProjectBuilder19import java.time.Duration20import java.time.ZonedDateTime21class CreateTaskSpec : FunSpec({22 context("A project with create task") {23 withEnvironment(mapOf("XDG_DATA_HOME" to tempdir().path)) {24 val projectDir = tempdir()25 val project = ProjectBuilder.builder()26 .withProjectDir(projectDir)27 .withName(PROJECT_NAME)28 .build()29 project.pluginManager.apply(CaPlugin::class.java)30 test("should have a task named ${CaPlugin.CREATE_TASK_NAME}") {31 shouldNotThrowAny {32 project.tasks.named(CaPlugin.CREATE_TASK_NAME, TrustAnchor::class)33 }34 }35 test("should have a task names ${CaPlugin.TRUSTSTORE_TASK_NAME}") {36 shouldNotThrowAny {37 project.tasks.named(CaPlugin.TRUSTSTORE_TASK_NAME, TrustStore::class)38 }39 }40 test("certificate file defaults to \$XDG_DATA_HOME/wolkenschloss/ca/ca.crt") {41 val create = project.tasks.named(CaPlugin.CREATE_TASK_NAME, TrustAnchor::class.java)42 create.get().certificate.get().asFile shouldStartWithPath Directories.certificateAuthorityHome.resolve("ca.crt")43 }44 test("private key file defaults to \$XDG_DATA_HOME/wolkenschloss/ca/ca.key") {45 val create = project.tasks.named(CaPlugin.CREATE_TASK_NAME, TrustAnchor::class.java)46 create.get().privateKey.get().asFile shouldStartWithPath Directories.certificateAuthorityHome.resolve("ca.key")47 }48 test("The default for the start of validity is the current time") {49 val ca by project.tasks.existing(TrustAnchor::class)50 ca.get().notBefore.get().shouldBeWithin(Duration.ofSeconds(5), ZonedDateTime.now())51 }52 test("The default validity period is 5 years") {53 val ca by project.tasks.existing(TrustAnchor::class)54 ca.get().notAfter.get().shouldBeWithin(Duration.ofSeconds(5), ZonedDateTime.now().plusYears(10))55 }56 test("should have default subject") {57 val ca by project.tasks.existing(TrustAnchor::class)58 ca.get().subject.get() shouldBe CaPlugin.TRUST_ANCHOR_DEFAULT_SUBJECT59 }60 test("should stop execution if certificate already exists") {61 val certificate = tempfile()62 val create = project.tasks.create("crash", TrustAnchor::class.java)63 create.certificate.set(certificate)64 val exception = shouldThrow<StopExecutionException> {65 create.execute()66 }67 exception.message shouldBe "Certificate already exists"68 }69 test("should stop execution if private key already exists") {70 val create by project.tasks.creating(TrustAnchor::class) {71 notBefore.set(ZonedDateTime.now())72 notAfter.set(ZonedDateTime.now().plusYears(5))73 privateKey.set(tempfile())74 certificate.set(projectDir.resolve("build/ca/certificate"))75 }76 val exception = shouldThrow<StopExecutionException> {77 create.execute()78 }79 exception.message shouldBe "Private key already exists"80 }81 test("should customize subject") {82 val custom by project.tasks.registering(TrustAnchor::class) {83 subject {84 addRDN(BCStyle.CN, "Wolkenschloss Root CA")85 addRDN(BCStyle.OU, "Development")86 addRDN(BCStyle.O, "Wolkenschloss")87 addRDN(BCStyle.C, "DE")88 }89 }90 X500Name(custom.get().subject.get()) shouldBe X500Name(CaPlugin.TRUST_ANCHOR_DEFAULT_SUBJECT)91 }92 test("should customize subject with dsl") {93 val customDsl by project.tasks.registering(TrustAnchor::class) {94 subject {95 this[BCStyle.CN] = "Wolkenschloss Root CA"96 }97 }98 customDsl.get().subject.get() shouldBe "CN=Wolkenschloss Root CA"99 }100 }101 }102}) {103 companion object {104 const val PROJECT_NAME = "ca"105 }106}...

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

TiltaksansvarligGjennomforingTilgangRepositoryTest.kt

Source:TiltaksansvarligGjennomforingTilgangRepositoryTest.kt Github

copy

Full Screen

1package no.nav.amt.tiltak.tilgangskontroll.tiltaksansvarlig_tilgang2import ch.qos.logback.classic.Level3import ch.qos.logback.classic.Logger4import io.kotest.core.spec.style.FunSpec5import io.kotest.matchers.collections.shouldHaveSize6import io.kotest.matchers.date.shouldBeBefore7import io.kotest.matchers.shouldBe8import no.nav.amt.tiltak.test.database.DbTestDataUtils9import no.nav.amt.tiltak.test.database.DbUtils.shouldBeCloseTo10import no.nav.amt.tiltak.test.database.DbUtils.shouldBeEqualTo11import no.nav.amt.tiltak.test.database.SingletonPostgresContainer12import no.nav.amt.tiltak.test.database.data.TestData.GJENNOMFORING_113import no.nav.amt.tiltak.test.database.data.TestData.NAV_ANSATT_114import no.nav.amt.tiltak.test.database.data.TestDataRepository15import no.nav.amt.tiltak.test.database.data.commands.InsertTiltaksansvarligGjennomforingTilgangCommand16import org.slf4j.LoggerFactory17import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate18import java.time.ZonedDateTime19import java.util.*20class TiltaksansvarligGjennomforingTilgangRepositoryTest : FunSpec({21 val dataSource = SingletonPostgresContainer.getDataSource()22 lateinit var repository: TiltaksansvarligGjennomforingTilgangRepository23 lateinit var testDataRepository: TestDataRepository24 beforeEach {25 val rootLogger: Logger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME) as Logger26 rootLogger.level = Level.WARN27 repository = TiltaksansvarligGjennomforingTilgangRepository(NamedParameterJdbcTemplate(dataSource))28 testDataRepository = TestDataRepository(NamedParameterJdbcTemplate(dataSource))29 DbTestDataUtils.cleanAndInitDatabaseWithTestData(dataSource)30 }31 test("hentAktiveTilganger - skal hente tilganger") {32 val id = UUID.randomUUID()33 repository.opprettTilgang(34 id = id,35 navAnsattId = NAV_ANSATT_1.id,36 gjennomforingId = GJENNOMFORING_1.id,37 gyldigTil = ZonedDateTime.now().plusDays(1)38 )39 repository.opprettTilgang(40 id = UUID.randomUUID(),41 navAnsattId = NAV_ANSATT_1.id,42 gjennomforingId = GJENNOMFORING_1.id,43 gyldigTil = ZonedDateTime.now().minusDays(1)44 )45 val tilganger = repository.hentAktiveTilganger(NAV_ANSATT_1.id)46 tilganger shouldHaveSize 147 tilganger.first().id shouldBe id48 }49 test("opprettTilgang - skal opprette tilgang") {50 val id = UUID.randomUUID()51 val gyldigTil = ZonedDateTime.now().plusDays(1)52 repository.opprettTilgang(53 id = id,54 navAnsattId = NAV_ANSATT_1.id,55 gjennomforingId = GJENNOMFORING_1.id,56 gyldigTil = gyldigTil57 )58 val tilgang = repository.hentTilgang(id)59 tilgang.id shouldBe id60 tilgang.navAnsattId shouldBe NAV_ANSATT_1.id61 tilgang.gjennomforingId shouldBe GJENNOMFORING_1.id62 tilgang.gyldigTil shouldBeEqualTo gyldigTil63 tilgang.createdAt shouldBeCloseTo ZonedDateTime.now()64 }65 test("stopTilgang - skal stoppe tilgang") {66 val id = UUID.randomUUID()67 val gyldigTil = ZonedDateTime.now().plusDays(1)68 testDataRepository.insertTiltaksansvarligGjennomforingTilgang(69 InsertTiltaksansvarligGjennomforingTilgangCommand(70 id = id,71 navAnsattId = NAV_ANSATT_1.id,72 gjennomforingId = GJENNOMFORING_1.id,73 gyldigTil = gyldigTil,74 createdAt = ZonedDateTime.now()75 )76 )77 repository.stopTilgang(id)78 val tilgang = repository.hentTilgang(id)79 tilgang.gyldigTil shouldBeBefore ZonedDateTime.now()80 }81})...

Full Screen

Full Screen

ZonedDateTimeSerializerSpec.kt

Source:ZonedDateTimeSerializerSpec.kt Github

copy

Full Screen

1package common.serializers2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.core.spec.style.StringSpec4import io.kotest.matchers.ints.shouldBeExactly5import io.kotest.matchers.shouldBe6import kotlinx.serialization.ExperimentalSerializationApi7import kotlinx.serialization.Serializable8import kotlinx.serialization.decodeFromString9import kotlinx.serialization.json.Json10import org.kiva.bioauthservice.common.serializers.ZonedDateTimeSerializer11import java.time.Month12import java.time.ZoneId13import java.time.ZonedDateTime14import java.time.format.DateTimeParseException15import java.util.concurrent.TimeUnit16@ExperimentalSerializationApi17@Serializable18data class MyDto(19 @Serializable(with = ZonedDateTimeSerializer::class) val myDate: ZonedDateTime20)21@ExperimentalSerializationApi22class ZonedDateTimeSerializerSpec : StringSpec({23 "should be able to convert an ISO-8601 Instant string to a ZonedDateTime" {24 val jsonInput = """25 {26 "myDate": "2011-12-03T10:15:30Z"27 }28 """.trimIndent()29 val dto: MyDto = Json.decodeFromString(jsonInput)30 val zdt: ZonedDateTime = dto.myDate31 zdt.year shouldBeExactly 201132 zdt.month shouldBe Month.DECEMBER33 zdt.dayOfMonth shouldBeExactly 334 zdt.zone.normalized() shouldBe ZoneId.of("UTC").normalized()35 zdt.hour shouldBeExactly 1036 zdt.minute shouldBeExactly 1537 zdt.second shouldBeExactly 3038 zdt.offset.totalSeconds shouldBeExactly 039 }40 "should be able to convert an ISO-8601 string with offset to a ZonedDateTime" {41 val jsonInput = """42 {43 "myDate": "2011-12-03T10:15:30+01:00"44 }45 """.trimIndent()46 val dto: MyDto = Json.decodeFromString(jsonInput)47 val zdt: ZonedDateTime = dto.myDate48 zdt.year shouldBeExactly 201149 zdt.month shouldBe Month.DECEMBER50 zdt.dayOfMonth shouldBeExactly 351 zdt.zone.normalized() shouldBe ZoneId.of("UTC+1").normalized()52 zdt.hour shouldBeExactly 1053 zdt.minute shouldBeExactly 1554 zdt.second shouldBeExactly 3055 zdt.offset.totalSeconds shouldBeExactly TimeUnit.HOURS.toSeconds(1).toInt()56 }57 "should be able to convert an ISO-8601 string with offset and zone to a ZonedDateTime" {58 val jsonInput = """59 {60 "myDate": "2011-12-03T10:15:30+01:00[Europe/Paris]"61 }62 """.trimIndent()63 val dto: MyDto = Json.decodeFromString(jsonInput)64 val zdt: ZonedDateTime = dto.myDate65 zdt.year shouldBeExactly 201166 zdt.month shouldBe Month.DECEMBER67 zdt.dayOfMonth shouldBeExactly 368 zdt.zone shouldBe ZoneId.of("Europe/Paris")69 zdt.hour shouldBeExactly 1070 zdt.minute shouldBeExactly 1571 zdt.second shouldBeExactly 3072 zdt.offset.totalSeconds shouldBeExactly TimeUnit.HOURS.toSeconds(1).toInt()73 }74 "should fail to convert an ISO-8601 string with no offset and zone to a ZonedDateTime" {75 val jsonInput = """76 {77 "myDate": "2011-12-03T10:15:30"78 }79 """.trimIndent()80 shouldThrow<DateTimeParseException> {81 Json.decodeFromString<MyDto>(jsonInput)82 }83 }84})...

Full Screen

Full Screen

CartRepositorySpec.kt

Source:CartRepositorySpec.kt Github

copy

Full Screen

1package com.helloworld.domain.cart2import com.helloworld.redis.config.RedisConfig3import io.kotest.core.spec.style.DescribeSpec4import io.kotest.matchers.ints.shouldBeGreaterThan5import io.kotest.matchers.shouldBe6import io.kotest.matchers.shouldNotBe7import org.springframework.boot.test.autoconfigure.data.redis.DataRedisTest8import org.springframework.context.annotation.Import9import org.springframework.test.context.ActiveProfiles10import java.math.BigDecimal11import java.time.ZonedDateTime12@DataRedisTest13@Import(RedisConfig::class)14@ActiveProfiles("test")15class CartRepositorySpec(private val cartRepository: CartRepository) : DescribeSpec() {16 init {17 describe("cart") {18 val accountId = 1L19 val id = Cart.getId(accountId)20 val channelType: String = "channelType"21 val deviceId: String = "deviceId"22 val shop: CartShop = CartShop(1L, "FIRST", "shopName", 1L)23 val cart = Cart(24 id = id,25 channelType = channelType,26 deviceId = deviceId,27 accountId = accountId,28 shop = shop,29 createdAt = ZonedDateTime.now(),30 updatedAt = ZonedDateTime.now()31 )32 val cartLineItem = CartLineItem(33 cartId = cart.id,34 productId = 1L,35 productName = "productName",36 productDescription = "productDescription",37 productType = "productType",38 amount = BigDecimal.valueOf(1000L),39 salesAmount = BigDecimal.valueOf(2000L),40 discountAmount = BigDecimal.valueOf(1000L)41 )42 val cartLineItemOption = CartLineItemOption(43 productId = cartLineItem.productId,44 optionId = 1L,45 optionName = "optionName",46 optionGroupId = 1L,47 optionGroupName = "optionGroupName",48 amount = BigDecimal.valueOf(500L),49 salesAmount = BigDecimal.valueOf(1000L),50 discountAmount = BigDecimal.valueOf(500L)51 )52 cartLineItem.addLineItemOption(cartLineItemOption)53 cart.addLineItem(cartLineItem)54 it("create") {55 cart.calculate()56 val result = cartRepository.save(cart)57 result.shouldNotBe(null)58 result.totalAmount.shouldBe(BigDecimal.valueOf(1500L))59 result.amount.shouldBe(BigDecimal.valueOf(1500L))60 result.salesAmount.shouldBe(BigDecimal.valueOf(3000L))61 result.discountAmount.shouldBe(BigDecimal.valueOf(1500L))62 }63 it("read") {64 var result = cartRepository.findAllByAccountId(accountId).toList().sortedByDescending { it.updatedAt }.firstOrNull()65 result.shouldNotBe(null)66 }67 it("read list") {68 cartRepository.findAllByAccountId(accountId).toList().size.shouldBeGreaterThan(0)69 }70 }71 }72}...

Full Screen

Full Screen

SpecOrdering.kt

Source:SpecOrdering.kt Github

copy

Full Screen

1package kotest.sandbox2import io.kotest.core.spec.Order3import io.kotest.core.spec.style.FunSpec4import io.kotest.core.spec.style.StringSpec5import io.kotest.core.test.TestCaseOrder6import io.kotest.matchers.string.shouldHaveLength7import java.time.ZonedDateTime8@Order(1)9class FooTest: FunSpec({10 test("sam should be a three letter name") {11 "sam".shouldHaveLength(3)12 println("FooTest ${ZonedDateTime.now()}")13 }14})15@Order(1)16class BarTest: FunSpec({17 test("sam should be a three letter name") {18 "sam".shouldHaveLength(3)19 println("BarTest ${ZonedDateTime.now()}")20 }21})22@Order(0)23class FarTest: FunSpec({24 test("sam should be a three letter name") {25 "sam".shouldHaveLength(3)26 println("FarTest ${ZonedDateTime.now()}")27 }28})29class BooTest: FunSpec({30 test("sam should be a three letter name") {31 "sam".shouldHaveLength(3)32 println("BooTest ${ZonedDateTime.now()}")33 }34})35@Order(2)36class BazTest: FunSpec({37 test("sam should be a three letter name") {38 "sam".shouldHaveLength(3)39 println("BazTest ${ZonedDateTime.now()}")40 }41})42class SequentialSpec : StringSpec() {43 override fun testCaseOrder(): TestCaseOrder? = TestCaseOrder.Sequential44 init {45 "foo" {46 println("I run first as I'm defined first")47 }48 "bar" {49 println("I run second as I'm defined second")50 }51 }52}53class RandomSpec : StringSpec() {54 override fun testCaseOrder(): TestCaseOrder? = TestCaseOrder.Random55 init {56 "foo" {57 println("foo: This test may run first or second")58 }59 "bar" {60 println("bar: This test may run first or second")61 }62 }63}64class LexicographicSpec : StringSpec() {65 override fun testCaseOrder(): TestCaseOrder? = TestCaseOrder.Lexicographic66 init {67 "foo" {68 println("I run second as bar < foo")69 }70 "bar" {71 println("I run first as bar < foo")72 }73 }74}...

Full Screen

Full Screen

SerializationTest.kt

Source:SerializationTest.kt Github

copy

Full Screen

1package servers2import io.kotest.core.spec.style.DescribeSpec3import io.kotest.matchers.shouldBe4import kotlinx.serialization.KSerializer5import kotlinx.serialization.Serializable6import kotlinx.serialization.decodeFromString7import kotlinx.serialization.descriptors.PrimitiveKind8import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor9import kotlinx.serialization.descriptors.SerialDescriptor10import kotlinx.serialization.encodeToString11import kotlinx.serialization.encoding.Decoder12import kotlinx.serialization.encoding.Encoder13import kotlinx.serialization.json.Json14import java.time.ZoneOffset15import java.time.ZonedDateTime16object ZonedDateTimeSerializer : KSerializer<ZonedDateTime> {17 override val descriptor: SerialDescriptor =18 PrimitiveSerialDescriptor("servers.ZonedDateTimeSerializer", PrimitiveKind.STRING)19 override fun deserialize(decoder: Decoder): ZonedDateTime =20 ZonedDateTime.parse(decoder.decodeString())21 override fun serialize(encoder: Encoder, value: ZonedDateTime) =22 encoder.encodeString(value.toString())23}24@Serializable25data class Person(26 val name: String,27 @Serializable(ZonedDateTimeSerializer::class)28 val bornWhen: ZonedDateTime29)30class SerializationTest : DescribeSpec({31 describe("Kotlin serialization") {32 it("serialises JSON as expected") {33 val mikeBornWhen = ZonedDateTime.of(1961, 1, 4, 9, 4, 0, 0, ZoneOffset.ofHours(10))34 Json.encodeToString(Person("Mike", mikeBornWhen)) shouldBe35 """{"name":"Mike","bornWhen":"1961-01-04T09:04+10:00"}"""36 }37 it("deserialises JSON as expected") {38 val lucyBornWhen = ZonedDateTime.of(1961, 1, 4, 9, 15, 0, 0, ZoneOffset.ofHours(10))39 Json.decodeFromString<Person>("""{"name":"Lucy","bornWhen":"1961-01-04T09:15+10:00"}""") shouldBe40 Person("Lucy", lucyBornWhen)41 }42 }43})...

Full Screen

Full Screen

DbUtils.kt

Source:DbUtils.kt Github

copy

Full Screen

1package no.nav.amt.tiltak.test.database2import io.kotest.matchers.date.shouldBeWithin3import io.kotest.matchers.shouldNotBe4import java.time.Duration5import java.time.LocalDate6import java.time.LocalDateTime7import java.time.ZonedDateTime8object DbUtils {9 /**10 * A helping function as SQL Timestamp and LocalDateTime does not have the same precision11 */12 fun LocalDateTime.isEqualTo(other: LocalDateTime?): Boolean {13 if (other == null) {14 return false15 }16 return this.year == other.year17 && this.month == other.month18 && this.dayOfMonth == other.dayOfMonth19 && this.hour == other.hour20 && this.minute == other.minute21 && this.second == other.second22 }23 /**24 * Should be used to check equality, 1 second skew is allowed to work around different precision on milliseconds25 */26 infix fun ZonedDateTime.shouldBeEqualTo(expected: ZonedDateTime?) {27 expected shouldNotBe null28 expected!!.shouldBeWithin(Duration.ofSeconds(1), this)29 }30 infix fun ZonedDateTime.shouldBeCloseTo(expected: ZonedDateTime?) {31 expected shouldNotBe null32 expected!!.shouldBeWithin(Duration.ofSeconds(10), this)33 }34 fun LocalDate.isEqualTo(other: LocalDate?): Boolean {35 if (other == null) {36 return false37 }38 return this.year == other.year39 && this.month == other.month40 && this.dayOfMonth == other.dayOfMonth41 }42}...

Full Screen

Full Screen

zoneddatetime

Using AI Code Generation

copy

Full Screen

1val date = ZonedDateTime.now()2date should beAfter(ZonedDateTime.now().minusDays(1))3date should beAfterOrEqual(ZonedDateTime.now().minusDays(1))4date should beBefore(ZonedDateTime.now().plusDays(1))5date should beBeforeOrEqual(ZonedDateTime.now().plusDays(1))6date should beBetween(ZonedDateTime.now().minusDays(1), ZonedDateTime.now().plusDays(1))7date should beBetweenOrEqual(ZonedDateTime.now().minusDays(1), ZonedDateTime.now().plusDays(1))8date should beEqual(ZonedDateTime.now())9date should beEqualIgnoringNanos(ZonedDateTime.now())10date should beEqualIgnoringSeconds(ZonedDateTime.now())11date should beEqualIgnoringMillis(ZonedDateTime.now())12date should beEqualIgnoringMinutes(ZonedDateTime.now())13date should beEqualIgnoringHours(ZonedDateTime.now())14date should beEqualIgnoringDays(ZonedDateTime.now())15date should beEqualIgnoringMonths(ZonedDateTime.now())16date should beEqualIgnoringYears(ZonedDateTime.now())17date should beEqualIgnoringTime(ZonedDateTime.now())18date should beEqualIgnoringTimeZone(ZonedDateTime.now())19date should beEqualIgnoringTimeZoneAndTime(ZonedDateTime.now())20date should beEqualIgnoringTimeZoneAndTimeIgnoringNanos(ZonedDateTime.now())21date should beEqualIgnoringTimeZoneAndTimeIgnoringSeconds(ZonedDateTime.now())22date should beEqualIgnoringTimeZoneAndTimeIgnoringMillis(ZonedDateTime.now())23date should beEqualIgnoringTimeZoneAndTimeIgnoringMinutes(ZonedDateTime.now())24date should beEqualIgnoringTimeZoneAndTimeIgnoringHours(ZonedDateTime.now())25date should beEqualIgnoringTimeZoneAndTimeIgnoringDays(ZonedDateTime.now())26date should beEqualIgnoringTimeZoneAndTimeIgnoringMonths(ZonedDateTime.now())27date should beEqualIgnoringTimeZoneAndTimeIgnoringYears(ZonedDateTime.now())28date should beEqualIgnoringTimeZoneAndTimeIgnoringTime(ZonedDateTime.now())29date should beEqualIgnoringTimeZoneAndTimeIgnoringTimeZone(ZonedDateTime.now())30date should beEqualIgnoringTimeZoneAndTimeIgnoringTimeZoneAndTime(ZonedDateTime.now())31date should beEqualIgnoringTimeZoneAndTimeIgnoringTimeZoneAndTimeIgnoringNanos(ZonedDateTime.now())32date should beEqualIgnoringTimeZoneAndTimeIgnoringTimeZoneAndTimeIgnoringSeconds(ZonedDateTime.now())33date should beEqualIgnoringTimeZoneAndTimeIgnoringTimeZoneAndTimeIgnoringMillis(ZonedDateTime.now())34date should beEqualIgnoringTimeZoneAndTimeIgnoringTimeZoneAndTimeIgnoringMinutes(ZonedDateTime.now())35date should beEqualIgnoringTimeZoneAndTimeIgnoringTimeZoneAndTimeIgnoringHours(ZonedDateTime.now())36date should beEqualIgnoringTimeZoneAndTimeIgnoringTimeZoneAndTimeIgnoringDays(ZonedDateTime.now())

Full Screen

Full Screen

zoneddatetime

Using AI Code Generation

copy

Full Screen

1val date = ZonedDateTime.now()2date shouldBeToday()3date shouldNotBeToday()4date shouldBeYesterday()5date shouldNotBeYesterday()6date shouldBeTomorrow()7date shouldNotBeTomorrow()8date shouldBeBefore(ZonedDateTime.now().plusDays(1))9date shouldBeAfter(ZonedDateTime.now().minusDays(1))10date shouldBeBetween(ZonedDateTime.now().minusDays(1), ZonedDateTime.now().plusDays(1))11date shouldNotBeBetween(ZonedDateTime.now().minusDays(1), ZonedDateTime.now().plusDays(1))12date shouldBeBeforeOrEqualTo(ZonedDateTime.now().plusDays(1))13date shouldBeAfterOrEqualTo(ZonedDateTime.now().minusDays(1))14date shouldBeBeforeToday()15date shouldBeAfterToday()16date shouldBeBeforeYesterday()17date shouldBeAfterYesterday()18date shouldBeBeforeTomorrow()19date shouldBeAfterTomorrow()20date shouldBeBeforeOrEqualToToday()21date shouldBeAfterOrEqualToToday()22date shouldBeBeforeOrEqualToYesterday()23date shouldBeAfterOrEqualToYesterday()24date shouldBeBeforeOrEqualToTomorrow()25date shouldBeAfterOrEqualToTomorrow()26date shouldBeSameDayAs(ZonedDateTime.now())27date shouldNotBeSameDayAs(ZonedDateTime.now())28date shouldBeSameMonthAs(ZonedDateTime.now())29date shouldNotBeSameMonthAs(ZonedDateTime.now())30date shouldBeSameYearAs(ZonedDateTime.now())31date shouldNotBeSameYearAs(ZonedDateTime.now())32date shouldBeSameHourAs(ZonedDateTime.now())33date shouldNotBeSameHourAs(ZonedDateTime.now())34date shouldBeSameMinuteAs(ZonedDateTime.now())35date shouldNotBeSameMinuteAs(ZonedDateTime.now())36date shouldBeSameSecondAs(ZonedDateTime.now())37date shouldNotBeSameSecondAs(ZonedDateTime.now())38date shouldBeSameInstantAs(ZonedDateTime.now())39date shouldNotBeSameInstantAs(ZonedDateTime.now())40date shouldBeSameInstantAs(Instant.now())41date shouldNotBeSameInstantAs(Instant.now())42date shouldBeSameYearMonthAs(ZonedDateTime.now())43date shouldNotBeSameYearMonthAs(ZonedDateTime.now())44date shouldBeSameMonthDayAs(ZonedDateTime.now())45date shouldNotBeSameMonthDayAs(ZonedDateTime.now())46date shouldBeSameHourMinuteAs(ZonedDateTime.now())47date shouldNotBeSameHourMinuteAs(ZonedDateTime.now())48date shouldBeSameHourMinuteSecondAs(ZonedDateTime.now())49date shouldNotBeSameHourMinuteSecondAs(ZonedDateTime.now())50date shouldBeSameYearMonthDayAs(ZonedDateTime.now())51date shouldNotBeSameYearMonthDayAs(ZonedDateTime.now())52date shouldBeSameYearMonthDayHourAs(ZonedDateTime.now())

Full Screen

Full Screen

zoneddatetime

Using AI Code Generation

copy

Full Screen

1 import io.kotest.matchers.date.shouldBeSameDayAs2 import java.time.ZoneId3 import java.time.ZonedDateTime4 fun main() {5 val now = ZonedDateTime.now()6 val today = now.withHour(0).withMinute(0).withSecond(0).withNano(0)7 val sameDay = today.withZoneSameInstant(ZoneId.of("America/Los_Angeles"))8 now.shouldBeSameDayAs(sameDay)9 }10 Expected ZonedDateTime(2020-09-29T13:40:53.767-07:00[America/Los_Angeles]) to be same day as ZonedDateTime(2020-09-29T00:00-07:00[America/Los_Angeles]) but was not

Full Screen

Full Screen

zoneddatetime

Using AI Code Generation

copy

Full Screen

1import io.kotest.matchers.date.*2import java.time.*3val dateTime = ZonedDateTime.of(2021, 6, 16, 13, 0, 0, 0, ZoneId.of("UTC"))4dateTime should beBefore(ZonedDateTime.of(2021, 6, 16, 14, 0, 0, 0, ZoneId.of("UTC")))5dateTime should beAfter(ZonedDateTime.of(2021, 6, 16, 12, 0, 0, 0, ZoneId.of("UTC")))6dateTime should beSameOrBefore(ZonedDateTime.of(2021, 6, 16, 14, 0, 0, 0, ZoneId.of("UTC")))7dateTime should beSameOrAfter(ZonedDateTime.of(2021, 6, 16, 12, 0, 0, 0, ZoneId.of("UTC")))8dateTime should beSameOrAfter(ZonedDateTime.of(2021, 6, 16, 13, 0, 0, 0, ZoneId.of("UTC")))9dateTime should beSameOrBefore(ZonedDateTime.of(2021, 6, 16, 13, 0, 0, 0, ZoneId.of("UTC")))10dateTime should beSameInstantAs(ZonedDateTime.of(2021, 6, 16, 13, 0, 0, 0, ZoneId.of("UTC")))11dateTime should beSameDayAs(ZonedDateTime.of(2021, 6, 16, 13, 0, 0, 0, ZoneId.of("UTC")))12dateTime should beSameMonthAs(ZonedDateTime.of(2021, 6, 16, 13, 0, 0, 0, ZoneId.of("UTC")))13dateTime should beSameYearAs(ZonedDateTime.of(2021, 6, 16, 13, 0, 0, 0, ZoneId.of("UTC")))14dateTime should beSameHourAs(ZonedDateTime.of(2021, 6, 16, 13, 0, 0, 0, ZoneId.of("UTC")))15dateTime should beSameMinuteAs(ZonedDateTime.of(2021, 6, 16, 13, 0, 0, 0, ZoneId.of("UTC"))

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