How to use after method of io.kotest.matchers.date.matchers class

Best Kotest code snippet using io.kotest.matchers.date.matchers.after

FailingKotestAsserts.kt

Source:FailingKotestAsserts.kt Github

copy

Full Screen

1package testing.failing2import arrow.core.*3import io.kotest.assertions.arrow.either.shouldBeLeft4import io.kotest.assertions.arrow.either.shouldBeRight5import io.kotest.assertions.arrow.nel.shouldContain6import io.kotest.assertions.arrow.nel.shouldContainNull7import io.kotest.assertions.arrow.option.shouldBeNone8import io.kotest.assertions.arrow.option.shouldBeSome9import io.kotest.assertions.arrow.validation.shouldBeInvalid10import io.kotest.assertions.arrow.validation.shouldBeValid11import io.kotest.assertions.asClue12import io.kotest.assertions.assertSoftly13import io.kotest.assertions.json.*14import io.kotest.assertions.throwables.shouldThrowAny15import io.kotest.assertions.throwables.shouldThrowExactly16import io.kotest.assertions.withClue17import io.kotest.matchers.Matcher18import io.kotest.matchers.MatcherResult19import io.kotest.matchers.booleans.shouldBeFalse20import io.kotest.matchers.booleans.shouldBeTrue21import io.kotest.matchers.collections.shouldBeEmpty22import io.kotest.matchers.collections.shouldBeOneOf23import io.kotest.matchers.collections.shouldBeSameSizeAs24import io.kotest.matchers.collections.shouldBeSorted25import io.kotest.matchers.collections.shouldContain26import io.kotest.matchers.date.shouldBeAfter27import io.kotest.matchers.ints.shouldBeEven28import io.kotest.matchers.ints.shouldBeGreaterThan29import io.kotest.matchers.ints.shouldBeGreaterThanOrEqual30import io.kotest.matchers.ints.shouldBeLessThan31import io.kotest.matchers.ints.shouldBeLessThanOrEqual32import io.kotest.matchers.ints.shouldBeZero33import io.kotest.matchers.maps.shouldBeEmpty34import io.kotest.matchers.maps.shouldContain35import io.kotest.matchers.maps.shouldContainKey36import io.kotest.matchers.maps.shouldContainValue37import io.kotest.matchers.nulls.shouldBeNull38import io.kotest.matchers.should39import io.kotest.matchers.shouldBe40import io.kotest.matchers.shouldNot41import io.kotest.matchers.string.shouldBeBlank42import io.kotest.matchers.string.shouldBeEmpty43import io.kotest.matchers.string.shouldBeUpperCase44import io.kotest.matchers.string.shouldContain45import io.kotest.matchers.string.shouldNotBeBlank46import java.time.LocalDate47import org.junit.jupiter.api.Test48/**49 * Kotest assertions50 *51 * - [Kotest Assertions Documentation](https://kotest.io/assertions/)52 * - [Github](https://github.com/kotest/kotest/)53 */54class FailingKotestAsserts {55 @Test56 fun `General assertions`() {57 assertSoftly {58 "text" shouldBe "txet"59 "hi".shouldBeBlank()60 " ".shouldNotBeBlank()61 "hi".shouldBeEmpty()62 "hi".shouldBeUpperCase()63 "hello".shouldContain("hi")64 false.shouldBeTrue()65 true.shouldBeFalse()66 "not null".shouldBeNull()67 10 shouldBeLessThan 1068 10 shouldBeLessThanOrEqual 969 11 shouldBeGreaterThan 1170 11 shouldBeGreaterThanOrEqual 1271 9.shouldBeEven()72 1.shouldBeZero()73 }74 }75 @Test76 fun `Exception assertions`() {77 assertSoftly {78 shouldThrowExactly<IllegalArgumentException> {79 angryFunction()80 }81 shouldThrowAny {82 "I'm not throwing anything"83 }84 }85 }86 @Test87 fun `Collection assertions`() {88 assertSoftly {89 listOf(1, 2, 3).shouldBeEmpty()90 listOf(1, 2, 3) shouldContain 491 listOf(1, 3, 2).shouldBeSorted()92 listOf(1, 2, 3, 4) shouldBeSameSizeAs listOf(4, 5, 6)93 1 shouldBeOneOf listOf(2, 3)94 mapOf(1 to "one", 2 to "two", 3 to "three").shouldBeEmpty()95 mapOf(1 to "one", 2 to "two", 3 to "three") shouldContainKey 496 mapOf(1 to "one", 2 to "two", 3 to "three") shouldContainValue "five"97 mapOf(1 to "one", 2 to "two", 3 to "three") shouldContain (6 to "six")98 }99 }100 @Test101 fun `Arrow assertions`() {102 assertSoftly {103 val optionNone = none<String>()104 val optionSome = Some("I am something").toOption()105 optionSome.shouldBeNone()106 optionNone.shouldBeSome()107 val rightEither = Either.Right(1)108 val leftEither = Either.Left("ERROR!!")109 leftEither.shouldBeRight()110 leftEither shouldBeRight 1111 rightEither.shouldBeLeft()112 rightEither shouldBeLeft "ERROR!!"113 val nonEmptyList = NonEmptyList.of(1, 2, 3, 4, 5)114 nonEmptyList shouldContain 6115 nonEmptyList.shouldContainNull()116 val valid = Validated.valid()117 val invalid = Validated.invalid()118 invalid.shouldBeValid()119 valid.shouldBeInvalid()120 }121 }122 @Test123 fun `Json assertions`() {124 val jsonString = "{\"test\": \"property\", \"isTest\": true }"125 assertSoftly {126 jsonString shouldMatchJson "{\"test\": \"otherProperty\"}"127 jsonString shouldContainJsonKey "$.anotherTest"128 jsonString shouldNotContainJsonKey "$.test"129 jsonString.shouldContainJsonKeyValue("$.isTest", false)130 }131 }132 @Test133 fun `Custom assertions`() {134 assertSoftly {135 val sentMail = Mail(136 dateCreated = LocalDate.of(2020, 10, 27),137 sent = true, message = "May you have an amazing day"138 )139 val unsentMail = Mail(140 dateCreated = LocalDate.of(2020, 10, 27),141 sent = false, message = "May you have an amazing day"142 )143 // This is possible144 unsentMail.sent should beSent()145 sentMail.sent shouldNot beSent()146 // This is recommended147 unsentMail.shouldBeSent()148 sentMail.shouldNotBeSent()149 }150 }151 @Test152 fun `withClue usage`() {153 val mail = Mail(154 dateCreated = LocalDate.of(2020, 10, 27),155 sent = false, message = "May you have an amazing day"156 )157 withClue("sent field should be true") {158 mail.sent shouldBe true159 }160 mail.asClue {161 it.dateCreated shouldBeAfter LocalDate.of(2020, 10, 26)162 it.sent shouldBe true163 }164 }165 @Test166 fun `asClue usage`() {167 val mail = Mail(168 dateCreated = LocalDate.of(2020, 10, 27),169 sent = false, message = "May you have an amazing day"170 )171 mail.asClue {172 it.dateCreated shouldBeAfter LocalDate.of(2020, 10, 26)173 it.sent shouldBe true174 }175 }176 fun beSent() = object : Matcher<Boolean> {177 override fun test(value: Boolean) = MatcherResult(value, "Mail.sent should be true", "Mail.sent should be false")178 }179 fun Mail.shouldBeSent() = this.sent should beSent()180 fun Mail.shouldNotBeSent() = this.sent shouldNot beSent()181}182data class Mail(val dateCreated: LocalDate, val sent: Boolean, val message: String)183fun angryFunction() {184 throw IllegalStateException("How dare you!")185}...

Full Screen

Full Screen

NoteViewModelTest.kt

Source:NoteViewModelTest.kt Github

copy

Full Screen

...42 libraryRepository.createLibrary(Library(id = 2, title = "Home", position = 0))43 noteRepository.createNote(Note(id = 1, libraryId = 1, title = "Title", body = "Body", position = 0))44 viewModel = get { parametersOf(1L, 1L) }45 }46 afterEach {47 stopKoin()48 }49 "get library should return library with matching id" {50 val library = viewModel.state51 .map { it.library }52 .first()53 library.id shouldBeExactly 154 library.title shouldBeEqualIgnoringCase "Work"55 }56 "get note should return a default note when note id is 0" {57 viewModel = get { parametersOf(1L, 0L) }58 val note = viewModel.state59 .map { it.note }60 .first()...

Full Screen

Full Screen

KotestAsserts.kt

Source:KotestAsserts.kt Github

copy

Full Screen

1package testing.asserts2import arrow.core.*3import io.kotest.assertions.arrow.either.shouldBeLeft4import io.kotest.assertions.arrow.either.shouldBeRight5import io.kotest.assertions.arrow.nel.shouldContain6import io.kotest.assertions.arrow.nel.shouldContainNull7import io.kotest.assertions.arrow.option.shouldBeNone8import io.kotest.assertions.arrow.option.shouldBeSome9import io.kotest.assertions.arrow.validation.shouldBeInvalid10import io.kotest.assertions.arrow.validation.shouldBeValid11import io.kotest.assertions.asClue12import io.kotest.assertions.json.*13import io.kotest.assertions.throwables.shouldThrowAny14import io.kotest.assertions.throwables.shouldThrowExactly15import io.kotest.assertions.withClue16import io.kotest.matchers.Matcher17import io.kotest.matchers.MatcherResult18import io.kotest.matchers.booleans.shouldBeFalse19import io.kotest.matchers.booleans.shouldBeTrue20import io.kotest.matchers.collections.shouldBeEmpty21import io.kotest.matchers.collections.shouldBeOneOf22import io.kotest.matchers.collections.shouldBeSameSizeAs23import io.kotest.matchers.collections.shouldBeSorted24import io.kotest.matchers.collections.shouldContain25import io.kotest.matchers.date.shouldBeAfter26import io.kotest.matchers.ints.shouldBeEven27import io.kotest.matchers.ints.shouldBeGreaterThan28import io.kotest.matchers.ints.shouldBeGreaterThanOrEqual29import io.kotest.matchers.ints.shouldBeLessThan30import io.kotest.matchers.ints.shouldBeLessThanOrEqual31import io.kotest.matchers.ints.shouldBeZero32import io.kotest.matchers.maps.shouldBeEmpty33import io.kotest.matchers.maps.shouldContain34import io.kotest.matchers.maps.shouldContainKey35import io.kotest.matchers.maps.shouldContainValue36import io.kotest.matchers.nulls.shouldBeNull37import io.kotest.matchers.should38import io.kotest.matchers.shouldBe39import io.kotest.matchers.shouldNot40import io.kotest.matchers.string.shouldBeBlank41import io.kotest.matchers.string.shouldBeEmpty42import io.kotest.matchers.string.shouldBeUpperCase43import io.kotest.matchers.string.shouldContain44import io.kotest.matchers.string.shouldNotBeBlank45import java.time.LocalDate46import org.junit.jupiter.api.Test47/**48 * Kotest assertions49 *50 * - [Kotest Assertions Documentation](https://kotest.io/assertions/)51 * - [Github](https://github.com/kotest/kotest/)52 */53class KotestAsserts {54 @Test55 fun `General assertions`() {56 "text" shouldBe "text"57 " ".shouldBeBlank()58 "hi".shouldNotBeBlank()59 "".shouldBeEmpty()60 "HI".shouldBeUpperCase()61 "hello".shouldContain("ll")62 true.shouldBeTrue()63 false.shouldBeFalse()64 null.shouldBeNull()65 10 shouldBeLessThan 1166 10 shouldBeLessThanOrEqual 1067 11 shouldBeGreaterThan 1068 11 shouldBeGreaterThanOrEqual 1169 10.shouldBeEven()70 0.shouldBeZero()71 }72 @Test73 fun `Exception assertions`() {74 shouldThrowExactly<IllegalStateException> {75 angryFunction()76 }77 shouldThrowAny {78 angryFunction()79 }80 }81 @Test82 fun `Collection assertions`() {83 emptyList<Int>().shouldBeEmpty()84 listOf(1, 2, 3) shouldContain 385 listOf(1, 2, 3).shouldBeSorted()86 listOf(1, 2, 3) shouldBeSameSizeAs listOf(4, 5, 6)87 1 shouldBeOneOf listOf(1, 2, 3)88 emptyMap<Int, String>().shouldBeEmpty()89 mapOf(1 to "one", 2 to "two", 3 to "three") shouldContainKey 190 mapOf(1 to "one", 2 to "two", 3 to "three") shouldContainValue "two"91 mapOf(1 to "one", 2 to "two", 3 to "three") shouldContain (3 to "three")92 }93 @Test94 fun `Arrow assertions`() {95 val optionNone = none<String>()96 val optionSome = Some("I am something").toOption()97 optionNone.shouldBeNone()98 optionSome.shouldBeSome()99 val rightEither = Either.Right(1)100 val leftEither = Either.Left("ERROR!!")101 rightEither.shouldBeRight()102 rightEither shouldBeRight 1103 leftEither.shouldBeLeft()104 leftEither shouldBeLeft "ERROR!!"105 val nonEmptyList = NonEmptyList.of(1, 2, 3, 4, 5, null)106 nonEmptyList shouldContain 1107 nonEmptyList.shouldContainNull()108 val valid = Validated.valid()109 val invalid = Validated.invalid()110 valid.shouldBeValid()111 invalid.shouldBeInvalid()112 }113 @Test114 fun `Json assertions`() {115 val jsonString = "{\"test\": \"property\", \"isTest\": true }"116 jsonString shouldMatchJson jsonString117 jsonString shouldContainJsonKey "$.test"118 jsonString shouldNotContainJsonKey "$.notTest"119 jsonString.shouldContainJsonKeyValue("$.isTest", true)120 }121 @Test122 fun `Custom assertions`() {123 val sentMail = Mail(124 dateCreated = LocalDate.of(2020, 10, 27),125 sent = true, message = "May you have an amazing day"126 )127 val unsentMail = Mail(128 dateCreated = LocalDate.of(2020, 10, 27),129 sent = false, message = "May you have an amazing day"130 )131 // This is possible132 sentMail.sent should beSent()133 unsentMail.sent shouldNot beSent()134 // This is recommended135 sentMail.shouldBeSent()136 unsentMail.shouldNotBeSent()137 }138 @Test139 fun `withClue usage`() {140 val mail = Mail(141 dateCreated = LocalDate.of(2020, 10, 27),142 sent = false, message = "May you have an amazing day"143 )144 withClue("sent field should be false") {145 mail.sent shouldBe false146 }147 mail.asClue {148 it.dateCreated shouldBeAfter LocalDate.of(2020, 10, 26)149 it.sent shouldBe false150 }151 }152 @Test153 fun `asClue usage`() {154 val mail = Mail(155 dateCreated = LocalDate.of(2020, 10, 27),156 sent = false, message = "May you have an amazing day"157 )158 mail.asClue {159 it.dateCreated shouldBeAfter LocalDate.of(2020, 10, 26)160 it.sent shouldBe false161 }162 }163 fun beSent() = object : Matcher<Boolean> {164 override fun test(value: Boolean) = MatcherResult(value, "Mail.sent should be true", "Mail.sent should be false")165 }166 fun Mail.shouldBeSent() = this.sent should beSent()167 fun Mail.shouldNotBeSent() = this.sent shouldNot beSent()168}169data class Mail(val dateCreated: LocalDate, val sent: Boolean, val message: String)170fun angryFunction() {171 throw IllegalStateException("How dare you!")172}...

Full Screen

Full Screen

AuthenticationIntegrationTest.kt

Source:AuthenticationIntegrationTest.kt Github

copy

Full Screen

1package com.github.njuro.jard.security2import com.github.njuro.jard.*3import com.github.njuro.jard.common.Constants.JWT_COOKIE_NAME4import com.github.njuro.jard.common.Mappings5import com.github.njuro.jard.config.security.JsonUsernamePasswordAuthenticationFilter6import com.github.njuro.jard.user.UserFacade7import com.github.njuro.jard.utils.validation.ValidationErrors.OBJECT_ERROR8import io.kotest.matchers.date.shouldBeAfter9import io.kotest.matchers.nulls.shouldBeNull10import io.kotest.matchers.nulls.shouldNotBeNull11import io.kotest.matchers.should12import io.kotest.matchers.shouldBe13import io.kotest.matchers.string.shouldContainIgnoringCase14import org.junit.jupiter.api.DisplayName15import org.junit.jupiter.api.Nested16import org.junit.jupiter.api.Test17import org.springframework.beans.factory.annotation.Autowired18import org.springframework.beans.factory.annotation.Value19import org.springframework.http.HttpHeaders20import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf21import org.springframework.test.web.servlet.get22import org.springframework.test.web.servlet.post23import java.time.OffsetDateTime24@WithContainerDatabase25internal class AuthenticationIntegrationTest : MockMvcTest() {26 @Autowired27 private lateinit var userFacade: UserFacade28 @Value("\${app.jwt.expiration:604800}")29 private val jwtExpiration = 030 @Nested31 @DisplayName("login")32 inner class Login {33 private fun login(34 loginRequest: JsonUsernamePasswordAuthenticationFilter.LoginRequest,35 ip: String = "127.0.0.1"36 ) =37 mockMvc.post("${Mappings.API_ROOT}/login") {38 body(loginRequest)39 with { it.apply { remoteAddr = ip } }40 }41 @Test42 fun `valid login`() {43 val baseDate = OffsetDateTime.now()44 val user = userFacade.createUser(user(username = "user", password = "password").toForm())45 login(loginRequest(user.username, "password"), ip = "127.0.0.2").andExpect {46 status { isOk() }47 cookie {48 path(JWT_COOKIE_NAME, "/")49 maxAge(JWT_COOKIE_NAME, -1)50 secure(JWT_COOKIE_NAME, false)51 httpOnly(JWT_COOKIE_NAME, true)52 }53 jsonPath("$.username") { value("user") }54 jsonPath("$.role") { exists() }55 jsonPath("$.authorities") { exists() }56 jsonPath("$.email") { exists() }57 jsonPath("$.registrationIp") { doesNotExist() }58 }.andReturn().response.getHeader(HttpHeaders.SET_COOKIE).shouldContainIgnoringCase("SameSite=Strict")59 userFacade.resolveUser(user.username).should {60 it.lastLoginIp shouldBe "127.0.0.2"61 it.lastLogin shouldBeAfter baseDate62 }63 }64 @Test65 fun `valid login with remember me option`() {66 val user = userFacade.createUser(user(username = "user", password = "password").toForm())67 login(loginRequest(user.username, "password", rememberMe = true)).andExpect {68 status { isOk() }69 cookie { maxAge(JWT_COOKIE_NAME, jwtExpiration) }70 }71 }72 @Test73 fun `invalid login`() {74 val user = userFacade.createUser(user(username = "user", password = "password").toForm())75 login(loginRequest(user.username, "something")).andExpect {76 status { isUnauthorized() }77 match(validationError(OBJECT_ERROR))78 }79 }80 }81 @Test82 @WithMockJardUser83 fun logout() {84 userFacade.currentUser.shouldNotBeNull()85 mockMvc.post("${Mappings.API_ROOT}/logout") { with(csrf()) }.andExpect {86 status { isOk() }87 cookie { maxAge(JWT_COOKIE_NAME, 0) }88 }89 userFacade.currentUser.shouldBeNull()90 }91 @Test92 @WithMockJardUser93 fun `authenticated request`() {94 mockMvc.get("${Mappings.API_ROOT}/secured") { setUp() }.andExpect { status { isOk() } }95 }96 @Test97 fun `unauthenticated request`() {98 mockMvc.get("${Mappings.API_ROOT}/secured") { setUp() }.andExpect { status { isUnauthorized() } }99 }100}...

Full Screen

Full Screen

DataTimeTests.kt

Source:DataTimeTests.kt Github

copy

Full Screen

1import com.meowool.sweekt.datetime.currentHour2import com.meowool.sweekt.datetime.currentMinute3import com.meowool.sweekt.datetime.currentMonth4import com.meowool.sweekt.datetime.currentSecond5import com.meowool.sweekt.datetime.currentYear6import com.meowool.sweekt.datetime.format7import com.meowool.sweekt.datetime.inRange8import com.meowool.sweekt.datetime.nowDateTime9import com.meowool.sweekt.datetime.nowInstant10import com.meowool.sweekt.datetime.toDateTime11import com.meowool.sweekt.datetime.toInstant12import com.meowool.sweekt.datetime.todayOfMonth13import io.kotest.core.spec.style.StringSpec14import io.kotest.matchers.kotlinx.datetime.shouldBeAfter15import io.kotest.matchers.kotlinx.datetime.shouldBeBefore16import io.kotest.matchers.kotlinx.datetime.shouldHaveSameDayAs17import io.kotest.matchers.kotlinx.datetime.shouldHaveSameMonthAs18import io.kotest.matchers.kotlinx.datetime.shouldHaveSameYearAs19import io.kotest.matchers.kotlinx.datetime.shouldNotBeAfter20import io.kotest.matchers.kotlinx.datetime.shouldNotBeBefore21import io.kotest.matchers.kotlinx.datetime.shouldNotHaveSameYearAs22import io.kotest.matchers.should23import io.kotest.matchers.shouldBe24import java.time.Month25/**26 * Tests for DataTimes.kt27 *28 * @author 凛 (RinOrz)29 */30class DataTimeTests : StringSpec({31 val instant = nowInstant32 val dateTime = nowDateTime33 "effective instant time" {34 val instantTime = instant.toDateTime()35 dateTime shouldHaveSameYearAs instantTime36 dateTime shouldHaveSameMonthAs instantTime37 dateTime shouldHaveSameDayAs instantTime38 dateTime.second shouldBe instantTime.second39 }40 "resolved date time string" {41 val resolvedTime = "2020-2-11 07:00".toDateTime("yyyy-M-d HH:mm")42 val resolvedInstant = "2020-2-11 07:00".toInstant("yyyy-M-d HH:mm")43 val resolvedInstantTime = resolvedInstant.toDateTime()44 resolvedTime.toInstant() shouldBe resolvedInstant45 resolvedTime shouldHaveSameYearAs resolvedInstantTime46 resolvedTime shouldHaveSameMonthAs resolvedInstantTime47 resolvedTime shouldHaveSameDayAs resolvedInstantTime48 resolvedTime should {49 it.year shouldBe 202050 it.month shouldBe Month.FEBRUARY51 it.dayOfMonth shouldBe 1152 it.hour shouldBe 753 it.minute shouldBe 054 it.second shouldBe 055 }56 }57 "correct formatting date time" {58 val dateFormatted = dateTime.format("yyyy-M-d H:m:s")59 dateFormatted shouldBe instant.format("yyyy-M-d H:m:s")60 dateFormatted shouldBe "$currentYear-$currentMonth-$todayOfMonth $currentHour:$currentMinute:$currentSecond"61 }62 "date in range" {63 val start = "2010-1-2".toDateTime("yyyy-M-d")64 val stop = "2011-2-4".toDateTime("yyyy-M-d")65 val early = "2010-11-12".toDateTime("yyyy-M-d")66 val lately = "2111-5-8".toDateTime("yyyy-M-d")67 start shouldNotBeAfter stop68 stop shouldNotBeBefore start69 early shouldBeAfter start70 early shouldBeBefore stop71 lately shouldBeAfter start72 lately shouldNotBeBefore stop73 early.inRange(start, stop) shouldBe true74 lately.inRange(start, stop) shouldBe false75 }76 "time in range" {77 val start = "2022-1-2 02:00".toDateTime("yyyy-M-d HH:mm")78 val stop = "2022-1-2 22:54".toDateTime("yyyy-M-d HH:mm")79 val inRange = "2022-1-2 07:00".toDateTime("yyyy-M-d HH:mm")80 val notRange = "2022-1-2 00:00".toDateTime("yyyy-M-d HH:mm")81 val unknownDate = "07:00".toDateTime("HH:mm")82 start shouldHaveSameYearAs stop83 start shouldHaveSameMonthAs stop84 start shouldHaveSameDayAs stop85 inRange shouldNotBeAfter stop86 notRange shouldBeBefore start87 unknownDate shouldNotHaveSameYearAs start88 unknownDate shouldNotHaveSameYearAs stop89 inRange.inRange(start, stop) shouldBe true90 notRange.inRange(start, stop) shouldBe false91 unknownDate.inRange(start, stop) shouldBe false92 }93})...

Full Screen

Full Screen

UserTokenServiceTest.kt

Source:UserTokenServiceTest.kt Github

copy

Full Screen

1package com.github.njuro.jard.user.token2import com.github.njuro.jard.TestDataRepository3import com.github.njuro.jard.WithContainerDatabase4import com.github.njuro.jard.common.Constants5import com.github.njuro.jard.user6import com.github.njuro.jard.userToken7import io.kotest.matchers.booleans.shouldBeTrue8import io.kotest.matchers.date.shouldBeAfter9import io.kotest.matchers.nulls.shouldBeNull10import io.kotest.matchers.nulls.shouldNotBeNull11import io.kotest.matchers.should12import io.kotest.matchers.shouldBe13import io.kotest.matchers.string.shouldNotBeBlank14import org.junit.jupiter.api.Test15import org.springframework.beans.factory.annotation.Autowired16import org.springframework.boot.test.context.SpringBootTest17import org.springframework.scheduling.config.FixedRateTask18import org.springframework.scheduling.config.ScheduledTask19import org.springframework.scheduling.config.ScheduledTaskHolder20import org.springframework.transaction.annotation.Transactional21import java.time.Duration22@SpringBootTest23@WithContainerDatabase24@Transactional25internal class UserTokenServiceTest {26 @Autowired27 private lateinit var userTokenService: UserTokenService28 @Autowired29 private lateinit var scheduledTaskHolder: ScheduledTaskHolder30 @Autowired31 private lateinit var db: TestDataRepository32 @Test33 fun `generate user token`() {34 val user = db.insert(user(username = "user"))35 userTokenService.generateToken(user, UserTokenType.PASSWORD_RESET).should {36 it.value.shouldNotBeBlank()37 it.type shouldBe UserTokenType.PASSWORD_RESET38 it.issuedAt.shouldNotBeNull()39 it.expirationAt.shouldNotBeNull()40 it.expirationAt shouldBeAfter it.issuedAt41 it.user.username shouldBe user.username42 }43 }44 @Test45 fun `resolve token`() {46 val user = db.insert(user(username = "user"))47 val token = db.insert(userToken(user, "abcde", UserTokenType.EMAIL_VERIFICATION))48 userTokenService.resolveToken(token.value, UserTokenType.EMAIL_VERIFICATION).shouldNotBeNull()49 }50 @Test51 fun `don't resolve non-existing token`() {52 userTokenService.resolveToken("xxx", UserTokenType.EMAIL_VERIFICATION).shouldBeNull()53 }54 @Test55 fun `removal of expired tokens is scheduled`() {56 val interval = Duration.parse(Constants.EXPIRED_USER_TOKENS_CHECK_PERIOD).toMillis()57 scheduledTaskHolder.scheduledTasks.map(ScheduledTask::getTask)58 .filterIsInstance<FixedRateTask>()59 .any { it.interval == interval }.shouldBeTrue()60 }61}...

Full Screen

Full Screen

NormalTests.kt

Source:NormalTests.kt Github

copy

Full Screen

1package de.babsek.demo.testingconcepts.part1simpletests2import io.kotest.assertions.json.shouldContainJsonKeyValue3import io.kotest.assertions.json.shouldEqualJson4import io.kotest.assertions.throwables.shouldThrow5import io.kotest.matchers.collections.*6import io.kotest.matchers.date.shouldBeAfter7import io.kotest.matchers.ints.shouldBeGreaterThan8import io.kotest.matchers.should9import io.kotest.matchers.shouldBe10import org.intellij.lang.annotations.Language11import org.junit.jupiter.api.BeforeEach12import org.junit.jupiter.api.Test13import java.time.LocalDate14class NormalTests {15 var x = 516 @BeforeEach17 fun `init tests`() {18 x = 719 }20 @Test21 fun `simple test`() {22 x shouldBe 723 }24 @Test25 fun `numbers are greater or smaller`() {26 7 shouldBeGreaterThan 527 }28 @Test29 fun `true or false`() {30 (7 > 5) shouldBe true31 }32 @Test33 fun `list contains and does not contain element`() {34 (listOf(1, 2) - listOf(1, 2, 3)) should beEmpty()35 (listOf(1, 2) - listOf(2, 3)) shouldHaveSize 136 listOf(1, 2, 3, 4, 5) shouldContain 137 listOf(1, 2, 3, 4, 5) shouldContainInOrder listOf(2, 3)38 listOf(1, 2, 3, 4, 5) shouldNotContain 739 }40 @Test41 fun `something throws`() {42 shouldThrow<IllegalStateException> {43 throw IllegalStateException()44 }45 }46 @Test47 fun `date`() {48 val today = LocalDate.parse("2021-10-14")49 today shouldBeAfter today.minusDays(1)50 }51 @Test52 fun `json`() {53 """{"a": 7}""" shouldEqualJson """{ "a" :7}"""54 testJson55 .shouldContainJsonKeyValue("$.b.field2[1]", 2)56 }57}58@Language("json")59val testJson = """60{61"a": "abcdef",62"b": {63 "field1": "34",64 "field2": [1,2,3]65 }66}67""".trimIndent()...

Full Screen

Full Screen

DateTimeTests.kt

Source:DateTimeTests.kt Github

copy

Full Screen

1import com.meowool.sweekt.datetime.nowDateTime2import com.meowool.sweekt.datetime.nowInstant3import com.meowool.sweekt.datetime.toDateTime4import io.kotest.core.spec.style.StringSpec5import io.kotest.matchers.kotlinx.datetime.shouldBeAfter6import io.kotest.matchers.kotlinx.datetime.shouldHaveSameDayAs7import io.kotest.matchers.kotlinx.datetime.shouldHaveSameMonthAs8import io.kotest.matchers.kotlinx.datetime.shouldHaveSameYearAs9import io.kotest.matchers.shouldBe10/**11 * Tests for /datetime12 *13 * @author 凛 (RinOrz)14 */15class DateTimeTests : StringSpec({16 val instant = nowInstant17 val dateTime = nowDateTime18 "effective instant time" {19 val instantTime = instant.toDateTime()20 nowInstant shouldBeAfter instant21 dateTime shouldHaveSameYearAs instantTime22 dateTime shouldHaveSameMonthAs instantTime23 dateTime shouldHaveSameDayAs instantTime24 dateTime.second shouldBe instantTime.second25 }26})...

Full Screen

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:

YouTube

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful