How to use Iterable.shouldContain method of io.kotest.matchers.collections.contain class

Best Kotest code snippet using io.kotest.matchers.collections.contain.Iterable.shouldContain

MongoDropRepositoryTest.kt

Source:MongoDropRepositoryTest.kt Github

copy

Full Screen

1package com.dunamu.dive.infra.mongo.repository.drop2import com.dunamu.dive.infra.mongo.testsupport.DomainFixture.Factory.aMongoDrop3import com.dunamu.dive.infra.mongo.testsupport.MongoTest4import com.dunamu.dive.support.extension.minusHours5import com.dunamu.dive.support.extension.minusMinutes6import com.dunamu.dive.support.extension.plusHours7import com.dunamu.dive.support.page.CursorUtil8import io.kotest.core.listeners.TestListener9import io.kotest.core.spec.style.StringSpec10import io.kotest.core.test.TestCase11import io.kotest.matchers.collections.shouldContain12import io.kotest.matchers.shouldBe13import io.kotest.spring.SpringListener14import org.springframework.beans.factory.annotation.Autowired15import java.time.Instant16@MongoTest17class MongoDropRepositoryTest : StringSpec({18}) {19 override fun listeners(): List<TestListener> = listOf(SpringListener)20 @Autowired21 private lateinit var mongoDropRepository: MongoDropRepository22 override fun beforeEach(testCase: TestCase) {23 super.beforeEach(testCase)24 mongoDropRepository.deleteAll().block()25 }26 init {27 "UPCOMING 상태의 drop을 불러와야한다" {28 mongoDropRepository.saveAll(29 listOf(30 aMongoDrop().apply {31 packId = 132 packType = MongoDropPackType.AUCTION33 auctionStatus = MongoDropAuctionStatus.READY34 displayStartAt = Instant.now().minusHours(1)35 displayEndAt = Instant.now().plusHours(1)36 },37 aMongoDrop().apply {38 packId = 239 packType = MongoDropPackType.AUCTION40 auctionStatus = MongoDropAuctionStatus.OPENED41 displayStartAt = Instant.now().minusHours(1)42 displayEndAt = Instant.now().plusHours(1)43 },44 aMongoDrop().apply {45 packId = 346 packType = MongoDropPackType.RANDOM47 randomStatus = MongoDropRandomStatus.READY48 displayStartAt = Instant.now().minusHours(1)49 displayEndAt = Instant.now().plusHours(1)50 },51 aMongoDrop().apply {52 packId = 453 packType = MongoDropPackType.FCFS54 fcfsStatus = MongoDropFcfsStatus.READY55 displayStartAt = Instant.now().minusHours(1)56 displayEndAt = Instant.now().plusHours(1)57 },58 aMongoDrop().apply {59 packId = 560 packType = MongoDropPackType.AUCTION61 auctionStatus = MongoDropAuctionStatus.CLOSED62 displayStartAt = Instant.now().minusHours(1)63 displayEndAt = Instant.now().plusHours(1)64 },65 )66 ).toIterable().toList()67 val drops = mongoDropRepository.findDropsByCondition(68 MongoDropQueryCondition(69 pageSize = 4,70 prev = null,71 next = null,72 sortType = MongoDropQueryConditionSortType.SALE_START_AT_ASC,73 artistId = null,74 dropStatus = MongoDropQueryConditionDropStatus.UPCOMING75 )76 ).toIterable().toList()77 drops.size shouldBe 378 }79 "ENDED 상태의 drop을 불러와야한다" {80 mongoDropRepository.saveAll(81 listOf(82 aMongoDrop().apply {83 packId = 184 packType = MongoDropPackType.AUCTION85 auctionStatus = MongoDropAuctionStatus.READY86 displayStartAt = Instant.now().minusHours(1)87 displayEndAt = Instant.now().plusHours(1)88 },89 aMongoDrop().apply {90 packId = 291 packType = MongoDropPackType.AUCTION92 auctionStatus = MongoDropAuctionStatus.DONE93 displayStartAt = Instant.now().minusHours(1)94 displayEndAt = Instant.now().plusHours(1)95 },96 aMongoDrop().apply {97 packId = 398 packType = MongoDropPackType.RANDOM99 randomStatus = MongoDropRandomStatus.READY100 displayStartAt = Instant.now().minusHours(1)101 displayEndAt = Instant.now().plusHours(1)102 },103 aMongoDrop().apply {104 packId = 4105 packType = MongoDropPackType.FCFS106 fcfsStatus = MongoDropFcfsStatus.READY107 displayStartAt = Instant.now().minusHours(1)108 displayEndAt = Instant.now().plusHours(1)109 },110 aMongoDrop().apply {111 packId = 5112 packType = MongoDropPackType.AUCTION113 auctionStatus = MongoDropAuctionStatus.CLOSED114 displayStartAt = Instant.now().minusHours(1)115 displayEndAt = Instant.now().plusHours(1)116 },117 )118 ).toIterable().toList()119 val drops = mongoDropRepository.findDropsByCondition(120 MongoDropQueryCondition(121 pageSize = 4,122 prev = null,123 next = null,124 sortType = MongoDropQueryConditionSortType.SALE_START_AT_ASC,125 artistId = null,126 dropStatus = MongoDropQueryConditionDropStatus.ENDED127 )128 ).toIterable().toList()129 println(drops.map { it.packId })130 drops.size shouldBe 2131 }132 "saleStartAt, packId로 정렬되어야한다" {133 val now = Instant.now()134 mongoDropRepository.saveAll(135 listOf(136 aMongoDrop().apply {137 packId = 1138 packType = MongoDropPackType.AUCTION139 auctionStatus = MongoDropAuctionStatus.READY140 displayStartAt = now.minusHours(1)141 displayEndAt = now.plusHours(1)142 saleStartAt = now.minusMinutes(60)143 },144 aMongoDrop().apply {145 packId = 5146 packType = MongoDropPackType.AUCTION147 auctionStatus = MongoDropAuctionStatus.READY148 displayStartAt = now.minusHours(1)149 displayEndAt = now.plusHours(1)150 saleStartAt = now.minusMinutes(15)151 },152 aMongoDrop().apply {153 packId = 3154 packType = MongoDropPackType.RANDOM155 randomStatus = MongoDropRandomStatus.READY156 displayStartAt = now.minusHours(1)157 displayEndAt = now.plusHours(1)158 saleStartAt = now.minusMinutes(40)159 },160 aMongoDrop().apply {161 packId = 4162 packType = MongoDropPackType.FCFS163 fcfsStatus = MongoDropFcfsStatus.READY164 displayStartAt = now.minusHours(1)165 displayEndAt = now.plusHours(1)166 saleStartAt = now.minusMinutes(20)167 },168 aMongoDrop().apply {169 packId = 2170 packType = MongoDropPackType.AUCTION171 auctionStatus = MongoDropAuctionStatus.READY172 displayStartAt = now.minusHours(1)173 displayEndAt = now.plusHours(1)174 saleStartAt = now.minusMinutes(15)175 },176 )177 ).toIterable().toList()178 val drops = mongoDropRepository.findDropsByCondition(179 MongoDropQueryCondition(180 pageSize = 5,181 prev = null,182 next = null,183 sortType = MongoDropQueryConditionSortType.SALE_START_AT_ASC,184 artistId = null,185 dropStatus = MongoDropQueryConditionDropStatus.UPCOMING186 )187 ).toIterable().toList()188 drops.size shouldBe 5189 drops[0].packId shouldBe 1190 drops[1].packId shouldBe 3191 drops[2].packId shouldBe 4192 drops[3].packId shouldBe 2193 drops[4].packId shouldBe 5194 }195 "next cursor가 작동해야한다" {196 val now = Instant.now()197 mongoDropRepository.saveAll(198 listOf(199 aMongoDrop().apply {200 packId = 1201 packType = MongoDropPackType.AUCTION202 auctionStatus = MongoDropAuctionStatus.READY203 displayStartAt = now.minusHours(1)204 displayEndAt = now.plusHours(1)205 saleStartAt = now.minusMinutes(5)206 },207 aMongoDrop().apply {208 packId = 2209 packType = MongoDropPackType.AUCTION210 auctionStatus = MongoDropAuctionStatus.READY211 displayStartAt = now.minusHours(1)212 displayEndAt = now.plusHours(1)213 saleStartAt = now.minusMinutes(15)214 },215 aMongoDrop().apply {216 packId = 3217 packType = MongoDropPackType.RANDOM218 randomStatus = MongoDropRandomStatus.READY219 displayStartAt = now.minusHours(1)220 displayEndAt = now.plusHours(1)221 saleStartAt = now.minusMinutes(10)222 },223 aMongoDrop().apply {224 packId = 4225 packType = MongoDropPackType.FCFS226 fcfsStatus = MongoDropFcfsStatus.READY227 displayStartAt = now.minusHours(1)228 displayEndAt = now.plusHours(1)229 saleStartAt = now.minusMinutes(10)230 },231 aMongoDrop().apply {232 packId = 5233 packType = MongoDropPackType.AUCTION234 auctionStatus = MongoDropAuctionStatus.READY235 displayStartAt = now.minusHours(1)236 displayEndAt = now.plusHours(1)237 saleStartAt = now.minusMinutes(15)238 },239 )240 ).toIterable().toList()241 val drops = mongoDropRepository.findDropsByCondition(242 MongoDropQueryCondition(243 pageSize = 3,244 prev = null,245 next = CursorUtil.toHash(2, now.minusMinutes(15).toEpochMilli()),246 sortType = MongoDropQueryConditionSortType.SALE_START_AT_ASC,247 artistId = null,248 dropStatus = MongoDropQueryConditionDropStatus.UPCOMING249 )250 ).toIterable().toList()251 drops.size shouldBe 4252 drops[0].packId shouldBe 5253 drops[1].packId shouldBe 3254 drops[2].packId shouldBe 4255 drops[3].packId shouldBe 1256 }257 "prev cursor가 작동해야한다" {258 val now = Instant.now()259 mongoDropRepository.saveAll(260 listOf(261 aMongoDrop().apply {262 packId = 1263 packType = MongoDropPackType.AUCTION264 auctionStatus = MongoDropAuctionStatus.READY265 displayStartAt = now.minusHours(1)266 displayEndAt = now.plusHours(1)267 saleStartAt = now.minusMinutes(5)268 },269 aMongoDrop().apply {270 packId = 2271 packType = MongoDropPackType.AUCTION272 auctionStatus = MongoDropAuctionStatus.READY273 displayStartAt = now.minusHours(1)274 displayEndAt = now.plusHours(1)275 saleStartAt = now.minusMinutes(15)276 },277 aMongoDrop().apply {278 packId = 3279 packType = MongoDropPackType.RANDOM280 randomStatus = MongoDropRandomStatus.READY281 displayStartAt = now.minusHours(1)282 displayEndAt = now.plusHours(1)283 saleStartAt = now.minusMinutes(10)284 },285 aMongoDrop().apply {286 packId = 4287 packType = MongoDropPackType.FCFS288 fcfsStatus = MongoDropFcfsStatus.READY289 displayStartAt = now.minusHours(1)290 displayEndAt = now.plusHours(1)291 saleStartAt = now.minusMinutes(10)292 },293 aMongoDrop().apply {294 packId = 5295 packType = MongoDropPackType.AUCTION296 auctionStatus = MongoDropAuctionStatus.READY297 displayStartAt = now.minusHours(1)298 displayEndAt = now.plusHours(1)299 saleStartAt = now.minusMinutes(15)300 },301 )302 ).toIterable().toList()303 val drops = mongoDropRepository.findDropsByCondition(304 MongoDropQueryCondition(305 pageSize = 3,306 prev = CursorUtil.toHash(4, now.minusMinutes(10).toEpochMilli()),307 next = null,308 sortType = MongoDropQueryConditionSortType.SALE_START_AT_ASC,309 artistId = null,310 dropStatus = MongoDropQueryConditionDropStatus.UPCOMING311 )312 ).toIterable().toList()313 drops.size shouldBe 3314 drops[0].packId shouldBe 2315 drops[1].packId shouldBe 5316 drops[2].packId shouldBe 3317 }318 "artistId로 필터하여 조회되어야한다." {319 mongoDropRepository.saveAll(320 listOf(321 aMongoDrop().apply {322 packId = 1323 artistIds = listOf(1)324 packType = MongoDropPackType.AUCTION325 auctionStatus = MongoDropAuctionStatus.READY326 displayStartAt = Instant.now().minusHours(1)327 displayEndAt = Instant.now().plusHours(1)328 },329 aMongoDrop().apply {330 packId = 2331 artistIds = listOf(1, 2)332 packType = MongoDropPackType.AUCTION333 auctionStatus = MongoDropAuctionStatus.READY334 displayStartAt = Instant.now().minusHours(1)335 displayEndAt = Instant.now().plusHours(1)336 },337 aMongoDrop().apply {338 packId = 3339 artistIds = listOf(2, 3)340 packType = MongoDropPackType.RANDOM341 randomStatus = MongoDropRandomStatus.READY342 displayStartAt = Instant.now().minusHours(1)343 displayEndAt = Instant.now().plusHours(1)344 },345 aMongoDrop().apply {346 packId = 4347 artistIds = listOf(1, 2, 3, 4)348 packType = MongoDropPackType.FCFS349 fcfsStatus = MongoDropFcfsStatus.READY350 displayStartAt = Instant.now().minusHours(1)351 displayEndAt = Instant.now().plusHours(1)352 },353 aMongoDrop().apply {354 packId = 5355 artistIds = listOf(3, 4)356 packType = MongoDropPackType.AUCTION357 auctionStatus = MongoDropAuctionStatus.READY358 displayStartAt = Instant.now().minusHours(1)359 displayEndAt = Instant.now().plusHours(1)360 },361 )362 ).toIterable().toList()363 val drops = mongoDropRepository.findDropsByCondition(364 MongoDropQueryCondition(365 pageSize = 4,366 prev = null,367 next = null,368 sortType = MongoDropQueryConditionSortType.SALE_START_AT_ASC,369 artistId = 1,370 dropStatus = MongoDropQueryConditionDropStatus.UPCOMING371 )372 ).toIterable().toList()373 drops.size shouldBe 3374 drops.map { it.packId } shouldContain 1375 drops.map { it.packId } shouldContain 2376 drops.map { it.packId } shouldContain 4377 }378 }379}...

