Best Kotest code snippet using io.kotest.matchers.time.duration
KesTestSetupTest.kt
Source:KesTestSetupTest.kt
1package no.ks.kes.test2import io.kotest.assertions.asClue3import io.kotest.assertions.fail4import io.kotest.assertions.failure5import io.kotest.assertions.timing.eventually6import io.kotest.core.spec.style.FunSpec7import io.kotest.matchers.collections.shouldContain8import io.kotest.matchers.collections.shouldHaveSize9import io.kotest.matchers.shouldBe10import io.kotest.matchers.shouldNotBe11import io.kotest.matchers.types.shouldBeSameInstanceAs12import io.kotest.property.Arb13import io.kotest.property.arbitrary.UUIDVersion14import io.kotest.property.arbitrary.uuid15import io.kotest.property.checkAll16import no.ks.kes.lib.Projections17import no.ks.kes.lib.Sagas18import no.ks.kes.serdes.jackson.JacksonCmdSerdes19import no.ks.kes.serdes.jackson.JacksonEventSerdes20import no.ks.kes.test.example.*21import java.util.*22import kotlin.time.DurationUnit23import kotlin.time.ExperimentalTime24import kotlin.time.toDuration25@ExperimentalTime26class KesTestSetupTest : FunSpec({27 test("Creates subscriberFactory") {28 withKes(eventSerdes = JacksonEventSerdes(emptySet()), cmdSerdes = JacksonCmdSerdes(emptySet())) {29 kesTestSetup -> kesTestSetup.subscriberFactory shouldNotBe null30 }31 }32 test("Creates aggregateRepository") {33 withKes(eventSerdes = JacksonEventSerdes(emptySet()), cmdSerdes = JacksonCmdSerdes(emptySet())) {34 kesTestSetup -> kesTestSetup.aggregateRepository shouldNotBe null35 }36 }37 test("Exposes eventSerdes") {38 val eventSerdes = JacksonEventSerdes(emptySet())39 withKes(eventSerdes = eventSerdes, cmdSerdes = JacksonCmdSerdes(emptySet())) {40 kesTestSetup -> kesTestSetup.eventSerdes shouldBeSameInstanceAs eventSerdes41 }42 }43 test("Exposes cmdSerdes") {44 val cmdSerdes = JacksonCmdSerdes(emptySet())45 withKes(eventSerdes = JacksonEventSerdes(emptySet()), cmdSerdes = cmdSerdes) {46 kesTestSetup -> kesTestSetup.cmdSerdes shouldBeSameInstanceAs cmdSerdes47 }48 }49 test("Projections using test framework") {50 val enginesProjection = EnginesProjection()51 withKes(eventSerdes = Events.serdes, cmdSerdes = Cmds.serdes) {52 Projections.initialize(53 eventSubscriberFactory = it.subscriberFactory,54 subscriber = testCase.displayName,55 projectionRepository = it.projectionRepository,56 projections = setOf(enginesProjection)57 )58 val cmdHandler = EngineCmdHandler(repository = it.aggregateRepository)59 val aggregateId = UUID.randomUUID()60 cmdHandler.handle(Cmds.Create(aggregateId))61 eventually(5.toDuration(DurationUnit.SECONDS)) {62 enginesProjection.all shouldContain aggregateId63 }64 }65 }66 test("Project a lot of events") {67 val enginesProjection = EnginesProjection()68 withKes(eventSerdes = Events.serdes, cmdSerdes = Cmds.serdes) { kes ->69 Projections.initialize(70 eventSubscriberFactory = kes.subscriberFactory,71 subscriber = testCase.displayName,72 projectionRepository = kes.projectionRepository,73 projections = setOf(enginesProjection)74 )75 val cmdHandler = EngineCmdHandler(repository = kes.aggregateRepository)76 val aggregatesToCreate = 10_00077 checkAll(iterations = aggregatesToCreate, Arb.uuid(UUIDVersion.V4, false)) { aggregationId ->78 cmdHandler.handle(Cmds.Create(aggregationId))79 }80 eventually(5.toDuration(DurationUnit.SECONDS)) {81 enginesProjection.all shouldHaveSize aggregatesToCreate82 kes.eventStream.eventCount() shouldBe aggregatesToCreate83 }84 }85 }86 test("Sagas using test framework") {87 withKes(eventSerdes = Events.serdes, cmdSerdes = Cmds.serdes) { kes ->88 val cmdHandler = EngineCmdHandler(repository = kes.aggregateRepository)89 val commandQueue = kes.createCommandQueue(setOf(cmdHandler))90 val sagaRepository = kes.createSagaRepository(commandQueue)91 Sagas.initialize(eventSubscriberFactory = kes.subscriberFactory,92 sagaRepository = sagaRepository,93 sagas = setOf(EngineSaga),94 commandQueue = commandQueue,95 pollInterval = 1096 ) {97 e -> failure("Failed to process event for saga", e)98 }99 val aggregateId = UUID.randomUUID()100 cmdHandler.handle(Cmds.Create(aggregateId)).asClue {101 it.id shouldBe aggregateId102 }103 eventually(10.toDuration(DurationUnit.SECONDS)) {104 sagaRepository.getSagaState(aggregateId, SAGA_SERILIZATION_ID, EngineSagaState::class)?.asClue {105 it.stoppedBySaga shouldBe true106 } ?: fail("EngineSaga did not change state of aggregate to be stopped")107 }108 }109 }110})...
EpochTest.kt
Source:EpochTest.kt
1package io.blockfrost.sdk_kotlin.itests2import io.blockfrost.sdk_kotlin.api.CardanoEpochsApi3import io.blockfrost.sdk_kotlin.infrastructure.BlockfrostConfig4import io.kotest.core.spec.style.DescribeSpec5import io.kotest.matchers.collections.shouldNotBeEmpty6import io.kotest.matchers.floats.plusOrMinus7import io.kotest.matchers.ints.shouldBeLessThan8import io.kotest.matchers.nulls.shouldBeNull9import io.kotest.matchers.nulls.shouldNotBeNull10import io.kotest.matchers.shouldBe11import kotlin.properties.Delegates12import kotlin.time.Duration13import kotlin.time.ExperimentalTime14@OptIn(ExperimentalTime::class)15class EpochTest : DescribeSpec({16 var api: CardanoEpochsApi by Delegates.notNull()17 System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "INFO")18 describe("epochs"){19 beforeTest {20 api = CardanoEpochsApi(config = BlockfrostConfig.defaulMainNetConfig)21 }22 it("getLatest").config(timeout = Duration.Companion.seconds(10)){23 val r = api.getLatestEpoch()24 r.shouldNotBeNull()25 }26 it("epoch0").config(timeout = Duration.Companion.seconds(10)){27 val r = api.getEpoch(0)28 r.shouldNotBeNull()29 r.epoch.shouldBe(0)30 r.startTime.shouldBe(1506203091)31 r.endTime.shouldBe(1506635091)32 r.firstBlockTime.shouldBe(1506203091)33 r.lastBlockTime.shouldBe(1506635071)34 r.blockCount.shouldBe(21587)35 r.txCount.shouldBe(33)36 r.output.shouldBe("10378568796482912")37 r.fees.shouldBe("3458053")38 r.activeStake.shouldBeNull()39 }40 it("epoch242").config(timeout = Duration.Companion.seconds(10)){41 val r = api.getEpoch(242)42 r.shouldNotBeNull()43 r.epoch.shouldBe(242)44 r.startTime.shouldBe(1610747091)45 r.endTime.shouldBe(1611179091)46 r.firstBlockTime.shouldBe(1610747091)47 r.lastBlockTime.shouldBe(1611179076)48 r.blockCount.shouldBe(21418)49 r.txCount.shouldBe(74057)50 r.output.shouldBe("63148817438049616")51 r.fees.shouldBe("16905060417")52 r.activeStake.shouldNotBeNull().shouldBe("21755094259019945")53 }54 it("stakes242").config(timeout = Duration.Companion.seconds(10)){55 val r = api.getActiveStakesForEpoch(242)56 r.shouldNotBeNull()57 }58 it("parameters267").config(timeout = Duration.Companion.seconds(10)){59 val r = api.getEpochParam(267)60 r.shouldNotBeNull()61 r.minFeeA.shouldBe(44)62 r.minFeeB.shouldBe(155381)63 r.maxBlockSize.shouldBe(65536)64 r.maxTxSize.shouldBe(16384)65 r.maxBlockHeaderSize.shouldBe(1100)66 r.keyDeposit.shouldBe("2000000")67 r.poolDeposit.shouldBe("500000000")68 r.eMax.shouldBe(18)69 r.nOpt.shouldBe(500)70 r.a0.shouldBe(0.3f.plusOrMinus(0.00001f))71 r.rho.shouldBe(0.003f.plusOrMinus(0.00001f))72 r.tau.shouldBe(0.2f.plusOrMinus(0.00001f))73 r.decentralisationParam.shouldBe(0.0f.plusOrMinus(0.00001f))74 r.extraEntropy.shouldBeNull()75 r.protocolMajorVer.shouldBe(4)76 r.protocolMinorVer.shouldBe(0)77 r.minUtxo.shouldBe("1000000")78 r.minPoolCost.shouldBe("340000000")79 }80 it("next").config(timeout = Duration.Companion.seconds(10)){81 val r = api.getNextEpochs(242)82 r.shouldNotBeEmpty()83 r.first().epoch.shouldBe(243)84 }85 it("prev").config(timeout = Duration.Companion.seconds(10)){86 val r = api.getPreviousEpochs(242)87 r.shouldNotBeEmpty()88 r.first().epoch.shouldBeLessThan(242)89 }90 it("blocks").config(timeout = Duration.Companion.seconds(10)){91 val r = api.getBlocksForEpoch(242, count = 2)92 r.shouldNotBeEmpty()93 }94 it("blocksAndPool").config(timeout = Duration.Companion.seconds(10)){95 val r = api.getBlocksForEpochAndPool(242, "pool1pu5jlj4q9w9jlxeu370a3c9myx47md5j5m2str0naunn2q3lkdy")96 r.shouldNotBeEmpty()97 }98 }99})...
AssetsTest.kt
Source:AssetsTest.kt
1package io.blockfrost.sdk_kotlin.itests2import io.blockfrost.sdk_kotlin.api.CardanoAssetsApi3import io.blockfrost.sdk_kotlin.infrastructure.BlockfrostConfig4import io.blockfrost.sdk_kotlin.models.AssetHistory5import io.kotest.core.spec.style.DescribeSpec6import io.kotest.matchers.collections.shouldContainExactly7import io.kotest.matchers.collections.shouldNotBeEmpty8import io.kotest.matchers.ints.shouldBeGreaterThan9import io.kotest.matchers.maps.shouldContainExactly10import io.kotest.matchers.nulls.shouldBeNull11import io.kotest.matchers.nulls.shouldNotBeNull12import io.kotest.matchers.shouldBe13import io.kotest.matchers.string.shouldNotBeBlank14import kotlin.properties.Delegates15import kotlin.time.Duration16import kotlin.time.ExperimentalTime17@OptIn(ExperimentalTime::class)18class AssetsTest : DescribeSpec({19 var api: CardanoAssetsApi by Delegates.notNull()20 System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "INFO")21 describe("load assets"){22 beforeTest {23 api = CardanoAssetsApi(config = BlockfrostConfig.defaulMainNetConfig)24 }25 it("all").config(timeout = Duration.Companion.seconds(10)){26 val r = api.getAssets()27 r.shouldNotBeNull()28 }29 it("by id").config(timeout = Duration.Companion.seconds(10)){30 val r = api.getAsset("b863bc7369f46136ac1048adb2fa7dae3af944c3bbb2be2f216a8d4f42657272795361707068697265")31 r.shouldNotBeNull()32 r.asset.shouldBe("b863bc7369f46136ac1048adb2fa7dae3af944c3bbb2be2f216a8d4f42657272795361707068697265")33 r.assetName.shouldBe("42657272795361707068697265")34 r.fingerprint.shouldBe("asset1hwnpal5vap799t6kkjmjf6myhse4zl2vu4ahzz")35 r.initialMintTxHash.shouldBe("6556b532acf59835084f62d30675f3a55b78c61959bca44a86ea02c320fbf822")36 r.metadata.shouldBeNull()37 r.mintOrBurnCount.shouldBe(1)38 r.onchainMetadata.shouldNotBeNull()39 r.onchainMetadata!!.shouldContainExactly(mapOf(40 "color" to "#0F52BA",41 "image" to "ipfs://ipfs/QmWxK9BvEbLGFZuQHL8zbHXSv469JrqnX3kUcZafjsoka4",42 "name" to "Berry Sapphire",43 ))44 r.policyId.shouldBe("b863bc7369f46136ac1048adb2fa7dae3af944c3bbb2be2f216a8d4f")45 r.quantity.shouldBe("1")46 }47 it("history").config(timeout = Duration.Companion.seconds(10)){48 val r = api.getAssetHistory("00000002df633853f6a47465c9496721d2d5b1291b8398016c0e87ae6e7574636f696e")49 r.shouldNotBeEmpty()50 r.shouldContainExactly(51 AssetHistory(txHash = "e252be4c7e40d35919f741c9649ff207c3e49d53bb819e5c1cb458055fd363ed", action = AssetHistory.Action.minted, amount = "1"),52 )53 }54 it("historyAll").config(timeout = Duration.Companion.seconds(120)){55 val r = api.getAssetHistoryAllList("d894897411707efa755a76deb66d26dfd50593f2e70863e1661e98a07370616365636f696e73")56 r.shouldNotBeEmpty()57 r.size.shouldBeGreaterThan(2320)58 r.forEach {59 it.txHash.shouldNotBeBlank()60 it.amount.shouldNotBeBlank()61 }62 }63 it("transactions").config(timeout = Duration.Companion.seconds(10)){64 val r = api.getAssetTransactions("00000002df633853f6a47465c9496721d2d5b1291b8398016c0e87ae6e7574636f696e")65 r.shouldNotBeEmpty()66 }67 it("addresses").config(timeout = Duration.Companion.seconds(10)){68 val r = api.getAssetAddresses("00000002df633853f6a47465c9496721d2d5b1291b8398016c0e87ae6e7574636f696e")69 r.shouldNotBeEmpty()70 }71 it("policy").config(timeout = Duration.Companion.seconds(10)){72 val r = api.getPolicyAssets("b863bc7369f46136ac1048adb2fa7dae3af944c3bbb2be2f216a8d4f")73 r.shouldNotBeEmpty()74 }75 }76})...
UserApiV1Test.kt
Source:UserApiV1Test.kt
1package io.andrewohara.tabbychat.protocol.v1.api2import dev.forkhandles.result4k.valueOrNull3import dev.mrbergin.kotest.result4k.shouldBeFailure4import dev.mrbergin.kotest.result4k.shouldBeSuccess5import io.andrewohara.tabbychat.*6import io.andrewohara.tabbychat.auth.Realm7import io.andrewohara.tabbychat.contacts.TokenData8import io.andrewohara.tabbychat.protocol.v1.client.UserClientV19import io.andrewohara.tabbychat.protocol.v1.toDtoV110import io.andrewohara.utils.jdk.minus11import io.kotest.matchers.collections.shouldBeEmpty12import io.kotest.matchers.collections.shouldContainExactly13import io.kotest.matchers.collections.shouldHaveSize14import io.kotest.matchers.nulls.shouldBeNull15import io.kotest.matchers.shouldBe16import org.http4k.core.Uri17import org.junit.jupiter.api.Test18import java.time.Duration19class UserApiV1Test {20 private val driver = TestDriver()21 private val provider = driver.createProvider(Realm(Uri.of("http://tabby.chat")))22 private val self = provider.createUser("self")23 private val selfToken: TokenData = provider.service.createAccessToken(self.id).valueOrNull()!!24 private val contact = provider.createUser("contact").also {25 driver.givenContacts(self, it)26 }27 private val other = provider.createUser("other")28 private val client = UserClientV1(selfToken.toDtoV1(), provider)29 @Test30 fun `get contact`() {31 client.getContact(contact.id.toDtoV1()) shouldBeSuccess contact.toDtoV1()32 }33 @Test34 fun `list contacts`() {35 client.listContactIds().shouldBeSuccess {36 it.shouldContainExactly(contact.id.toDtoV1())37 }38 }39 @Test40 fun `send message`() {41 client.sendMessage(contact.id.toDtoV1(), "hai".toMessageContent().toDtoV1()).shouldBeSuccess { receipt ->42 receipt.sender shouldBe self.id.toDtoV1()43 receipt.recipient shouldBe contact.id.toDtoV1()44 }45 }46 @Test47 fun `send message - not contact`() {48 client.sendMessage(other.id.toDtoV1(), "hai".toMessageContent().toDtoV1()) shouldBeFailure TabbyChatError.NotFound49 }50 @Test51 fun `delete contact - not contact`() {52 client.deleteContact(other.id.toDtoV1()) shouldBeFailure TabbyChatError.NotFound53 }54 @Test55 fun `delete contact`() {56 client.deleteContact(contact.id.toDtoV1()) shouldBeSuccess Unit57 provider.contactsDao[self.id].shouldBeEmpty()58 provider.contactsDao[contact.id].shouldBeEmpty()59 }60 @Test61 fun `create invitation`() {62 client.createInvitation().shouldBeSuccess { token ->63 token.realm shouldBe provider.realm.value64 }65 }66 @Test67 fun `list messages`() {68 provider.service.saveMessage(userId = self.id, senderId = contact.id, recipientId = self.id, "hai".toMessageContent()).shouldBeSuccess()69 driver.clock += Duration.ofSeconds(10)70 provider.service.saveMessage(userId = self.id, senderId = self.id, recipientId = contact.id, "sup".toMessageContent()).shouldBeSuccess()71 client.listMessages(driver.clock - Duration.ofSeconds(30)).shouldBeSuccess { page ->72 page.nextTime.shouldBeNull()73 page.messages.shouldHaveSize(2)74 }75 }76 @Test77 fun `accept invitation`() {78 val invitation = provider.service.createInvitation(other.id).valueOrNull()!!79 client.acceptInvitation(invitation.toDtoV1()) shouldBeSuccess other.toDtoV1()80 client.sendMessage(other.id.toDtoV1(), "sup".toMessageContent().toDtoV1()).shouldBeSuccess()81 }82}...
ScenarioRunnerSpecification.kt
Source:ScenarioRunnerSpecification.kt
1package io.perfometer.runner2import io.kotest.matchers.collections.shouldHaveSize3import io.kotest.matchers.comparables.shouldBeGreaterThan4import io.kotest.matchers.comparables.shouldBeGreaterThanOrEqualTo5import io.kotest.matchers.nulls.shouldBeNull6import io.kotest.matchers.nulls.shouldNotBeNull7import io.perfometer.dsl.scenario8import io.perfometer.http.*9import io.perfometer.http.client.HttpClient10import org.junit.Test11import org.junit.jupiter.api.assertDoesNotThrow12import java.time.Duration13@Suppress("FunctionName")14abstract class ScenarioRunnerSpecification {15 private val requests = mutableListOf<HttpRequest>()16 protected val httpClient = object : HttpClient {17 override suspend fun executeHttp(request: HttpRequest): HttpResponse {18 synchronized(this) {19 requests += request20 }21 return HttpResponse(HttpStatus(200), emptyMap())22 }23 }24 protected abstract val runner: ScenarioRunner25 @Test26 fun `should execute single GET request for a single user`() {27 val summary = scenario("https://perfometer.io") {28 get {29 path("/")30 }31 }.runner(runner).run(1, Duration.ofMillis(100))32 requests.size shouldBeGreaterThan 033 requests.map { it.url.toString() }.filter { it != "https://perfometer.io" } shouldHaveSize 034 requests.map { it.method }.filter { it != HttpMethod.GET } shouldHaveSize 035 requests.map { it.pathWithParams }.filter { it != "/" } shouldHaveSize 036 summary.totalSummary.shouldNotBeNull()37 .requestCount shouldBeGreaterThan 038 }39 @Test40 fun `should execute 8 requests total on two async users`() {41 val summary = scenario("http://perfometer.io") {42 get {43 path("/")44 }45 get {46 path("/")47 }48 delete {49 path("/delete")50 }51 delete {52 path("/delete")53 }54 }.runner(runner).run(2, Duration.ofMillis(100))55 requests.size shouldBeGreaterThan 856 summary.totalSummary.shouldNotBeNull()57 .requestCount shouldBeGreaterThan 858 }59 @Test60 fun `should pause for at least two seconds`() {61 val startTime = System.currentTimeMillis()62 val summary = scenario("https://perfometer.io") {63 pause(Duration.ofSeconds(2))64 }.runner(runner).run(1, Duration.ofMillis(2100))65 val diff = System.currentTimeMillis() - startTime66 diff shouldBeGreaterThanOrEqualTo 2000L67 summary.totalSummary.shouldBeNull()68 }69 @Test70 fun `should timeout scenario event if there are parallel tasks still running`() {71 assertDoesNotThrow {72 scenario("https://perfometer.io") {73 get { path("/") }74 parallel {75 pause(Duration.ofSeconds(1500))76 }77 }.runner(runner).run(1, Duration.ofMillis(100))78 }79 }80}...
UserTokenServiceTest.kt
Source:UserTokenServiceTest.kt
1package com.github.njuro.jard.user.token2import com.github.njuro.jard.TestDataRepository3import com.github.njuro.jard.WithContainerDatabase4import com.github.njuro.jard.common.Constants5import com.github.njuro.jard.user6import com.github.njuro.jard.userToken7import io.kotest.matchers.booleans.shouldBeTrue8import io.kotest.matchers.date.shouldBeAfter9import io.kotest.matchers.nulls.shouldBeNull10import io.kotest.matchers.nulls.shouldNotBeNull11import io.kotest.matchers.should12import io.kotest.matchers.shouldBe13import io.kotest.matchers.string.shouldNotBeBlank14import org.junit.jupiter.api.Test15import org.springframework.beans.factory.annotation.Autowired16import org.springframework.boot.test.context.SpringBootTest17import org.springframework.scheduling.config.FixedRateTask18import org.springframework.scheduling.config.ScheduledTask19import org.springframework.scheduling.config.ScheduledTaskHolder20import org.springframework.transaction.annotation.Transactional21import java.time.Duration22@SpringBootTest23@WithContainerDatabase24@Transactional25internal class UserTokenServiceTest {26 @Autowired27 private lateinit var userTokenService: UserTokenService28 @Autowired29 private lateinit var scheduledTaskHolder: ScheduledTaskHolder30 @Autowired31 private lateinit var db: TestDataRepository32 @Test33 fun `generate user token`() {34 val user = db.insert(user(username = "user"))35 userTokenService.generateToken(user, UserTokenType.PASSWORD_RESET).should {36 it.value.shouldNotBeBlank()37 it.type shouldBe UserTokenType.PASSWORD_RESET38 it.issuedAt.shouldNotBeNull()39 it.expirationAt.shouldNotBeNull()40 it.expirationAt shouldBeAfter it.issuedAt41 it.user.username shouldBe user.username42 }43 }44 @Test45 fun `resolve token`() {46 val user = db.insert(user(username = "user"))47 val token = db.insert(userToken(user, "abcde", UserTokenType.EMAIL_VERIFICATION))48 userTokenService.resolveToken(token.value, UserTokenType.EMAIL_VERIFICATION).shouldNotBeNull()49 }50 @Test51 fun `don't resolve non-existing token`() {52 userTokenService.resolveToken("xxx", UserTokenType.EMAIL_VERIFICATION).shouldBeNull()53 }54 @Test55 fun `removal of expired tokens is scheduled`() {56 val interval = Duration.parse(Constants.EXPIRED_USER_TOKENS_CHECK_PERIOD).toMillis()57 scheduledTaskHolder.scheduledTasks.map(ScheduledTask::getTask)58 .filterIsInstance<FixedRateTask>()59 .any { it.interval == interval }.shouldBeTrue()60 }61}...
TimeFormattingUtilTest.kt
Source:TimeFormattingUtilTest.kt
...5import io.kotest.matchers.string.shouldNotBeEmpty6import java.time.Duration7class TimeFormattingUtilTest : DescribeSpec({8 describe("Time Formatting Unit Tests") {9 it("should parse the durations correctly") {10 val threeSeconds = "3s"11 parseDuration(threeSeconds).shouldBe(Duration.ofSeconds(3))12 val fourtyHours = "40h"13 parseDuration(fourtyHours).shouldBe(Duration.ofHours(40))14 val thirteenHoursAndTwoMinutes = "13h 2m"15 parseDuration(thirteenHoursAndTwoMinutes).shouldBe(Duration.ofHours(13) + Duration.ofMinutes(2))16 val threeDaysFourHoursAndThirtyFiveSeconds = "3d 35s 4h"17 parseDuration(threeDaysFourHoursAndThirtyFiveSeconds).shouldBe(Duration.ofDays(3) + Duration.ofHours(4) + Duration.ofSeconds(35))18 val incorrectDuration = "I'm blue da ba dee da ba die"19 parseDuration(incorrectDuration).shouldBeNull()20 }21 it("should print out the durations correctly - long") {22 val threeSeconds = Duration.ofSeconds(3)23 formatDurationLong(threeSeconds).shouldBe("3 seconds")24 val fourtyHours = Duration.ofHours(40)25 formatDurationLong(fourtyHours).shouldBe("1 day, 16 hours")26 val thirteenHoursAndTwoMinutes = Duration.ofHours(13) + Duration.ofMinutes(2)27 formatDurationLong(thirteenHoursAndTwoMinutes).shouldBe("13 hours, 2 minutes")28 val threeDaysFourHoursAndThirtyFiveSeconds = Duration.ofDays(3) + Duration.ofHours(4) + Duration.ofSeconds(35)29 formatDurationLong(threeDaysFourHoursAndThirtyFiveSeconds).shouldBe("3 days, 4 hours, 35 seconds")30 formatDurationLong(Duration.ZERO).shouldNotBeEmpty()31 }32 }33})...
CreateTrialUserImplTest.kt
Source:CreateTrialUserImplTest.kt
1package com.falcon.falcon.core.usecase.trial2import com.falcon.falcon.core.entity.User3import com.falcon.falcon.core.enumeration.UserType4import com.falcon.falcon.core.usecase.user.CreateUserUseCase5import io.kotest.matchers.date.shouldBeBetween6import io.kotest.matchers.shouldBe7import io.kotest.matchers.string.shouldBeUUID8import io.kotest.matchers.types.shouldBeTypeOf9import io.mockk.clearAllMocks10import io.mockk.every11import io.mockk.mockk12import org.junit.jupiter.api.BeforeEach13import org.junit.jupiter.api.Test14import org.junit.jupiter.api.TestInstance15import java.time.Instant16import java.time.temporal.ChronoUnit17@TestInstance(TestInstance.Lifecycle.PER_CLASS)18internal class CreateTrialUserImplTest {19 private val createUserUseCase: CreateUserUseCase = mockk()20 private val trialDuration = 1L21 private val underTest: CreateTrialUserImpl = CreateTrialUserImpl(createUserUseCase, trialDuration)22 @BeforeEach23 fun init() {24 clearAllMocks()25 }26 @Test27 fun `Should generate random user`() {28 // Given29 every { createUserUseCase.execute(any()) } returnsArgument 030 // When31 val result = underTest.execute()32 // Then33 result.shouldBeTypeOf<User>()34 result.username.shouldBeUUID()35 result.password.shouldBeUUID()36 result.type.shouldBe(UserType.TRIAL)37 result.expirationDate?.shouldBeBetween(38 Instant.now().plus(50, ChronoUnit.MINUTES),39 Instant.now().plus(70, ChronoUnit.MINUTES),40 )41 }42}...
duration
Using AI Code Generation
1val duration = Duration.ofSeconds(10)2duration should beLessThan(Duration.ofSeconds(15))3duration should beLessThanOrEqual(Duration.ofSeconds(10))4duration should beGreaterThan(Duration.ofSeconds(5))5duration should beGreaterThanOrEqual(Duration.ofSeconds(10))6val duration = Duration.ofSeconds(10)7duration should beLessThan(Duration.ofSeconds(15))8duration should beLessThanOrEqual(Duration.ofSeconds(10))9duration should beGreaterThan(Duration.ofSeconds(5))10duration should beGreaterThanOrEqual(Duration.ofSeconds(10))11val duration = Duration.ofSeconds(10)12duration should beLessThan(Duration.ofSeconds(15))13duration should beLessThanOrEqual(Duration.ofSeconds(10))14duration should beGreaterThan(Duration.ofSeconds(5))15duration should beGreaterThanOrEqual(Duration.ofSeconds(10))16val duration = Duration.ofSeconds(10)17duration should beLessThan(Duration.ofSeconds(15))18duration should beLessThanOrEqual(Duration.ofSeconds(10))19duration should beGreaterThan(Duration.ofSeconds(5))20duration should beGreaterThanOrEqual(Duration.ofSeconds(10))21val duration = Duration.ofSeconds(10)22duration should beLessThan(Duration.ofSeconds(15))23duration should beLessThanOrEqual(Duration.ofSeconds(10))24duration should beGreaterThan(Duration.ofSeconds(5))25duration should beGreaterThanOrEqual(Duration.ofSeconds(10))26val duration = Duration.ofSeconds(10)27duration should beLessThan(Duration.ofSeconds(15))28duration should beLessThanOrEqual(Duration.ofSeconds(10))29duration should beGreaterThan(Duration.ofSeconds(5))30duration should beGreaterThanOrEqual(Duration.ofSeconds(10))31val duration = Duration.ofSeconds(10)32duration should beLessThan(Duration.ofSeconds(15))33duration should beLessThanOrEqual(Duration.ofSeconds(10))34duration should beGreaterThan(Duration.ofSeconds(5))35duration should beGreaterThanOrEqual(Duration.ofSeconds(10))36val duration = Duration.ofSeconds(10)37duration should beLessThan(Duration.ofSeconds(15))38duration should beLessThanOrEqual(Duration.of
duration
Using AI Code Generation
1val duration = Duration.ofSeconds(1)2duration.shouldBeLessThan(Duration.ofSeconds(2))3val duration = java.time.Duration.ofSeconds(1)4duration.shouldBeLessThan(java.time.Duration.ofSeconds(2))5val duration = java.time.Duration.ofSeconds(1)6duration.shouldBeLessThan(java.time.Duration.ofSeconds(2))7val duration = java.time.Duration.ofSeconds(1)8duration.shouldBeLessThan(java.time.Duration.ofSeconds(2))9val duration = java.time.Duration.ofSeconds(1)10duration.shouldBeLessThan(java.time.Duration.ofSeconds(2))11val duration = java.time.Duration.ofSeconds(1)12duration.shouldBeLessThan(java.time.Duration.ofSeconds(2))13val duration = java.time.Duration.ofSeconds(1)14duration.shouldBeLessThan(java.time.Duration.ofSeconds(2))15val duration = java.time.Duration.ofSeconds(1)16duration.shouldBeLessThan(java.time.Duration.ofSeconds(2))17val duration = java.time.Duration.ofSeconds(1)18duration.shouldBeLessThan(java.time.Duration.ofSeconds(2))19val duration = java.time.Duration.ofSeconds(1)20duration.shouldBeLessThan(java.time.Duration.ofSeconds(2))21val duration = java.time.Duration.ofSeconds(1)22duration.shouldBeLessThan(java.time.Duration.ofSeconds(2))23val duration = java.time.Duration.ofSeconds(1)24duration.shouldBeLessThan(java.time.Duration.ofSeconds(2))25val duration = java.time.Duration.ofSeconds(1)26duration.shouldBeLessThan(java.time.Duration.ofSeconds(2))27val duration = java.time.Duration.ofSeconds(1)28duration.shouldBeLessThan(java.time.Duration.ofSeconds
duration
Using AI Code Generation
1val duration = Duration.ofSeconds( 1 )2duration.shouldBeLessThan( 2 .seconds)3duration.shouldBeLessThan( 2000 .milliseconds)4duration.shouldBeLessThan( 2000000 .microseconds)5duration.shouldBeLessThan( 2000000000 .nanoseconds)6val duration = java.time.Duration.ofSeconds( 1 )7duration.shouldBeLessThan( 2 .seconds)8duration.shouldBeLessThan( 2000 .milliseconds)9duration.shouldBeLessThan( 2000000 .microseconds)10duration.shouldBeLessThan( 2000000000 .nanoseconds)11val duration = java.util.concurrent.TimeUnit.SECONDS.toMillis( 1 )12duration.shouldBeLessThan( 2 .seconds)13duration.shouldBeLessThan( 2000 .milliseconds)14duration.shouldBeLessThan( 2000000 .microseconds)15duration.shouldBeLessThan( 2000000000 .nanoseconds)16val duration = java.util.concurrent.TimeUnit.SECONDS.toMillis( 1 )17duration.shouldBeLessThan( 2 .seconds)18duration.shouldBeLessThan( 2000 .milliseconds)19duration.shouldBeLessThan( 2000000 .microseconds)20duration.shouldBeLessThan( 2000000000 .nanoseconds)21val duration = java.time.temporal.ChronoUnit.SECONDS.getDuration()22duration.shouldBeLessThan( 2 .seconds)23duration.shouldBeLessThan( 2000 .milliseconds)24duration.shouldBeLessThan( 2000000 .microseconds)25duration.shouldBeLessThan( 2000000000 .nanoseconds)26val duration = org.joda.time.Duration.standardSeconds( 1 )27duration.shouldBeLessThan( 2 .seconds)28duration.shouldBeLessThan( 2000 .milliseconds)29duration.shouldBeLessThan( 2000000 .microseconds)30duration.shouldBeLessThan( 200000000
duration
Using AI Code Generation
1import io.kotest.matchers.time.*2import java.time.Duration3test("duration should be positive") {4val duration = Duration.ofSeconds(10)5}6import io.kotest.matchers.time.*7import java.time.Duration8test("duration should be negative") {9val duration = Duration.ofSeconds(-10)10}11import io.kotest.matchers.time.*12import java.time.Duration13test("duration should be zero") {14val duration = Duration.ofSeconds(0)15}16import io.kotest.matchers.time.*17import java.time.Duration18test("duration should not be zero") {19val duration = Duration.ofSeconds(10)20}21import io.kotest.matchers.time.*22import java.time.Duration23test("duration should be equal") {24val duration1 = Duration.ofSeconds(10)25val duration2 = Duration.ofSeconds(10)26}27import io.kotest.matchers.time.*28import java.time.Duration29test("duration should not be equal") {30val duration1 = Duration.ofSeconds(10)31val duration2 = Duration.ofSeconds(20)32}33import io.kotest.matchers.time.*34import java.time.Duration35test("duration should be less than") {36val duration1 = Duration.ofSeconds(10)37val duration2 = Duration.ofSeconds(20)38duration1 should beLessThan(duration2)39}40import io.kotest.matchers.time.*41import java.time.Duration42test("duration should be less than or equal to") {43val duration1 = Duration.ofSeconds(10)44val duration2 = Duration.ofSeconds(20)45duration1 should beLessThanOrEqual(duration2)46}47import io.kotest.matchers.time.*48import java.time
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!