How to use offsetdatetime class of io.kotest.matchers.date package

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

BanFacadeTest.kt

Source:BanFacadeTest.kt Github

copy

Full Screen

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}...

Full Screen

Full Screen

CreateFlightUseCaseTest.kt

Source:CreateFlightUseCaseTest.kt Github

copy

Full Screen

1package com.example.airline.flight.usecase.flight2import com.example.airline.flight.domain.aircraft.AircraftId3import com.example.airline.flight.domain.flight.AircraftIsAvailableOnTime4import com.example.airline.flight.domain.flight.AirportAllowsFlightOnTime5import com.example.airline.flight.domain.flight.FlightIdGenerator6import com.example.airline.flight.usecase.*7import com.example.airline.flight.usecase.flight.CreateFlightUseCaseError.AircraftIsNotAvailableOnTimeUseCaseError8import com.example.airline.flight.usecase.flight.CreateFlightUseCaseError.AirportNotAllowFlightOnTimeUseCaseError9import io.kotest.assertions.arrow.either.shouldBeLeft10import io.kotest.assertions.arrow.either.shouldBeRight11import io.kotest.matchers.maps.shouldBeEmpty12import io.kotest.matchers.nulls.shouldNotBeNull13import io.kotest.matchers.shouldBe14import org.junit.jupiter.api.Test15import java.time.OffsetDateTime16internal class CreateFlightUseCaseTest {17 @Test18 fun `successfully added`() {19 val departureAirport = airport()20 val arrivalAirport = airport()21 val flightDate = flightDate()22 val aircraftId = aircraftId()23 val persister = TestFlightPersister()24 val result = CreateFlightUseCase(25 flightPersister = persister,26 idGenerator = TestFlightIdGenerator,27 aircraftIsAvailable = AircraftIsAvailable,28 airportAllowsFlight = AirportAllowsFlight29 ).execute(30 CreateFlightRequest(31 departureAirport = departureAirport,32 arrivalAirport = arrivalAirport,33 flightDate = flightDate,34 aircraftId = aircraftId35 )36 )37 val id = TestFlightIdGenerator.id38 result shouldBeRight {39 it shouldBe id40 }41 val flight = persister[id]42 flight.shouldNotBeNull()43 flight.id shouldBe id44 flight.departureAirport shouldBe departureAirport45 flight.arrivalAirport shouldBe arrivalAirport46 flight.flightDate shouldBe flightDate47 flight.aircraftId shouldBe aircraftId48 }49 @Test50 fun `aircraft is not available`() {51 val persister = TestFlightPersister()52 val result = CreateFlightUseCase(53 flightPersister = persister,54 idGenerator = TestFlightIdGenerator,55 aircraftIsAvailable = AircraftIsNotAvailable,56 airportAllowsFlight = AirportAllowsFlight57 ).execute(58 CreateFlightRequest(59 departureAirport = airport(),60 arrivalAirport = airport(),61 flightDate = flightDate(),62 aircraftId = aircraftId()63 )64 )65 result shouldBeLeft AircraftIsNotAvailableOnTimeUseCaseError66 persister.shouldBeEmpty()67 }68 @Test69 fun `airport does not allow flight`() {70 val persister = TestFlightPersister()71 val result = CreateFlightUseCase(72 flightPersister = persister,73 idGenerator = TestFlightIdGenerator,74 aircraftIsAvailable = AircraftIsAvailable,75 airportAllowsFlight = AirportNotAllowsFlight76 ).execute(77 CreateFlightRequest(78 departureAirport = airport(),79 arrivalAirport = airport(),80 flightDate = flightDate(),81 aircraftId = aircraftId()82 )83 )84 result shouldBeLeft AirportNotAllowFlightOnTimeUseCaseError85 persister.shouldBeEmpty()86 }87 object TestFlightIdGenerator : FlightIdGenerator {88 val id = flightId()89 override fun generate() = id90 }91 object AircraftIsAvailable : AircraftIsAvailableOnTime {92 override fun check(aircraftId: AircraftId, datetime: OffsetDateTime) = true93 }94 object AircraftIsNotAvailable : AircraftIsAvailableOnTime {95 override fun check(aircraftId: AircraftId, datetime: OffsetDateTime) = false96 }97 object AirportAllowsFlight : AirportAllowsFlightOnTime {98 override fun check(datetime: OffsetDateTime) = true99 }100 object AirportNotAllowsFlight : AirportAllowsFlightOnTime {101 override fun check(datetime: OffsetDateTime) = false102 }103}...