Full Screen

Full Screen

ParticipantServiceTest.kt

Source:ParticipantServiceTest.kt Github

copy

Full Screen

1/**2 * This file is part of the CSzG backend.3 *4 * The CSzG backend is free software: you can redistribute it and/or modify5 * it under the terms of the GNU General Public License as published by6 * the Free Software Foundation, either version 3 of the License, or7 * (at your option) any later version.8 *9 * The CSzG backend is distributed in the hope that it will be useful,10 * but WITHOUT ANY WARRANTY; without even the implied warranty of11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12 * GNU General Public License for more details.13 *14 * You should have received a copy of the GNU General Public License15 * along with Foobar. If not, see https://www.gnu.org/licenses/.16 */17package uk.ac.nott.cs.das.cszgbackend.service18import io.kotest.assertions.arrow.either.shouldBeLeft19import io.kotest.assertions.arrow.either.shouldBeRight20import io.kotest.core.spec.style.DescribeSpec21import io.kotest.matchers.collections.shouldContain22import io.kotest.matchers.nulls.shouldBeNull23import io.kotest.matchers.nulls.shouldNotBeNull24import io.kotest.matchers.shouldBe25import io.mockk.every26import io.mockk.mockk27import org.springframework.http.HttpStatus28import uk.ac.nott.cs.das.cszgbackend.model.participant.Participant29import uk.ac.nott.cs.das.cszgbackend.model.participant.ParticipantAti30import uk.ac.nott.cs.das.cszgbackend.model.participant.ParticipantAtiRepository31import uk.ac.nott.cs.das.cszgbackend.model.participant.ParticipantBioDto32import uk.ac.nott.cs.das.cszgbackend.model.participant.ParticipantRepository33import uk.ac.nott.cs.das.cszgbackend.model.participant.ParticipantTlx34import uk.ac.nott.cs.das.cszgbackend.model.participant.ParticipantTlxRepository35import uk.ac.nott.cs.das.cszgbackend.model.participant.ParticipantTrust36import uk.ac.nott.cs.das.cszgbackend.model.participant.ParticipantTrustRepository37import java.io.IOException38import java.util.*39class ParticipantServiceTest : DescribeSpec({40 describe("ParticipantService") {41 lateinit var participantRepo: ParticipantRepository42 lateinit var atiRepo: ParticipantAtiRepository43 lateinit var tlxRepo: ParticipantTlxRepository44 lateinit var trustRepo: ParticipantTrustRepository45 lateinit var service: ParticipantService46 beforeEach {47 participantRepo = mockk()48 atiRepo = mockk()49 tlxRepo = mockk()50 trustRepo = mockk()51 service = ParticipantServiceImpl(participantRepo, atiRepo, tlxRepo, trustRepo)52 }53 describe("#getAllParticipants") {54 it("should return an iterable of Participants") {55 every { participantRepo.findAll() } returns listOf(Participant(username = "abcd"))56 val participants = service.getAllParticipants()57 participants.shouldBeRight {58 it.count().shouldBe(1)59 }60 }61 it("should return an exception if the repo fails") {62 every { participantRepo.findAll() } throws IOException()63 val participants = service.getAllParticipants()64 participants.shouldBeLeft {65 it.status.shouldBe(HttpStatus.INTERNAL_SERVER_ERROR)66 }67 }68 }69 describe("#getParticipant") {70 it("should return the participant if the id exists") {71 val id = UUID.randomUUID()72 val p = Participant(id, "abcd")73 every { participantRepo.findById(id) } returns Optional.of(p)74 val result = service.getParticipant(id)75 result.shouldBeRight {76 it.id.shouldBe(id)77 }78 }79 it("should return an exception if the id doesn't exist") {80 every { participantRepo.findById(any()) } returns Optional.empty()81 val result = service.getParticipant(UUID.randomUUID())82 result.shouldBeLeft {83 it.status.shouldBe(HttpStatus.NOT_FOUND)84 }85 }86 it("should return an exception if the repo fails") {87 every { participantRepo.findById(any()) } throws IOException()88 val result = service.getParticipant(UUID.randomUUID())89 result.shouldBeLeft {90 it.status.shouldBe(HttpStatus.INTERNAL_SERVER_ERROR)91 }92 }93 }94 describe("#createParticipant") {95 it("should return the participant if creation succeeds") {96 val p = Participant(username = "abcd")97 every { participantRepo.save(p) } returns p98 val result = service.createParticipant(p)99 result.shouldBeRight {100 it.shouldBe(p)101 }102 }103 it("should return an exception if the repo fails") {104 every { participantRepo.save(any()) } throws IOException()105 val p = Participant(username = "abcd")106 val result = service.createParticipant(p)107 result.shouldBeLeft {108 it.status.shouldBe(HttpStatus.INTERNAL_SERVER_ERROR)109 }110 }111 }112 describe("#setParticipantAti") {113 val id = UUID.randomUUID()114 lateinit var participant: Participant115 lateinit var ati: ParticipantAti116 beforeEach {117 participant = Participant(id, "abcd")118 ati = ParticipantAti(119 response1 = 1,120 response2 = 1,121 response3 = 1,122 response4 = 1,123 response5 = 1,124 response6 = 1,125 response7 = 1,126 response8 = 1,127 response9 = 1128 )129 }130 it("should return the participant with the ATI set if all succeeds") {131 every { participantRepo.findById(id) } returns Optional.of(participant)132 every { participantRepo.save(any()) } answers { firstArg() }133 every { atiRepo.save(any()) } answers { firstArg() }134 val result = service.setParticipantAti(id, ati)135 result.shouldBeRight {136 it.ati.shouldNotBeNull().participant.shouldBe(participant)137 }138 }139 it("should return an exception if the participant ID doesn't exist") {140 every { participantRepo.findById(any()) } returns Optional.empty()141 val result = service.setParticipantAti(id, ati)142 result.shouldBeLeft {143 it.status.shouldBe(HttpStatus.NOT_FOUND)144 }145 }146 it("should return an exception if saving the ATI fails") {147 every { participantRepo.findById(id) } returns Optional.of(participant)148 every { atiRepo.save(any()) } throws IOException()149 val result = service.setParticipantAti(id, ati)150 result.shouldBeLeft {151 it.status.shouldBe(HttpStatus.INTERNAL_SERVER_ERROR)152 }153 }154 it("should return an exception if saving the participant fails") {155 every { participantRepo.findById(id) } returns Optional.of(participant)156 every { atiRepo.save(any()) } answers { firstArg() }157 every { participantRepo.save(any()) } throws IOException()158 val result = service.setParticipantAti(id, ati)159 result.shouldBeLeft {160 it.status.shouldBe(HttpStatus.INTERNAL_SERVER_ERROR)161 }162 }163 }164 describe("#setParticipantBio") {165 val id = UUID.randomUUID()166 lateinit var participant: Participant167 lateinit var bio: ParticipantBioDto168 beforeEach {169 participant = Participant(id, "abcd")170 bio = ParticipantBioDto(1, 'f', null)171 }172 it("should return the participant with the bio set if the ID exists") {173 every { participantRepo.findById(id) } returns Optional.of(participant)174 every { participantRepo.save(any()) } answers { firstArg() }175 val result = service.setParticipantBio(id, bio)176 result.shouldBeRight {177 it.id.shouldBe(id)178 it.age.shouldBe(bio.age)179 it.gender.shouldBe(bio.gender)180 it.genderDescription.shouldBeNull()181 }182 }183 it("should return an exception if the ID doesn't exist") {184 every { participantRepo.findById(id) } returns Optional.empty()185 val result = service.setParticipantBio(id, bio)186 result.shouldBeLeft {187 it.status.shouldBe(HttpStatus.NOT_FOUND)188 }189 }190 it("should return an exception if the repo fails when finding the participant") {191 every { participantRepo.findById(any()) } throws IOException()192 val result = service.setParticipantBio(id, bio)193 result.shouldBeLeft {194 it.status.shouldBe(HttpStatus.INTERNAL_SERVER_ERROR)195 }196 }197 it("should return an exception if the repo fails when saving the participant") {198 every { participantRepo.findById(id) } returns Optional.of(participant)199 every { participantRepo.save(any()) } throws IOException()200 val result = service.setParticipantBio(id, bio)201 result.shouldBeLeft {202 it.status.shouldBe(HttpStatus.INTERNAL_SERVER_ERROR)203 }204 }205 }206 describe("#setParticipantTlx") {207 val id = UUID.randomUUID()208 lateinit var participant: Participant209 lateinit var tlx: ParticipantTlx210 beforeEach {211 participant = Participant(id, "abcd")212 tlx = ParticipantTlx(213 taskNo = 1,214 mentalDemand = 1,215 physicalDemand = 1,216 temporalDemand = 1,217 effort = 1,218 performance = 1,219 frustration = 1220 )221 }222 it("should return the participant with TLX set if the ID exists") {223 every { participantRepo.findById(id) } returns Optional.of(participant)224 every { tlxRepo.save(any()) } answers { firstArg() }225 every { participantRepo.save(any()) } answers { firstArg() }226 val result = service.setParticipantTlx(id, tlx)227 result.shouldBeRight {228 it.tlx.shouldContain(tlx)229 }230 }231 it("should return an exception if the ID doesn't exist") {232 every { participantRepo.findById(any()) } returns Optional.empty()233 val result = service.setParticipantTlx(id, tlx)234 result.shouldBeLeft {235 it.status.shouldBe(HttpStatus.NOT_FOUND)236 }237 }238 it("should return an exception if getting the participant fails") {239 every { participantRepo.findById(any()) } throws IOException()240 val result = service.setParticipantTlx(id, tlx)241 result.shouldBeLeft {242 it.status.shouldBe(HttpStatus.INTERNAL_SERVER_ERROR)243 }244 }245 it("should return an exception if saving the TLX fails") {246 every { participantRepo.findById(id) } returns Optional.of(participant)247 every { tlxRepo.save(any()) } throws IOException()248 val result = service.setParticipantTlx(id, tlx)249 result.shouldBeLeft {250 it.status.shouldBe(HttpStatus.INTERNAL_SERVER_ERROR)251 }252 }253 it("should return an exception if saving the participant fails") {254 every { participantRepo.findById(id) } returns Optional.of(participant)255 every { tlxRepo.save(any()) } answers { firstArg() }256 every { participantRepo.save(any()) } throws IOException()257 val result = service.setParticipantTlx(id, tlx)258 result.shouldBeLeft {259 it.status.shouldBe(HttpStatus.INTERNAL_SERVER_ERROR)260 }261 }262 }263 describe("#setParticipantTrust") {264 val id = UUID.randomUUID()265 lateinit var participant: Participant266 lateinit var trust: ParticipantTrust267 beforeEach {268 participant = Participant(id, "abcd")269 trust = ParticipantTrust(270 taskNo = 1,271 response1 = 1,272 response2 = 1,273 response3 = 1,274 response4 = 1,275 response5 = 1,276 response6 = 1,277 response7 = 1,278 response8 = 1,279 response9 = 1280 )281 }282 it("should return the participant with trust set if the ID exists") {283 every { participantRepo.findById(id) } returns Optional.of(participant)284 every { trustRepo.save(any()) } answers { firstArg() }285 every { participantRepo.save(any()) } answers { firstArg() }286 val result = service.setParticipantTrust(id, trust)287 result.shouldBeRight {288 it.trust.shouldContain(trust)289 }290 }291 it("should return an exception if the ID doesn't exist") {292 every { participantRepo.findById(any()) } returns Optional.empty()293 val result = service.setParticipantTrust(id, trust)294 result.shouldBeLeft {295 it.status.shouldBe(HttpStatus.NOT_FOUND)296 }297 }298 it("should return an exception if getting the participant fails") {299 every { participantRepo.findById(any()) } throws IOException()300 val result = service.setParticipantTrust(id, trust)301 result.shouldBeLeft {302 it.status.shouldBe(HttpStatus.INTERNAL_SERVER_ERROR)303 }304 }305 it("should return an exception if saving the TLX fails") {306 every { participantRepo.findById(id) } returns Optional.of(participant)307 every { trustRepo.save(any()) } throws IOException()308 val result = service.setParticipantTrust(id, trust)309 result.shouldBeLeft {310 it.status.shouldBe(HttpStatus.INTERNAL_SERVER_ERROR)311 }312 }313 it("should return an exception if saving the participant fails") {314 every { participantRepo.findById(id) } returns Optional.of(participant)315 every { trustRepo.save(any()) } answers { firstArg() }316 every { participantRepo.save(any()) } throws IOException()317 val result = service.setParticipantTrust(id, trust)318 result.shouldBeLeft {319 it.status.shouldBe(HttpStatus.INTERNAL_SERVER_ERROR)320 }321 }322 }323 }324})...

