How to use Optional.shouldBeEmpty method of io.kotest.matchers.optional.matchers class

Best Kotest code snippet using io.kotest.matchers.optional.matchers.Optional.shouldBeEmpty

DelegateMethodHandlerRegisterTest.kt

Source:DelegateMethodHandlerRegisterTest.kt Github

copy

Full Screen

1package ru.tinkoff.top.camunda.delegator.delegates.register2import io.kotest.matchers.collections.shouldBeEmpty3import io.kotest.matchers.collections.shouldContainExactly4import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder5import io.kotest.matchers.shouldBe6import io.kotest.matchers.shouldNotBe7import io.kotest.matchers.string.shouldStartWith8import org.camunda.bpm.engine.delegate.DelegateExecution9import org.junit.Assert.assertEquals10import org.junit.jupiter.api.Test11import org.junit.jupiter.api.assertThrows12import org.mockito.kotlin.any13import org.mockito.kotlin.isNull14import org.mockito.kotlin.mock15import org.mockito.kotlin.spy16import org.mockito.kotlin.verify17import ru.tinkoff.top.camunda.delegator.annotations.CamundaDelegate18import ru.tinkoff.top.camunda.delegator.annotations.DelegateAliases19import ru.tinkoff.top.camunda.delegator.annotations.DelegateExecute20import ru.tinkoff.top.camunda.delegator.delegates.DelegateInformation21import ru.tinkoff.top.camunda.delegator.delegates.JavaDelegateWithParams22import ru.tinkoff.top.camunda.delegator.delegates.executors.DelegateExecutor23import ru.tinkoff.top.camunda.delegator.delegates.executors.interceptors.DelegateInterceptor24class DelegateMethodHandlerRegisterTest {25 private val mainDelegateExecutor: DelegateExecutor = mock()26 @CamundaDelegate27 private class TestDelegate {28 @DelegateExecute29 fun test() = Unit30 @DelegateExecute31 fun second() = Unit32 }33 @Test34 fun `check register delegates`() {35 val register = DelegateMethodHandlerRegister(emptyList(), mainDelegateExecutor)36 register.initDelegates(listOf(TestDelegate()))37 val firstDelegate = register.getDelegateMethodHandler("testDelegate_test")38 firstDelegate shouldNotBe null39 with(firstDelegate!!.delegateInformation.metaInformation) {40 delegateClass shouldBe TestDelegate::class.java41 delegateName shouldBe "testDelegate"42 delegateVersion shouldBe "test"43 delegateFullName shouldBe "testDelegate_test"44 delegateAliases.shouldBeEmpty()45 }46 val secondDelegate = register.getDelegateMethodHandler("testDelegate_second")47 secondDelegate shouldNotBe null48 with(secondDelegate!!.delegateInformation.metaInformation) {49 delegateClass shouldBe TestDelegate::class.java50 delegateName shouldBe "testDelegate"51 delegateVersion shouldBe "second"52 delegateFullName shouldBe "testDelegate_second"53 delegateAliases.shouldBeEmpty()54 }55 }56 @Test57 fun `check register java delegates`() {58 val register = DelegateMethodHandlerRegister(emptyList(), mainDelegateExecutor)59 register.initDelegates(listOf(ru.tinkoff.top.camunda.delegator.delegates.JavaDelegateWithParams()))60 val firstDelegate = register.getDelegateMethodHandler("javaDelegateWithParams_requiredParams")61 firstDelegate shouldNotBe null62 with(firstDelegate!!.delegateInformation.metaInformation) {63 delegateClass shouldBe ru.tinkoff.top.camunda.delegator.delegates.JavaDelegateWithParams::class.java64 delegateName shouldBe "javaDelegateWithParams"65 delegateVersion shouldBe "requiredParams"66 delegateFullName shouldBe "javaDelegateWithParams_requiredParams"67 delegateAliases.shouldContainExactly(hashSetOf("alias1"))68 }69 val secondDelegate = register.getDelegateMethodHandler("javaDelegateWithParams_optionalParams")70 secondDelegate shouldNotBe null71 with(secondDelegate!!.delegateInformation.metaInformation) {72 delegateClass shouldBe ru.tinkoff.top.camunda.delegator.delegates.JavaDelegateWithParams::class.java73 delegateName shouldBe "javaDelegateWithParams"74 delegateVersion shouldBe "optionalParams"75 delegateFullName shouldBe "javaDelegateWithParams_optionalParams"76 delegateAliases.shouldBeEmpty()77 }78 }79 @CamundaDelegate80 class TestDelegateAliases {81 @DelegateExecute82 @DelegateAliases("alias1", "alias2")83 fun test() = Unit84 }85 @Test86 fun `when delegate aliases exists then also register by alias`() {87 val register = DelegateMethodHandlerRegister(emptyList(), mainDelegateExecutor)88 register.initDelegates(listOf(TestDelegateAliases()))89 val delegateByFullName = register.getDelegateMethodHandler("testDelegateAliases_test")90 delegateByFullName shouldNotBe null91 with(delegateByFullName!!.delegateInformation.metaInformation) {92 delegateClass shouldBe TestDelegateAliases::class.java93 delegateName shouldBe "testDelegateAliases"94 delegateVersion shouldBe "test"95 delegateFullName shouldBe "testDelegateAliases_test"96 delegateAliases shouldContainExactlyInAnyOrder hashSetOf("alias1", "alias2")97 }98 val delegateByFirstAlias = register.getDelegateMethodHandler("alias1")99 delegateByFirstAlias shouldNotBe null100 val delegateBySecondAlias = register.getDelegateMethodHandler("alias2")101 delegateBySecondAlias shouldNotBe null102 assertEquals(delegateByFullName, delegateByFirstAlias)103 assertEquals(delegateByFirstAlias, delegateBySecondAlias)104 }105 @CamundaDelegate106 private class TestDelegate1 {107 @DelegateExecute108 fun test() = Unit109 }110 @CamundaDelegate111 private class TestDelegate2 {112 @DelegateExecute113 fun test() = Unit114 }115 @Test116 fun `when delegate exists in 2 class then register both`() {117 val register = DelegateMethodHandlerRegister(emptyList(), mainDelegateExecutor)118 register.initDelegates(listOf(TestDelegate1(), TestDelegate2()))119 val firstDelegate = register.getDelegateMethodHandler("testDelegate1_test")120 firstDelegate shouldNotBe null121 val secondDelegate = register.getDelegateMethodHandler("testDelegate2_test")122 secondDelegate shouldNotBe null123 }124 @CamundaDelegate("testDelegate")125 private class TestDelegate3 {126 @DelegateExecute127 fun test() = Unit128 }129 @CamundaDelegate("testDelegate")130 private class TestDelegate4 {131 @DelegateExecute132 fun test() = Unit133 }134 @Test135 fun `when delegate exists in 2 class then registration error`() {136 val register = DelegateMethodHandlerRegister(emptyList(), mainDelegateExecutor)137 val error = assertThrows<IllegalArgumentException> {138 register.initDelegates(listOf(TestDelegate3(), TestDelegate4()))139 }140 error.message shouldStartWith "Delegate testDelegate with version test defined twice."141 }142 @CamundaDelegate143 class TestDelegate5 {144 @DelegateExecute145 @DelegateAliases("testalias")146 fun test1() = Unit147 }148 @CamundaDelegate149 class TestDelegate6 {150 @DelegateExecute151 @DelegateAliases("testalias")152 fun test2() = Unit153 }154 @Test155 fun `when same alias exists in 2 delegates then registration error`() {156 val register = DelegateMethodHandlerRegister(emptyList(), mainDelegateExecutor)157 val error = assertThrows<IllegalArgumentException> {158 register.initDelegates(listOf(TestDelegate5(), TestDelegate6()))159 }160 error.message shouldStartWith "Alias testalias used twice."161 }162 @CamundaDelegate163 private class TestDelegateInterceptor {164 @DelegateExecute165 fun test() = Unit166 }167 @Test168 fun `when delegate interceptor not present then chain not building`() {169 val register = DelegateMethodHandlerRegister(emptyList(), mainDelegateExecutor)170 register.initDelegates(listOf(TestDelegateInterceptor()))171 val firstDelegate = register.getDelegateMethodHandler("testDelegateInterceptor_test")172 firstDelegate!!.execute(mock())173 verify(mainDelegateExecutor).execute(any(), any(), isNull())174 }175 @Test176 fun `when delegate interceptor present then chain building`() {177 open class SimpleInterceptor : DelegateInterceptor() {178 override fun execute(179 execution: DelegateExecution,180 delegateInfo: DelegateInformation,181 delegateArguments: Array<Any?>?182 ): Any? {183 return nextExecutor.execute(execution, delegateInfo, delegateArguments)184 }185 }186 val spyInterceptor = spy(SimpleInterceptor())187 val register = DelegateMethodHandlerRegister(listOf(spyInterceptor), mainDelegateExecutor)188 register.initDelegates(listOf(TestDelegateInterceptor()))189 val firstDelegate = register.getDelegateMethodHandler("testDelegateInterceptor_test")190 firstDelegate!!.execute(mock())191 verify(mainDelegateExecutor).execute(any(), any(), isNull())192 }193}...

Full Screen

Full Screen

ArgumentsTest.kt

Source:ArgumentsTest.kt Github

copy

Full Screen

1package de.qualersoft.robotframework.gradleplugin.utils2import io.kotest.assertions.assertSoftly3import io.kotest.core.spec.style.AnnotationSpec4import io.kotest.matchers.Matcher5import io.kotest.matchers.MatcherResult6import io.kotest.matchers.collections.shouldHaveElementAt7import io.kotest.matchers.collections.shouldHaveSize8import io.kotest.matchers.should9import io.kotest.matchers.shouldNot10import java.io.File11class ArgumentsTest : AnnotationSpec() {12 private lateinit var sut: Arguments13 @BeforeEach14 fun setupTest() {15 sut = Arguments()16 }17 @Test18 fun givenNewArgumentsThenResultIsEmpty() {19 sut.shouldBeEmpty()20 }21 @Test22 fun whenAddingAnOptionalFileOfNullThenResultIsEmpty() {23 sut.addOptionalFile(null, "a")24 sut.shouldBeEmpty()25 }26 @Test27 fun whenAddingAnOptionalNonNullFileThenResultIsNotEmpty() {28 sut.addOptionalFile(File("./test"), "a")29 assertSoftly {30 sut.shouldNotBeEmpty()31 val arr = sut.toArray()32 arr.shouldHaveSize(2)33 arr.shouldHaveElementAt(0, "a")34 arr.shouldHaveElementAt(1, File("./test").path)35 }36 }37 @Test38 fun whenAddingNullFileThenItsConvertedToNone() {39 sut.addFileToArguments(null, "f")40 assertSoftly {41 sut.shouldNotBeEmpty()42 val arr = sut.toArray()43 arr.shouldHaveSize(2)44 arr.shouldHaveElementAt(0, "f")45 arr.shouldHaveElementAt(1, "NONE")46 }47 }48 @Test49 fun whenAddingNonEmptyFileThenItWillBeInResult() {50 sut.addFileToArguments(File("./test"), "f")51 assertSoftly {52 sut.shouldNotBeEmpty()53 val arr = sut.toArray()54 arr.shouldHaveSize(2)55 arr.shouldHaveElementAt(0, "f")56 arr.shouldHaveElementAt(1, File("./test").path)57 }58 }59 @Test60 fun whenAddingEmptyFileThenItsNotInResult() {61 sut.addFileToArguments(File(""), "f")62 sut.shouldBeEmpty()63 }64 @Test65 fun whenAddingNullStringThenItsNotInResult() {66 sut.addNonEmptyStringToArguments(null, "s")67 sut.shouldBeEmpty()68 }69 @Test70 fun whenAddingEmptyStringThenItsNotInResult() {71 sut.addNonEmptyStringToArguments("", "s")72 sut.shouldBeEmpty()73 }74 @Test75 fun whenAddingNonEmptyStringThenItsInResult() {76 sut.addNonEmptyStringToArguments("notEmpty", "s")77 assertSoftly {78 sut.shouldNotBeEmpty()79 val arr = sut.toArray()80 arr.shouldHaveSize(2)81 arr.shouldHaveElementAt(0, "s")82 arr.shouldHaveElementAt(1, "notEmpty")83 }84 }85 @Test86 fun whenAddingEmptyMapThenItsNotInResult() {87 sut.addMapToArguments(mapOf(), "m")88 sut.shouldBeEmpty()89 }90 @Test91 fun whenAddingMapThenItsInResult() {92 sut.addMapToArguments(mapOf("key" to "val"), "m")93 assertSoftly {94 sut.shouldNotBeEmpty()95 val arr = sut.toArray()96 arr.shouldHaveSize(2)97 arr.shouldHaveElementAt(0, "m")98 arr.shouldHaveElementAt(1, "key:val")99 }100 }101 @Test102 fun whenAddingMultiMapThenItsInResult() {103 sut.addMapToArguments(mapOf("key1" to "val1", "key2" to "val2"), "m")104 assertSoftly {105 sut.shouldNotBeEmpty()106 val arr = sut.toArray()107 arr.shouldHaveSize(4)108 arr.shouldHaveElementAt(0, "m")109 arr.shouldHaveElementAt(1, "key1:val1")110 arr.shouldHaveElementAt(2, "m")111 arr.shouldHaveElementAt(3, "key2:val2")112 }113 }114 @Test115 fun whenAddingNullFlagThenItsNotInResult() {116 sut.addFlagToArguments(null, "b")117 sut.shouldBeEmpty()118 }119 @Test120 fun whenAddingFalseFlagThenItsNotInResult() {121 sut.addFlagToArguments(false, "b")122 sut.shouldBeEmpty()123 }124 @Test125 fun whenAddingTrueFlagThenItsInResult() {126 sut.addFlagToArguments(true, "b")127 assertSoftly {128 sut.shouldNotBeEmpty()129 val arr = sut.toArray()130 arr.shouldHaveSize(1)131 arr.shouldHaveElementAt(0, "b")132 }133 }134 @Test135 fun whenAddingOptionalNullStringThenItsNotInResult() {136 sut.addStringToArguments(null, "s")137 sut.shouldBeEmpty()138 }139 @Test140 fun whenAddingOptionalEmptyStringThenItsInResult() {141 sut.addStringToArguments("", "s")142 assertSoftly {143 sut.shouldNotBeEmpty()144 val arr = sut.toArray()145 arr.shouldHaveSize(2)146 arr.shouldHaveElementAt(0, "s")147 arr.shouldHaveElementAt(1, "")148 }149 }150 @Test151 fun whenAddingOptionalNonEmptyStringThenItsInResult() {152 sut.addStringToArguments("NotEmpty", "s")153 assertSoftly {154 sut.shouldNotBeEmpty()155 val arr = sut.toArray()156 arr.shouldHaveSize(2)157 arr.shouldHaveElementAt(0, "s")158 arr.shouldHaveElementAt(1, "NotEmpty")159 }160 }161 @Test162 fun whenAddNullStringListThenItsNotInResult() {163 sut.addListToArguments(null as String?, "s")164 sut.shouldBeEmpty()165 }166 @Test167 fun whenAddStringListThenItsInResult() {168 sut.addListToArguments("aString", "s")169 assertSoftly {170 sut.shouldNotBeEmpty()171 val arr = sut.toArray()172 arr.shouldHaveSize(2)173 arr.shouldHaveElementAt(0, "s")174 arr.shouldHaveElementAt(1, "aString")175 }176 }177 @Test178 fun whenAddingMultiStringListThenEachIsInResult() {179 sut.addListToArguments("str1, str2", "s")180 assertSoftly {181 sut.shouldNotBeEmpty()182 val arr = sut.toArray()183 arr.shouldHaveSize(4)184 arr.shouldHaveElementAt(0, "s")185 arr.shouldHaveElementAt(1, "str1")186 arr.shouldHaveElementAt(2, "s")187 arr.shouldHaveElementAt(3, "str2")188 }189 }190 @Test191 fun whenAddingNullListThenItsNotInResult() {192 sut.addListToArguments(null as List<String?>?, "ls")193 sut.shouldBeEmpty()194 }195 @Test196 fun whenAddingEmptyListThenItsNotInResult() {197 sut.addListToArguments(listOf(), "ls")198 sut.shouldBeEmpty()199 }200 @Test201 fun whenAddingListWithNullThenItsNotInResult() {202 sut.addListToArguments(listOf<String?>(null), "ls")203 sut.shouldBeEmpty()204 }205 @Test206 fun whenAddingListWithEmptyThenItsNotInResult() {207 sut.addListToArguments(listOf(""), "ls")208 sut.shouldBeEmpty()209 }210 @Test211 fun whenAddingListThenItsInResult() {212 sut.addListToArguments(listOf("str"), "ls")213 assertSoftly {214 sut.shouldNotBeEmpty()215 val arr = sut.toArray()216 arr.shouldHaveSize(2)217 arr.shouldHaveElementAt(0, "ls")218 arr.shouldHaveElementAt(1, "str")219 }220 }221 @Test222 fun whenAddingListWithMoreElemsThenEachIsInResult() {223 sut.addListToArguments(listOf("str1", "str2"), "ls")224 assertSoftly {225 sut.shouldNotBeEmpty()226 val arr = sut.toArray()227 arr.shouldHaveSize(4)228 arr.shouldHaveElementAt(0, "ls")229 arr.shouldHaveElementAt(1, "str1")230 arr.shouldHaveElementAt(2, "ls")231 arr.shouldHaveElementAt(3, "str2")232 }233 }234 @Test235 fun whenAddingNullFileListThenItsNotInResult() {236 sut.addFileListToArguments(null, "fl")237 sut.shouldBeEmpty()238 }239 @Test240 fun whenAddingEmptyFileListThenItsNotInResult() {241 sut.addFileListToArguments(listOf(), "fl")242 sut.shouldBeEmpty()243 }244 @Test245 fun whenAddingFileListWithEmptyFileThenItsNotInResult() {246 sut.addFileListToArguments(listOf(File("")), "fl")247 sut.shouldBeEmpty()248 }249 @Test250 fun whenAddingFileListWithFileThenItsInResult() {251 sut.addFileListToArguments(listOf(File("./test")), "fl")252 assertSoftly {253 sut.shouldNotBeEmpty()254 val arr = sut.toArray()255 arr.shouldHaveSize(2)256 arr.shouldHaveElementAt(0, "fl")257 arr.shouldHaveElementAt(1, File("./test").path)258 }259 }260 // <editor-fold desc="Helper extensions">261 private fun beEmpty() = object : Matcher<Arguments> {262 override fun test(value: Arguments) = MatcherResult(263 value.toArray().isEmpty(),264 "Arguments $value should be empty",265 "String $value should not be empty"266 )267 }268 private fun Arguments.shouldBeEmpty() = this should beEmpty()269 private fun Arguments.shouldNotBeEmpty() = this shouldNot beEmpty()270 // </editor-fold>271}...

Full Screen

Full Screen

PostRepositoryTest.kt

Source:PostRepositoryTest.kt Github

copy

Full Screen

1package com.github.njuro.jard.post2import com.github.njuro.jard.TestDataRepository3import com.github.njuro.jard.WithContainerDatabase4import com.github.njuro.jard.WithTestDataRepository5import com.github.njuro.jard.board6import com.github.njuro.jard.board.Board7import com.github.njuro.jard.post8import com.github.njuro.jard.thread9import com.github.njuro.jard.thread.Thread10import io.kotest.matchers.collections.shouldContainExactly11import io.kotest.matchers.optional.shouldBeEmpty12import io.kotest.matchers.optional.shouldBePresent13import io.kotest.matchers.shouldBe14import org.junit.jupiter.api.BeforeEach15import org.junit.jupiter.api.Test16import org.springframework.beans.factory.annotation.Autowired17import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest18import org.springframework.transaction.annotation.Transactional19@DataJpaTest20@WithTestDataRepository21@WithContainerDatabase22@Transactional23internal class PostRepositoryTest {24 @Autowired25 private lateinit var postRepository: PostRepository26 @Autowired27 private lateinit var db: TestDataRepository28 private lateinit var board: Board29 private lateinit var thread: Thread30 @BeforeEach31 fun setUp() {32 board = db.insert(board(label = "r"))33 thread = db.insert(thread(board))34 }35 @Test36 fun `find by board label and post number`() {37 val reply = postRepository.save(post(thread, postNumber = 2L))38 postRepository.findByThreadBoardLabelAndPostNumber(board.label, reply.postNumber).shouldBePresent {39 it.postNumber shouldBe reply.postNumber40 }41 postRepository.findByThreadBoardLabelAndPostNumber(board.label, 3L).shouldBeEmpty()42 }43 @Test44 fun `find by thread id and post number greater than`() {45 (2..4).forEach { postRepository.save(post(thread, postNumber = it.toLong())) }46 postRepository.findByThreadIdAndPostNumberGreaterThanOrderByCreatedAtAsc(thread.id, 2L).map(Post::getPostNumber)47 .shouldContainExactly(3L, 4L)48 }49 @Test50 fun `find by thread id excluding original post`() {51 (2L..4L).forEach { postRepository.save(post(thread, postNumber = it)) }52 postRepository.findByThreadIdAndIdIsNotOrderByCreatedAtAsc(thread.id, thread.originalPost.id)53 .map(Post::getPostNumber)54 .shouldContainExactly(2L, 3L, 4L)55 }56 @Test57 fun `find 5 latest replies by thread id`() {58 (2L..8L).forEach { postRepository.save(post(thread, postNumber = it)) }59 postRepository.findTop5ByThreadIdAndIdIsNotOrderByCreatedAtDesc(thread.id, thread.originalPost.id)60 .map(Post::getPostNumber)61 .shouldContainExactly(8L, 7L, 6L, 5L, 4L)62 }63 @Test64 fun `count number of posts in thread`() {65 (2L..5L).forEach { postRepository.save(post(thread, postNumber = it)) }66 postRepository.countByThreadId(thread.id) shouldBe 567 }68}...

Full Screen

Full Screen

OptionalMatchersTest.kt

Source:OptionalMatchersTest.kt Github

copy

Full Screen

1package com.sksamuel.kotest.matchers.optional2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.core.spec.style.ShouldSpec4import io.kotest.matchers.optional.beEmpty5import io.kotest.matchers.optional.bePresent6import io.kotest.matchers.optional.shouldBeEmpty7import io.kotest.matchers.optional.shouldBePresent8import io.kotest.matchers.optional.shouldNotBeEmpty9import io.kotest.matchers.optional.shouldNotBePresent10import io.kotest.matchers.should11import io.kotest.matchers.shouldBe12import io.kotest.matchers.shouldNot13import io.kotest.matchers.throwable.shouldHaveMessage14import java.util.Optional15class OptionalMatchersTest : ShouldSpec({16 context("Empty optional") {17 val optional = Optional.empty<Any>()18 should("Be empty") {19 optional.shouldBeEmpty()20 optional should beEmpty()21 }22 should("Not be present") {23 optional.shouldNotBePresent()24 optional shouldNot bePresent()25 }26 should("Fail to be notEmpty") {27 shouldThrow<AssertionError> { optional.shouldNotBeEmpty() }28 shouldThrow<AssertionError> { optional shouldNot beEmpty() }29 }30 should("Fail to be present") {31 shouldThrow<AssertionError> { optional.shouldBePresent() }32 shouldThrow<AssertionError> { optional should bePresent() }33 }34 }35 context("Present optional") {36 val optional = Optional.of("A")37 should("Be present") {38 optional.shouldBePresent()39 optional should bePresent()40 }41 42 should("Return the present value for usage in more assertions") {43 optional.shouldBePresent() shouldBe "A"44 } 45 should("Allow matchers with present value as a receiver") {46 optional shouldBePresent {47 this shouldBe "A"48 }49 }50 51 should("Allow matchers with present value as parameter") {52 optional shouldBePresent {53 it shouldBe "A"54 }55 }56 57 should("Execute code inside the receiver") {58 shouldThrow<RuntimeException> {59 optional shouldBePresent {60 throw RuntimeException("Ensuring the block is actually executed")61 }62 } shouldHaveMessage "Ensuring the block is actually executed"63 64 shouldThrow<AssertionError> {65 optional shouldBePresent {66 this shouldBe "B"67 }68 }69 }70 }71}) ...

Full Screen

Full Screen

ThreadServiceTest.kt

Source:ThreadServiceTest.kt Github

copy

Full Screen

1package com.github.njuro.jard.thread2import com.github.njuro.jard.TestDataRepository3import 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"))30 }31 @Test32 fun `create thread`() {33 val thread = threadService.saveThread(thread(board))34 db.select(thread).shouldBePresent()35 }36 @Test37 fun `resolve existing thread`() {38 val thread = threadService.saveThread(thread(board))39 threadService.resolveThread(board.label, thread.threadNumber).id shouldBe thread.id40 }41 @Test42 fun `don't resolve non-existing thread`() {43 shouldThrow<ThreadNotFoundException> {44 threadService.resolveThread(board.label, -1)45 }46 }47 @Test48 @Suppress("UNUSED_VARIABLE")49 fun `delete stalest thread from board`() {50 val baseTime = OffsetDateTime.now().minusWeeks(1)51 val thread1 = db.insert(thread(board, lastBumpAt = baseTime, stickied = true), threadNumber = 1L)52 val thread2 = db.insert(thread(board, lastBumpAt = baseTime.minusDays(1)), threadNumber = 2L)53 val thread3 = db.insert(thread(board, lastBumpAt = baseTime.minusDays(2)), threadNumber = 3L)54 threadService.deleteStalestThread(board.id)55 threadService.getAllThreadsFromBoard(board.id).map(Thread::getId)56 .shouldContainExactlyInAnyOrder(thread1.id, thread2.id)57 }58 @Test59 fun `delete thread by id`() {60 val thread = db.insert(thread(board))61 threadService.deleteThread(thread)62 db.select(thread).shouldBeEmpty()63 }64}...

Full Screen

Full Screen

UserServiceTest.kt

Source:UserServiceTest.kt Github

copy

Full Screen

1package com.github.njuro.jard.user2import 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 }29 @Test30 fun `get all users`() {31 repeat(3) { db.insert(user(username = "User $it", email = "user$it@email.com")) }32 userService.allUsers shouldHaveSize 333 }34 @Test35 fun `check that user exists`() {36 val user = db.insert(user(username = "Anonymous"))37 userService.doesUserExists(user.username).shouldBeTrue()38 userService.doesUserExists("other").shouldBeFalse()39 }40 @Test41 @WithMockJardUser(username = "Anonymous")42 fun `get current user`() {43 userService.currentUser.username shouldBe "Anonymous"44 }45 @Test46 @WithMockJardUser(UserAuthority.MANAGE_BOARDS, UserAuthority.MANAGE_USERS)47 fun `check if current user has authority`() {48 userService.hasCurrentUserAuthority(UserAuthority.MANAGE_BOARDS).shouldBeTrue()49 userService.hasCurrentUserAuthority(UserAuthority.MANAGE_USERS).shouldBeTrue()50 userService.hasCurrentUserAuthority(UserAuthority.MANAGE_BANS).shouldBeFalse()51 }52 @Test53 fun `delete user`() {54 val user = db.insert(user(username = "Anonymous"))55 db.select(user).shouldBePresent()56 userService.deleteUser(user)57 db.select(user).shouldBeEmpty()58 }59}...

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 1L28 }29 @Test30 fun `find all boards sorted by creation date`() {31 val baseDate = OffsetDateTime.now()32 val first = db.insert(board(label = "r", createdAt = baseDate))33 val second = db.insert(board(label = "sp", createdAt = baseDate.plusDays(1)))34 val third = db.insert(board(label = "fit", createdAt = baseDate.minusDays(1)))35 boardService.allBoards.shouldContainInOrder(third, first, second)36 }37 @Test38 fun `resolve board by label`() {39 val board = db.insert(board(label = "r"))40 boardService.resolveBoard(board.label) shouldBe board41 }42 @Test43 fun `don't resolve non-existing board`() {44 shouldThrow<BoardNotFoundException> {45 boardService.resolveBoard("xxx")46 }47 }48 @Test49 fun `register new post`() {50 val board = db.insert(board(label = "r", postCounter = 5L))51 boardService.registerNewPost(board) shouldBe board.postCounter52 db.select(board).shouldBePresent { it.postCounter shouldBe board.postCounter + 1 }53 }54 @Test55 fun `delete board`() {56 val board = db.insert(board(label = "r"))57 boardService.deleteBoard(board)58 db.select(board).shouldBeEmpty()59 }60}...

Full Screen

Full Screen

BoardRepositoryTest.kt

Source:BoardRepositoryTest.kt Github

copy

Full Screen

1package com.github.njuro.jard.board2import com.github.njuro.jard.WithContainerDatabase3import com.github.njuro.jard.board4import io.kotest.matchers.optional.shouldBeEmpty5import io.kotest.matchers.optional.shouldBePresent6import io.kotest.matchers.shouldBe7import org.junit.jupiter.api.Test8import org.springframework.beans.factory.annotation.Autowired9import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest10@DataJpaTest11@WithContainerDatabase12internal class BoardRepositoryTest {13 @Autowired14 private lateinit var boardRepository: BoardRepository15 @Test16 fun `find board by label`() {17 val expectedBoard = board(label = "fit")18 boardRepository.save(expectedBoard)19 val actualBoard = boardRepository.findByLabel(expectedBoard.label)20 actualBoard.shouldBePresent { it.label shouldBe expectedBoard.label }21 }22 @Test23 fun `don't find non-existing board by label`() {24 boardRepository.findByLabel("xxx").shouldBeEmpty()25 }26 @Test27 fun `retrieve post counter of board`() {28 val board = board(label = "r", postCounter = 10)29 boardRepository.save(board)30 boardRepository.getPostCounter(board.label) shouldBe board.postCounter31 }32 @Test33 fun `increase post counter of board`() {34 val board = board(label = "sp", postCounter = 15)35 boardRepository.save(board)36 boardRepository.increasePostNumber(board.label)37 boardRepository.findByLabel(board.label).shouldBePresent { it.postCounter shouldBe board.postCounter + 1 }38 }39}...

Full Screen

Full Screen

Optional.shouldBeEmpty

Using AI Code Generation

copy

Full Screen

1optional.shouldBeEmpty()2optional.shouldBePresent()3optional.shouldBePresentWith { it shouldBe 1 }4optional.shouldBePresentWithValue(1)5optional.shouldBePresentWithValueIn(1..10)6optional.shouldBePresentWithValueInstanceOf(Int::class)7optional.shouldBePresentWithValueMatch { it shouldBe 1 }8optional.shouldBePresentWithValueNotIn(2..10)9optional.shouldBePresentWithValueOfType<Int>()10optional.shouldBePresentWithValueNotOfType<String>()11optional.shouldBePresentWithValueNotOfType<String>()12optional.shouldBePresentWithValueNotOfType<String>()13optional.shouldBePresentWithValueNotOfType<String>()14optional.shouldBePresentWithValueNotOfType<String>()15optional.shouldBePresentWithValueNotOfType<String>()16optional.shouldBePresentWithValueNotOfType<String>()

Full Screen

Full Screen

Optional.shouldBeEmpty

Using AI Code Generation

copy

Full Screen

1optional.shouldBeEmpty()2optional.shouldNotBeEmpty()3optional.shouldContain(value)4optional.shouldNotContain(value)5optional.shouldContainInstanceOf(type)6optional.shouldNotContainInstanceOf(type)7optional.shouldContainSame(value)8optional.shouldNotContainSame(value)9optional.shouldContainOnlyNulls()10optional.shouldNotContainOnlyNulls()11optional.shouldContainNull()12optional.shouldNotContainNull()13optional.shouldContainAll(values)14optional.shouldNotContainAll(values)15optional.shouldContainAllIn(values)16optional.shouldNotContainAllIn(values)17optional.shouldContainInOrder(values)18optional.shouldNotContainInOrder(values)

Full Screen

Full Screen

Optional.shouldBeEmpty

Using AI Code Generation

copy

Full Screen

1val optional : Optional<String> = Optional.of("Hello")2optional.shouldBeEmpty()3val optional : Optional<String> = Optional.of("Hello")4optional.shouldNotBeEmpty()5val optional : Optional<String> = Optional.of("Hello")6optional.shouldBePresent()7val optional : Optional<String> = Optional.of("Hello")8optional.shouldBePresent()9val optional : Optional<String> = Optional.of("Hello")10optional.shouldBePresent()11val optional : Optional<String> = Optional.of("Hello")12optional.shouldBePresent()13val optional : Optional<String> = Optional.of("Hello")14optional.shouldBePresent()15val optional : Optional<String> = Optional.of("Hello")16optional.shouldBePresent()17val optional : Optional<String> = Optional.of("Hello")18optional.shouldBePresent()19val optional : Optional<String> = Optional.of("Hello")20optional.shouldBePresent()21val optional : Optional<String> = Optional.of("Hello")22optional.shouldBePresent()23val optional : Optional<String> = Optional.of("Hello")24optional.shouldBePresent()25val optional : Optional<String> = Optional.of("Hello")26optional.shouldBePresent()

Full Screen

Full Screen

Optional.shouldBeEmpty

Using AI Code Generation

copy

Full Screen

1 import io.kotest.matchers.optional.matchers.shouldBeEmpty2 import org.junit.jupiter.api.Test3 import org.junit.jupiter.api.assertThrows4 import java.util.Optional5 import java.util.Optional.empty6 import java.util.Optional.of7 class OptionalMatchersTest {8 fun `test optional should be empty`() {9 val optional = empty<String>()10 optional.shouldBeEmpty()11 }12 fun `test optional should be empty with error message`() {13 val optional = of("foo")14 assertThrows<AssertionError> {15 optional.shouldBeEmpty("optional should be empty")16 }17 }18 }

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