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

Best Kotest code snippet using io.kotest.matchers.date.date.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

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

CaPluginTest.kt

Source:CaPluginTest.kt Github

copy

Full Screen

1package family.haschka.wolkenschloss.gradle.ca2import family.haschka.wolkenschloss.testing.Template3import family.haschka.wolkenschloss.testing.createRunner4import io.kotest.assertions.assertSoftly5import io.kotest.core.spec.IsolationMode6import io.kotest.core.spec.style.FunSpec7import io.kotest.engine.spec.tempdir8import io.kotest.matchers.file.shouldBeReadable9import io.kotest.matchers.file.shouldContainFile10import io.kotest.matchers.file.shouldExist11import io.kotest.matchers.file.shouldNotBeWriteable12import io.kotest.matchers.ints.shouldBeGreaterThan13import io.kotest.matchers.shouldBe14import org.bouncycastle.asn1.x500.X500Name15import org.bouncycastle.asn1.x509.KeyUsage16import org.gradle.testkit.runner.TaskOutcome17import java.time.LocalDate18import java.time.LocalTime19import java.time.ZoneOffset20import java.time.ZonedDateTime21import java.util.*22class CaPluginTest : FunSpec({23 autoClose(Template("ca")).withClone {24 context("A project using com.github.wolkenschloss.ca gradle plugin") {25 val xdgDataHome = tempdir()26 val environment = mapOf("XDG_DATA_HOME" to xdgDataHome.absolutePath)27 context("executing ca task") {28 val result = createRunner()29 .withArguments(CaPlugin.CREATE_TASK_NAME)30 .withEnvironment(environment)31 .build()32 test("should be successful") {33 result.task(":${CaPlugin.CREATE_TASK_NAME}")!!.outcome shouldBe TaskOutcome.SUCCESS34 }35 test("should create self signed root certificate") {36 assertSoftly(CertificateWrapper.read(xdgDataHome.resolve("wolkenschloss/ca/ca.crt"))) {37 x509Certificate.basicConstraints shouldBeGreaterThan -138 x509Certificate.basicConstraints shouldBe Int.MAX_VALUE39 keyUsage.hasUsages(KeyUsage.keyCertSign) shouldBe true40 issuer shouldBe X500Name(CaPlugin.TRUST_ANCHOR_DEFAULT_SUBJECT)41 subject shouldBe X500Name(CaPlugin.TRUST_ANCHOR_DEFAULT_SUBJECT)42 }43 }44 test("should create read only certificate") {45 assertSoftly(xdgDataHome.resolve("wolkenschloss/ca/ca.crt")) {46 shouldBeReadable()47 shouldNotBeWriteable()48 }49 }50 test("should create readonly private key") {51 assertSoftly(xdgDataHome.resolve("wolkenschloss/ca/ca.key")) {52 shouldNotBeWriteable()53 shouldBeReadable()54 readPrivateKey().algorithm shouldBe "RSA"55 }56 }57 }58 context("executing truststore task") {59 val result = createRunner()60 .withArguments(CaPlugin.TRUSTSTORE_TASK_NAME)61 .withEnvironment(environment)62 .build()63 test("should execute successfully") {64 result.task(":${CaPlugin.TRUSTSTORE_TASK_NAME}")!!.outcome shouldBe TaskOutcome.SUCCESS65 }66 test("should create truststore file") {67 xdgDataHome.resolve("wolkenschloss/ca/ca.jks").shouldExist()68 }69 }70 test("should customize validity") {71 val start = ZonedDateTime.of(72 LocalDate.of(2022, 2, 4),73 LocalTime.MIDNIGHT,74 ZoneOffset.UTC75 )76 val end = ZonedDateTime.of(77 LocalDate.of(2027, 2, 4),78 LocalTime.MIDNIGHT,79 ZoneOffset.UTC80 )81 val result = createRunner()82 .withArguments(CaPlugin.CREATE_TASK_NAME, "-DnotBefore=$start", "-DnotAfter=$end")83 .withEnvironment(environment)84 .build()85 result.task(":${CaPlugin.CREATE_TASK_NAME}")!!.outcome shouldBe TaskOutcome.SUCCESS86 val certificate = xdgDataHome.resolve("wolkenschloss/ca/ca.crt")87 .readX509Certificate()88 assertSoftly(certificate) {89 notBefore.toUtc() shouldBe start90 notAfter.toUtc() shouldBe end91 }92 }93 test("should create output in user defined location") {94 val result = createRunner()95 .withArguments("createInUserDefinedLocation")96 .withEnvironment(environment)97 .build()98 result.task(":createInUserDefinedLocation")!!.outcome shouldBe TaskOutcome.SUCCESS99 assertSoftly(workingDirectory.resolve("build/ca")) {100 shouldContainFile("ca.crt")101 shouldContainFile("ca.key")102 }103 }104 }105 }106}) {107 override fun isolationMode(): IsolationMode = IsolationMode.InstancePerLeaf108}109private fun Date.toUtc(): ZonedDateTime {110 return ZonedDateTime.ofInstant(this.toInstant(), ZoneOffset.UTC)111}...

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

FabricationTest.kt

Source:FabricationTest.kt Github

copy

Full Screen

...52 exception.explain() shouldBe "Expected: E, Actual: A"53 }54 }55 }56 given("an expiration date after now") {57 `when`("Fabrication is validated") {58 then("it should not throw any exception") {59 val expirationDateMock = mockk<ExpirationDate>()60 every { expirationDateMock.mustBeValid() } returns expirationDateMock61 shouldNotThrowAny {62 fabrication {63 company = UUID.randomUUID().toString()64 batch = mockk()65 expirationDate = expirationDateMock66 }.mustBeValid()67 }68 }69 }70 }...

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

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

after

Using AI Code Generation

copy

Full Screen

1fun Date.shouldBeAfter(date: Date) = this should beAfter(date)2fun Date.shouldBeBefore(date: Date) = this should beBefore(date)3fun Date.shouldBeEqual(date: Date) = this should beEqual(date)4fun Date.shouldBeEqualOrAfter(date: Date) = this should beEqualOrAfter(date)5fun Date.shouldBeEqualOrBefore(date: Date) = this should beEqualOrBefore(date)6fun Date.shouldBeInRange(date1: Date, date2: Date) = this should beInRange(date1, date2)7fun Date.shouldBeInRange(range: ClosedRange<Date>) = this should beInRange(range)8fun Date.shouldBeInRange(range: DateRange) = this should beInRange(range)9fun Date.shouldBeInRange(range: Range<Date>) = this should beInRange(range)10fun Date.shouldBeInRange(range: io.kotest.matchers.date.dateRange) = this should beInRange(range)11fun Date.shouldBeInSameDayAs(date: Date) = this should beInSameDayAs(date)12fun Date.shouldBeInSameHourAs(date: Date) = this should beInSameHourAs(date)13fun Date.shouldBeInSameMinuteAs(date: Date) = this should beInSameMinuteAs(date)

Full Screen

Full Screen

after

Using AI Code Generation

copy

Full Screen

1test( "Date should be in the past" ) {2 val date = Date( 1 )3}4test( "Date should not be in the past" ) {5 val date = Date( 1000000 )6}7test( "Date should be in the future" ) {8 val date = Date( 1000000 )9}10test( "Date should not be in the future" ) {11 val date = Date( 1 )12}13test( "Date should be today" ) {14 val date = Date()15}16test( "Date should not be today" ) {17 val date = Date( 1 )18}19test( "Date should be yesterday" ) {20 val date = Date( 1 )21}22test( "Date should not be yesterday" ) {23 val date = Date()24}25test( "Date should be tomorrow" ) {26 val date = Date( 1000000 )27}28test( "Date should not be tomorrow" ) {29 val date = Date()30}31test( "Date should be in the same year as" ) {32 val date = Date( 1000000 )33}34test( "Date should not be in the same year as" ) {35 val date = Date( 1 )36}37test( "Date should be in the same month as" ) {38 val date = Date( 1000000 )39}40test( "Date should not be in the same month as" ) {41 val date = Date( 1 )42 date shouldNot beInTheSameMonthAs( Date( 100

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.

Most used method in date

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful