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

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

DateMatchersTest.kt

Source:DateMatchersTest.kt Github

copy

Full Screen

...277 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC) shouldNotBe within(Duration.ofDays(1), LocalDateTime.of(2014, 2, 1, 3, 2, 1).atOffset(ZoneOffset.UTC))278 LocalDateTime.of(2014, 1, 2, 4, 3, 2).atOffset(ZoneOffset.UTC).shouldBeWithin(Duration.ofDays(1), LocalDateTime.of(2014, 1, 3, 4, 3, 2).atOffset(ZoneOffset.UTC))279 LocalDateTime.of(2014, 1, 2, 3, 2, 1).atOffset(ZoneOffset.UTC).shouldNotBeWithin(Duration.ofDays(1), LocalDateTime.of(2014, 2, 1, 3, 2, 1).atOffset(ZoneOffset.UTC))280 }281 "LocalTime shouldBe between" {282 LocalTime.of(14, 20, 50, 1000).shouldBeBetween(LocalTime.of(14, 20, 49), LocalTime.of(14, 20, 51))283 LocalTime.of(14, 20, 50, 1000).shouldNotBeBetween(LocalTime.of(14, 20, 51), LocalTime.of(14, 20, 52))284 }285 "LocalDate shouldBe between" {286 LocalDate.of(2019, 2, 16).shouldBeBetween(LocalDate.of(2019, 2, 15), LocalDate.of(2019, 2, 17))287 LocalDate.of(2019, 2, 16).shouldNotBeBetween(LocalDate.of(2019, 2, 17), LocalDate.of(2019, 2, 18))288 }289 "LocalDateTime shouldBe between" {290 LocalDateTime.of(2019, 2, 16, 12, 0, 0).shouldBeBetween(LocalDateTime.of(2019, 2, 15, 12, 0, 0), LocalDateTime.of(2019, 2, 17, 12, 0, 0))291 LocalDateTime.of(2019, 2, 16, 12, 0, 0).shouldBeBetween(LocalDateTime.of(2019, 2, 16, 10, 0, 0), LocalDateTime.of(2019, 2, 16, 14, 0, 0))292 LocalDateTime.of(2019, 2, 16, 12, 0, 0).shouldNotBeBetween(LocalDateTime.of(2019, 2, 17, 12, 0, 0), LocalDateTime.of(2019, 2, 18, 12, 0, 0))293 LocalDateTime.of(2019, 2, 16, 12, 0, 0).shouldNotBeBetween(LocalDateTime.of(2019, 2, 16, 18, 0, 0), LocalDateTime.of(2019, 2, 16, 20, 0, 0))294 }295 "ZonedDateTime shouldBe between" {296 ZonedDateTime.of(2019, 2, 16, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo")).shouldBeBetween(ZonedDateTime.of(2019, 2, 15, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo")), ZonedDateTime.of(2019, 2, 17, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo")))297 ZonedDateTime.of(2019, 2, 16, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo")).shouldNotBeBetween(ZonedDateTime.of(2019, 2, 17, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo")), ZonedDateTime.of(2019, 2, 18, 12, 0, 0, 0, ZoneId.of("America/Sao_Paulo")))298 }299 "OffsetDateTime shouldBe between" {300 OffsetDateTime.of(2019, 2, 16, 12, 0, 0, 0, ZoneOffset.ofHours(-3)).shouldBeBetween(OffsetDateTime.of(2019, 2, 15, 12, 0, 0, 0, ZoneOffset.ofHours(-3)), OffsetDateTime.of(2019, 2, 17, 12, 0, 0, 0, ZoneOffset.ofHours(-3)))301 OffsetDateTime.of(2019, 2, 15, 12, 0, 0, 0, ZoneOffset.ofHours(-3)).shouldNotBeBetween(OffsetDateTime.of(2019, 2, 16, 12, 0, 0, 0, ZoneOffset.ofHours(-3)), OffsetDateTime.of(2019, 2, 17, 12, 0, 0, 0, ZoneOffset.ofHours(-3)))302 }303 "LocalDate.shouldBeToday() should match today" {304 LocalDate.now().shouldBeToday()305 }306 "LocalDateTime.shouldBeToday() should match today" {307 LocalDateTime.now().shouldBeToday()308 }309 "LocalDate.shouldBeToday() should not match the past" {310 shouldFail {311 LocalDate.of(2002, Month.APRIL, 1).shouldBeToday()312 }313 }...

Full Screen

Full Screen

matchers.kt

Source:matchers.kt Github

copy

Full Screen

...122 shouldNotBeEmpty()123 }124 // executable, hidden, readable, smaller, writeable, containFile, extension, path, ...125 LocalDate.now().shouldBeToday()126 // before/after, within, same, between, have year/month/day/hour/...127 LocalTime.now().shouldHaveSameHoursAs(LocalTime.now())128 // before/after/between, sameMinute/Seconds/Nanos129 }130 it("numbers") {131 1 shouldBeLessThan 2132 1 shouldBeLessThanOrEqual 1 // Int-based; returns this133 1 shouldBeLessThanOrEqualTo 1 // Comparble-based; void134 1 shouldBeEqualComparingTo 1 // Comparable-based135 1.shouldBeBetween(0, 2)136 1 shouldBeInRange 0..2137 0.shouldBeZero()138 1.shouldBePositive()139 1.shouldBeOdd()140 (1.2).shouldBe(1.20001.plusOrMinus(Percentage(20.0)))141 (1.2).shouldNotBeNaN()142 }143 it("strings") {144 // generic: "abc" shouldBe "abc"145 "aBc" shouldBeEqualIgnoringCase "abc"146 "".shouldBeEmpty()147 " ".shouldBeBlank() // empty or whitespace148 "abc" shouldContain ("b")149 "aBc" shouldContainIgnoringCase "bc"150 "x-a-x" shouldContain """\-[a-z]\-""".toRegex()151 "-a-" shouldMatch """\-[a-z]\-""".toRegex()152 "abc" shouldStartWith ("a")153 "abc" shouldEndWith ("c")154 "ab aa" shouldContainOnlyOnce "aa"155 "abc".shouldBeLowerCase()156 "ABC".shouldBeUpperCase()157 "abc" shouldHaveLength 3158 "a\nb" shouldHaveLineCount 2159 "ab" shouldHaveMinLength 1 shouldHaveMaxLength 3160 "abc" shouldHaveSameLengthAs "foo"161 "1".shouldBeInteger()162 "12".shouldContainOnlyDigits()163 "abc1".shouldContainADigit() // at least one164 }165 it("types") {166 @Connotation167 open class SuperType()168 class SubType : SuperType()169 val sameRef = SuperType()170 sameRef.shouldBeSameInstanceAs(sameRef)171 val superType: SuperType = SubType()172 superType.shouldBeTypeOf<SubType>() // exact runtime match (SuperType won't work!)173 superType.shouldBeInstanceOf<SuperType>() // T or below174// SubType().shouldHaveAnnotation(Connotation::class)175 val nullable: String? = null176 nullable.shouldBeNull()177 }178 it("collections") {179 emptyList<Int>().iterator().shouldBeEmpty()180 listOf(1).iterator().shouldHaveNext()181 listOf(1, 2) shouldContain 1 // at least182 listOf(1, 2) shouldContainExactly listOf(1, 2) // in-order; not more183 listOf(1, 2) shouldContainExactlyInAnyOrder listOf(2, 1) // out-order; not more184 listOf(0, 3, 0, 4, 0).shouldContainInOrder(3, 4) // possible items in between185 listOf(1) shouldNotContainAnyOf listOf(2, 3) // black list186 listOf(1, 2, 3) shouldContainAll listOf(3, 2) // out-order; more187 listOf(1, 2, 3).shouldBeUnique() // no duplicates188 listOf(1, 2, 2).shouldContainDuplicates() // at least one duplicate189 listOf(1, 2).shouldNotHaveElementAt(1, 3)190 listOf(1, 2) shouldStartWith 1191 listOf(1, 2) shouldEndWith 2192 listOf(1, 2) shouldContainAnyOf listOf(2, 3)193 val x = SomeType(1)194 x shouldBeOneOf listOf(x) // by reference/instance195 x shouldBeIn listOf(SomeType(1)) // by equality/structural196 listOf(1, 2, null).shouldContainNull()197 listOf(1) shouldHaveSize 1198 listOf(1).shouldBeSingleton() // size == 1...

Full Screen

Full Screen

timestampTest.kt

Source:timestampTest.kt Github

copy

Full Screen

...48 "timestamp of current instance should not be before the another timestamp of same instance" {49 val nowInstance = Instant.now()50 Timestamp.from(nowInstance) shouldNotBeBefore Timestamp.from(nowInstance)51 }52 "current timestamp should be between timestamp of past and future" {53 val nowInstant = Instant.now()54 val currentTimestamp = Timestamp.from(nowInstant)55 val pastTimestamp = Timestamp.from(nowInstant.minusMillis(5000))56 val futureTimestamp = Timestamp.from(nowInstant.plusMillis(5000))57 currentTimestamp.shouldBeBetween(pastTimestamp, futureTimestamp)58 }59 "past timestamp should not be between timestamp of current instant and future" {60 val nowInstant = Instant.now()61 val currentTimestamp = Timestamp.from(nowInstant)62 val pastTimestamp = Timestamp.from(nowInstant.minusMillis(5000))63 val futureTimestamp = Timestamp.from(nowInstant.plusMillis(5000))64 pastTimestamp.shouldNotBeBetween(currentTimestamp, futureTimestamp)65 }66 "future timestamp should not be between timestamp of current instant and future" {67 val nowInstant = Instant.now()68 val currentTimestamp = Timestamp.from(nowInstant)69 val pastTimestamp = Timestamp.from(nowInstant.minusMillis(5000))70 val futureTimestamp = Timestamp.from(nowInstant.plusMillis(5000))71 futureTimestamp.shouldNotBeBetween(pastTimestamp, currentTimestamp)72 }73 }74}...

Full Screen

Full Screen

UpdateQueryBuilderTest.kt

Source:UpdateQueryBuilderTest.kt Github

copy

Full Screen

...52 builder = builder!!53 .set { TestEntity::dateTime.eq(values[0]) }54 .where {55 TestEntity::id.eq(values[1]) or {56 fieldOf(TestEntity::number).between(values[2]).and(values[3])57 } and {58 fieldOf(TestEntity::enum).neq(values[4]) and fieldOf(TestEntity::name).inList(values[5] as List<*>)59 }60 }61 val queryString = builder!!.getQueryString()62 queryString shouldBe "UPDATE TestEntity SET dateTime = :DateTime WHERE id = :Id OR (number BETWEEN :Number1 AND :Number2) AND (enum != :Enum AND name IN :Name)"63 if (mocking) {64 for (i in values.indices) {65 builder!!.build()66 values[i] shouldBeIn parameters67 }68 } else {69 val tx = session.transaction70 tx.begin()...

Full Screen

Full Screen

StampsAndCoinsGeneratorKtTest.kt

Source:StampsAndCoinsGeneratorKtTest.kt Github

copy

Full Screen

...20 main(arrayOf())21 }22 }23 "getRandomDimMM" should {24 "Get dim between considered range" {25 getRandomDimMM(1, 10) shouldBeInRange (LongRange(1, 10))26 }27 }28 "getRandomDiameterMM" should {29 getRandomDiameterMM(1, 10) shouldBeInRange (LongRange(1, 10))30 }31 "getRandomCurrency" should {32 getRandomCurrency() shouldBeIn Currency.values()33 }34 "getRandomValueUpTo" should {35 getRandomValueUpTo(10) shouldBeInRange LongRange(1, 10)36 }37 "getRandomYearFrom" should {38 getRandomYearFrom(1900) shouldBeGreaterThanOrEqual 1900...

Full Screen

Full Screen

instantMatcherTest.kt

Source:instantMatcherTest.kt Github

copy

Full Screen

...48 }49 "instant of same time should not be after another instant of same time" {50 Instant.ofEpochMilli(30000) shouldNotBeAfter Instant.ofEpochMilli(30000)51 }52 "current instant should be between past instant and future instant" {53 val currentInstant = Instant.now()54 val pastInstant = currentInstant.minusMillis(30000)55 val futureInstant = currentInstant.plusMillis(30000)56 currentInstant.shouldBeBetween(pastInstant, futureInstant)57 }58 "past instant should not be between current instant and future instant" {59 val currentInstant = Instant.now()60 val pastInstant = currentInstant.minusMillis(30000)61 val futureInstant = currentInstant.plusMillis(30000)62 pastInstant.shouldNotBeBetween(currentInstant, futureInstant)63 }64 "future instant should not be between past instant and current instant" {65 val currentInstant = Instant.now()66 val pastInstant = currentInstant.minusMillis(30000)67 val futureInstant = currentInstant.plusMillis(30000)68 futureInstant.shouldNotBeBetween(pastInstant, currentInstant)69 }70 }71}...

Full Screen

Full Screen

MoneyTransferTest.kt

Source:MoneyTransferTest.kt Github

copy

Full Screen

...25 accountA = accountA.process(MakeDeposit(accountA.aggregateId, Money.of(100.0), LocalDate.now())).orNull()!!26 accountB = AccountAggregate(UUID.randomUUID(), eventStore)27 transferId = UUID.randomUUID()28 }29 "should transfer money between two account" {30 val date = LocalDate.now()31 MoneyTransfer.transferMoney(accountA, accountB, Money.of(100.0), date, transferId)32 eventStore.retrieveEvents(accountA) shouldContainAll listOf(TransferWithdrawMade(accountA.aggregateId, transferId, Money.of(100.0), date))33 eventStore.retrieveEvents(accountB) shouldContainAll listOf(TransferDepositMade(accountB.aggregateId, transferId, Money.of(100.0), date))34 loadAccount(accountB.aggregateId, eventStore)!!.balance shouldBe Money.of(100.0)35 loadAccount(accountA.aggregateId, eventStore)!!.balance shouldBe Money.of(0.0)36 }37 "should not transfer money if withdraw account has not enough money" {38 val result = MoneyTransfer.transferMoney(accountB, accountA, Money.of(100.0), LocalDate.now(), transferId)39 result shouldBe Either.Left(NotEnoughMoney(Money.of(100.0)))40 }41 "should cancel transfer and put back money if deposit part fail" {42 val exception = Exception("simulated error")43 accountB = AccountAggregate(UUID.randomUUID(), object : EventStore {...

Full Screen

Full Screen

CreateTrialUserImplTest.kt

Source:CreateTrialUserImplTest.kt Github

copy

Full Screen

1package com.falcon.falcon.core.usecase.trial2import com.falcon.falcon.core.entity.User3import com.falcon.falcon.core.enumeration.UserType4import com.falcon.falcon.core.usecase.user.CreateUserUseCase5import io.kotest.matchers.date.shouldBeBetween6import io.kotest.matchers.shouldBe7import io.kotest.matchers.string.shouldBeUUID8import io.kotest.matchers.types.shouldBeTypeOf9import io.mockk.clearAllMocks10import io.mockk.every11import io.mockk.mockk12import org.junit.jupiter.api.BeforeEach13import org.junit.jupiter.api.Test14import org.junit.jupiter.api.TestInstance15import java.time.Instant16import java.time.temporal.ChronoUnit17@TestInstance(TestInstance.Lifecycle.PER_CLASS)18internal class CreateTrialUserImplTest {19 private val createUserUseCase: CreateUserUseCase = mockk()20 private val trialDuration = 1L21 private val underTest: CreateTrialUserImpl = CreateTrialUserImpl(createUserUseCase, trialDuration)22 @BeforeEach23 fun init() {24 clearAllMocks()25 }26 @Test27 fun `Should generate random user`() {28 // Given29 every { createUserUseCase.execute(any()) } returnsArgument 030 // When31 val result = underTest.execute()32 // Then33 result.shouldBeTypeOf<User>()34 result.username.shouldBeUUID()35 result.password.shouldBeUUID()36 result.type.shouldBe(UserType.TRIAL)37 result.expirationDate?.shouldBeBetween(38 Instant.now().plus(50, ChronoUnit.MINUTES),39 Instant.now().plus(70, ChronoUnit.MINUTES),40 )41 }42}...

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