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

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

AbstractDependencyNavigatorTest.kt

Source:AbstractDependencyNavigatorTest.kt Github

copy

Full Screen

...17 * License-Filename: LICENSE18 */19package org.ossreviewtoolkit.model20import io.kotest.core.spec.style.WordSpec21import io.kotest.matchers.collections.beEmpty22import 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 ),208 Identifier("Maven:com.fasterxml.jackson.core:jackson-databind:2.8.9") to listOf(209 Identifier("Maven:net.logstash.logback:logstash-logback-encoder:4.11")210 ),211 Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.6") to listOf(212 Identifier("Maven:com.typesafe.akka:akka-stream_2.12:2.5.6")213 ),214 Identifier("Maven:com.typesafe.akka:akka-stream_2.12:2.5.6") to emptyList(),215 Identifier("Maven:com.typesafe:config:1.3.1") to emptyList(),216 Identifier("Maven:com.typesafe.scala-logging:scala-logging_2.12:3.7.2") to emptyList(),217 Identifier("Maven:com.typesafe:ssl-config-core_2.12:0.2.2") to listOf(218 Identifier("Maven:com.typesafe.akka:akka-stream_2.12:2.5.6")219 ),220 Identifier("Maven:net.logstash.logback:logstash-logback-encoder:4.11") to emptyList(),221 Identifier("Maven:org.scala-lang:scala-library:2.12.3") to emptyList(),222 Identifier("Maven:org.scala-lang:scala-reflect:2.12.2") to listOf(223 Identifier("Maven:com.typesafe.scala-logging:scala-logging_2.12:3.7.2")224 ),225 Identifier("Maven:org.scala-lang.modules:scala-java8-compat_2.12:0.8.0") to listOf(226 Identifier("Maven:com.typesafe.akka:akka-stream_2.12:2.5.6"),227 Identifier("Maven:com.typesafe.akka:akka-actor_2.12:2.5.6")228 ),229 Identifier("Maven:org.reactivestreams:reactive-streams:1.0.1") to listOf(230 Identifier("Maven:com.typesafe.akka:akka-stream_2.12:2.5.6")231 ),232 Identifier("Maven:org.slf4j:jcl-over-slf4j:1.7.25") to emptyList(),233 Identifier("Maven:org.slf4j:slf4j-api:1.7.25") to listOf(234 Identifier("Maven:ch.qos.logback:logback-classic:1.2.3")235 ),236 )237 }238 }239 }240 "projectDependencies" should {241 "return the dependencies of a project" {242 val scopeDependencies = navigator.scopeDependencies(testProject)243 val projectDependencies = navigator.projectDependencies(testProject)244 scopeDependencies.keys should containExactlyInAnyOrder("compile", "test")245 val expectedDependencies = scopeDependencies.getValue("compile") + scopeDependencies.getValue("test")246 projectDependencies should containExactlyInAnyOrder(expectedDependencies)247 }248 "support filtering the dependencies of a project" {249 val dependencies = navigator.projectDependencies(testProject, 1) {250 it.linkage != PackageLinkage.PROJECT_DYNAMIC251 }252 dependencies should containExactlyInAnyOrder(253 Identifier("Maven:ch.qos.logback:logback-classic:1.2.3"),254 Identifier("Maven:com.typesafe:config:1.3.1"),255 Identifier("Maven:com.typesafe.akka:akka-stream_2.12:2.5.6"),256 Identifier("Maven:com.typesafe.scala-logging:scala-logging_2.12:3.7.2"),257 Identifier("Maven:net.logstash.logback:logstash-logback-encoder:4.11"),258 Identifier("Maven:org.scala-lang:scala-library:2.12.3"),259 Identifier("Maven:org.slf4j:jcl-over-slf4j:1.7.25"),260 Identifier("Maven:org.scalacheck:scalacheck_2.12:1.13.5"),261 Identifier("Maven:org.scalatest:scalatest_2.12:3.0.4")262 )263 }264 "return no dependencies for a maxDepth of 0" {265 val dependencies = navigator.projectDependencies(testProject, 0)266 dependencies should beEmpty()267 }268 }269 "collectSubProjects" should {270 "find all the sub projects of a project" {271 val projectId = Identifier("SBT:com.pbassiner:multi1_2.12:0.1-SNAPSHOT")272 testResult.getProject(projectId) shouldNotBeNull {273 val subProjectIds = navigator.collectSubProjects(this)274 subProjectIds should containExactly(PROJECT_ID)275 }276 }277 }278 "dependencyTreeDepth" should {279 "calculate the dependency tree depth for a project" {280 navigator.dependencyTreeDepth(testProject, "compile") shouldBe 3...

Full Screen

Full Screen

matchers.kt

Source:matchers.kt Github

copy

Full Screen

...295 { "[$actual] did not contain the elements [$subsequence] in order" },296 { "[$actual] should not contain the elements [$subsequence] in order" }297 )298}299fun <T> Sequence<T>.shouldBeEmpty() = this should beEmpty()300fun <T> Sequence<T>.shouldNotBeEmpty() = this shouldNot beEmpty()301fun <T> beEmpty(): Matcher<Sequence<T>> = object : Matcher<Sequence<T>> {302 override fun test(value: Sequence<T>): MatcherResult = MatcherResult(303 value.count() == 0,304 { "Sequence should be empty" },305 { "Sequence should not be empty" }306 )307}308fun <T> Sequence<T>.shouldContainAll(vararg ts: T) = this should containAll(ts.asSequence())309infix fun <T> Sequence<T>.shouldContainAll(ts: Collection<T>) = this should containAll(ts.asSequence())310infix fun <T> Sequence<T>.shouldContainAll(ts: Sequence<T>) = this should containAll(ts)311fun <T> Sequence<T>.shouldNotContainAll(vararg ts: T) = this shouldNot containAll(ts.asSequence())312infix fun <T> Sequence<T>.shouldNotContainAll(ts: Collection<T>) = this shouldNot containAll(ts.asSequence())313infix fun <T> Sequence<T>.shouldNotContainAll(ts: Sequence<T>) = this shouldNot containAll(ts)314fun <T, C : Sequence<T>> containAll(ts: C): Matcher<Sequence<T>> = object : Matcher<Sequence<T>> {315 override fun test(value: Sequence<T>): MatcherResult = MatcherResult(...

Full Screen

Full Screen

DeviceRepositoryTestBase.kt

Source:DeviceRepositoryTestBase.kt Github

copy

Full Screen

...7import de.igorakkerman.demo.deviceconfig.application.Display8import de.igorakkerman.demo.deviceconfig.application.DisplayUpdate9import de.igorakkerman.demo.deviceconfig.application.Resolution10import io.kotest.assertions.throwables.shouldThrow11import io.kotest.matchers.collections.beEmpty12import io.kotest.matchers.collections.containExactlyInAnyOrder13import io.kotest.matchers.sequences.shouldExist14import io.kotest.matchers.should15import io.kotest.matchers.shouldBe16import org.junit.jupiter.api.Test17import org.springframework.transaction.annotation.Propagation18import org.springframework.transaction.annotation.Transactional19import javax.validation.ConstraintViolationException20@Transactional21abstract class DeviceRepositoryTestBase(22 private val deviceRepository: DeviceRepository,23) {24 private val computer = Computer(25 id = "pc-win10-0815",26 name = "workpc-0815",27 username = "root",28 password = "topsecret",29 ipAddress = "127.0.0.1",30 )31 private val display = Display(32 id = "screen-samsung4k-4711",33 name = "workscreen-4711",34 resolution = Resolution.UHD35 )36 @Test37 fun `create two Devices, findDeviceById should find the right one`() {38 // given39 deviceRepository.createDevice(computer)40 deviceRepository.createDevice(display)41 flushAndClear()42 // when43 val foundComputer = deviceRepository.findDeviceById(computer.id)44 val foundDisplay = deviceRepository.findDeviceById(display.id)45 // then46 foundComputer shouldBe computer47 foundDisplay shouldBe display48 }49 @Test50 fun `create Device, findDeviceById should not find by unknown id`() {51 // given52 deviceRepository.createDevice(computer)53 flushAndClear()54 // when / then55 shouldThrow<DeviceNotFoundException> {56 deviceRepository.findDeviceById(display.id)57 }58 }59 @Test60 fun `create two Devices, findDeviceTypeById should find the type`() {61 // given62 deviceRepository.createDevice(computer)63 deviceRepository.createDevice(display)64 flushAndClear()65 // when66 val foundDisplayType = deviceRepository.findDeviceTypeById(display.id)67 val foundComputerType = deviceRepository.findDeviceTypeById(computer.id)68 // then69 foundComputerType shouldBe Computer::class70 foundDisplayType shouldBe Display::class71 }72 @Test73 fun `creating two Devices of same type with the same id should throw Exception`() {74 // given75 deviceRepository.createDevice(computer)76 flushAndClear()77 // when/then78 shouldThrow<DeviceAreadyExistsException> {79 deviceRepository.createDevice(80 computer.copy(81 id = computer.id,82 name = "different name",83 username = "different username"84 )85 )86 flushAndClear()87 }88 }89 @Test90 fun `creating two Devices of different type with the same id should throw Exception`() {91 // given92 deviceRepository.createDevice(computer)93 flushAndClear()94 // when/then95 shouldThrow<DeviceAreadyExistsException> {96 deviceRepository.createDevice(97 display.copy(98 id = computer.id99 )100 )101 flushAndClear()102 }103 }104 @Test105 fun `create, then update data of Computer, findDeviceById should return updated values`() {106 // given107 deviceRepository.createDevice(computer)108 flushAndClear()109 val computerUpdate = ComputerUpdate(110 name = "deskscreen-0815",111 ipAddress = "192.168.178.111"112 )113 // when114 deviceRepository.updateDevice(computer.id, computerUpdate)115 flushAndClear()116 // then117 val foundDevice = deviceRepository.findDeviceById(computer.id)118 foundDevice shouldBe computer.copy(119 name = computerUpdate.name!!,120 ipAddress = computerUpdate.ipAddress!!121 )122 }123 @Test124 fun `create, then update data of Display, findDeviceById should return updated values`() {125 // given126 deviceRepository.createDevice(display)127 flushAndClear()128 val displayUpdate = DisplayUpdate(129 name = "deskscreen-0815",130 resolution = Resolution.HD131 )132 // when133 deviceRepository.updateDevice(display.id, displayUpdate)134 flushAndClear()135 // then136 val foundDevice = deviceRepository.findDeviceById(display.id)137 foundDevice shouldBe display.copy(138 name = displayUpdate.name!!,139 resolution = displayUpdate.resolution!!140 )141 }142 @Test143 fun `update data in unknown device should throw Exception`() {144 // given145 // empty database146 // when/then147 shouldThrow<DeviceNotFoundException> {148 deviceRepository.updateDevice("unknown-id", DisplayUpdate())149 }150 }151 @Test152 fun `create, then replace Computer, findDeviceById should return updated values`() {153 // given154 deviceRepository.createDevice(computer)155 flushAndClear()156 // when157 val updatedComputer = computer.copy(158 name = "deskpc-0815",159 ipAddress = "34.245.198.211"160 )161 deviceRepository.replaceDevice(updatedComputer)162 flushAndClear()163 // then164 val foundDevice = deviceRepository.findDeviceById(computer.id)165 foundDevice shouldBe updatedComputer166 }167 @Test168 fun `create, then replace Display, findDeviceById should return updated values`() {169 // given170 deviceRepository.createDevice(display)171 flushAndClear()172 val updatedDisplay = display.copy(173 name = "deskscreen-0815",174 resolution = Resolution.HD175 )176 // when177 deviceRepository.replaceDevice(updatedDisplay)178 flushAndClear()179 // then180 val foundDevice = deviceRepository.findDeviceById(display.id)181 foundDevice shouldBe updatedDisplay182 }183 @Test184 fun `replace unknown device should throw Exception`() {185 // given186 // empty database187 // when/then188 shouldThrow<DeviceNotFoundException> {189 deviceRepository.replaceDevice(display.copy(id = "unknown-id"))190 }191 }192 @Test193 fun `create two Devices, findAllDevices should find both Devices`() {194 // given195 deviceRepository.createDevice(computer)196 deviceRepository.createDevice(display)197 flushAndClear()198 // when199 val foundDevices = deviceRepository.findAllDevices()200 // then201 foundDevices should containExactlyInAnyOrder(computer, display)202 }203 @Test204 fun `in empty database, findAllDevices should return empty list`() {205 // given206 // empty database207 // when208 val foundDevices = deviceRepository.findAllDevices()209 // then210 foundDevices should beEmpty()211 }212 @Test213 // allow catching TransactionException from repository transaction214 // alternative: run non-transactional, that is, outside a @DataJpaTest or @Transactional-annotated class215 @Transactional(propagation = Propagation.SUPPORTS)216 fun `ip address should have IPv4 format`() {217 // A bad ip address should not even make it to the application layer (or the persistence layer).218 // This test makes sure that if for some reason the prior level checks fail,219 // the item is not persisted and the persistence layer responds with some kind of Exception,220 // that has, at some point down the cause stack, a ConstraintViolationException.221 // The actual Exception type or the level of exceptions are implementation details and not part of the test.222 // given223 val newComputer = computer.copy(224 ipAddress = "::1"...

Full Screen

Full Screen

beEmpty

Using AI Code Generation

copy

Full Screen

1shouldHaveSize(2)2shouldHaveAtLeastSize(2)3shouldHaveAtMostSize(2)4shouldContain(2)5shouldContainAll(2, 3)6shouldContainNone(2, 3)7shouldContainExactly(2, 3)8shouldContainExactlyInAnyOrder(2, 3)9shouldContainOnly(2, 3)10shouldContainInOrder(2, 3)11shouldContainSame(2, 3)12shouldContainSameInAnyOrder(2, 3)13shouldContainSameInOrder(2, 3)14shouldContainAllInOrder(2, 3)15shouldContainAllInAnyOrder(2

Full Screen

Full Screen

beEmpty

Using AI Code Generation

copy

Full Screen

1 val seq = sequenceOf(1, 2, 3)2 seq should beEmpty()3 seq should notBeEmpty()4 val coll = listOf(1, 2, 3)5 coll should beEmpty()6 coll should notBeEmpty()

Full Screen

Full Screen

beEmpty

Using AI Code Generation

copy

Full Screen

1@DisplayName ( "Empty Sequence" )2fun testSequenceEmpty() {3val emptySequence = sequenceOf()4emptySequence.shouldBeEmpty()5}6@DisplayName ( "Empty Collection" )7fun testCollectionEmpty() {8val emptyCollection = listOf()9emptyCollection.shouldBeEmpty()10}11@DisplayName ( "Empty Map" )12fun testMapEmpty() {13val emptyMap = mapOf()14emptyMap.shouldBeEmpty()15}16}

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