Full Screen

Full Screen

OrderRepositoryTest.kt

Source:OrderRepositoryTest.kt Github

copy

Full Screen

1package kr.bistroad.orderservice.order.infrastructure2import io.kotest.matchers.collections.shouldBeEmpty3import io.kotest.matchers.nulls.shouldBeNull4import io.kotest.matchers.nulls.shouldNotBeNull5import io.kotest.matchers.shouldBe6import kr.bistroad.orderservice.order.domain.*7import org.junit.jupiter.api.AfterEach8import org.junit.jupiter.api.Test9import org.springframework.beans.factory.annotation.Autowired10import org.springframework.boot.test.context.SpringBootTest11import org.springframework.data.repository.findByIdOrNull12import java.time.OffsetDateTime13import java.util.*14@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)15internal class OrderRepositoryTest {16 @Autowired17 private lateinit var orderRepository: OrderRepository18 @AfterEach19 fun clear() = orderRepository.deleteAll()20 @Test21 fun `Saves an order`() {22 val order = randomOrder()23 orderRepository.save(order)24 val foundOrder = orderRepository.findByIdOrNull(order.id)25 foundOrder.shouldNotBeNull()26 foundOrder.shouldBe(order)27 }28 @Test29 fun `Deletes a user`() {30 val order = randomOrder()31 orderRepository.save(order)32 val orderId = order.id33 val numDeleted = orderRepository.removeById(orderId)34 numDeleted.shouldBe(1)35 orderRepository.findByIdOrNull(orderId).shouldBeNull()36 orderRepository.findAll().shouldBeEmpty()37 }38 private fun randomOrder() = PlacedOrder(39 store = Store(40 id = UUID.randomUUID(),41 owner = StoreOwner(UUID.randomUUID()),42 name = "Store"43 ),44 customer = Customer(45 id = UUID.randomUUID()46 ),47 orderLines = mutableListOf(48 OrderLine(49 item = OrderedItem(50 id = UUID.randomUUID(),51 name = "a",52 price = 1000.053 ),54 amount = 155 ),56 OrderLine(57 item = OrderedItem(58 id = UUID.randomUUID(),59 name = "b",60 price = 0.00161 ),62 amount = 263 )64 ),65 timestamp = OffsetDateTime.now(),66 tableNum = 0,67 progress = OrderProgress.REQUESTED68 )69}...

Full Screen

Full Screen

BoardServiceTest.kt

Source:BoardServiceTest.kt Github

copy

Full Screen

1package com.github.njuro.jard.board2import com.github.njuro.jard.TestDataRepository3import com.github.njuro.jard.WithContainerDatabase4import com.github.njuro.jard.board5import io.kotest.assertions.throwables.shouldThrow6import io.kotest.matchers.collections.shouldContainInOrder7import io.kotest.matchers.optional.shouldBeEmpty8import io.kotest.matchers.optional.shouldBePresent9import io.kotest.matchers.shouldBe10import io.kotest.matchers.shouldNotBe11import org.junit.jupiter.api.Test12import org.springframework.beans.factory.annotation.Autowired13import org.springframework.boot.test.context.SpringBootTest14import java.time.OffsetDateTime15@SpringBootTest16@WithContainerDatabase17internal class BoardServiceTest {18 @Autowired19 private lateinit var boardService: BoardService20 @Autowired21 private lateinit var db: TestDataRepository22 @Test23 fun `save board`() {24 val board = board("r", postCounter = 0L)25 val created = boardService.saveBoard(board)26 created.id shouldNotBe null27 created.postCounter shouldBe 1L28 }29 @Test30 fun `find all boards sorted by creation date`() {31 val baseDate = OffsetDateTime.now()32 val first = db.insert(board(label = "r", createdAt = baseDate))33 val second = db.insert(board(label = "sp", createdAt = baseDate.plusDays(1)))34 val third = db.insert(board(label = "fit", createdAt = baseDate.minusDays(1)))35 boardService.allBoards.shouldContainInOrder(third, first, second)36 }37 @Test38 fun `resolve board by label`() {39 val board = db.insert(board(label = "r"))40 boardService.resolveBoard(board.label) shouldBe board41 }42 @Test43 fun `don't resolve non-existing board`() {44 shouldThrow<BoardNotFoundException> {45 boardService.resolveBoard("xxx")46 }47 }48 @Test49 fun `register new post`() {50 val board = db.insert(board(label = "r", postCounter = 5L))51 boardService.registerNewPost(board) shouldBe board.postCounter52 db.select(board).shouldBePresent { it.postCounter shouldBe board.postCounter + 1 }53 }54 @Test55 fun `delete board`() {56 val board = db.insert(board(label = "r"))57 boardService.deleteBoard(board)58 db.select(board).shouldBeEmpty()59 }60}...

Full Screen

Full Screen

AircraftTest.kt

Source:AircraftTest.kt Github

copy

Full Screen

1package com.example.airline.leasing.domain.aircraft2import io.kotest.assertions.arrow.either.shouldBeLeft3import io.kotest.assertions.arrow.either.shouldBeRight4import io.kotest.matchers.collections.shouldContainExactly5import io.kotest.matchers.shouldBe6import org.junit.jupiter.api.Test7import java.time.OffsetDateTime8class AircraftTest {9 val id = aircraftId()10 private val idGenerator = object : AircraftIdGenerator {11 override fun generate() = id12 }13 @Test14 fun `create aircraft - success`() {15 val manufacturer = manufacturer()16 val payload = payload()17 val releaseDate = OffsetDateTime.now()18 val registrationNumber = registrationNumber()19 val contractNumber = contractNumber()20 val seats = seats()21 val result = Aircraft.create(idGenerator = idGenerator,22 manufacturer = manufacturer,23 payload = payload,24 releaseDate = releaseDate,25 registrationNumber = registrationNumber,26 contractNumber = contractNumber,27 seats = seats)28 result shouldBeRight {29 it.id shouldBe id30 it.manufacturer shouldBe manufacturer31 it.payload shouldBe payload32 it.releaseDate shouldBe releaseDate33 it.registrationNumber shouldBe registrationNumber34 it.contractNumber shouldBe contractNumber35 it.seats shouldBe seats36 it.popEvents() shouldContainExactly listOf(AircraftCreatedDomainEvent(id))37 }38 }39 @Test40 fun `create aircraft - no seats`() {41 val manufacturer = manufacturer()42 val payload = payload()43 val releaseDate = OffsetDateTime.now()44 val registrationNumber = registrationNumber()45 val contractNumber = contractNumber()46 val seats = emptySet<Seat>()47 val result = Aircraft.create(idGenerator = idGenerator,48 manufacturer = manufacturer,49 payload = payload,50 releaseDate = releaseDate,51 registrationNumber = registrationNumber,52 contractNumber = contractNumber,53 seats = seats)54 result shouldBeLeft EmptySeatMapError55 }56}...

Full Screen

Full Screen

DateTimeSpec.kt

Source:DateTimeSpec.kt Github

copy

Full Screen

1package com.musinsa.shared.util.datetime2import com.musinsa.shared.test.matchers.string.beValidISODateTimeString3import io.kotest.core.spec.style.DescribeSpec4import io.kotest.matchers.should5import io.kotest.property.checkAll6import java.sql.Timestamp7import java.time.LocalDateTime8import java.time.ZoneId9class DateTimeSpec : DescribeSpec(10 {11 describe("dateTimeToString()") {12 it("should return a string as a datetime format") {13 checkAll<LocalDateTime>(100) {14 val offsetDateTime = it15 .atZone(ZoneId.systemDefault())16 .toOffsetDateTime()17 dateTimeToString(offsetDateTime) should beValidISODateTimeString<String>()18 dateTimeToString(it) should beValidISODateTimeString<String>()19 }20 }21 }22 describe("timestampToString()") {23 it("should return a string as a datetime format") {24 checkAll<LocalDateTime>(100) {25 timestampToString(Timestamp.valueOf(it)) should beValidISODateTimeString<String>()26 }27 }28 }29 }30)...

