How to use Map.shouldNotContain method of io.kotest.matchers.maps.matchers class

Best Kotest code snippet using io.kotest.matchers.maps.matchers.Map.shouldNotContain

DownloadManagerActorTest.kt

Source:DownloadManagerActorTest.kt Github

copy

Full Screen

1/*2 * Copyright (C) 2018 The Tachiyomi Open Source Project3 *4 * This Source Code Form is subject to the terms of the Mozilla Public5 * License, v. 2.0. If a copy of the MPL was not distributed with this6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.7 */8package tachiyomi.domain.download.service9import io.kotest.core.spec.style.FunSpec10import io.kotest.core.test.TestContext11import io.kotest.matchers.collections.shouldBeEmpty12import io.kotest.matchers.collections.shouldBeSameSizeAs13import io.kotest.matchers.collections.shouldContain14import io.kotest.matchers.collections.shouldHaveSize15import io.kotest.matchers.collections.shouldNotContain16import io.kotest.matchers.maps.shouldBeEmpty17import io.kotest.matchers.maps.shouldHaveSize18import io.kotest.matchers.nulls.shouldBeNull19import io.kotest.matchers.nulls.shouldNotBeNull20import io.kotest.matchers.types.shouldBeInstanceOf21import io.mockk.Runs22import io.mockk.clearAllMocks23import io.mockk.coEvery24import io.mockk.every25import io.mockk.just26import io.mockk.mockk27import io.mockk.spyk28import io.mockk.verify29import kotlinx.coroutines.Dispatchers30import kotlinx.coroutines.Job31import kotlinx.coroutines.channels.Channel32import kotlinx.coroutines.channels.ClosedReceiveChannelException33import kotlinx.coroutines.launch34import okio.FileSystem35import okio.Path36import tachiyomi.core.prefs.Preference37import tachiyomi.domain.download.model.SavedDownload38import tachiyomi.domain.download.service.DownloadManagerActor.Message39import tachiyomi.domain.download.service.DownloadManagerActor.State40import tachiyomi.domain.manga.model.Chapter41import tachiyomi.domain.manga.model.Manga42import kotlin.time.DurationUnit43import kotlin.time.ExperimentalTime44import kotlin.time.toDuration45@ExperimentalTime46class DownloadManagerActorTest : FunSpec({47 lateinit var messages: Channel<Message>48 val compressPreference = mockk<Preference<Boolean>>()49 val preferences = mockk<DownloadPreferences>()50 val downloader = mockk<Downloader>()51 val compressor = mockk<DownloadCompressor>()52 val repository = mockk<DownloadRepository>()53 val fileSystem = spyk(FileSystem.SYSTEM)54 val tmpFile = mockk<Path>()55 lateinit var actor: TestDownloadManagerActor56 val withActor: suspend TestContext.(suspend () -> Unit) -> Unit = { fn ->57 launch(Dispatchers.Unconfined) {58 try {59 actor.receiveAll()60 } catch (e: ClosedReceiveChannelException) {61 // Ignored62 }63 }64 fn()65 messages.close()66 }67 afterTest { clearAllMocks() }68 beforeTest {69 every { preferences.compress() } returns compressPreference70 messages = Channel()71 actor = TestDownloadManagerActor(72 messages, preferences, downloader, compressor, repository, fileSystem73 )74 every { compressPreference.get() } returns false75 coEvery { repository.findAll() } returns emptyList()76 coEvery { downloader.worker(any(), any(), any()) } returns Job()77 coEvery { compressor.worker(any(), any(), any(), any()) } returns Job()78 coEvery { repository.delete(any<Long>()) } just Runs79 every { tmpFile.toString() } returns "/tmp/nonexistentfile_tmp"80 every { fileSystem.atomicMove(any(), any()) } returns Unit81 }82 context("restore") {83 test("saved downloads") {84 val savedDownloads = listOf(85 SavedDownload(86 chapterId = 1, mangaId = 1, priority = 0, sourceId = 1, mangaName = "", chapterKey = "",87 chapterName = "", scanlator = ""88 )89 )90 coEvery { repository.findAll() } returns savedDownloads91 withActor {92 actor._downloads shouldHaveSize 193 }94 }95 }96 context("add") {97 test("chapters to queue") {98 withActor {99 messages.send(Message.Add(getTestChaptersToDownload(2)))100 actor._downloads shouldHaveSize 2101 }102 }103 test("chapters to queue without duplicates") {104 withActor {105 messages.send(Message.Add(getTestChaptersToDownload(1)))106 messages.send(Message.Add(getTestChaptersToDownload(3)))107 actor._downloads shouldHaveSize 3108 }109 }110 }111 context("remove") {112 test("non existing chapter from queue") {113 val chapterToRemove = Chapter(100, 1, "ch1", "Chapter 100")114 withActor {115 messages.send(Message.Add(getTestChaptersToDownload(1)))116 messages.send(Message.Remove(listOf(chapterToRemove)))117 actor._downloads shouldHaveSize 1118 }119 }120 test("existing chapter from queue") {121 val chaptersToAdd = getTestChaptersToDownload(1)122 withActor {123 messages.send(Message.Add(chaptersToAdd))124 messages.send(Message.Remove(chaptersToAdd.values.first()))125 actor._downloads.shouldBeEmpty()126 }127 }128 test("clear all chapters") {129 val chaptersToAdd = getTestChaptersToDownload(5)130 withActor {131 messages.send(Message.Add(chaptersToAdd))132 messages.send(Message.Clear)133 actor._downloads.shouldBeEmpty()134 }135 }136 }137 context("download") {138 val testDownloadsMultiManga = (1..5L).associate { mangaId ->139 Manga(mangaId, mangaId, "manga $mangaId", "Manga $mangaId") to (1..3L).map {140 val chapterId = (mangaId - 1) * 100 + it141 Chapter(chapterId, mangaId, "chapter $chapterId", "Chapter $chapterId")142 }143 }144 val testDownloadsSingleManga = testDownloadsMultiManga.filterKeys { it.id == 1L }145 test("does nothing when there are no downloads") {146 withActor {147 messages.send(Message.Start)148 actor._workerJob.shouldBeNull()149 actor._states.shouldBeEmpty()150 }151 }152 test("begins downloading chapters") {153 withActor {154 messages.send(Message.Add(testDownloadsSingleManga))155 messages.send(Message.Start)156 actor._workerJob.shouldNotBeNull()157 actor._states shouldHaveSize 1158 actor._states.values.first().shouldBeInstanceOf<State.Downloading>()159 }160 }161 test("begins downloading chapters simultaneously from multiple sources") {162 withActor {163 messages.send(Message.Add(testDownloadsMultiManga))164 messages.send(Message.Start)165 // Up to 3 workers spawn, so we can have 3 simultaneous downloads max166 actor._states shouldHaveSize 3167 actor._states.values.forEach { it.shouldBeInstanceOf<State.Downloading>() }168 }169 }170 test("downloads a chapter") {171 withActor {172 messages.send(Message.Add(testDownloadsSingleManga))173 messages.send(Message.Start)174 val download = (actor._states.values.first() as State.Downloading).download175 val downloadResult = Downloader.Result.Success(download, tmpFile)176 actor._downloadResults.send(downloadResult)177 actor._downloads shouldNotContain download178 actor._states[download.chapterId].shouldBeNull()179 verify { fileSystem.atomicMove(tmpFile, any()) }180 }181 }182 test("fails to download a chapter") {183 withActor {184 messages.send(Message.Add(testDownloadsSingleManga))185 messages.send(Message.Start)186 val download = (actor._states.values.first() as State.Downloading).download187 val downloadResult = Downloader.Result.Failure(download, Exception("Download error"))188 actor._downloadResults.send(downloadResult)189 actor._downloads shouldContain download190 actor._states[download.chapterId].shouldBeInstanceOf<State.Failed>()191 verify(exactly = 0) { fileSystem.atomicMove(tmpFile, any()) }192 }193 }194 test("downloads next chapter on completion") {195 withActor {196 messages.send(Message.Add(testDownloadsMultiManga))197 messages.send(Message.Start)198 val prevDownloads = actor._states.values.filterIsInstance<State.Downloading>()199 .map { it.download.chapterId }200 val download = (actor._states.values.first() as State.Downloading).download201 val downloadResult = Downloader.Result.Success(download, tmpFile)202 actor._downloadResults.send(downloadResult)203 val newDownloads = actor._states.values.filterIsInstance<State.Downloading>()204 .map { it.download.chapterId }205 prevDownloads shouldBeSameSizeAs newDownloads206 prevDownloads shouldContain download.chapterId207 newDownloads shouldNotContain download.chapterId208 }209 }210 test("downloads next chapter on failure") {211 withActor {212 messages.send(Message.Add(testDownloadsMultiManga))213 messages.send(Message.Start)214 val prevDownloads = actor._states.values.filterIsInstance<State.Downloading>()215 .map { it.download.chapterId }216 val download = (actor._states.values.first() as State.Downloading).download217 val downloadResult = Downloader.Result.Failure(download, Exception("Download error"))218 actor._downloadResults.send(downloadResult)219 val newDownloads = actor._states.values.filterIsInstance<State.Downloading>()220 .map { it.download.chapterId }221 prevDownloads shouldBeSameSizeAs newDownloads222 prevDownloads shouldContain download.chapterId223 newDownloads shouldNotContain download.chapterId224 }225 }226 test("downloads chapters until none is left").config(227 timeout = 1.toDuration(DurationUnit.SECONDS)228 ) {229 withActor {230 messages.send(Message.Add(testDownloadsMultiManga))231 messages.send(Message.Start)232 while (true) {233 val currentlyDownloading = actor._states.values.filterIsInstance<State.Downloading>()234 if (currentlyDownloading.isEmpty()) break235 for (downloading in currentlyDownloading) {236 val downloadResult = Downloader.Result.Success(downloading.download, tmpFile)237 actor._downloadResults.send(downloadResult)238 }239 }240 actor._downloads.shouldBeEmpty()241 actor._workerJob.shouldBeNull()242 }243 }244 test("downloads chapters until stopped") {245 withActor {246 messages.send(Message.Add(testDownloadsMultiManga))247 messages.send(Message.Start)248 val download = (actor._states.values.first() as State.Downloading).download249 val downloadResult = Downloader.Result.Success(download, tmpFile)250 actor._downloadResults.send(downloadResult)251 messages.send(Message.Stop)252 actor._states.shouldBeEmpty()253 actor._workerJob.shouldBeNull()254 }255 }256 test("schedules chapter compression") {257 every { compressPreference.get() } returns true258 withActor {259 messages.send(Message.Add(testDownloadsSingleManga))260 messages.send(Message.Start)261 val download = (actor._states.values.first() as State.Downloading).download262 val downloadResult = Downloader.Result.Success(download, tmpFile)263 actor._downloadResults.send(downloadResult)264 actor._downloads shouldContain download265 actor._states[download.chapterId].shouldBeInstanceOf<State.Compressing>()266 }267 }268 test("compresses a chapter") {269 every { compressPreference.get() } returns true270 withActor {271 messages.send(Message.Add(testDownloadsSingleManga))272 messages.send(Message.Start)273 val download = (actor._states.values.first() as State.Downloading).download274 val downloadResult = Downloader.Result.Success(download, tmpFile)275 actor._downloadResults.send(downloadResult)276 val compressionResult = DownloadCompressor.Result.Success(download, tmpFile)277 actor._compressionResults.send(compressionResult)278 actor._downloads shouldNotContain download279 actor._states[download.chapterId].shouldBeNull()280 verify { fileSystem.atomicMove(tmpFile, any()) }281 }282 }283 test("fails to compress a chapter") {284 every { compressPreference.get() } returns true285 withActor {286 messages.send(Message.Add(testDownloadsSingleManga))287 messages.send(Message.Start)288 val download = (actor._states.values.first() as State.Downloading).download289 val downloadResult = Downloader.Result.Success(download, tmpFile)290 actor._downloadResults.send(downloadResult)291 val compressionResult = DownloadCompressor.Result.Failure(download, Exception("Error"))292 actor._compressionResults.send(compressionResult)293 actor._downloads shouldContain download294 actor._states[download.chapterId].shouldBeInstanceOf<State.Failed>()295 verify(exactly = 0) { fileSystem.atomicMove(tmpFile, any()) }296 }297 }298 test("keeps a locked chapter") {299 withActor {300 messages.send(Message.Add(testDownloadsSingleManga))301 messages.send(Message.Start)302 val download = (actor._states.values.first() as State.Downloading).download303 messages.send(Message.LockSourceFiles(download.chapterId))304 val downloadResult = Downloader.Result.Success(download, tmpFile)305 actor._downloadResults.send(downloadResult)306 actor._downloads shouldContain download307 actor._states[download.chapterId].shouldBeInstanceOf<State.Completing>()308 verify(exactly = 0) { fileSystem.atomicMove(tmpFile, any()) }309 }310 }311 test("keeps a locked chapter until unlocked") {312 withActor {313 messages.send(Message.Add(testDownloadsSingleManga))314 messages.send(Message.Start)315 val download = (actor._states.values.first() as State.Downloading).download316 messages.send(Message.LockSourceFiles(download.chapterId))317 val downloadResult = Downloader.Result.Success(download, tmpFile)318 actor._downloadResults.send(downloadResult)319 actor._states[download.chapterId].shouldBeInstanceOf<State.Completing>()320 messages.send(Message.UnlockSourceFiles(download.chapterId))321 actor._downloads shouldNotContain download322 actor._states[download.chapterId].shouldBeNull()323 verify { fileSystem.atomicMove(tmpFile, any()) }324 }325 }326 }327})328@Suppress("PropertyName")329private class TestDownloadManagerActor(330 messages: Channel<Message>,331 preferences: DownloadPreferences,332 downloader: Downloader,333 compressor: DownloadCompressor,334 repository: DownloadRepository,335 fileSystem: FileSystem336) : DownloadManagerActor(messages, preferences, downloader, compressor, repository, fileSystem) {337 val _downloads get() = downloads338 val _workerJob get() = workerJob339 val _downloadResults get() = downloadResults340 val _compressionResults get() = compressionResults341 val _states get() = states342}343private fun getTestChaptersToDownload(numChapters: Int): Map<Manga, List<Chapter>> {344 return mapOf(345 Manga(1, 1, "manga1", "Manga 1") to (1..numChapters).map {346 Chapter(it.toLong(), 1, "chapter$it", "Chapter $it")347 }348 )349}...

Full Screen

Full Screen

BrokerCallServiceIntegrationTest.kt

Source:BrokerCallServiceIntegrationTest.kt Github

copy

Full Screen

1package de.hennihaus.services.callservices2import de.hennihaus.configurations.BrokerConfiguration.ACTIVE_MQ_HEADER_AUTHORIZATION3import de.hennihaus.configurations.BrokerConfiguration.ACTIVE_MQ_HEADER_ORIGIN4import de.hennihaus.configurations.BrokerConfiguration.ACTIVE_MQ_HOST5import de.hennihaus.configurations.BrokerConfiguration.ACTIVE_MQ_PORT6import de.hennihaus.configurations.BrokerConfiguration.ACTIVE_MQ_PROTOCOL7import de.hennihaus.configurations.BrokerConfiguration.ACTIVE_MQ_RETRIES8import de.hennihaus.configurations.BrokerConfiguration.brokerModule9import de.hennihaus.containers.BrokerContainer10import de.hennihaus.models.generated.GetQueuesResponse11import de.hennihaus.models.generated.GetTopicsResponse12import de.hennihaus.models.generated.Queue13import de.hennihaus.models.generated.Topic14import de.hennihaus.objectmothers.BrokerContainerObjectMother.OBJECT_NAME_DEFAULT_PREFIX15import de.hennihaus.objectmothers.BrokerContainerObjectMother.QUEUE_OBJECT_NAME_SUFFIX16import de.hennihaus.objectmothers.BrokerContainerObjectMother.TOPIC_OBJECT_NAME_SUFFIX17import de.hennihaus.objectmothers.BrokerContainerObjectMother.getTestJobs18import de.hennihaus.objectmothers.BrokerContainerObjectMother.getTestQueues19import de.hennihaus.objectmothers.BrokerContainerObjectMother.getTestTopics20import de.hennihaus.objectmothers.BrokerObjectMother.JMS_BANK_A_QUEUE21import de.hennihaus.plugins.BrokerException22import de.hennihaus.plugins.ErrorMessage.BROKER_EXCEPTION_DEFAULT_MESSAGE23import de.hennihaus.plugins.initKoin24import de.hennihaus.services.BrokerServiceImpl.Companion.DESTINATION_NAME_DELIMITER25import de.hennihaus.services.BrokerServiceImpl.Companion.DESTINATION_TYPE_DELIMITER26import io.kotest.assertions.ktor.client.shouldHaveStatus27import io.kotest.assertions.throwables.shouldThrow28import io.kotest.matchers.collections.shouldBeEmpty29import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder30import io.kotest.matchers.collections.shouldHaveSize31import io.kotest.matchers.collections.shouldNotBeEmpty32import io.kotest.matchers.collections.shouldNotContain33import io.kotest.matchers.maps.shouldNotBeEmpty34import io.kotest.matchers.nulls.shouldNotBeNull35import io.kotest.matchers.should36import io.kotest.matchers.shouldBe37import io.kotest.matchers.shouldNotBe38import io.kotest.matchers.string.shouldContain39import io.kotest.matchers.types.beInstanceOf40import io.ktor.client.statement.HttpResponse41import io.ktor.client.statement.bodyAsText42import io.ktor.http.HttpStatusCode43import kotlinx.coroutines.runBlocking44import org.junit.jupiter.api.AfterAll45import org.junit.jupiter.api.BeforeEach46import org.junit.jupiter.api.Nested47import org.junit.jupiter.api.Test48import org.junit.jupiter.api.TestInstance49import org.junit.jupiter.api.extension.RegisterExtension50import org.koin.core.context.stopKoin51import org.koin.ksp.generated.defaultModule52import org.koin.test.KoinTest53import org.koin.test.inject54import org.koin.test.junit5.KoinTestExtension55@TestInstance(TestInstance.Lifecycle.PER_CLASS)56class BrokerCallServiceIntegrationTest : KoinTest {57 private val brokerContainer = BrokerContainer.INSTANCE58 private val classUnderTest: BrokerCallService by inject()59 @JvmField60 @RegisterExtension61 @Suppress("unused")62 val koinTestInstance = KoinTestExtension.create {63 initKoin(64 properties = mapOf(65 ACTIVE_MQ_PROTOCOL to BrokerContainer.ACTIVE_MQ_PROTOCOL.name,66 ACTIVE_MQ_HOST to brokerContainer.host,67 ACTIVE_MQ_PORT to brokerContainer.firstMappedPort.toString(),68 ACTIVE_MQ_RETRIES to BrokerContainer.ACTIVE_MQ_RETRIES.toString(),69 ACTIVE_MQ_HEADER_AUTHORIZATION to BrokerContainer.ACTIVE_MQ_AUTHORIZATION_HEADER,70 ACTIVE_MQ_HEADER_ORIGIN to BrokerContainer.ACTIVE_MQ_ORIGIN_HEADER71 ),72 modules = listOf(defaultModule, brokerModule)73 )74 }75 @BeforeEach76 fun init() = BrokerContainer.resetState()77 @AfterAll78 fun cleanUp() = stopKoin()79 @Nested80 inner class GetAllQueues {81 @Test82 fun `should return 200 and a queue list containing correct objectName`() = runBlocking<Unit> {83 BrokerContainer.addTestData(queues = getTestQueues())84 val result: GetQueuesResponse = classUnderTest.getAllQueues()85 result.shouldNotBeNull()86 result.status shouldBe HttpStatusCode.OK.value87 result.value shouldHaveSize getTestQueues().size88 result.value shouldContainExactlyInAnyOrder getTestQueues().map {89 Queue(90 objectName = """91 $OBJECT_NAME_DEFAULT_PREFIX92 $DESTINATION_NAME_DELIMITER93 $it94 $DESTINATION_TYPE_DELIMITER95 $QUEUE_OBJECT_NAME_SUFFIX96 """.trimIndent().replace("\n", "")97 )98 }99 }100 @Test101 fun `should return 200 and an empty list when no queues available`() = runBlocking<Unit> {102 BrokerContainer.addTestData(queues = emptyList())103 val result: GetQueuesResponse = classUnderTest.getAllQueues()104 result.shouldNotBeNull()105 result.status shouldBe HttpStatusCode.OK.value106 result.value.shouldBeEmpty()107 }108 }109 @Nested110 inner class GetAllTopics {111 @Test112 fun `should return 200 and a topic list containing correct objectName`() = runBlocking<Unit> {113 BrokerContainer.addTestData(topics = getTestTopics())114 val result: GetTopicsResponse = classUnderTest.getAllTopics()115 result.shouldNotBeNull()116 result.status shouldBe HttpStatusCode.OK.value117 result.value shouldHaveSize getTestTopics().size118 result.value shouldContainExactlyInAnyOrder getTestTopics().map {119 Topic(120 objectName = """121 $OBJECT_NAME_DEFAULT_PREFIX122 $DESTINATION_NAME_DELIMITER123 $it124 $DESTINATION_TYPE_DELIMITER125 $TOPIC_OBJECT_NAME_SUFFIX126 """.trimIndent().replace("\n", "")127 )128 }129 }130 @Test131 fun `should return 200 and an empty list when no topics available`() = runBlocking<Unit> {132 BrokerContainer.addTestData(topics = emptyList())133 val result: GetTopicsResponse = classUnderTest.getAllTopics()134 result.shouldNotBeNull()135 result.status shouldBe HttpStatusCode.OK.value136 result.value.shouldBeEmpty()137 }138 }139 @Nested140 inner class DeleteAllJobs {141 @Test142 fun `should return 200 and delete all open jobs in broker`() = runBlocking {143 BrokerContainer.addTestData(jobs = getTestJobs())144 BrokerContainer.getTestJobs().value.shouldNotBeEmpty()145 val response: HttpResponse = classUnderTest.deleteAllJobs()146 response shouldHaveStatus HttpStatusCode.OK147 response.bodyAsText() shouldContain HTTP_STATUS_OK148 BrokerContainer.getTestJobs().value shouldBe emptyMap()149 }150 @Test151 fun `should return 200 and not throw an exception when no jobs is in broker`() = runBlocking {152 BrokerContainer.addTestData(jobs = emptyMap())153 val response: HttpResponse = classUnderTest.deleteAllJobs()154 response shouldHaveStatus HttpStatusCode.OK155 response.bodyAsText() shouldContain HTTP_STATUS_OK156 BrokerContainer.getTestJobs().value shouldBe emptyMap()157 }158 }159 @Nested160 inner class DeleteQueueByName {161 @Test162 fun `should delete a queue by name`() = runBlocking<Unit> {163 BrokerContainer.addTestData(queues = listOf(JMS_BANK_A_QUEUE))164 BrokerContainer.getTestQueues().value.shouldNotBeEmpty()165 val response: HttpResponse = classUnderTest.deleteQueueByName(name = JMS_BANK_A_QUEUE)166 response shouldHaveStatus HttpStatusCode.OK167 response.bodyAsText() shouldContain HTTP_STATUS_OK168 BrokerContainer.getTestQueues().value.shouldBeEmpty()169 }170 @Test171 fun `should return 200 and not throw an exception when queue was not found`() = runBlocking<Unit> {172 val name = "unknownQueue"173 val response: HttpResponse = classUnderTest.deleteQueueByName(name = name)174 response shouldHaveStatus HttpStatusCode.OK175 response.bodyAsText() shouldContain HTTP_STATUS_OK176 BrokerContainer.getTestQueues().value.shouldBeEmpty()177 }178 @Test179 fun `should throw an exception when queue in request is empty`() = runBlocking {180 val name = ""181 val response = shouldThrow<BrokerException> { classUnderTest.deleteQueueByName(name = name) }182 response should beInstanceOf<BrokerException>()183 response.message shouldNotBe BROKER_EXCEPTION_DEFAULT_MESSAGE184 }185 }186 @Nested187 inner class DeleteTopicByName {188 @Test189 fun `should delete a topic by name`() = runBlocking<Unit> {190 BrokerContainer.addTestData(topics = listOf(JMS_BANK_A_QUEUE))191 BrokerContainer.getTestTopics().value.shouldNotBeEmpty()192 val response: HttpResponse = classUnderTest.deleteTopicByName(name = JMS_BANK_A_QUEUE)193 response shouldHaveStatus HttpStatusCode.OK194 response.bodyAsText() shouldContain HTTP_STATUS_OK195 BrokerContainer.getTestTopics().value shouldNotContain Topic(196 objectName = """197 $OBJECT_NAME_DEFAULT_PREFIX198 $DESTINATION_NAME_DELIMITER199 $JMS_BANK_A_QUEUE200 $DESTINATION_TYPE_DELIMITER201 $TOPIC_OBJECT_NAME_SUFFIX202 """.trimIndent().replace("\n", "")203 )204 }205 @Test206 fun `should return 200 and not throw an exception when topic was not found`() = runBlocking<Unit> {207 val name = "unknownTopic"208 val response: HttpResponse = classUnderTest.deleteTopicByName(name = name)209 response shouldHaveStatus HttpStatusCode.OK210 response.bodyAsText() shouldContain HTTP_STATUS_OK211 BrokerContainer.getTestTopics().value.shouldBeEmpty()212 }213 @Test214 fun `should throw an exception when topic in request is empty`() = runBlocking {215 val name = ""216 val response = shouldThrow<BrokerException> { classUnderTest.deleteTopicByName(name = name) }217 response should beInstanceOf<BrokerException>()218 response.message shouldNotBe BROKER_EXCEPTION_DEFAULT_MESSAGE219 }220 }221 companion object {222 const val HTTP_STATUS_OK = """"status":200"""223 }224}...

Full Screen

Full Screen

ApplicationsTest.kt

Source:ApplicationsTest.kt Github

copy

Full Screen

1package app.civa.vaccination.domain2import io.kotest.assertions.throwables.shouldNotThrowAny3import io.kotest.assertions.throwables.shouldThrowExactly4import io.kotest.core.spec.style.BehaviorSpec5import io.kotest.data.forAll6import io.kotest.data.row7import io.kotest.matchers.maps.shouldBeEmpty8import io.kotest.matchers.maps.shouldContain9import io.kotest.matchers.maps.shouldNotBeEmpty10import io.kotest.matchers.maps.shouldNotContain11import io.kotest.matchers.nulls.shouldNotBeNull12import io.kotest.matchers.shouldBe13import io.kotest.matchers.types.shouldBeSameInstanceAs14import io.mockk.every15import io.mockk.mockk16import io.mockk.verify17import org.junit.jupiter.api.assertDoesNotThrow18import java.util.*19class ApplicationsTest : BehaviorSpec({20 given("a vaccine application to be added") {21 `when`("it is the first application of that name") {22 then("it should be added successfully") {23 val vaccineMock = mockk<Vaccine>()24 every { vaccineMock.makeKey() } returns "Name Test"25 val applications = Applications()26 shouldNotThrowAny {27 val application = application {28 id = mockk()29 vaccine = vaccineMock30 createdOn = mockk()31 petWeight = mockk()32 }33 applications add application34 applications.shouldNotBeNull().shouldNotBeEmpty()35 applications shouldContain ("Name Test" to listOf(application))36 applications.size shouldBe 137 }38 verify { vaccineMock.makeKey() }39 }40 }41 `when`("it is not the first application of that name") {42 and("it has happened after interval") {43 then("it should be added to applications successfully") {44 val vaccineMock = mockk<Vaccine>()45 every { vaccineMock.makeKey() } returns "Name Test"46 val vaccineApplicationMock = mockk<VaccineApplication>()47 every {48 vaccineApplicationMock mapStatusFrom any()49 } returns DateTimeStatus.VALID50 every { vaccineApplicationMock.getKey() } returns "Name Test"51 val applications = Applications()52 applications add vaccineApplicationMock53 shouldNotThrowAny {54 val application = application {55 id = mockk()56 vaccine = vaccineMock57 createdOn = mockk()58 petWeight = mockk()59 }60 applications add application61 applications.shouldNotBeNull().shouldNotBeEmpty()62 applications.size shouldBe 163 applications shouldContain ("Name Test" to listOf(64 vaccineApplicationMock,65 application66 ))67 }68 verify {69 vaccineApplicationMock.getKey()70 vaccineMock.makeKey()71 vaccineApplicationMock mapStatusFrom any()72 }73 }74 }75 and("it is not valid") {76 then("it should not be added") {77 forAll(78 row(DateTimeStatus.BEFORE),79 row(DateTimeStatus.SAME),80 row(DateTimeStatus.INTERVAL)81 ) {82 val vaccineMock = mockk<Vaccine>()83 every { vaccineMock.makeKey() } returns "Name Test"84 val vaccineApplicationMock = mockk<VaccineApplication>()85 every { vaccineApplicationMock mapStatusFrom any() } returns it86 every { vaccineApplicationMock.getKey() } returns "Name Test"87 val applications = Applications()88 applications add vaccineApplicationMock89 shouldThrowExactly<InvalidApplicationException> {90 val application = application {91 id = mockk()92 vaccine = vaccineMock93 createdOn = mockk()94 petWeight = mockk()95 }96 applications add application97 applications.shouldNotBeNull().shouldNotBeEmpty()98 applications.size shouldBe 199 applications shouldNotContain ("Name Test" to listOf(100 vaccineApplicationMock,101 application102 ))103 }104 verify {105 vaccineApplicationMock.getKey()106 vaccineMock.makeKey()107 vaccineApplicationMock mapStatusFrom any()108 }109 }110 }111 }112 }113 }114 given("an application id to be removed") {115 `when`("the application is found") {116 and("there's only one application with certain name") {117 then("it should be removed successfully") {118 val vaccineMock = mockk<Vaccine>()119 every { vaccineMock.makeKey() } returns "Name Test"120 val uuid = UUID.randomUUID()121 val vaccineApplication = application {122 id = uuid123 vaccine = vaccineMock124 createdOn = mockk()125 petWeight = mockk()126 }127 val applications = Applications()128 applications add vaccineApplication129 assertDoesNotThrow { applications deleteBy uuid }130 applications.shouldNotBeNull().shouldBeEmpty()131 applications shouldNotContain ("Name Test" to listOf(vaccineApplication))132 verify { vaccineMock.makeKey() }133 }134 }135 and("there's more than one application with the same name") {136 then("it should be removed successfully") {137 val vaccineMock = mockk<Vaccine>()138 every { vaccineMock.makeKey() } returns "Name Test"139 val createdOnMock = mockk<ApplicationDateTime>()140 every { createdOnMock mapStatus any() } returns DateTimeStatus.VALID141 val uuid = UUID.randomUUID()142 val vaccineApplication = application {143 id = uuid144 vaccine = vaccineMock145 createdOn = createdOnMock146 petWeight = mockk()147 }148 val applications = Applications()149 applications add vaccineApplication150 applications add application {151 id = UUID.randomUUID()152 vaccine = vaccineMock153 createdOn = mockk()154 petWeight = mockk()155 }156 assertDoesNotThrow { applications deleteBy uuid }157 applications.shouldNotBeNull().shouldNotBeEmpty()158 applications shouldNotContain ("Name Test" to listOf(vaccineApplication))159 verify { vaccineMock.makeKey() }160 }161 }162 }163 `when`("applications is empty") {164 then("there won't be any to remove") {165 val applications = Applications()166 shouldThrowExactly<ApplicationNotFoundException> {167 applications deleteBy UUID.randomUUID()168 }169 applications.shouldNotBeNull().shouldBeEmpty()170 }171 }172 }173 given("an application id to be found") {174 `when`("the application is present") {175 then("it must be retrieved") {176 val vaccineMock = mockk<Vaccine>()177 every { vaccineMock.makeKey() } returns "Vaccine Key"178 val uuid = UUID.randomUUID()179 val vaccineApplication = application {180 id = uuid181 vaccine = vaccineMock182 createdOn = mockk()183 petWeight = mockk()184 }185 val applications = Applications()186 applications add vaccineApplication187 shouldNotThrowAny {188 val foundApplication = applications findBy uuid189 foundApplication shouldBeSameInstanceAs vaccineApplication190 }191 }192 }193 `when`("the application is not found") {194 then("it should not be retrieved") {195 val applications = Applications()196 shouldThrowExactly<ApplicationNotFoundException> {197 applications findBy UUID.randomUUID()198 }199 }200 }201 }202})...

Full Screen

Full Screen

GameTest.kt

Source:GameTest.kt Github

copy

Full Screen

1package org.techninja.go.domain2import io.kotest.assertions.assertSoftly3import io.kotest.matchers.collections.shouldContain4import io.kotest.matchers.collections.shouldContainExactly5import io.kotest.matchers.collections.shouldNotContain6import io.kotest.matchers.maps.shouldContainExactly7import io.kotest.matchers.shouldBe8import org.junit.jupiter.api.Test9class GameTest {10 private val blackPlayer = Player(Color.BLACK, mutableSetOf())11 private val whitePlayer = Player(Color.WHITE, mutableSetOf())12 private val nineByNineBoard = Board(13 lowerBound = Point(1, 1),14 upperBound = Point(9, 9),15 state = mutableMapOf()16 )17 private val board = nineByNineBoard.copy(18 state = mutableMapOf(19 Point(1, 1) to Stone(Color.WHITE, Point(1, 1)),20 Point(2, 1) to Stone(Color.WHITE, Point(2, 1)),21 Point(3, 1) to Stone(Color.WHITE, Point(3, 1)),22 Point(4, 2) to Stone(Color.WHITE, Point(4, 2)),23 Point(3, 3) to Stone(Color.WHITE, Point(3, 3)),24 Point(2, 3) to Stone(Color.WHITE, Point(2, 3)),25 Point(1, 3) to Stone(Color.WHITE, Point(1, 3)),26 Point(2, 2) to Stone(Color.BLACK, Point(2, 2)),27 Point(3, 2) to Stone(Color.BLACK, Point(3, 2)),28 )29 )30 private val boardWithSquareTerritory = nineByNineBoard.copy(31 state = mutableMapOf(32 Point(2, 5) to Stone(Color.WHITE, Point(2, 5)),33 Point(3, 5) to Stone(Color.WHITE, Point(3, 5)),34 Point(4, 5) to Stone(Color.WHITE, Point(4, 5)),35 Point(5, 5) to Stone(Color.WHITE, Point(5, 5)),36 Point(2, 4) to Stone(Color.WHITE, Point(2, 4)),37 Point(3, 4) to Stone(Color.BLACK, Point(3, 4)),38 Point(4, 4) to Stone(Color.BLACK, Point(4, 4)),39 Point(5, 4) to Stone(Color.WHITE, Point(5, 4)),40 Point(2, 3) to Stone(Color.WHITE, Point(2, 3)),41 Point(5, 3) to Stone(Color.WHITE, Point(5, 3)),42 Point(2, 2) to Stone(Color.WHITE, Point(2, 2)),43 Point(3, 2) to Stone(Color.WHITE, Point(3, 2)),44 Point(4, 2) to Stone(Color.WHITE, Point(4, 2)),45 Point(5, 2) to Stone(Color.WHITE, Point(5, 2)),46 )47 )48 @Test49 fun `should play a move on the board for a player`() {50 val game = Game(51 gameId = "1",52 players = listOf(blackPlayer, whitePlayer),53 board = nineByNineBoard,54 currentPlayer = Color.BLACK55 )56 game.play(Color.BLACK, Point(3, 3))57 assertSoftly {58 game.board.getState() shouldBe mutableMapOf(Point(3, 3) to Stone(Color.BLACK, Point(3, 3)))59 game.players.find { it.stoneColor == Color.BLACK }!!.moves shouldContain Stone(Color.BLACK, Point(3, 3))60 game.currentPlayer shouldBe Color.WHITE61 }62 }63 @Test64 fun `should not play if it's not turn of that player`() {65 val game = Game(66 gameId = "1",67 players = listOf(blackPlayer, whitePlayer),68 board = nineByNineBoard,69 currentPlayer = Color.BLACK70 )71 game.play(Color.WHITE, Point(3, 3))72 assertSoftly {73 game.board.getState() shouldBe mutableMapOf()74 game.players.find { it.stoneColor == Color.BLACK }!!.moves shouldNotContain Stone(Color.BLACK, Point(3, 3))75 }76 }77 @Test78 fun `should play moves for different players`() {79 val game = Game(80 gameId = "1",81 players = listOf(blackPlayer, whitePlayer),82 board = nineByNineBoard,83 currentPlayer = Color.BLACK84 )85 game.play(Color.BLACK, Point(3, 3))86 game.play(Color.WHITE, Point(2, 3))87 game.play(Color.BLACK, Point(4, 3))88 game.play(Color.WHITE, Point(1, 3))89 assertSoftly {90 game.board.getState() shouldBe mutableMapOf(91 Point(3, 3) to Stone(Color.BLACK, Point(3, 3)),92 Point(4, 3) to Stone(Color.BLACK, Point(4, 3)),93 Point(2, 3) to Stone(Color.WHITE, Point(2, 3)),94 Point(1, 3) to Stone(Color.WHITE, Point(1, 3))95 )96 game.players.find { it.stoneColor == Color.BLACK }!!.moves shouldContainExactly listOf(97 Stone(Color.BLACK, Point(3, 3)),98 Stone(Color.BLACK, Point(4, 3))99 )100 game.players.find { it.stoneColor == Color.WHITE }!!.moves shouldContainExactly listOf(101 Stone(Color.WHITE, Point(2, 3)),102 Stone(Color.WHITE, Point(1, 3))103 )104 }105 }106 @Test107 fun `should capture stones`() {108 val game = Game(109 gameId = "1",110 players = listOf(blackPlayer, whitePlayer),111 board = board,112 currentPlayer = Color.WHITE113 )114 game.play(Color.WHITE, Point(1, 2))115 assertSoftly {116 game.board.getState() shouldContainExactly mutableMapOf(117 Point(1, 1) to Stone(Color.WHITE, Point(1, 1)),118 Point(2, 1) to Stone(Color.WHITE, Point(2, 1)),119 Point(3, 1) to Stone(Color.WHITE, Point(3, 1)),120 Point(4, 2) to Stone(Color.WHITE, Point(4, 2)),121 Point(3, 3) to Stone(Color.WHITE, Point(3, 3)),122 Point(2, 3) to Stone(Color.WHITE, Point(2, 3)),123 Point(1, 3) to Stone(Color.WHITE, Point(1, 3)),124 Point(1, 2) to Stone(Color.WHITE, Point(1, 2))125 )126 val whitePlayer = game.players.find { it.stoneColor == Color.WHITE }!!127 whitePlayer.moves shouldContain Stone(Color.WHITE, Point(1, 2))128 whitePlayer.getCaptured() shouldBe 2129 }130 }131 @Test132 fun `should not capture stones if opponent stones has a liberty`() {133 val game = Game(134 gameId = "1",135 players = listOf(blackPlayer, whitePlayer),136 board = boardWithSquareTerritory,137 currentPlayer = Color.WHITE138 )139 game.play(Color.WHITE, Point(3, 3))140 assertSoftly {141 game.board.getState() shouldContainExactly mutableMapOf(142 Point(2, 5) to Stone(Color.WHITE, Point(2, 5)),143 Point(3, 5) to Stone(Color.WHITE, Point(3, 5)),144 Point(4, 5) to Stone(Color.WHITE, Point(4, 5)),145 Point(5, 5) to Stone(Color.WHITE, Point(5, 5)),146 Point(2, 4) to Stone(Color.WHITE, Point(2, 4)),147 Point(3, 4) to Stone(Color.BLACK, Point(3, 4)),148 Point(4, 4) to Stone(Color.BLACK, Point(4, 4)),149 Point(5, 4) to Stone(Color.WHITE, Point(5, 4)),150 Point(2, 3) to Stone(Color.WHITE, Point(2, 3)),151 Point(3, 3) to Stone(Color.WHITE, Point(3, 3)),152 Point(5, 3) to Stone(Color.WHITE, Point(5, 3)),153 Point(2, 2) to Stone(Color.WHITE, Point(2, 2)),154 Point(3, 2) to Stone(Color.WHITE, Point(3, 2)),155 Point(4, 2) to Stone(Color.WHITE, Point(4, 2)),156 Point(5, 2) to Stone(Color.WHITE, Point(5, 2)),157 )158 val whitePlayer = game.players.find { it.stoneColor == Color.WHITE }!!159 whitePlayer.moves shouldContain Stone(Color.WHITE, Point(3, 3))160 whitePlayer.getCaptured() shouldBe 0161 }162 }163}...

Full Screen

Full Screen

MainTest.kt

Source:MainTest.kt Github

copy

Full Screen

1import io.kotest.core.spec.style.AnnotationSpec2import io.kotest.core.spec.style.StringSpec3import io.kotest.matchers.collections.shouldContain4import io.kotest.matchers.comparables.shouldBeEqualComparingTo5import io.kotest.matchers.maps.shouldContain6import io.kotest.matchers.should7import io.kotest.matchers.shouldBe8import io.kotest.matchers.shouldNot9import io.kotest.matchers.string.endWith10import io.kotest.matchers.string.shouldNotContain11import io.kotest.matchers.string.startWith12import io.kotest.property.Arb13import io.kotest.property.arbitrary.string14import io.kotest.property.checkAll15import org.jsoup.Jsoup16import org.jsoup.select.Elements17class GetListWordsSpec : StringSpec({18 "list should be found" {19 val html : String = """20 <html>21 <div>22 <ul>23 <li>Coffee</li>24 <li>Tea</li>25 <li>IceTea</li>26 </ul>27 </div>28 </html>29 """.trimIndent()30 val elements = Jsoup.parse(html).allElements31 val values = getListWords(elements)32 values shouldContain "Coffee"33 values shouldContain "Tea"34 values shouldContain "IceTea"35 println(values)36 values.size shouldBe 337 }38 "No list within html should return zero words" {39 val html : String = """40 <html>41 <div>42 <ul>43 <blah>Coffee</blah>44 <blah>Tea</blah>45 <blah>IceTea</blah>46 </ul>47 </div>48 </html>49 """.trimIndent()50 val elements = Jsoup.parse(html).allElements51 val values = getListWords(elements)52 values.size shouldBe 053 }54 "empty hmtl string should return zero words" {55 val html : String = ""56 val elements = Jsoup.parse(html).allElements57 val values = getListWords(elements)58 println(values)59 values.size shouldBe 060 }61 "serve no correct element by Jsoup" {62 val html : String = ""63 val elements = Jsoup.parse(html).getElementsByClass("beautiful")64 val values = getListWords(elements)65 println(values)66 values.size shouldBe 067 }68})69class WordFilterSpec : StringSpec({70 "<li> at the beginning should be removed" {71 val filteredWord = filterWord("<li>hello")72 filteredWord shouldNot startWith("<li>")73 }74 "</li> at the end should be remove" {75 val filteredWord = filterWord("hello</li>")76 filteredWord shouldNot endWith("</li>")77 }78 "- should be removed at every position" {79 val filteredWord = filterWord("a-t-a-t")80 filteredWord shouldBe "atat"81 }82 "soft hypen should be removed from word" {83 val filteredWord = filterWord("test\u00ADword")84 filteredWord shouldNotContain "\u00AD"85 filteredWord shouldBe "testword"86 }87 "< should be removed at every position" {88 val filteredWord = filterWord("<abp")89 filteredWord shouldBe "abp"90 }91 "> should be removed at every position" {92 val filteredWord = filterWord("abp>")93 filteredWord shouldBe "abp"94 }95 "<strong> should be removed at the beginning" {96 val filteredWord = filterWord("<strong>Eigenschaften")97 filteredWord shouldNot startWith("<strong>")98 filteredWord shouldBe "eigenschaften"99 }100 "Words should be parsed lowercase" {101 val filterWord = filterWord("AaAaAaAaBbBbBZz")102 filterWord shouldNotContain "A"103 filterWord shouldNotContain "B"104 filterWord shouldNotContain "Z"105 }106 "Should parse all letters lowercase" {107 val arb = Arb.string()108 arb.checkAll { a ->109 val filterWord = filterWord(a)110 for (c in 'A'..'Z') {111 filterWord shouldNotContain c.toString()112 }113 }114 }115})116class AddToModelSpec : AnnotationSpec() {117 fun `Word should be sucessfully added to model`() {118 addWordToModel("test")119 Model.items.keys shouldContain "test"120 }121 fun `Increment should work`() {122 addWordToModel("increment")123 addWordToModel("increment")124 Model.items.keys shouldContain "increment"125 Model.items["increment"] shouldBe 2126 }127 fun `Many Increment should work`() {128 val number = 20129 repeat(number) {130 addWordToModel("many")131 }132 Model.items.keys shouldContain "many"133 Model.items["many"] shouldBe number134 }135 suspend fun `randomized insertion test should work`() {136 val number = 20137 val arb = Arb.string()138 arb.checkAll { a ->139 repeat(number) {140 addWordToModel(a)141 }142 Model.items.keys shouldContain filterWord(a)143 Model.items[filterWord(a)] shouldBe number144 }145 }146 @BeforeEach147 fun clearModel() {148 Model.items = HashMap<String, Int>()149 }150}...

Full Screen

Full Screen

RoleHandlerTest.kt

Source:RoleHandlerTest.kt Github

copy

Full Screen

1package org.tesserakt.diskordin.core.cache.handler2import io.kotest.core.spec.style.FunSpec3import io.kotest.matchers.collections.shouldContain4import io.kotest.matchers.collections.shouldNotContain5import io.kotest.matchers.maps.shouldBeEmpty6import io.kotest.matchers.nulls.shouldNotBeNull7import io.kotest.matchers.types.shouldNotBeSameInstanceAs8import kotlinx.coroutines.runBlocking9import org.tesserakt.diskordin.core.cache.CacheSnapshotBuilder.Companion.mutate10import org.tesserakt.diskordin.core.cache.MemoryCacheSnapshot11import org.tesserakt.diskordin.core.client.InternalTestAPI12import org.tesserakt.diskordin.core.data.asSnowflake13import org.tesserakt.diskordin.core.data.json.response.GuildResponse14import org.tesserakt.diskordin.core.data.json.response.RoleResponse15import org.tesserakt.diskordin.core.entity.client16import org.tesserakt.diskordin.impl.core.client.DiscordClientBuilder17import org.tesserakt.diskordin.impl.core.client.configure18import org.tesserakt.diskordin.impl.core.entity.Guild19import org.tesserakt.diskordin.impl.core.entity.Role20import org.tesserakt.diskordin.rest.WithoutRest21@InternalTestAPI22class RoleHandlerTest : FunSpec({23 // many entities rely on discord client, for context, rest etc.24 runBlocking {25 (DiscordClientBuilder[WithoutRest] configure {26 +disableTokenVerification()27 }).client28 }29 val guild = Guild(30 GuildResponse(31 12345678911.asSnowflake(),32 "Test guild",33 null,34 null,35 owner_id = 12345678912.asSnowflake(),36 region = "",37 afk_channel_id = null,38 afk_timeout = -1,39 verification_level = 0,40 default_message_notifications = 0,41 explicit_content_filter = 0,42 roles = emptySet(),43 emojis = emptyList(),44 features = emptyList(),45 mfa_level = 0,46 application_id = null,47 system_channel_id = null,48 max_members = null,49 max_presences = null,50 vanity_url_code = null,51 description = null,52 banner = null,53 widget_channel_id = null,54 premiumSubscribersCount = null55 )56 )57 val fakeRole = Role(58 RoleResponse(59 12345678901.asSnowflake(),60 "Test",61 -1,62 false,63 -1,64 -1,65 managed = false,66 mentionable = false67 ), 12345678911.asSnowflake()68 )69 context("updater") {70 val handler = RoleUpdater71 test("Cache should be mutated after add") {72 val cache = MemoryCacheSnapshot.empty().copy(guilds = mapOf(guild.id to guild)).mutate()73 handler.handle(cache, fakeRole)74 val cachedGuild = cache.getGuild(guild.id) as? Guild75 cachedGuild.shouldNotBeNull()76 cachedGuild.raw shouldNotBeSameInstanceAs guild.raw77 cachedGuild.roles.map { (it as Role).raw } shouldContain fakeRole.raw78 }79 test("Cache should be mutated after modify") {80 val newGuild = guild.copy { it.copy(roles = setOf(fakeRole.raw)) }81 val newRole = fakeRole.copy { it.copy(color = 2) } as Role82 val cache = MemoryCacheSnapshot.empty().copy(guilds = mapOf(newGuild.id to newGuild)).mutate()83 val cachedGuild = cache.getGuild(newGuild.id)84 fakeRole.raw shouldNotBeSameInstanceAs newRole.raw85 cachedGuild.shouldNotBeNull()86 cachedGuild.roles.map { (it as Role).raw } shouldContain fakeRole.raw87 handler.handle(cache, newRole)88 cachedGuild.roles.map { (it as Role).raw } shouldNotContain newRole.raw89 cache.getGuild(newGuild.id)!!.roles.map { (it as Role).raw } shouldContain newRole.raw90 }91 test("Nothing should be changed if there is no guild in cache") {92 val cache = handler.handleAndGet(MemoryCacheSnapshot.empty().mutate(), fakeRole)93 cache.guilds.shouldBeEmpty()94 }95 }96 context("deleter") {97 val handler = RoleDeleter98 test("Nothing should happened with empty cache") {99 val cache = MemoryCacheSnapshot.empty().mutate()100 cache.guilds.shouldBeEmpty()101 handler.handle(cache, fakeRole)102 cache.guilds.shouldBeEmpty()103 }104 test("Item should be deleted from cache") {105 val cache = MemoryCacheSnapshot.empty().copy(guilds = mapOf(guild.id to guild)).mutate()106 RoleUpdater.handle(cache, fakeRole)107 handler.handle(cache, fakeRole)108 val cachedGuild = cache.getGuild(guild.id)109 cachedGuild.shouldNotBeNull()110 cachedGuild.roles.map { (it as Role).raw } shouldNotContain fakeRole111 }112 }113})...

Full Screen

Full Screen

MapTest.kt

Source:MapTest.kt Github

copy

Full Screen

1package io.opengood.commons.kotlin.extension.method2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.core.spec.style.FunSpec4import io.kotest.matchers.booleans.shouldBeFalse5import io.kotest.matchers.booleans.shouldBeTrue6import io.kotest.matchers.maps.shouldContain7import io.kotest.matchers.maps.shouldNotContain8import io.kotest.matchers.shouldBe9import io.opengood.commons.kotlin.function.makeEntry10class MapTest : FunSpec({11 test("map containsMultipleListItems extension method returns true when more than one item exists in values list for key") {12 val map = mapOf("foo" to listOf("bar", "baz"))13 map.containsMultipleListItems("foo").shouldBeTrue()14 }15 test("map containsMultipleListItems extension method returns false when one item exists in values list for key") {16 val map = mapOf("foo" to listOf("bar"))17 map.containsMultipleListItems("foo").shouldBeFalse()18 }19 test("map containsMultipleListItems extension method returns false when no items exist in values list for key") {20 val map = mapOf("foo" to emptyList<String>())21 map.containsMultipleListItems("foo").shouldBeFalse()22 }23 test("map containsMultipleListItems extension method returns false when key does not exist") {24 val map = emptyMap<String, List<String>>()25 map.containsMultipleListItems("foo").shouldBeFalse()26 }27 test("map keyByIndex extension method returns key at specified index") {28 val map = mapOf("foo" to "bar")29 map.keyByIndex(0) shouldBe "foo"30 }31 test("map keyByIndex extension method throws exception when key does not exist") {32 val map = emptyMap<String, String>()33 shouldThrow<IndexOutOfBoundsException> {34 map.keyByIndex(0)35 }36 }37 test("map notContainsKey extension method returns true when key does not exist") {38 val map = emptyMap<String, String>()39 map.notContainsKey("foo").shouldBeTrue()40 }41 test("map notContainsKey extension method returns false when key exists") {42 val map = mapOf("foo" to "bar")43 map.notContainsKey("foo").shouldBeFalse()44 }45 test("map notContainsValue extension method returns true when value does not exist") {46 val map = emptyMap<String, String>()47 map.notContainsValue("foo").shouldBeTrue()48 }49 test("map notContainsValue extension method returns false when value exists") {50 val map = mapOf("foo" to "bar")51 map.notContainsValue("bar").shouldBeFalse()52 }53 test("map putIfNotAbsent extension method adds map entry to map when it does not exist") {54 val map = mutableMapOf<String, String>()55 val entry = makeEntry("foo", "bar")56 map.putIfNotAbsent(entry)57 map.shouldContain("foo", "bar")58 }59 test("map putIfNotAbsent extension method does not add map entry to map when it already exists") {60 val map = mutableMapOf(Pair("foo", "bar"))61 val entry = makeEntry("foo", "baz")62 map.putIfNotAbsent(entry)63 map.shouldContain("foo", "bar")64 map.shouldNotContain("foo", "baz")65 }66 test("map valueByIndex extension method returns value at specified index") {67 val map = mapOf("foo" to "bar")68 map.valueByIndex(0) shouldBe "bar"69 }70 test("map valueByIndex extension method throws exception when value does not exist") {71 val map = emptyMap<String, String>()72 shouldThrow<IndexOutOfBoundsException> {73 map.valueByIndex(0)74 }75 }76})...

Full Screen

Full Screen

CaseInsensitiveMapTests.kt

Source:CaseInsensitiveMapTests.kt Github

copy

Full Screen

1package me.l3n.bot.discord.lod.collection2import io.kotest.assertions.throwables.shouldNotThrowAny3import io.kotest.core.spec.style.StringSpec4import io.kotest.matchers.maps.shouldContain5import io.kotest.matchers.maps.shouldNotContain6private val dravenPair = ("draven" to 1337)7private val capitalizedDravenPair = ("Draven" to 1337)8private val capitalizedDravenDifferentValuePair = ("Draven" to 400)9private val hecarimPair = ("Hecarim" to 120)10private val evelynnPair = ("EVELYNN" to 404)11private val differentPairs = arrayOf(dravenPair, hecarimPair, evelynnPair)12private val sameInsensitivePairs = arrayOf(dravenPair, evelynnPair, capitalizedDravenPair)13private val differentInsensitivePairs = arrayOf(14 dravenPair, evelynnPair, capitalizedDravenDifferentValuePair15)16class CaseInsensitiveMapTests : StringSpec({17 "should create map with pairs successfully" {18 val map = shouldNotThrowAny { caseInsensitiveMapOf(*differentPairs) }19 map shouldContain dravenPair20 map shouldContain hecarimPair21 map shouldContain evelynnPair22 }23 "should add pair successfully" {24 val map = caseInsensitiveMapOf(*differentPairs)25 map[dravenPair.first] = dravenPair.second26 map shouldContain dravenPair27 map shouldContain capitalizedDravenPair28 }29 "should get case insensitive pair" {30 val map = caseInsensitiveMapOf(*differentPairs)31 map shouldContain dravenPair32 map shouldContain capitalizedDravenPair33 map shouldContain evelynnPair34 }35 "should replace same case insensitive pair" {36 val map = caseInsensitiveMapOf(*sameInsensitivePairs)37 map shouldContain dravenPair38 map shouldContain capitalizedDravenPair39 map shouldContain evelynnPair40 }41 "should replace different case insensitive pair" {42 val map = caseInsensitiveMapOf(*differentInsensitivePairs)43 map shouldNotContain dravenPair44 map shouldContain capitalizedDravenDifferentValuePair45 map shouldContain evelynnPair46 }47})...

Full Screen

Full Screen

Map.shouldNotContain

Using AI Code Generation

copy

Full Screen

1Map.shouldNotContain(key: K, value: V)2Map.shouldNotContainKey(key: K)3Map.shouldNotContainValue(value: V)4Map.shouldNotHaveSize(size: Int)5Map.shouldNotHaveSameSizeAs(other: Iterable<*>)6Map.shouldNotHaveSameSizeAs(other: Array<*>)7Map.shouldNotHaveSameSizeAs(other: CharSequence)8Map.shouldNotHaveSameSizeAs(other: Map<*, *>)9Map.shouldNotHaveSameSizeAs(other: Collection<*>)10Map.shouldNotHaveSameSizeAs(other: String)11Map.shouldNotHaveSameSizeAs(other: Byte)12Map.shouldNotHaveSameSizeAs(other: Short)13Map.shouldNotHaveSameSizeAs(other: Int)14Map.shouldNotHaveSameSizeAs(other: Long)15Map.shouldNotHaveSameSizeAs(other: Float

Full Screen

Full Screen

Map.shouldNotContain

Using AI Code Generation

copy

Full Screen

1 fun `should not contain`() {2 val map = mapOf("a" to 1, "b" to 2, "c" to 3)3 map.shouldNotContain("d" to 4)4 map.shouldNotContain("d" to 1)5 map.shouldNotContain("a" to 4)6 }7 fun `should contain keys`() {8 val map = mapOf("a" to 1, "b" to 2, "c" to 3)9 map.shouldContainKeys("a", "b")10 map.shouldContainKeys("a", "b", "c")11 map.shouldContainKeys("a")12 }13 fun `should not contain keys`() {14 val map = mapOf("a" to 1, "b" to 2, "c" to 3)15 map.shouldNotContainKeys("d", "e")16 map.shouldNotContainKeys("a", "d")17 map.shouldNotContainKeys("d")18 }19 fun `should contain value`() {20 val map = mapOf("a" to 1, "b" to 2, "c" to 3)21 map.shouldContainValue(1)22 map.shouldContainValue(2)23 map.shouldContainValue(3)24 }25 fun `should not contain value`() {26 val map = mapOf("a" to 1, "b" to 2, "c" to 3)27 map.shouldNotContainValue(4)28 map.shouldNotContainValue(5)29 map.shouldNotContainValue(6)30 }31 fun `should have size`() {32 val map = mapOf("a" to 1, "

Full Screen

Full Screen

Map.shouldNotContain

Using AI Code Generation

copy

Full Screen

1 map.shouldNotContain(3 to "three")2 map.shouldNotContain(3 to "three", 4 to "four")3 map.shouldNotContain(3 to "three", 4 to "four", 5 to "five")4 map.shouldNotContain(3 to "three", 4 to "four", 5 to "five", 6 to "six")5 map.shouldNotContain(3 to "three", 4 to "four", 5 to "five", 6 to "six", 7 to "seven")6 map.shouldNotContain(3 to "three", 4 to "four", 5 to "five", 6 to "six", 7 to "seven", 8 to "eight")7 map.shouldNotContain(3 to "three", 4 to "four", 5 to "five", 6 to "six", 7 to "seven", 8 to "eight", 9 to "nine")8 map.shouldNotContain(3 to "three", 4 to "four", 5 to "five", 6 to "six", 7 to "seven", 8 to "eight", 9 to "nine", 10 to "ten")9 map.shouldNotContain(3 to "three", 4 to "four", 5 to "five", 6 to "six", 7 to "seven", 8 to "eight", 9 to "nine", 10 to "ten", 11 to "eleven")10 map.shouldNotContain(3 to "three", 4 to "four", 5 to "five", 6 to "six", 7 to "seven", 8 to "eight", 9 to "nine", 10 to "ten", 11 to "eleven", 12 to "twelve")11 map.shouldNotContain(3 to "three", 4 to "four", 5 to "five", 6 to "six", 7 to "seven", 8 to "eight", 9 to "nine", 10 to "ten", 11 to "eleven", 12 to "twelve", 13 to "thirteen")12 map.shouldNotContain(3 to "three", 4 to "four", 5 to "five", 6 to "six", 7 to "seven", 8 to "eight",

Full Screen

Full Screen

Map.shouldNotContain

Using AI Code Generation

copy

Full Screen

1 fun `shouldNotContain`() {2 val map = mapOf("a" to 1, "b" to 2, "c" to 3)3 }4 fun `shouldNotContainAll`() {5 val map = mapOf("a" to 1, "b" to 2, "c" to 3)6 map shouldNotContainAll listOf("d")7 map shouldNotContainAll listOf("a", "d")8 map shouldNotContainAll listOf("a", "b", "d")9 map shouldNotContainAll listOf("a", "b", "c", "d")10 }11 fun `shouldNotContainKeys`() {12 val map = mapOf("a" to 1, "b" to 2, "c" to 3)13 map shouldNotContainKeys listOf("d")14 map shouldNotContainKeys listOf("a", "d")15 map shouldNotContainKeys listOf("a", "b", "d")16 map shouldNotContainKeys listOf("a", "b", "c", "d")17 }18 fun `shouldNotContainValue`() {19 val map = mapOf("a" to 1, "b" to 2, "c" to 3)20 }21 fun `shouldNotContainValues`() {22 val map = mapOf("a" to 1, "b" to 2, "c" to 3)23 map shouldNotContainValues listOf(4)24 map shouldNotContainValues listOf(

Full Screen

Full Screen

Map.shouldNotContain

Using AI Code Generation

copy

Full Screen

1 val map = mapOf("a" to 1, "b" to 2, "c" to 3)2 map.shouldNotContain("d")3 }4 fun shouldContainAllTest() {5 val map = mapOf("a" to 1, "b" to 2, "c" to 3)6 map.shouldContainAll("a", "b")7 }8 fun shouldNotContainAllTest() {9 val map = mapOf("a" to 1, "b" to 2, "c" to 3)10 map.shouldNotContainAll("a", "d")11 }12 fun shouldContainKeyTest() {13 val map = mapOf("a" to 1, "b" to 2, "c" to 3)14 map.shouldContainKey("a")15 }16 fun shouldNotContainKeyTest() {17 val map = mapOf("a" to 1, "b" to 2, "c" to 3)18 map.shouldNotContainKey("d")19 }20 fun shouldContainKeysTest() {21 val map = mapOf("a" to 1, "b" to 2, "c" to 3)22 map.shouldContainKeys("a", "b")23 }24 fun shouldNotContainKeysTest() {

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