Full Screen

Full Screen

ModuleImporterTests.kt

Source:ModuleImporterTests.kt Github

copy

Full Screen

1package prog8tests2import com.github.michaelbull.result.getErrorOrElse3import com.github.michaelbull.result.getOrElse4import io.kotest.assertions.fail5import io.kotest.assertions.throwables.shouldThrow6import io.kotest.assertions.withClue7import io.kotest.core.spec.style.FunSpec8import io.kotest.matchers.collections.shouldBeIn9import io.kotest.matchers.shouldBe10import io.kotest.matchers.string.shouldContain11import prog8.ast.Program12import prog8.code.core.IErrorReporter13import prog8.code.core.SourceCode14import prog8.code.core.internedStringsModuleName15import prog8.compiler.ModuleImporter16import prog8.parser.ParseError17import prog8tests.helpers.*18import kotlin.io.path.*19class TestModuleImporter: FunSpec({20 val count = listOf("1st", "2nd", "3rd", "4th", "5th")21 lateinit var program: Program22 beforeTest {23 program = Program("foo", DummyFunctions, DummyMemsizer, DummyStringEncoder)24 }25 fun makeImporter(errors: IErrorReporter? = null, searchIn: Iterable<String>) =26 ModuleImporter(program, "blah", errors ?: ErrorReporterForTests(false), searchIn.toList())27 fun makeImporter(errors: IErrorReporter?, vararg searchIn: String): ModuleImporter {28 return makeImporter(errors, searchIn.asList())29 }30 context("ImportModule") {31 context("WithInvalidPath") {32 test("testNonexisting") {33 val dirRel = Helpers.assumeDirectory(".", Helpers.workingDir.relativize(Helpers.fixturesDir))34 val importer = makeImporter(null, dirRel.invariantSeparatorsPathString)35 val srcPathRel = Helpers.assumeNotExists(dirRel, "i_do_not_exist")36 val srcPathAbs = srcPathRel.absolute()37 val error1 = importer.importModule(srcPathRel).getErrorOrElse { fail("should have import error") }38 withClue(".file should be normalized") {39 "${error1.file}" shouldBe "${error1.file.normalize()}"40 }41 withClue(".file should point to specified path") {42 error1.file.absolutePath shouldBe "${srcPathAbs.normalize()}"43 }44 program.modules.size shouldBe 145 val error2 = importer.importModule(srcPathAbs).getErrorOrElse { fail("should have import error") }46 withClue(".file should be normalized") {47 "${error2.file}" shouldBe "${error2.file.normalize()}"48 }49 withClue(".file should point to specified path") {50 error2.file.absolutePath shouldBe "${srcPathAbs.normalize()}"51 }52 program.modules.size shouldBe 153 }54 test("testDirectory") {55 val srcPathRel = Helpers.assumeDirectory(Helpers.workingDir.relativize(Helpers.fixturesDir))56 val srcPathAbs = srcPathRel.absolute()57 val searchIn = Path(".", "$srcPathRel").invariantSeparatorsPathString58 val importer = makeImporter(null, searchIn)59 shouldThrow<FileSystemException> { importer.importModule(srcPathRel) }60 .let {61 withClue(".file should be normalized") {62 "${it.file}" shouldBe "${it.file.normalize()}"63 }64 withClue(".file should point to specified path") {65 it.file.absolutePath shouldBe "${srcPathAbs.normalize()}"66 }67 }68 program.modules.size shouldBe 169 shouldThrow<FileSystemException> { importer.importModule(srcPathAbs) }70 .let {71 withClue(".file should be normalized") {72 "${it.file}" shouldBe "${it.file.normalize()}"73 }74 withClue(".file should point to specified path") {75 it.file.absolutePath shouldBe "${srcPathAbs.normalize()}"76 }77 }78 program.modules.size shouldBe 179 }80 }81 context("WithValidPath") {82 test("testAbsolute") {83 val searchIn = listOf(84 Path(".").div(Helpers.workingDir.relativize(Helpers.fixturesDir)), // we do want a dot "." in front85 ).map { it.invariantSeparatorsPathString }86 val importer = makeImporter(null, searchIn)87 val fileName = "ast_simple_main.p8"88 val path = Helpers.assumeReadableFile(searchIn[0], fileName)89 val module = importer.importModule(path.absolute()).getOrElse { throw it }90 program.modules.size shouldBe 291 module shouldBeIn program.modules92 module.program shouldBe program93 }94 test("testRelativeToWorkingDir") {95 val searchIn = listOf(96 Path(".").div(Helpers.workingDir.relativize(Helpers.fixturesDir)), // we do want a dot "." in front97 ).map { it.invariantSeparatorsPathString }98 val importer = makeImporter(null, searchIn)99 val fileName = "ast_simple_main.p8"100 val path = Helpers.assumeReadableFile(searchIn[0], fileName)101 withClue("sanity check: path should NOT be absolute") {102 path.isAbsolute shouldBe false103 }104 val module = importer.importModule(path).getOrElse { throw it }105 program.modules.size shouldBe 2106 module shouldBeIn program.modules107 module.program shouldBe program108 }109 test("testRelativeTo1stDirInSearchList") {110 val searchIn = Path(".")111 .div(Helpers.workingDir.relativize(Helpers.fixturesDir))112 .invariantSeparatorsPathString113 val importer = makeImporter(null, searchIn)114 val fileName = "ast_simple_main.p8"115 val path = Path(".", fileName)116 Helpers.assumeReadableFile(searchIn, path)117 val module = importer.importModule(path).getOrElse { throw it }118 program.modules.size shouldBe 2119 module shouldBeIn program.modules120 module.program shouldBe program121 }122 context("WithBadFile") {123 test("testWithSyntaxError") {124 val searchIn = Helpers.assumeDirectory("./", Helpers.workingDir.relativize(Helpers.fixturesDir))125 val importer = makeImporter(null, searchIn.invariantSeparatorsPathString)126 val srcPath = Helpers.assumeReadableFile(Helpers.fixturesDir, "ast_file_with_syntax_error.p8")127 val act = { importer.importModule(srcPath) }128 repeat(2) { n -> withClue(count[n] + " call") {129 shouldThrow<ParseError> { act() }.let {130 it.position.file shouldBe SourceCode.relative(srcPath).toString()131 withClue("line; should be 1-based") { it.position.line shouldBe 2 }132 withClue("startCol; should be 0-based") { it.position.startCol shouldBe 6 }133 withClue("endCol; should be 0-based") { it.position.endCol shouldBe 6 }134 }135 }136 program.modules.size shouldBe 1137 }138 }139 fun doTestImportingFileWithSyntaxError(repetitions: Int) {140 val searchIn = Helpers.assumeDirectory("./", Helpers.workingDir.relativize(Helpers.fixturesDir))141 val importer = makeImporter(null, searchIn.invariantSeparatorsPathString)142 val importing = Helpers.assumeReadableFile(Helpers.fixturesDir, "import_file_with_syntax_error.p8")143 val imported = Helpers.assumeReadableFile(Helpers.fixturesDir, "file_with_syntax_error.p8")144 val act = { importer.importModule(importing) }145 repeat(repetitions) { n -> withClue(count[n] + " call") {146 shouldThrow<ParseError> { act() }.let {147 it.position.file shouldBe SourceCode.relative(imported).toString()148 withClue("line; should be 1-based") { it.position.line shouldBe 2 }149 withClue("startCol; should be 0-based") { it.position.startCol shouldBe 6 }150 withClue("endCol; should be 0-based") { it.position.endCol shouldBe 6 }151 }152 }153 withClue("imported module with error in it should not be present") { program.modules.size shouldBe 1 }154 program.modules[0].name shouldBe internedStringsModuleName155 }156 }157 test("testImportingFileWithSyntaxError_once") {158 doTestImportingFileWithSyntaxError(1)159 }160 test("testImportingFileWithSyntaxError_twice") {161 doTestImportingFileWithSyntaxError(2)162 }163 }164 }165 }166 context("ImportLibraryModule") {167 context("WithInvalidName") {168 test("testWithNonExistingName") {169 val searchIn = Helpers.assumeDirectory("./", Helpers.workingDir.relativize(Helpers.fixturesDir))170 val errors = ErrorReporterForTests(false)171 val importer = makeImporter(errors, searchIn.invariantSeparatorsPathString)172 val filenameNoExt = Helpers.assumeNotExists(Helpers.fixturesDir, "i_do_not_exist").name173 val filenameWithExt = Helpers.assumeNotExists(Helpers.fixturesDir, "i_do_not_exist.p8").name174 repeat(2) { n ->175 val result = importer.importLibraryModule(filenameNoExt)176 withClue(count[n] + " call / NO .p8 extension") { result shouldBe null }177 withClue(count[n] + " call / NO .p8 extension") { errors.noErrors() shouldBe false }178 errors.errors.single() shouldContain "0:0: no module found with name i_do_not_exist"179 errors.report()180 program.modules.size shouldBe 1181 val result2 = importer.importLibraryModule(filenameWithExt)182 withClue(count[n] + " call / with .p8 extension") { result2 shouldBe null }183 withClue(count[n] + " call / with .p8 extension") { importer.errors.noErrors() shouldBe false }184 errors.errors.single() shouldContain "0:0: no module found with name i_do_not_exist.p8"185 errors.report()186 program.modules.size shouldBe 1187 }188 }189 }190 context("WithValidName") {191 context("WithBadFile") {192 test("testWithSyntaxError") {193 val searchIn = Helpers.assumeDirectory("./", Helpers.workingDir.relativize(Helpers.fixturesDir))194 val importer = makeImporter(null, searchIn.invariantSeparatorsPathString)195 val srcPath = Helpers.assumeReadableFile(Helpers.fixturesDir, "ast_file_with_syntax_error.p8")196 repeat(2) { n -> withClue(count[n] + " call") {197 shouldThrow<ParseError>()198 {199 importer.importLibraryModule(srcPath.nameWithoutExtension) }.let {200 it.position.file shouldBe SourceCode.relative(srcPath).toString()201 withClue("line; should be 1-based") { it.position.line shouldBe 2 }202 withClue("startCol; should be 0-based") { it.position.startCol shouldBe 6 }203 withClue("endCol; should be 0-based") { it.position.endCol shouldBe 6 }204 }205 }206 program.modules.size shouldBe 1207 }208 }209 fun doTestImportingFileWithSyntaxError(repetitions: Int) {210 val searchIn = Helpers.assumeDirectory("./", Helpers.workingDir.relativize(Helpers.fixturesDir))211 val importer = makeImporter(null, searchIn.invariantSeparatorsPathString)212 val importing = Helpers.assumeReadableFile(Helpers.fixturesDir, "import_file_with_syntax_error.p8")213 val imported = Helpers.assumeReadableFile(Helpers.fixturesDir, "file_with_syntax_error.p8")214 val act = { importer.importLibraryModule(importing.nameWithoutExtension) }215 repeat(repetitions) { n -> withClue(count[n] + " call") {216 shouldThrow<ParseError> {217 act() }.let {218 it.position.file shouldBe SourceCode.relative(imported).toString()219 withClue("line; should be 1-based") { it.position.line shouldBe 2 }220 withClue("startCol; should be 0-based") { it.position.startCol shouldBe 6 }221 withClue("endCol; should be 0-based") { it.position.endCol shouldBe 6 }222 }223 }224 withClue("imported module with error in it should not be present") { program.modules.size shouldBe 1 }225 program.modules[0].name shouldBe internedStringsModuleName226 importer.errors.report()227 }228 }229 test("testImportingFileWithSyntaxError_once") {230 doTestImportingFileWithSyntaxError(1)231 }232 test("testImportingFileWithSyntaxError_twice") {233 doTestImportingFileWithSyntaxError(2)234 }235 }236 }237 }238})...

Full Screen

Full Screen

contain.kt

Source:contain.kt Github

copy

Full Screen

1package io.kotest.matchers.collections2import io.kotest.assertions.print.print3import io.kotest.equals.Equality4import io.kotest.matchers.Matcher5import io.kotest.matchers.MatcherResult6import io.kotest.matchers.should7import io.kotest.matchers.shouldNot8// Infix9infix fun <T> Iterable<T>.shouldNotContain(t: T): Iterable<T> = shouldNotContain(t, Equality.default())10infix fun <T> Array<T>.shouldNotContain(t: T): Array<T> = shouldNotContain(t, Equality.default())11infix fun <T> Iterable<T>.shouldContain(t: T): Iterable<T> = shouldContain(t, Equality.default())12infix fun <T> Array<T>.shouldContain(t: T): Array<T> = shouldContain(t, Equality.default())13// Should not14fun <T> Iterable<T>.shouldNotContain(t: T, comparator: Equality<T>): Iterable<T> = apply {15 toList() shouldNot contain(t, comparator)16}17fun <T> Array<T>.shouldNotContain(t: T, comparator: Equality<T>): Array<T> = apply {18 asList().shouldNotContain(t, comparator)19}20// Should21fun <T> Iterable<T>.shouldContain(t: T, comparator: Equality<T>): Iterable<T> = apply {22 toList() should contain(t, comparator)23}24fun <T> Array<T>.shouldContain(t: T, comparator: Equality<T>): Array<T> = apply {25 asList().shouldContain(t, comparator)26}27// Matcher28fun <T, C : Collection<T>> contain(t: T, verifier: Equality<T> = Equality.default()) = object : Matcher<C> {29 override fun test(value: C) = MatcherResult(30 value.any { verifier.verify(it, t).areEqual() },31 {32 "Collection should contain element ${t.print().value} based on ${verifier.name()}; " +33 "but the collection is ${value.print().value}"34 },35 { "Collection should not contain element ${t.print().value} based on ${verifier.name()}" }36 )37}...

Full Screen

Full Screen

Iterable.shouldContain

Using AI Code Generation

copy

Full Screen

1val iterable = listOf(1, 2, 3)2val iterable = listOf(1, 2, 3)3iterable shouldContainAll listOf(1, 3)4val iterable = listOf(1, 2, 3)5iterable shouldContainExactly listOf(1, 2, 3)6val iterable = listOf(1, 2, 3)7iterable shouldContainInOrder listOf(1, 2)8val iterable = listOf(1, 2, 3)9iterable shouldContainNone listOf(4, 5)10val iterable = listOf(1, 2, 3)11iterable shouldContainOnly listOf(1, 2, 3)12val iterable = listOf(1, 2, 3)13iterable shouldContainSame listOf(3, 2, 1)14val iterable = listOf(1, 2, 3)15val iterable = listOf(1, 2, 3)16val iterable = listOf(1, 2, 3)17iterable shouldNotContainAll listOf(1, 4)18val iterable = listOf(1, 2, 3)19iterable shouldNotContainExactly listOf(1, 2)

Full Screen

Full Screen

Iterable.shouldContain

Using AI Code Generation

copy

Full Screen

1val iterable = listOf(1, 2, 3)2val iterable = listOf(1, 2, 3)3iterable shouldContainExactly listOf(1, 2, 3)4val iterable = listOf(1, 2, 3)5iterable shouldContainAll listOf(1, 2, 3)6val iterable = listOf(1, 2, 3)7iterable shouldContainNone listOf(4, 5, 6)8val iterable = listOf(1, 2, 3)9iterable shouldContainAnyOf listOf(1, 2, 3)10val iterable = listOf(1, 2, 3)11iterable shouldContainAllOf listOf(1, 2, 3)12val iterable = listOf(1, 2, 3)13iterable shouldContainNoneOf listOf(4, 5, 6)14val iterable = listOf(1, 2, 3)15iterable shouldContainInOrder listOf(1, 2, 3)16val iterable = listOf(1, 2, 3)17iterable shouldContainInOrderOnly listOf(1, 2, 3)18val iterable = listOf(1, 2, 3)19iterable shouldContainSame listOf(1, 2, 3)

Full Screen

Full Screen

Iterable.shouldContain

Using AI Code Generation

copy

Full Screen

1val list = listOf(1, 2, 3)2list shouldContainAll listOf(1, 2)3list shouldNotContainAll listOf(4, 5)4list shouldContainExactly listOf(1, 2, 3)5list shouldContainInOrder listOf(1, 2)6list shouldContainInOrderExactly listOf(1, 2, 3)7list shouldContainSame listOf(1, 2, 3)8list shouldContainSameInOrder listOf(1, 2, 3)9val list = listOf("one", "two", "three")10list shouldContainAll listOf("one", "two")11list shouldNotContainAll listOf("four", "five")12list shouldContainExactly listOf("one", "two", "three")13list shouldContainInOrder listOf("one", "two")14list shouldContainInOrderExactly listOf("one", "two", "three")15list shouldContainSame listOf("one", "two", "three")16list shouldContainSameInOrder listOf("one", "two", "three")17val list = listOf(1, 2, 3)18list shouldHaveAtLeastOneElementThat { it > 1 }19val list = listOf("one", "two", "three")20list shouldHaveAtLeastOneElementThat { it.length > 3 }21val list = listOf(1, 2, 3)22list shouldHaveAtLeastOneElementThat { it > 1 }23val list = listOf("one", "two", "three")24list shouldHaveAtLeastOneElementThat { it.length > 3 }

Full Screen

Full Screen

Iterable.shouldContain

Using AI Code Generation

copy

Full Screen

1fun <T> Iterable<T>.shouldContain(expected: T) = this should contain(expected)2fun <T> Iterable<T>.shouldContainAll(expected: Iterable<T>) = this should containAll(expected)3fun <T> Iterable<T>.shouldContainNone(expected: Iterable<T>) = this should containNone(expected)4fun <T> Iterable<T>.shouldContainExactly(expected: Iterable<T>) = this should containExactly(expected)5fun <T> Iterable<T>.shouldContainInOrder(expected: Iterable<T>) = this should containInOrder(expected)6fun <T> Iterable<T>.shouldContainInOrderOnly(expected: Iterable<T>) = this should containInOrderOnly(expected)7fun <T> Iterable<T>.shouldContainOnlyNulls() = this should containOnlyNulls()8fun <T> Iterable<T>.shouldContainNull() = this should containNull()9fun <T> Iterable<T>.shouldContainNotNull() = this should containNotNull()10fun <T> Iterable<T>.shouldContainExactlyInAnyOrder(expected: Iterable<T>) = this should containExactlyInAnyOrder(expected)11fun <T> Iterable<T>.shouldContainAllInAnyOrder(expected: Iterable<T>) = this should containAllInAnyOrder(expected)12fun <T> Iterable<T>.shouldContainNoneInAnyOrder(expected: Iterable<T>) = this should containNoneInAnyOrder(expected)13fun <T> Iterable<T>.shouldContainDuplicates() = this should containDuplicates()14fun <T> Iterable<T>.shouldContainNoDuplicates() = this should containNoDuplicates()15fun <T> Iterable<T>.shouldContainInstanceOf(expected: KClass<*>) = this should containInstanceOf(expected)16fun <T> Iterable<T>.shouldContainInstanceOf(expected: KClass<*>, occurrence: Int) = this should containInstanceOf(expected, occurrence)17fun <T> Iterable<T>.shouldContainInstanceOf(expected: KClass<*>, occurrence: Int, atLeast: Boolean) = this should containInstanceOf(expected, occurrence, atLeast)18fun <T> Iterable<T>.shouldContainInstanceOf(expected: KClass<*>, occurrence: Int, atMost: Boolean, atLeast: Boolean) = this should containInstanceOf(expected, occurrence, atMost, atLeast)19fun <T> Iterable<T>.shouldContainExactlyInAnyOrderElementsOf(expected: Iterable<T>) = this should containExactlyInAnyOrderElementsOf(expected)

Full Screen

Full Screen

Iterable.shouldContain

Using AI Code Generation

copy

Full Screen

1shouldContainAll(1, 2, 3)2shouldContainAll(1, 2, 3)3shouldNotContainAll(1, 2, 3)4shouldNotContainAll(1, 2, 3)5shouldContainExactly(1, 2, 3)6shouldContainExactly(1, 2, 3)7shouldNotContainExactly(1, 2, 3)8shouldNotContainExactly(1, 2, 3)9shouldContainOnly(1, 2, 3)10shouldContainOnly(1, 2, 3)11shouldContainNone(1, 2, 3)12shouldContainNone(1, 2, 3)13shouldContainAll(listOf(1, 2, 3))14shouldContainAll(listOf(1, 2, 3))15shouldNotContainAll(listOf(1, 2, 3))16shouldNotContainAll(listOf(1, 2, 3))17shouldContainExactly(listOf(1, 2, 3))18shouldContainExactly(listOf(1, 2, 3))19shouldNotContainExactly(listOf(1, 2, 3))20shouldNotContainExactly(listOf(1, 2, 3))21shouldContainOnly(listOf(1, 2, 3))22shouldContainOnly(listOf(1, 2, 3))23shouldContainNone(listOf(1, 2, 3))24shouldContainNone(listOf(1, 2, 3))25shouldContainAll(listOf(1, 2, 3).asIterable())26shouldContainAll(listOf(1, 2, 3).asIterable())27shouldNotContainAll(listOf(1, 2, 3).asIterable())28shouldNotContainAll(listOf(1, 2, 3).asIterable())29shouldContainExactly(listOf(1, 2, 3).asIterable())30shouldContainExactly(listOf(1, 2, 3).asIterable())31shouldNotContainExactly(listOf(1, 2, 3).asIterable())32shouldNotContainExactly(listOf(1, 2, 3).asIterable())33shouldContainOnly(listOf(1, 2, 3).asIterable())34shouldContainOnly(listOf(1, 2, 3).asIterable())35shouldContainNone(list

Full Screen

Full Screen

Iterable.shouldContain

Using AI Code Generation

copy

Full Screen

1val list = listOf(1,2,3)2val list = listOf(1,2,3)3val list = listOf(1,2,3)4val list = listOf(1,2,3)5val list = listOf(1,2,3)6val list = listOf(1,2,3)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful