How to use test method of io.kotest.matchers.optional.matchers class

Best Kotest code snippet using io.kotest.matchers.optional.matchers.test

AttachmentServiceTest.kt

Source:AttachmentServiceTest.kt Github

copy

Full Screen

...13import com.github.njuro.jard.embedData14import com.github.njuro.jard.metadata15import com.github.njuro.jard.multipartFile16import com.ninjasquad.springmockk.MockkBean17import io.kotest.matchers.booleans.shouldBeTrue18import io.kotest.matchers.file.shouldBeAFile19import io.kotest.matchers.file.shouldBeReadable20import io.kotest.matchers.file.shouldExist21import io.kotest.matchers.file.shouldHaveExtension22import io.kotest.matchers.file.shouldHaveNameWithoutExtension23import io.kotest.matchers.file.shouldNotBeEmpty24import io.kotest.matchers.file.shouldNotExist25import io.kotest.matchers.nulls.shouldBeNull26import io.kotest.matchers.nulls.shouldNotBeNull27import io.kotest.matchers.optional.shouldNotBePresent28import io.kotest.matchers.should29import io.kotest.matchers.shouldBe30import io.kotest.matchers.string.shouldNotBeBlank31import io.mockk.Runs32import io.mockk.every33import io.mockk.just34import org.junit.jupiter.api.AfterEach35import org.junit.jupiter.api.BeforeEach36import org.junit.jupiter.api.DisplayName37import org.junit.jupiter.api.Nested38import org.junit.jupiter.api.Test39import org.springframework.beans.factory.annotation.Autowired40import org.springframework.boot.test.context.SpringBootTest41import org.springframework.transaction.annotation.Transactional42import java.io.File43@SpringBootTest44@WithContainerDatabase45@Transactional46internal class AttachmentServiceTest {47 @Autowired48 private lateinit var attachmentService: AttachmentService49 @MockkBean50 private lateinit var remoteStorageService: RemoteStorageService51 @Autowired52 private lateinit var db: TestDataRepository53 @BeforeEach54 @AfterEach55 fun `delete test folder`() {56 val testFolder = attachmentPath(TEST_FOLDER_NAME).toFile()57 if (testFolder.exists()) {58 testFolder.deleteRecursively().shouldBeTrue()59 }60 }61 @Nested62 @DisplayName("save attachment")63 inner class SaveAttachment {64 private fun getRemoteUrl(folder: String, filename: String) = "https://remote-storage.com/$folder-$filename"65 @BeforeEach66 fun setUpMocks() {67 every {68 remoteStorageService.uploadFile(69 ofType(String::class),70 ofType(String::class),71 ofType(File::class)72 )...

Full Screen

Full Screen

BoardFacadeTest.kt

Source:BoardFacadeTest.kt Github

copy

Full Screen

...11import com.github.njuro.jard.thread.ThreadFacade12import com.github.njuro.jard.toForm13import com.github.njuro.jard.utils.validation.PropertyValidationException14import com.ninjasquad.springmockk.MockkBean15import io.kotest.assertions.throwables.shouldThrow16import io.kotest.matchers.collections.shouldHaveSize17import io.kotest.matchers.collections.shouldNotBeEmpty18import io.kotest.matchers.optional.shouldBeEmpty19import io.kotest.matchers.optional.shouldBePresent20import io.kotest.matchers.shouldBe21import io.mockk.every22import org.junit.jupiter.api.Test23import org.springframework.beans.factory.annotation.Autowired24import org.springframework.data.domain.Pageable25import org.springframework.http.MediaType26@WithContainerDatabase27internal class BoardFacadeTest : MapperTest() {28 @MockkBean29 private lateinit var threadFacade: ThreadFacade30 @MockkBean31 private lateinit var postFacade: PostFacade32 @Autowired33 private lateinit var boardFacade: BoardFacade34 @Autowired35 private lateinit var db: TestDataRepository36 @Test37 fun `create board`() {38 val boardForm = board(label = "r").toForm()39 val created = boardFacade.createBoard(boardForm)40 created.label shouldBe boardForm.label41 }42 @Test43 fun `don't create board which already exists`() {44 val boardForm = board(label = "r").toForm()45 boardFacade.createBoard(boardForm)46 shouldThrow<PropertyValidationException> {47 boardFacade.createBoard(boardForm)48 }49 }50 @Test51 fun `get board with threads`() {52 val board = db.insert(board(label = "r"))53 val thread = thread(board)54 val replies = listOf(post(thread).toDto(), post(thread).toDto())55 every {56 threadFacade.getThreadsFromBoard(57 board.toDto(),58 ofType(Pageable::class)59 )60 } returns listOf(thread.toDto())61 every { postFacade.getLatestRepliesForThread(thread.toDto()) } returns replies62 val actual = boardFacade.getBoard(board.toDto(), Pageable.unpaged())63 actual.threads shouldHaveSize 164 actual.threads.first().replies shouldHaveSize 265 }66 @Test67 fun `get board catalog`() {68 val board = board(label = "r")69 every { threadFacade.getAllThreadsFromBoard(board.toDto()) } returns listOf(70 thread(board).toDto(),71 thread(board).toDto()72 )73 boardFacade.getBoardCatalog(board.toDto()).threads shouldHaveSize 274 }75 @Test...

Full Screen

Full Screen

Tests.kt

Source:Tests.kt Github

copy

Full Screen

1package org.danilopianini.gradle.latex.test2import com.uchuhimo.konf.Config3import com.uchuhimo.konf.ConfigSpec4import com.uchuhimo.konf.source.yaml5import io.github.classgraph.ClassGraph6import io.kotest.core.spec.style.StringSpec7import io.kotest.matchers.shouldBe8import io.kotest.matchers.file.shouldExist9import io.kotest.matchers.file.shouldBeAFile10import org.gradle.internal.impldep.org.junit.rules.TemporaryFolder11import org.gradle.testkit.runner.GradleRunner12import org.gradle.testkit.runner.TaskOutcome13import org.slf4j.LoggerFactory14import java.io.File15fun folder(closure: TemporaryFolder.() -> Unit) = TemporaryFolder().apply {16 create()17 closure()18}19fun TemporaryFolder.file(name: String, content: () -> String) = newFile(name).writeText(content().trimIndent())20data class Configuration(val tasks: List<String>, val options: List<String>) {21 companion object : ConfigSpec() {22 val tasks by required<List<String>>()23 val options by optional<List<String>>(emptyList())24 }25}26data class Expectation(val file_exists: List<String>, val success: List<String>, val failure: List<String>) {27 companion object : ConfigSpec() {28 val file_exists by optional<List<String>>(emptyList())29 val success by optional<List<String>>(emptyList())30 val failure by optional<List<String>>(emptyList())31 }32}33data class Test(val description: String, val configuration: Configuration, val expectation: Expectation) {34 companion object : ConfigSpec() {35 val description by required<String>()36 val configuration by required<Configuration>()37 val expectation by required<Expectation>()38 }39}40object Root : ConfigSpec("") {41 val tests by required<List<Test>>()42}43class LatexTests : StringSpec(44 {45 val pluginClasspathResource = ClassLoader.getSystemClassLoader()46 .getResource("plugin-classpath.txt")47 ?: throw IllegalStateException("Did not find plugin classpath resource, run \"testClasses\" build task.")48 val classpath = pluginClasspathResource.openStream().bufferedReader().use { reader ->49 reader.readLines().map { File(it) }50 }51 val scan = ClassGraph()52 .enableAllInfo()53 .acceptPackages("org.danilopianini.gradle.latex.test")54 .scan()55 scan.getResourcesWithLeafName("test.yaml")56 .flatMap {57 log.debug("Found test list in $it")58 val yamlFile = File(it.classpathElementFile.absolutePath + "/" + it.path)59 val testConfiguration = Config {60 addSpec(Root)61 addSpec(Test)62 addSpec(Expectation)63 addSpec(Configuration)64 }.from.yaml.inputStream(it.open())65 testConfiguration[Root.tests].map { it to yamlFile.parentFile }66 }.forEach { (test, location) ->67 log.debug("Test to be executed: $test from $location")68 val testFolder = folder {69 location.copyRecursively(this.root)70 }71 log.debug("Test has been copied into $testFolder and is ready to get executed")72 test.description {73 val result = GradleRunner.create()74 .withProjectDir(testFolder.root)75 .withPluginClasspath(classpath)76 .withArguments(test.configuration.tasks + test.configuration.options)77 .build()78 println(result.tasks)79 println(result.output)80 test.expectation.success.forEach {81 val task = result.task(":$it")82 require(task != null) {83 "Task $it was not present among the executed tasks"84 }85 task.outcome shouldBe TaskOutcome.SUCCESS86 }87 test.expectation.file_exists.forEach {88 with(File("${testFolder.root.absolutePath}/$it")) {89 shouldExist()90 shouldBeAFile()91 }92 }93 }94 }95 }96) {97 companion object {98 val log = LoggerFactory.getLogger(LatexTests::class.java)99 }100}...

Full Screen

Full Screen

PotatoServiceMKTest.kt

Source:PotatoServiceMKTest.kt Github

copy

Full Screen

1package org.jesperancinha.std.flash5.persistence.domain;2import com.ninjasquad.springmockk.MockkBean3import io.kotest.core.spec.style.WordSpec4import io.kotest.core.test.TestCase5import io.kotest.matchers.collections.shouldContainAll6import io.kotest.matchers.collections.shouldHaveSize7import io.kotest.matchers.nulls.shouldBeNull8import io.kotest.matchers.nulls.shouldNotBeNull9import io.kotest.matchers.shouldBe10import io.mockk.every11import io.mockk.slot12import io.mockk.verify13import org.junit.jupiter.api.extension.ExtendWith14import org.springframework.beans.factory.annotation.Autowired15import org.springframework.test.context.ContextConfiguration16import org.springframework.test.context.junit.jupiter.SpringExtension17import java.util.*18@ExtendWith(SpringExtension::class)19@ContextConfiguration(classes = [PotatoService::class])20@MockkBean(PotatoRepository::class)21class PotatoServiceMKTest(22 @Autowired23 val potatoService: PotatoService,24 @Autowired25 val potatoRepository: PotatoRepository26) : WordSpec() {27 override fun beforeEach(testCase: TestCase) {28 super.beforeEach(testCase)29 val newPotato1 = Potato();30 newPotato1.form = "Sweet";31 val newPotato2 = Potato();32 newPotato2.form = "Kind";33 every { potatoRepository.findById(1L) } returns (Optional.of(newPotato1));34 every { potatoRepository.findById(2L) } returns (Optional.of(newPotato2));35 }36 init {37 "testing potato service" should {38 "create potato when calling method and retrieve it"{39 val newPotato = Potato();40 newPotato.form = "Kindest of them all"41 val savedPotato = Potato();42 savedPotato.form = "Kindest of the universe"43 savedPotato.id = 3L44 val potatoSlot = slot<Potato>()45 every { potatoRepository.save(capture(potatoSlot)) } returns (savedPotato);46 val potato = potatoService.createPotato(newPotato);47 potato.shouldNotBeNull()48 potato.form shouldBe "Kindest of the universe"49 potato.id.shouldNotBeNull()50 potato.id shouldBe 3L51 verify { potatoRepository.save(newPotato) }...

Full Screen

Full Screen

PostServiceTest.kt

Source:PostServiceTest.kt Github

copy

Full Screen

...5import com.github.njuro.jard.board.Board6import com.github.njuro.jard.post7import com.github.njuro.jard.thread8import com.github.njuro.jard.thread.Thread9import io.kotest.assertions.throwables.shouldThrow10import io.kotest.matchers.collections.shouldContainExactly11import io.kotest.matchers.nulls.shouldNotBeNull12import io.kotest.matchers.optional.shouldBePresent13import io.kotest.matchers.optional.shouldNotBePresent14import io.kotest.matchers.should15import io.kotest.matchers.shouldBe16import io.kotest.matchers.string.shouldContain17import org.junit.jupiter.api.BeforeEach18import org.junit.jupiter.api.Test19import org.springframework.beans.factory.annotation.Autowired20import org.springframework.boot.test.context.SpringBootTest21import org.springframework.transaction.annotation.Transactional22@SpringBootTest23@WithContainerDatabase24@Transactional25internal class PostServiceTest {26 @Autowired27 private lateinit var postService: PostService28 @Autowired29 private lateinit var postRepository: PostRepository30 @Autowired31 private lateinit var db: TestDataRepository32 private lateinit var board: Board33 private lateinit var thread: Thread34 @BeforeEach35 fun setUp() {36 board = db.insert(board(label = "r"))37 thread = db.insert(thread(board))38 }39 @Test40 fun `create new post`() {41 val post = post(thread, postNumber = 0L, body = "Test post\n")42 postService.savePost(post).should {43 it.id.shouldNotBeNull()44 it.postNumber shouldBe 1L45 it.body.shouldContain("<br/>")46 }47 }48 @Test49 fun `resolve post`() {50 val post = db.insert(post(thread, postNumber = 2L))51 postService.resolvePost(board.label, post.postNumber).postNumber shouldBe post.postNumber52 }53 @Test54 fun `don't resolve non-existing post`() {55 shouldThrow<PostNotFoundException> {56 postService.resolvePost(board.label, 0L)57 }58 }59 @Test60 fun `get latest replies for thread`() {61 (2L..8L).forEach { db.insert(post(thread, postNumber = it)) }62 postService.getLatestRepliesForThread(thread.id, thread.originalPost.id).map(Post::getPostNumber)63 .shouldContainExactly(4L, 5L, 6L, 7L, 8L)64 }65 @Test66 fun `delete single post`() {67 val reply = db.insert(post(thread, postNumber = 2L))68 db.select(reply).shouldBePresent()69 postService.deletePost(reply)70 db.select(reply).shouldNotBePresent()71 }72 @Test73 fun `delete multiple posts`() {74 val replies = (2L..5L).map { db.insert(post(thread, postNumber = it)) }75 postRepository.countByThreadId(thread.id) shouldBe 5L76 postService.deletePosts(replies)...

Full Screen

Full Screen

ThreadServiceTest.kt

Source:ThreadServiceTest.kt Github

copy

Full Screen

...3import com.github.njuro.jard.WithContainerDatabase4import com.github.njuro.jard.board5import com.github.njuro.jard.board.Board6import com.github.njuro.jard.thread7import io.kotest.assertions.throwables.shouldThrow8import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder9import io.kotest.matchers.optional.shouldBeEmpty10import io.kotest.matchers.optional.shouldBePresent11import io.kotest.matchers.shouldBe12import org.junit.jupiter.api.BeforeEach13import org.junit.jupiter.api.Test14import org.springframework.beans.factory.annotation.Autowired15import org.springframework.boot.test.context.SpringBootTest16import org.springframework.transaction.annotation.Transactional17import java.time.OffsetDateTime18@SpringBootTest19@WithContainerDatabase20@Transactional21internal class ThreadServiceTest {22 @Autowired23 private lateinit var threadService: ThreadService24 @Autowired25 private lateinit var db: TestDataRepository26 private lateinit var board: Board27 @BeforeEach28 fun initializeBoard() {29 board = db.insert(board(label = "r"))...

Full Screen

Full Screen

UserServiceTest.kt

Source:UserServiceTest.kt Github

copy

Full Screen

2import com.github.njuro.jard.TestDataRepository3import com.github.njuro.jard.WithContainerDatabase4import com.github.njuro.jard.WithMockJardUser5import com.github.njuro.jard.user6import io.kotest.matchers.booleans.shouldBeFalse7import io.kotest.matchers.booleans.shouldBeTrue8import io.kotest.matchers.collections.shouldHaveSize9import io.kotest.matchers.optional.shouldBeEmpty10import io.kotest.matchers.optional.shouldBePresent11import io.kotest.matchers.shouldBe12import org.junit.jupiter.api.Test13import org.springframework.beans.factory.annotation.Autowired14import org.springframework.boot.test.context.SpringBootTest15import org.springframework.transaction.annotation.Transactional16@SpringBootTest17@WithContainerDatabase18@Transactional19internal class UserServiceTest {20 @Autowired21 private lateinit var userService: UserService22 @Autowired23 private lateinit var db: TestDataRepository24 @Test25 fun `save user`() {26 val user = user(username = "Anonymous")27 userService.saveUser(user).username shouldBe user.username28 }...

Full Screen

Full Screen

BoardServiceTest.kt

Source:BoardServiceTest.kt Github

copy

Full Screen

1package com.github.njuro.jard.board2import com.github.njuro.jard.TestDataRepository3import com.github.njuro.jard.WithContainerDatabase4import com.github.njuro.jard.board5import io.kotest.assertions.throwables.shouldThrow6import io.kotest.matchers.collections.shouldContainInOrder7import io.kotest.matchers.optional.shouldBeEmpty8import io.kotest.matchers.optional.shouldBePresent9import io.kotest.matchers.shouldBe10import io.kotest.matchers.shouldNotBe11import org.junit.jupiter.api.Test12import org.springframework.beans.factory.annotation.Autowired13import org.springframework.boot.test.context.SpringBootTest14import java.time.OffsetDateTime15@SpringBootTest16@WithContainerDatabase17internal class BoardServiceTest {18 @Autowired19 private lateinit var boardService: BoardService20 @Autowired21 private lateinit var db: TestDataRepository22 @Test23 fun `save board`() {24 val board = board("r", postCounter = 0L)25 val created = boardService.saveBoard(board)26 created.id shouldNotBe null27 created.postCounter shouldBe 1L...

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1val optional : Optional < String > = Optional . of ( "Hello" ) optional . shouldNotBeEmpty () optional . shouldBeEmpty ()2val optional : Optional < String > = Optional . of ( "Hello" ) optional . shouldBePresent () optional . shouldNotBePresent ()3val optional : Optional < String > = Optional . of ( "Hello" ) optional . shouldBePresentAndEqualTo ( "Hello" ) optional . shouldBePresentAndEqualTo ( "Hello" , String :: equalsIgnoreCase )4val optional : Optional < String > = Optional . of ( "Hello" ) optional . shouldBePresentAndNotEqualTo ( "hello" ) optional . shouldBePresentAndNotEqualTo ( "hello" , String :: equalsIgnoreCase )5val optional : Optional < String > = Optional . of ( "Hello" ) optional . shouldBePresentAndEqualTo ( "Hello" ) optional . shouldBePresentAndEqualTo ( "Hello" , String :: equalsIgnoreCase ) optional . shouldBePresentAndNotEqualTo ( "hello" ) optional . shouldBePresentAndNotEqualTo ( "hello" , String :: equalsIgnoreCase )6val optional : Optional < String > = Optional . of ( "Hello" ) optional . shouldBePresentAndEqualTo ( "Hello" ) optional . shouldBePresentAndEqualTo ( "Hello" , String :: equalsIgnoreCase ) optional . shouldBePresentAndNotEqualTo ( "hello" ) optional . shouldBePresentAndNotEqualTo ( "hello" , String :: equalsIgnoreCase )7val optional : Optional < String > = Optional . of ( "Hello" ) optional . shouldBePresentAndEqualTo ( "Hello" ) optional . shouldBePresentAndEqualTo ( "Hello" , String :: equalsIgnoreCase ) optional . shouldBePresentAndNotEqualTo ( "hello" ) optional . shouldBePresentAndNotEqualTo ( "hello" , String :: equalsIgnoreCase ) optional . shouldBeEmpty () optional . shouldNotBeEmpty () optional . shouldBePresent () optional . shouldNotBePresent ()

Full Screen

Full Screen

test

Using AI Code Generation

copy

Full Screen

1val optional = Optional . of ( 1 )2optional should beSome ( 1 )3optional should beSome ( 1 )4val optional = Optional . of ( 1 )5optional should beSome ( 1 )6optional should beSome ( 1 )7val optional = Optional . of ( 1 )8optional should beSome ( 1 )9optional should beSome ( 1 )10val optional = Optional . of ( 1 )11optional should beSome ( 1 )12optional should beSome ( 1 )13val optional = Optional . of ( 1 )14optional should beSome ( 1 )15optional should beSome ( 1 )16val optional = Optional . of ( 1 )17optional should beSome ( 1 )18optional should beSome ( 1 )19val optional = Optional . of ( 1 )20optional should beSome ( 1 )21optional should beSome ( 1 )22val optional = Optional . of ( 1 )23optional should beSome ( 1 )24optional should beSome ( 1 )25val optional = Optional . of ( 1 )26optional should beSome ( 1 )27optional should beSome ( 1 )28val optional = Optional . of ( 1 )29optional should beSome ( 1 )30optional should beSome ( 1 )

Full Screen

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:

YouTube

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

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