How to use matchers class of io.kotest.matchers.uri package

Best Kotest code snippet using io.kotest.matchers.uri.matchers

BasicEventTest.kt

Source:BasicEventTest.kt Github

copy

Full Screen

...8import dev.akkinoc.spring.boot.logback.access.test.type.TomcatServletWebTest9import dev.akkinoc.spring.boot.logback.access.test.type.UndertowReactiveWebTest10import dev.akkinoc.spring.boot.logback.access.test.type.UndertowServletWebTest11import io.kotest.assertions.throwables.shouldThrowUnit12import io.kotest.matchers.booleans.shouldBeFalse13import io.kotest.matchers.booleans.shouldBeTrue14import io.kotest.matchers.collections.shouldBeSingleton15import io.kotest.matchers.collections.shouldContainAll16import io.kotest.matchers.collections.shouldContainExactly17import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder18import io.kotest.matchers.collections.shouldNotContainAnyOf19import io.kotest.matchers.longs.shouldBeBetween20import io.kotest.matchers.longs.shouldBeGreaterThanOrEqual21import io.kotest.matchers.longs.shouldBePositive22import io.kotest.matchers.longs.shouldBeZero23import io.kotest.matchers.maps.shouldBeEmpty24import io.kotest.matchers.nulls.shouldBeNull25import io.kotest.matchers.nulls.shouldNotBeNull26import io.kotest.matchers.shouldBe27import io.kotest.matchers.shouldNotBe28import io.kotest.matchers.string.shouldBeEmpty29import io.kotest.matchers.string.shouldNotBeEmpty30import io.kotest.matchers.string.shouldStartWith31import org.junit.jupiter.api.Test32import org.junit.jupiter.api.extension.ExtendWith33import org.springframework.beans.factory.annotation.Autowired34import org.springframework.boot.test.web.client.TestRestTemplate35import org.springframework.boot.test.web.client.exchange36import org.springframework.boot.web.server.LocalServerPort37import org.springframework.http.RequestEntity38import org.springframework.test.context.TestPropertySource39import java.lang.System.currentTimeMillis40import java.util.concurrent.TimeUnit.MILLISECONDS41/**42 * Tests the appended Logback-access event in the case where the configuration is the default.43 *44 * @property supportsRequestParametersByFormData Whether to support request parameters by form data....

Full Screen

Full Screen

KotestHelpers.kt

Source:KotestHelpers.kt Github

copy

Full Screen

1package io.provenance.scope.loan.test2import com.google.protobuf.InvalidProtocolBufferException3import com.google.protobuf.Timestamp4import com.google.protobuf.util.Timestamps5import io.kotest.matchers.Matcher6import io.kotest.matchers.MatcherResult7import io.kotest.matchers.should8import io.kotest.matchers.shouldBe9import io.kotest.matchers.types.beInstanceOf10import io.kotest.property.Arb11import io.kotest.property.arbitrary.Codepoint12import io.kotest.property.arbitrary.UUIDVersion13import io.kotest.property.arbitrary.alphanumeric14import io.kotest.property.arbitrary.bind15import io.kotest.property.arbitrary.boolean16import io.kotest.property.arbitrary.filter17import io.kotest.property.arbitrary.filterNot18import io.kotest.property.arbitrary.int19import io.kotest.property.arbitrary.list20import io.kotest.property.arbitrary.long21import io.kotest.property.arbitrary.map22import io.kotest.property.arbitrary.pair23import io.kotest.property.arbitrary.set24import io.kotest.property.arbitrary.string25import io.kotest.property.arbitrary.uInt26import io.kotest.property.arbitrary.uuid27import io.provenance.scope.loan.utility.ContractEnforcement28import io.provenance.scope.loan.utility.ContractViolation29import io.provenance.scope.loan.utility.ContractViolationException30import io.provenance.scope.loan.utility.ContractViolationMap31import io.provenance.scope.loan.utility.UnexpectedContractStateException32import tech.figure.servicing.v1beta1.LoanStateOuterClass.LoanStateMetadata33import java.time.Instant34import tech.figure.util.v1beta1.Checksum as FigureTechChecksum35import tech.figure.util.v1beta1.UUID as FigureTechUUID36/**37 * Generators of [Arb]itrary instances.38 */39internal object LoanPackageArbs {40 /* Primitives */41 val anyNonEmptyString: Arb<String> = Arb.string().filter { it.isNotBlank() }42 val anyNonUuidString: Arb<String> = Arb.string().filterNot { it.length == 36 }43 val anyUli: Arb<String> = Arb.string(minSize = 23, maxSize = 45, codepoints = Codepoint.alphanumeric()) // TODO: Is this correct?44 val anyNonUliString: Arb<String> = Arb.string().filterNot { it.length in 23..45 } // TODO: Should be complement of anyUli45 /* Contract requirements */46 val anyContractViolation: Arb<ContractViolation> = Arb.string()47 val anyContractEnforcement: Arb<ContractEnforcement> = Arb.bind(48 Arb.boolean(),49 Arb.string(),50 ) { requirement, violationReport ->51 ContractEnforcement(requirement, violationReport)52 }53 val anyContractViolationMap: Arb<ContractViolationMap> = Arb.bind(54 Arb.list(anyContractViolation),55 Arb.list(Arb.uInt()),56 ) { violationList, countList ->57 violationList.zip(countList).toMap().toMutableMap()58 }59 /* Protobufs */60 val anyValidChecksum: Arb<FigureTechChecksum> = Arb.bind(61 anyNonEmptyString,62 Arb.string(),63 ) { checksumValue, algorithmType ->64 FigureTechChecksum.newBuilder().apply {65 checksum = checksumValue66 algorithm = algorithmType67 }.build()68 }69 val anyUuid: Arb<FigureTechUUID> = Arb.uuid(UUIDVersion.V4).map { arbUuidV4 ->70 FigureTechUUID.newBuilder().apply {71 value = arbUuidV4.toString()72 }.build()73 }74 val anyValidTimestamp: Arb<Timestamp> = anyTimestampComponents.map { (seconds, nanoSeconds) ->75 Timestamp.newBuilder().also { timestampBuilder ->76 timestampBuilder.seconds = seconds77 timestampBuilder.nanos = nanoSeconds78 }.build()79 }80 val anyValidLoanState: Arb<LoanStateMetadata> = Arb.bind(81 anyUuid,82 anyValidChecksum,83 anyValidTimestamp,84 anyNonEmptyString,85 ) { uuid, checksum, effectiveTime, uri ->86 LoanStateMetadata.newBuilder().also { loanStateBuilder ->87 loanStateBuilder.id = uuid88 loanStateBuilder.checksum = checksum89 loanStateBuilder.effectiveTime = effectiveTime90 loanStateBuilder.uri = uri91 }.build()92 }93 fun loanStateSet(size: Int, slippage: Int = 10): Arb<List<LoanStateMetadata>> =94 /** Since we need each *property* to be unique, we must fix the set size & construct the arbs from scratch with primitives */95 Arb.bind(96 Arb.set(gen = Arb.uuid(UUIDVersion.V4), size = size, slippage = slippage).map { it.toList() },97 Arb.set(gen = anyNonEmptyString, size = size, slippage = slippage).map { it.toList() },98 Arb.set(gen = anyNonEmptyString, size = size, slippage = slippage).map { it.toList() },99 Arb.set(gen = anyPastNonEpochTimestampComponents, size = size, slippage = slippage).map { it.toList() },100 ) { randomIds, randomChecksums, randomUris, randomTimestamps ->101 randomIds.indices.map { i ->102 LoanStateMetadata.newBuilder().also { loanStateBuilder ->103 loanStateBuilder.id = FigureTechUUID.newBuilder().also { uuidBuilder ->104 uuidBuilder.value = randomIds[i].toString()105 }.build()106 loanStateBuilder.checksum = FigureTechChecksum.newBuilder().also { checksumBuilder ->107 checksumBuilder.checksum = randomChecksums[i]108 }.build()109 loanStateBuilder.uri = randomUris[i]110 loanStateBuilder.effectiveTime = Timestamp.newBuilder().also { timestampBuilder ->111 timestampBuilder.seconds = randomTimestamps[i].first112 timestampBuilder.nanos = randomTimestamps[i].second113 }.build()114 }.build()115 }116 }117}118private val anyTimestampComponents: Arb<Pair<Long, Int>> = Arb.pair(119 Arb.long(min = Timestamps.MIN_VALUE.seconds, max = Timestamps.MAX_VALUE.seconds),120 Arb.int(min = Timestamps.MIN_VALUE.nanos, max = Timestamps.MAX_VALUE.nanos),121)122private val anyPastNonEpochTimestampComponents: Arb<Pair<Long, Int>> = Instant.now().let { now ->123 Arb.pair(124 Arb.long(min = Timestamps.MIN_VALUE.seconds, max = now.epochSecond),125 Arb.int(min = Timestamps.MIN_VALUE.nanos + 1, max = now.nano),126 )127}128/**129 * Defines a custom [Matcher] to check the violation count value in a [ContractViolationException].130 */131internal fun throwViolationCount(violationCount: UInt) = Matcher<ContractViolationException> { exception ->132 { count: UInt ->133 if (count == 1U) {134 "$count violation"135 } else {136 "$count violations"137 }138 }.let { violationPrinter: (UInt) -> String ->139 return@Matcher MatcherResult(140 exception.overallViolationCount == violationCount,141 {142 "Exception had ${violationPrinter(exception.overallViolationCount)} " +143 "but we expected ${violationPrinter(violationCount)}"144 },145 { "Exception should not have ${violationPrinter(violationCount)}" },146 )147 }148}149/**150 * Wraps the custom matcher [throwViolationCount] following the style outlined in the151 * [Kotest documentation](https://kotest.io/docs/assertions/custom-matchers.html#extension-variants).152 */153internal infix fun ContractViolationException.shouldHaveViolationCount(violationCount: UInt) = apply {154 this should throwViolationCount(violationCount)155}156internal infix fun UnexpectedContractStateException.shouldBeParseFailureFor(classifier: String) = apply {157 this.cause should beInstanceOf<InvalidProtocolBufferException>()158 this.message shouldBe "Could not unpack as class $classifier"159}...

Full Screen

Full Screen

ListingControllerImplITKoTest.kt

Source:ListingControllerImplITKoTest.kt Github

copy

Full Screen

1package org.jesperancinha.concerts.mvc.controllers2import io.kotest.core.spec.style.WordSpec3import io.kotest.core.test.TestCase4import io.kotest.extensions.spring.SpringExtension5import io.kotest.matchers.collections.shouldBeEmpty6import io.kotest.matchers.collections.shouldHaveSize7import io.kotest.matchers.collections.shouldNotBeEmpty8import io.kotest.matchers.nulls.shouldNotBeNull9import io.kotest.matchers.shouldBe10import io.kotest.matchers.shouldNotBe11import kotlinx.coroutines.Dispatchers12import kotlinx.coroutines.withContext13import org.jesperancinha.concerts.data.ArtistDto14import org.jesperancinha.concerts.data.ListingDto15import org.jesperancinha.concerts.data.MusicDto16import org.jesperancinha.concerts.mvc.controllers.TestKUtils.Companion.HEY_MAMA17import org.jesperancinha.concerts.mvc.model.Music18import org.jesperancinha.concerts.mvc.repos.ArtistRepository19import org.jesperancinha.concerts.mvc.repos.ConcertRepository20import org.jesperancinha.concerts.mvc.repos.ListingRepository21import org.jesperancinha.concerts.mvc.repos.MusicRepository22import org.jesperancinha.concerts.types.Gender.FEMALE23import org.springframework.beans.factory.annotation.Autowired24import org.springframework.boot.test.context.SpringBootTest...

Full Screen

Full Screen

ExtensionKtIT.kt

Source:ExtensionKtIT.kt Github

copy

Full Screen

1package ru.iopump.koproc2import io.kotest.assertions.asClue3import io.kotest.core.spec.style.StringSpec4import io.kotest.matchers.nulls.shouldBeNull5import io.kotest.matchers.shouldBe6import io.kotest.matchers.string.shouldBeBlank7import io.kotest.matchers.string.shouldContain8import io.kotest.matchers.string.shouldNotBeBlank9import io.kotest.matchers.types.shouldBeInstanceOf10import kotlinx.coroutines.delay11import org.junit.jupiter.api.assertThrows12import org.slf4j.LoggerFactory13import java.net.ConnectException14import java.net.HttpURLConnection15import java.net.URL16import java.nio.file.Paths17@Suppress("BlockingMethodInNonBlockingContext")18class ExtensionKtIT : StringSpec() {19 private companion object {20 private val log = LoggerFactory.getLogger("koproc")21 }22 init {23 "Java process should started by 'startProcess', provide http access and stopped by 'close' method" {...

Full Screen

Full Screen

MusicControllerImplITKoTest.kt

Source:MusicControllerImplITKoTest.kt Github

copy

Full Screen

1 package org.jesperancinha.concerts.mvc.controllers2import io.kotest.core.spec.style.WordSpec3import io.kotest.core.test.TestCase4import io.kotest.extensions.spring.SpringExtension5import io.kotest.matchers.collections.shouldBeEmpty6import io.kotest.matchers.collections.shouldHaveSize7import io.kotest.matchers.collections.shouldNotBeEmpty8import io.kotest.matchers.shouldBe9import io.kotest.matchers.shouldNotBe10import kotlinx.coroutines.Dispatchers11import kotlinx.coroutines.withContext12import org.jesperancinha.concerts.data.MusicDto13import org.jesperancinha.concerts.mvc.controllers.TestKUtils.Companion.HEY_MAMA14import org.jesperancinha.concerts.mvc.model.Music15import org.jesperancinha.concerts.mvc.repos.ArtistRepository16import org.jesperancinha.concerts.mvc.repos.ConcertRepository17import org.jesperancinha.concerts.mvc.repos.ListingRepository18import org.jesperancinha.concerts.mvc.repos.MusicRepository19import org.springframework.beans.factory.annotation.Autowired20import org.springframework.boot.test.context.SpringBootTest21import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT22import org.springframework.core.ParameterizedTypeReference23import org.springframework.core.env.Environment...

Full Screen

Full Screen

UserApiV1Test.kt

Source:UserApiV1Test.kt Github

copy

Full Screen

...7import 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 @Test...

Full Screen

Full Screen

uri.kt

Source:uri.kt Github

copy

Full Screen

1package org.http4k.kotest2import io.kotest.matchers.Matcher3import io.kotest.matchers.MatcherResult4import io.kotest.matchers.be5import io.kotest.matchers.neverNullMatcher6import io.kotest.matchers.should7import io.kotest.matchers.shouldNot8import io.kotest.matchers.string.contain9import org.http4k.core.Uri10internal fun <R> uriHas(name: String, extractValue: (Uri) -> R, match: Matcher<R>): Matcher<Uri> = object : Matcher<Uri> {11 override fun test(value: Uri): MatcherResult {12 val testResult = match.test(extractValue(value))13 return MatcherResult(14 testResult.passed(),15 { "Invalid Uri $name: ${testResult.failureMessage()}" },16 { "Invalid Uri $name: ${testResult.negatedFailureMessage()}" }17 )18 }19}20infix fun Uri.shouldHavePath(match: Matcher<String?>) = this should havePath(match)21infix fun Uri.shouldNotHavePath(match: Matcher<String?>) = this shouldNot havePath(match)22fun havePath(matcher: Matcher<String?>): Matcher<Uri> = uriHas("path", Uri::path, matcher)...

Full Screen

Full Screen

RequestLensTest.kt

Source:RequestLensTest.kt Github

copy

Full Screen

2import com.j0rsa.bujo.telegram.Config3import com.j0rsa.bujo.telegram.api.model.HabitRequest4import com.j0rsa.bujo.telegram.api.model.Period5import io.kotest.core.spec.style.ShouldSpec6import io.kotest.matchers.Matcher7import io.kotest.matchers.MatcherResult8import io.kotest.matchers.shouldNot9import org.http4k.core.MemoryBody10import org.http4k.core.Method11import org.http4k.core.Request12import org.http4k.core.Uri13class RequestLensTest: ShouldSpec() {14 @Suppress("SameParameterValue")15 private fun contain(otherSting: String) = object : Matcher<String> {16 override fun test(value: String) = MatcherResult(value.contains(otherSting), "String $value should include $otherSting", "String $value should not include $otherSting")17 }18 init {19 should("Not contain nulls") {20 val habit = HabitRequest(21 "name",22 emptyList(),...

Full Screen

Full Screen

matchers

Using AI Code Generation

copy

Full Screen

1println("URI is valid")2} catch (e: URISyntaxException) {3println("URI is not valid")4}5}6}

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