Full Screen

Full Screen

OffsetDateTimeSerializerTest.kt

Source:OffsetDateTimeSerializerTest.kt Github

copy

Full Screen

1package cloud.cosmin.checklister.lib.dto.internal2import io.kotest.core.spec.style.WordSpec3import io.kotest.matchers.comparables.shouldBeEqualComparingTo4import io.kotest.matchers.shouldBe5import kotlinx.serialization.ExperimentalSerializationApi6import kotlinx.serialization.decodeFromString7import kotlinx.serialization.json.Json8import kotlinx.serialization.json.JsonConfiguration9import java.time.OffsetDateTime10@ExperimentalSerializationApi11class OffsetDateTimeSerializerTest : WordSpec({12 "OffsetDateTimeSerializer" should {13 "should read back its own serialization" {14 val json = Json.Default15 val offsetDateTime = OffsetDateTime.parse("2020-07-10T01:00:00+05:00")16 val jsonData = json.encodeToString(OffsetDateTimeSerializer, offsetDateTime)17 jsonData.shouldBe("\"2020-07-10T01:00:00+05:00\"")18 val newOffsetDateTime = json.decodeFromString(OffsetDateTimeSerializer, jsonData)19 offsetDateTime.shouldBeEqualComparingTo(newOffsetDateTime)20 }21 }22})...

Full Screen

Full Screen

DateTimeTest.kt

Source:DateTimeTest.kt Github

copy

Full Screen

1package me.takehara.domain2import io.kotest.core.spec.style.FunSpec3import io.kotest.matchers.shouldBe4import io.mockk.every5import io.mockk.mockk6import io.mockk.mockkStatic7import java.time.OffsetDateTime8class DateTimeTest : FunSpec({9 test("現在時刻を持つ DateTime インスタンスを生成できる") {10 val dateTime = mockk<OffsetDateTime>()11 mockkStatic(OffsetDateTime::class)12 every { OffsetDateTime.now() } returns dateTime13 val actual = DateTime.getNow()14 actual shouldBe DateTime(dateTime)15 actual.value shouldBe dateTime16 }17})...

Full Screen

Full Screen

offsetdatetime

Using AI Code Generation

copy

Full Screen

1val offsetDateTime = OffsetDateTime.now()2offsetDateTime shouldBe (OffsetDateTime.now())3val zonedDateTime = ZonedDateTime.now()4zonedDateTime shouldBe (ZonedDateTime.now())5val duration = Duration.ofHours(1)6duration shouldBe (Duration.ofHours(1))7val period = Period.ofDays(1)8period shouldBe (Period.ofDays(1))9val temporalAmount = Duration.ofHours(1)10temporalAmount shouldBe (Duration.ofHours(1))11temporalUnit shouldBe (ChronoUnit.HOURS)12val temporal = OffsetDateTime.now()13temporal shouldBe (OffsetDateTime.now())14val temporalQuery = TemporalQueries.zoneId()15temporalQuery shouldBe (TemporalQueries.zoneId())16val temporalAdjuster = TemporalAdjusters.firstDayOfMonth()17temporalAdjuster shouldBe (TemporalAdjusters.firstDayOfMonth())18val temporalAmount = Duration.ofHours(1)19temporalAmount shouldBe (Duration.ofHours(1))20temporalUnit shouldBe (ChronoUnit.HOURS)21val temporal = OffsetDateTime.now()22temporal shouldBe (OffsetDateTime.now())23val temporalQuery = TemporalQueries.zoneId()24temporalQuery shouldBe (TemporalQueries.zoneId())25val temporalAdjuster = TemporalAdjusters.firstDayOfMonth()26temporalAdjuster shouldBe (TemporalAdjusters.firstDayOfMonth())

Full Screen

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:

YouTube

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

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful