How to use haveSize method of io.kotest.matchers.sequences.matchers class

Best Kotest code snippet using io.kotest.matchers.sequences.matchers.haveSize

AbstractDependencyNavigatorTest.kt

Source:AbstractDependencyNavigatorTest.kt Github

copy

Full Screen

...22import io.kotest.matchers.collections.contain23import io.kotest.matchers.collections.containAll24import io.kotest.matchers.collections.containExactly25import io.kotest.matchers.collections.containExactlyInAnyOrder26import io.kotest.matchers.collections.haveSize27import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder28import io.kotest.matchers.maps.containExactly as containExactlyEntries29import io.kotest.matchers.sequences.beEmpty as beEmptySequence30import io.kotest.matchers.sequences.containExactly as containSequenceExactly31import io.kotest.matchers.should32import io.kotest.matchers.shouldBe33import io.kotest.matchers.shouldNot34import io.kotest.matchers.shouldNotBe35import java.io.File36import java.time.Instant37import org.ossreviewtoolkit.utils.test.readOrtResult38import org.ossreviewtoolkit.utils.test.shouldNotBeNull39/**40 * A base class for tests of concrete [DependencyNavigator] implementations.41 *42 * The class is configured with an ORT result file that contains the expected results in a specific format. It then43 * runs tests on the [DependencyNavigator] of this result and checks whether it returns the correct dependency44 * information.45 */46abstract class AbstractDependencyNavigatorTest : WordSpec() {47 /** The name of the result file to be used by all test cases. */48 protected abstract val resultFileName: String49 /**50 * The name of the file with a result that contains issues. This is used by tests of the collectIssues() function.51 */52 protected abstract val resultWithIssuesFileName: String53 private val testResult by lazy { readOrtResult(resultFileName) }54 private val testProject by lazy { testResult.getProject(PROJECT_ID)!! }55 protected val navigator by lazy { testResult.dependencyNavigator }56 init {57 "scopeNames" should {58 "return the scope names of a project" {59 navigator.scopeNames(testProject) should containExactlyInAnyOrder("compile", "test")60 }61 }62 "directDependencies" should {63 "return the direct dependencies of a project" {64 navigator.directDependencies(testProject, "test").map { it.id } should containSequenceExactly(65 Identifier("Maven:org.scalacheck:scalacheck_2.12:1.13.5"),66 Identifier("Maven:org.scalatest:scalatest_2.12:3.0.4")67 )68 }69 "return an empty sequence for an unknown scope" {70 navigator.directDependencies(testProject, "unknownScope") should beEmptySequence()71 }72 }73 "scopeDependencies" should {74 "return a map with scopes and their dependencies for a project" {75 val scopeDependencies = navigator.scopeDependencies(testProject)76 scopeDependencies.keys should containExactlyInAnyOrder("compile", "test")77 scopeDependencies["compile"] shouldNotBeNull {78 this should haveSize(17)79 this should containAll(80 Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.6"),81 Identifier("Maven:org.scala-lang:scala-reflect:2.12.2"),82 Identifier("Maven:org.scala-lang:scala-library:2.12.3")83 )84 }85 scopeDependencies["test"] shouldNotBeNull {86 this should haveSize(6)87 this should containAll(88 Identifier("Maven:org.scalacheck:scalacheck_2.12:1.13.5"),89 Identifier("Maven:org.scalactic:scalactic_2.12:3.0.4")90 )91 }92 }93 "return a map with scopes and their direct dependencies by using maxDepth = 1" {94 val scopeDependencies = navigator.scopeDependencies(testProject, maxDepth = 1)95 scopeDependencies["compile"] shouldNotBeNull {96 this should haveSize(7)97 this shouldNot contain(Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.6"))98 }99 }100 "return a map with scopes and their dependencies up to a given maxDepth" {101 val scopeDependencies = navigator.scopeDependencies(testProject, maxDepth = 2)102 scopeDependencies["compile"] shouldNotBeNull {103 this should haveSize(14)104 this shouldNot contain(105 Identifier("Maven:org.scala-lang.modules:scala-java8-compat_2.12:0.8.0")106 )107 }108 }109 "return a map with scopes and their dependencies with filter criteria" {110 val matchedIds = mutableSetOf<Identifier>()111 val scopeDependencies = navigator.scopeDependencies(testProject) { node ->112 matchedIds += node.id113 node.id.namespace == "com.typesafe.akka"114 }115 scopeDependencies["compile"] shouldNotBeNull {116 this should containExactlyInAnyOrder(117 Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.6"),118 Identifier("Maven:com.typesafe.akka:akka-stream_2.12:2.5.6")119 )120 }121 matchedIds should haveSize(23)122 }123 }124 "dependenciesForScope" should {125 "return an empty set for an unknown scope" {126 navigator.dependenciesForScope(testProject, "unknownScope") should beEmpty()127 }128 "return the dependencies of a specific scope" {129 val compileDependencies = navigator.dependenciesForScope(testProject, "compile")130 compileDependencies should haveSize(17)131 compileDependencies should containAll(132 Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.6"),133 Identifier("Maven:org.scala-lang:scala-reflect:2.12.2"),134 Identifier("Maven:org.scala-lang:scala-library:2.12.3")135 )136 }137 "return the dependencies of a specific scope up to a given maxDepth" {138 val compileDependencies = navigator.dependenciesForScope(testProject, "compile", maxDepth = 2)139 compileDependencies should haveSize(14)140 compileDependencies shouldNot contain(141 Identifier("Maven:org.scala-lang.modules:scala-java8-compat_2.12:0.8.0")142 )143 }144 "return the dependencies of a specific scope with filter criteria" {145 val akkaDependencies = navigator.dependenciesForScope(testProject, "compile") { node ->146 "akka" in node.id.namespace147 }148 akkaDependencies.shouldContainExactlyInAnyOrder(149 Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.6"),150 Identifier("Maven:com.typesafe.akka:akka-stream_2.12:2.5.6")151 )152 }153 }154 "packageDependencies" should {155 "return the dependencies of an existing package in a project" {156 val pkgId = Identifier("Maven:com.typesafe.akka:akka-stream_2.12:2.5.6")157 val dependencies = navigator.packageDependencies(testProject, pkgId)158 dependencies should containExactlyInAnyOrder(159 Identifier("Maven:com.typesafe:ssl-config-core_2.12:0.2.2"),160 Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.6"),161 Identifier("Maven:org.scala-lang.modules:scala-java8-compat_2.12:0.8.0"),162 Identifier("Maven:org.reactivestreams:reactive-streams:1.0.1")163 )164 }165 "return an empty set for the dependencies of a non-existing package" {166 val pkgId = Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.7")167 val dependencies = navigator.packageDependencies(testProject, pkgId)168 dependencies should beEmpty()169 }170 "support a maxDepth filter" {171 val pkgId = Identifier("Maven:com.typesafe.akka:akka-stream_2.12:2.5.6")172 val dependencies = navigator.packageDependencies(testProject, pkgId, maxDepth = 1)173 dependencies should containExactlyInAnyOrder(174 Identifier("Maven:com.typesafe:ssl-config-core_2.12:0.2.2"),175 Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.6"),176 Identifier("Maven:org.reactivestreams:reactive-streams:1.0.1")177 )178 }179 "support a DependencyMatcher" {180 val pkgId = Identifier("Maven:com.typesafe.akka:akka-stream_2.12:2.5.6")181 val dependencies = navigator.packageDependencies(testProject, pkgId) { node ->182 node.id.namespace.startsWith("com.typesafe")183 }184 dependencies should containExactlyInAnyOrder(185 Identifier("Maven:com.typesafe:ssl-config-core_2.12:0.2.2"),186 Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.6")187 )188 }189 }190 "getShortestPaths" should {191 "return the shortest paths for a project" {192 val paths = navigator.getShortestPaths(testProject)193 paths.keys should haveSize(2)194 paths["compile"] shouldNotBeNull {195 this should containExactlyEntries(196 Identifier("Maven:ch.qos.logback:logback-classic:1.2.3") to emptyList(),197 Identifier("Maven:ch.qos.logback:logback-core:1.2.3") to listOf(198 Identifier("Maven:ch.qos.logback:logback-classic:1.2.3")199 ),200 Identifier("Maven:com.fasterxml.jackson.core:jackson-annotations:2.8.0") to listOf(201 Identifier("Maven:net.logstash.logback:logstash-logback-encoder:4.11"),202 Identifier("Maven:com.fasterxml.jackson.core:jackson-databind:2.8.9")203 ),204 Identifier("Maven:com.fasterxml.jackson.core:jackson-core:2.8.9") to listOf(205 Identifier("Maven:net.logstash.logback:logstash-logback-encoder:4.11"),206 Identifier("Maven:com.fasterxml.jackson.core:jackson-databind:2.8.9")207 ),...

Full Screen

Full Screen

matchers.kt

Source:matchers.kt Github

copy

Full Screen

...212infix fun <T> Sequence<T>.shouldNotHaveCount(count: Int) = this shouldNot haveCount(213 count)214infix fun <T> Sequence<T>.shouldHaveSize(size: Int) = this should haveCount(size)215infix fun <T> Sequence<T>.shouldNotHaveSize(size: Int) = this shouldNot haveCount(size)216//fun <T> haveSize(size: Int) = haveCount(size)217fun <T> haveSize(size: Int): Matcher<Sequence<T>> = haveCount(size)218fun <T> haveCount(count: Int): Matcher<Sequence<T>> = object : Matcher<Sequence<T>> {219 override fun test(value: Sequence<T>) =220 MatcherResult(221 value.count() == count,222 { "Sequence should have count $count but has count ${value.count()}" },223 { "Sequence should not have count $count" }224 )225}226infix fun <T, U> Sequence<T>.shouldBeLargerThan(other: Sequence<U>) = this should beLargerThan(other)227fun <T, U> beLargerThan(other: Sequence<U>) = object : Matcher<Sequence<T>> {228 override fun test(value: Sequence<T>) = MatcherResult(229 value.count() > other.count(),230 { "Sequence of count ${value.count()} should be larger than sequence of count ${other.count()}" },231 { "Sequence of count ${value.count()} should not be larger than sequence of count ${other.count()}" }...

Full Screen

Full Screen

size.kt

Source:size.kt Github

copy

Full Screen

...16 asList().shouldHaveSize(size)17 return this18}19infix fun <T> Collection<T>.shouldHaveSize(size: Int): Collection<T> {20 this should haveSize(size = size)21 return this22}23infix fun <T> Iterable<T>.shouldNotHaveSize(size: Int): Iterable<T> {24 toList().shouldNotHaveSize(size)25 return this26}27infix fun <T> Array<T>.shouldNotHaveSize(size: Int): Array<T> {28 asList().shouldNotHaveSize(size)29 return this30}31infix fun <T> Collection<T>.shouldNotHaveSize(size: Int): Collection<T> {32 this shouldNot haveSize(size)33 return this34}35infix fun <T, U> Iterable<T>.shouldBeSameSizeAs(other: Collection<U>): Iterable<T> {36 toList().shouldBeSameSizeAs(other)37 return this38}39infix fun <T, U> Array<T>.shouldBeSameSizeAs(other: Collection<U>): Array<T> {40 asList().shouldBeSameSizeAs(other)41 return this42}43infix fun <T, U> Iterable<T>.shouldBeSameSizeAs(other: Iterable<U>): Iterable<T> {44 toList().shouldBeSameSizeAs(other.toList())45 return this46}47infix fun <T, U> Array<T>.shouldBeSameSizeAs(other: Array<U>): Array<T> {48 asList().shouldBeSameSizeAs(other.asList())49 return this50}51infix fun <T, U> Collection<T>.shouldBeSameSizeAs(other: Collection<U>): Collection<T> {52 this should beSameSizeAs(other)53 return this54}55fun <T, U> beSameSizeAs(other: Collection<U>) = object : Matcher<Collection<T>> {56 override fun test(value: Collection<T>) = MatcherResult(57 value.size == other.size,58 { "Collection of size ${value.size} should be the same size as collection of size ${other.size}" },59 { "Collection of size ${value.size} should not be the same size as collection of size ${other.size}" })60}61infix fun <T> Iterable<T>.shouldHaveAtLeastSize(n: Int): Iterable<T> {62 toList().shouldHaveAtLeastSize(n)63 return this64}65infix fun <T> Array<T>.shouldHaveAtLeastSize(n: Int): Array<T> {66 asList().shouldHaveAtLeastSize(n)67 return this68}69infix fun <T> Collection<T>.shouldHaveAtLeastSize(n: Int): Collection<T> {70 this shouldHave atLeastSize(n)71 return this72}73fun <T> atLeastSize(n: Int) = object : Matcher<Collection<T>> {74 override fun test(value: Collection<T>) = MatcherResult(75 value.size >= n,76 { "Collection ${value.print().value} should contain at least $n elements" },77 {78 "Collection ${value.print().value} should contain less than $n elements"79 })80}81infix fun <T> Iterable<T>.shouldHaveAtMostSize(n: Int): Iterable<T> {82 toList().shouldHaveAtMostSize(n)83 return this84}85infix fun <T> Array<T>.shouldHaveAtMostSize(n: Int): Array<T> {86 asList().shouldHaveAtMostSize(n)87 return this88}89infix fun <T> Collection<T>.shouldHaveAtMostSize(n: Int): Collection<T> {90 this shouldHave atMostSize(n)91 return this92}93fun <T> atMostSize(n: Int) = object : Matcher<Collection<T>> {94 override fun test(value: Collection<T>) = MatcherResult(95 value.size <= n,96 { "Collection ${value.print().value} should contain at most $n elements" },97 {98 "Collection ${value.print().value} should contain more than $n elements"99 })100}101fun <T> haveSizeMatcher(size: Int) = object : Matcher<Collection<T>> {102 override fun test(value: Collection<T>) =103 MatcherResult(104 value.size == size,105 { "Collection should have size $size but has size ${value.size}. Values: ${value.print().value}" },106 { "Collection should not have size $size. Values: ${value.print().value}" }107 )108}...

Full Screen

Full Screen

haveSize

Using AI Code Generation

copy

Full Screen

1import io.kotest.matchers.sequences.shouldHaveSize2import io.kotest.matchers.sequences.shouldContain3import io.kotest.matchers.sequences.shouldContainAll4import io.kotest.matchers.sequences.shouldContainExactly5import io.kotest.matchers.sequences.shouldContainExactlyInAnyOrder6import io.kotest.matchers.sequences.shouldContainInOrder7import io.kotest.matchers.sequences.shouldContainNone8import io.kotest.matchers.sequences.shouldContainOnly9import io.kotest.matchers.sequences.shouldContainOnlyNulls10import io.kotest.matchers.sequences.shouldContainOnlyNulls11import io.kotest.matchers.sequences.shouldContainOnlyNulls12import io.kotest.matchers.sequences.shouldContainOnlyNulls13import io.kotest.matchers.sequences.shouldContainOnlyNulls14import io.kotest.matchers.sequences.shouldContainOnlyNulls

Full Screen

Full Screen

haveSize

Using AI Code Generation

copy

Full Screen

1assertThat(sequence).haveSize(3)2sequence shouldContainAll listOf(1, 2, 3)3sequence shouldContainExactly listOf(1, 2, 3)4sequence shouldContainExactlyInAnyOrder listOf(3, 2, 1)5sequence shouldContainAnyOf listOf(4, 5, 6)6sequence shouldContainNoneOf listOf(4, 5, 6)7sequence shouldContainInOrder listOf(1, 2, 3)

Full Screen

Full Screen

haveSize

Using AI Code Generation

copy

Full Screen

1val names = listOf( "John" , "Doe" , "Jane" )2val names = listOf( "John" , "Doe" , "Jane" )3val names = listOf( "John" , "Doe" , "Jane" )4val names = listOf( "John" , "Doe" , "Jane" )5val names = listOf( "John" , "Doe" , "Jane" )6val names = listOf( "John" , "Doe" , "Jane" )7val names = listOf( "John" , "Doe" , "Jane" )8val names = listOf( "John" , "Doe" , "Jane" )

Full Screen

Full Screen

haveSize

Using AI Code Generation

copy

Full Screen

1val  list  =  listOf( 1 , 2 , 3 , 4 )2 list  should  haveSize( 4 )3val  list  =  listOf( 1 , 2 , 3 , 4 )4 list  should  containAll( 1 , 2 , 3 , 4 )5val  list  =  listOf( 1 , 2 , 3 , 4 )6 list  should  containAllInOrder( 1 , 2 , 3 , 4 )7val  list  =  listOf( 1 , 2 , 3 , 4 )8 list  should  containAllInAnyOrder( 1 , 2 , 3 , 4 )9val  list  =  listOf( 1 , 2 , 3 , 4 )10 list  should  contain( 1 , 2 , 3 , 4 )11val  list  =  listOf( 1 , 2 , 3 , 4 )12 list  should  containInOrder( 1 , 2 , 3 , 4 )13val  list  =  listOf( 1 , 2 , 3 , 4 )14 list  should  containInAnyOrder( 1 , 2 , 3 , 4 )15val  list  =  listOf( 1

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful