Best Kotest code snippet using io.kotest.matchers.date.date.before
EventServiceImplTest.kt
Source:EventServiceImplTest.kt
...13import java.time.LocalDateTime14internal class EventServiceImplTest : ShouldSpec() {15 private lateinit var spyEventRepository: SpyEventRepository16 private lateinit var eventService: EventService17 override fun beforeEach(testCase: TestCase) {18 spyEventRepository = SpyEventRepository()19 eventService = EventServiceImpl(20 spyEventRepository21 )22 }23 init {24 should("EventRepository::save ì¤í") {25 val givenLocalDateTime = LocalDateTime.of(2021, 12, 25, 0, 0, 0)26 val givenRegisterEvent = RegisterEvent(27 id = 0,28 basePrice = 0,29 maxPrice = 0,30 limitOfEnrollment = 0,31 name = "",...
BanFacadeTest.kt
Source:BanFacadeTest.kt
1package com.github.njuro.jard.ban2import com.github.njuro.jard.MapperTest3import com.github.njuro.jard.TestDataRepository4import com.github.njuro.jard.WithContainerDatabase5import com.github.njuro.jard.ban6import com.github.njuro.jard.ban.dto.BanDto7import com.github.njuro.jard.common.Constants8import com.github.njuro.jard.toForm9import com.github.njuro.jard.toUnbanForm10import com.github.njuro.jard.user11import com.github.njuro.jard.user.User12import com.github.njuro.jard.user.UserFacade13import com.github.njuro.jard.utils.validation.PropertyValidationException14import com.ninjasquad.springmockk.MockkBean15import io.kotest.assertions.throwables.shouldThrow16import io.kotest.matchers.booleans.shouldBeTrue17import io.kotest.matchers.collections.shouldContainExactly18import io.kotest.matchers.nulls.shouldBeNull19import io.kotest.matchers.nulls.shouldNotBeNull20import io.kotest.matchers.optional.shouldBePresent21import io.kotest.matchers.should22import io.kotest.matchers.shouldBe23import io.mockk.every24import org.junit.jupiter.api.BeforeEach25import org.junit.jupiter.api.DisplayName26import org.junit.jupiter.api.Nested27import org.junit.jupiter.api.Test28import org.springframework.beans.factory.annotation.Autowired29import org.springframework.scheduling.config.FixedRateTask30import org.springframework.scheduling.config.ScheduledTask31import org.springframework.scheduling.config.ScheduledTaskHolder32import org.springframework.transaction.annotation.Transactional33import java.time.Duration34import java.time.OffsetDateTime35@WithContainerDatabase36@Transactional37internal class BanFacadeTest : MapperTest() {38 @Autowired39 private lateinit var banFacade: BanFacade40 @Autowired41 private lateinit var scheduledTaskHolder: ScheduledTaskHolder42 @MockkBean43 private lateinit var userFacade: UserFacade44 @Autowired45 private lateinit var db: TestDataRepository46 private lateinit var user: User47 @BeforeEach48 fun setUp() {49 user = db.insert(user(username = "user"))50 every { userFacade.currentUser } returns user.toDto()51 }52 @Nested53 @DisplayName("create ban")54 inner class CreateBan {55 @Test56 fun `create valid ban`() {57 val banForm = ban().toForm()58 banFacade.createBan(banForm).should {59 it.bannedBy.shouldNotBeNull()60 it.validFrom.shouldNotBeNull()61 }62 }63 @Test64 fun `create valid warning`() {65 val banForm = ban(status = BanStatus.WARNING, validTo = OffsetDateTime.now().plusDays(1)).toForm()66 banFacade.createBan(banForm).validTo.shouldBeNull()67 }68 @Test69 fun `don't create ban when no user is logged in`() {70 val banForm = ban().toForm()71 every { userFacade.currentUser } returns null72 shouldThrow<PropertyValidationException> {73 banFacade.createBan(banForm)74 }75 }76 @Test77 fun `don't create duplicate ban`() {78 db.insert(ban(ip = "127.0.0.1"))79 val banForm = ban(ip = "127.0.0.1").toForm()80 shouldThrow<PropertyValidationException> {81 banFacade.createBan(banForm)82 }83 }84 }85 @Test86 fun `get all bans sorted by start date`() {87 val baseDate = OffsetDateTime.now()88 val ban1 = db.insert(ban(validFrom = baseDate.minusDays(2)))89 val ban2 = db.insert(ban(validFrom = baseDate.plusDays(1)))90 val ban3 = db.insert(ban(validFrom = baseDate.minusDays(1)))91 banFacade.allBans.map(BanDto::getId).shouldContainExactly(ban2.id, ban3.id, ban1.id)92 }93 @Test94 fun `edit ban`() {95 val ban = db.insert(ban(ip = "127.0.0.1", reason = "Spam", validTo = OffsetDateTime.now().plusDays(1)))96 val updatedReason = "Offtopic"97 val updatedExpiration = OffsetDateTime.now().plusDays(10)98 val editForm = ban.toForm().apply { reason = updatedReason; validTo = updatedExpiration; ip = "127.0.0.2" }99 banFacade.editBan(ban.toDto(), editForm)100 db.select(ban).shouldBePresent {101 it.ip shouldBe ban.ip102 it.reason shouldBe updatedReason103 it.validTo shouldBe updatedExpiration104 }105 }106 @Nested107 @DisplayName("unban")108 inner class Unban {109 @Test110 fun `valid unban`() {111 val ban = db.insert(ban(status = BanStatus.ACTIVE))112 val unbanForm = ban.toUnbanForm(unbanReason = "Mistake")113 banFacade.unban(ban.toDto(), unbanForm).should {114 it.status shouldBe BanStatus.UNBANNED115 it.unbannedBy.shouldNotBeNull()116 it.unbanReason shouldBe unbanForm.reason117 }118 }119 @Test120 fun `don't unban when no user is logged in`() {121 val ban = db.insert(ban(status = BanStatus.ACTIVE))122 val unbanForm = ban.toUnbanForm(unbanReason = "Mistake")123 every { userFacade.currentUser } returns null124 shouldThrow<PropertyValidationException> {125 banFacade.unban(ban.toDto(), unbanForm)126 }127 }128 @Test129 fun `don't unban when there is no active ban on ip`() {130 val ban = db.insert(ban(status = BanStatus.EXPIRED))131 val unbanForm = ban.toUnbanForm(unbanReason = "Mistake")132 shouldThrow<PropertyValidationException> {133 banFacade.unban(ban.toDto(), unbanForm)134 }135 }136 @Test137 fun `unban expired bans`() {138 val ban = db.insert(ban(status = BanStatus.ACTIVE, validTo = OffsetDateTime.now().minusDays(1L)))139 banFacade.unbanExpired()140 db.select(ban).shouldBePresent { it.status shouldBe BanStatus.EXPIRED }141 }142 @Test143 fun `check that unban of expired bans is scheduled`() {144 val interval = Duration.parse(Constants.EXPIRED_BANS_CHECK_PERIOD).toMillis()145 scheduledTaskHolder.scheduledTasks.map(ScheduledTask::getTask)146 .filterIsInstance<FixedRateTask>()147 .any { it.interval == interval }.shouldBeTrue()148 }149 }150}...
FakerTest.kt
Source:FakerTest.kt
1package io.github.unredundant.satisfaketion.core2import io.github.unredundant.satisfaketion.core.Extensions.letterify3import io.github.unredundant.satisfaketion.core.util.AnotherSimpleClass4import io.github.unredundant.satisfaketion.core.util.SimpleDataClass5import io.github.unredundant.satisfaketion.core.util.SmolIntGenerator6import io.github.unredundant.satisfaketion.core.util.TestPhoneGenerator7import io.github.unredundant.satisfaketion.core.util.TimingStuff8import io.kotest.core.spec.style.DescribeSpec9import io.kotest.matchers.ints.shouldBeExactly10import io.kotest.matchers.ints.shouldBeGreaterThanOrEqual11import io.kotest.matchers.ints.shouldBeLessThanOrEqual12import io.kotest.matchers.kotlinx.datetime.shouldBeBefore13import io.kotest.matchers.shouldBe14import io.kotest.matchers.shouldNotBe15import io.kotest.matchers.string.shouldMatch16import io.kotest.matchers.string.shouldStartWith17import kotlinx.datetime.LocalDateTime18import org.junit.jupiter.api.assertThrows19class FakerTest : DescribeSpec({20 describe("Faker Core Functionality") {21 it("Can be instantiated around a data class") {22 // act23 val fake = Faker<SimpleDataClass> {24 SimpleDataClass::a { Generator { "feas" } }25 SimpleDataClass::b { Generator { 324 } }26 }27 // assert28 fake shouldNotBe null29 }30 it("Throws an error if a property is invoked multiple times") {31 // assert32 val exception = assertThrows<IllegalArgumentException> {33 Faker<SimpleDataClass> {34 SimpleDataClass::a { Generator { "nice" } }35 SimpleDataClass::a { Generator { "bad" } }36 }37 }38 exception.message shouldStartWith "a has already been registered"39 }40 it("Can generate a faked object") {41 // arrange42 val fake = Faker<SimpleDataClass> {43 SimpleDataClass::a { TestPhoneGenerator }44 SimpleDataClass::b { SmolIntGenerator }45 }46 // act47 val result = fake.generate()48 // assert49 result shouldNotBe null50 result.a shouldMatch "^[1-9]\\d{2}-\\d{3}-\\d{4}"51 result.b shouldBeLessThanOrEqual 2552 result.b shouldBeGreaterThanOrEqual 153 }54 it("Throws an error when not all members have registered a generator") {55 // arrange56 val badFake = Faker<SimpleDataClass> {57 SimpleDataClass::a { TestPhoneGenerator }58 }59 // act60 val result = assertThrows<IllegalArgumentException> {61 badFake.generate()62 }63 // assert64 result.message shouldStartWith "No argument provided for a required parameter: parameter #1 b of fun"65 }66 it("Can generate a class with a default parameter") {67 // arrange68 val fake = Faker<AnotherSimpleClass> {69 AnotherSimpleClass::c { Generator { true } }70 }71 // act72 val result = fake.generate()73 // assert74 result shouldNotBe null75 result.c shouldBe true76 result.d shouldBe "hey dude"77 }78 it("Can generate a class with an overridden default") {79 // arrange80 val fake = Faker<AnotherSimpleClass> {81 AnotherSimpleClass::c { Generator { true } }82 AnotherSimpleClass::d { TestPhoneGenerator }83 }84 // act85 val result = fake.generate()86 // assert87 result shouldNotBe null88 result.c shouldBe true89 result.d shouldNotBe "hey dude"90 }91 }92 describe("Correlated Generators") {93 it("Can perform a simple correlation") {94 // arrange95 val fake = Faker<SimpleDataClass> {96 SimpleDataClass::a { Generator { r -> "?".repeat(r.nextInt(100)).letterify(r) } }97 SimpleDataClass::b {98 CorrelatedPropertyGenerator(SimpleDataClass::a) { i, _ ->99 i.length100 }101 }102 }103 // act104 val result = fake.generate()105 // assert106 result.b shouldBeExactly result.a.length107 }108 it("Can nest multiple correlations") {109 // arrange110 val fake = Faker<TimingStuff> {111 TimingStuff::start {112 Generator { r ->113 LocalDateTime(114 year = r.nextInt(1995, 2022),115 monthNumber = r.nextInt(1, 12),116 dayOfMonth = r.nextInt(1, 28),117 hour = r.nextInt(1, 23),118 minute = r.nextInt(1, 59)119 )120 }121 }122 TimingStuff::end {123 CorrelatedPropertyGenerator(TimingStuff::start) { start, seed ->124 LocalDateTime(125 year = start.year.plus(seed.nextInt(5, 25)),126 monthNumber = seed.nextInt(1, 12),127 dayOfMonth = seed.nextInt(1, 28),128 hour = seed.nextInt(1, 23),129 minute = seed.nextInt(1, 59)130 )131 }132 }133 TimingStuff::middle {134 CorrelatedPropertyGenerator(TimingStuff::start) { start ->135 CorrelatedPropertyGenerator(TimingStuff::end) { end, seed ->136 LocalDateTime(137 year = seed.nextInt(start.year + 1, end.year - 1),138 monthNumber = seed.nextInt(1, 12),139 dayOfMonth = seed.nextInt(1, 28),140 hour = seed.nextInt(1, 23),141 minute = seed.nextInt(1, 59)142 )143 }144 }145 }146 }147 (0..1000).forEach { _ ->148 // act149 val result = fake.generate()150 // assert151 result.start shouldBeBefore result.middle152 result.middle shouldBeBefore result.end153 }154 }155 }156})...
CaPluginTest.kt
Source:CaPluginTest.kt
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}...
FabricationTest.kt
Source:FabricationTest.kt
...34 }35 }36 }37 }38 given("an expiration date before now") {39 `when`("Fabrication is validated") {40 then("it should throw VaccineExpiredException") {41 val expirationDateMock = mockk<ExpirationDate>()42 every { expirationDateMock.mustBeValid() } throws43 ExpiredVaccineException("Test expiration", "E", "A")44 val exception = shouldThrowExactly<ExpiredVaccineException> {45 fabrication {46 company = UUID.randomUUID().toString()47 batch = mockk()48 expirationDate = expirationDateMock49 }.mustBeValid()50 }51 exception shouldHaveMessage "Test expiration"52 exception.explain() shouldBe "Expected: E, Actual: A"...
DataTimeTests.kt
Source:DataTimeTests.kt
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})...
NormalTests.kt
Source:NormalTests.kt
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()...
CreateTrialUserImplTest.kt
Source:CreateTrialUserImplTest.kt
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}...
before
Using AI Code Generation
1 fun before() {2 println("Before")3 }4 fun after() {5 println("After")6 }7 fun beforeTest() {8 val currentDate = Date()9 val givenDate = Date(2020, 6, 1)10 currentDate should beBefore(givenDate)11 }12 fun afterTest() {13 val currentDate = Date()14 val givenDate = Date(2020, 6, 1)15 currentDate should beAfter(givenDate)16 }17 fun equalTest() {18 val currentDate = Date()19 val givenDate = Date()20 currentDate should beEqual(givenDate)21 }22 fun notEqualTest() {23 val currentDate = Date()24 val givenDate = Date(2020, 6, 1)25 currentDate shouldNot beEqual(givenDate)26 }27 fun beforeTest() {28 val currentDate = Date()29 val givenDate = Date(2020, 6, 1)30 currentDate should beBefore(givenDate)31 }32 fun afterTest() {33 val currentDate = Date()34 val givenDate = Date(2020, 6, 1)35 currentDate should beAfter(givenDate)36 }37 fun equalTest() {38 val currentDate = Date()39 val givenDate = Date()40 currentDate should beEqual(givenDate)41 }42 fun notEqualTest() {43 val currentDate = Date()44 val givenDate = Date(2020,
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!