From 942750d9d88fd6a1804e36567bee3398d5551fc3 Mon Sep 17 00:00:00 2001 From: Swordsteel Date: Thu, 11 Sep 2025 14:06:48 +0200 Subject: [PATCH] update AccountService with getById --- .../kotlin/ltd/lulz/service/AccountService.kt | 4 ++++ .../ltd/lulz/service/AccountServiceTest.kt | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/main/kotlin/ltd/lulz/service/AccountService.kt b/src/main/kotlin/ltd/lulz/service/AccountService.kt index ecccaa8..fa25bae 100644 --- a/src/main/kotlin/ltd/lulz/service/AccountService.kt +++ b/src/main/kotlin/ltd/lulz/service/AccountService.kt @@ -1,6 +1,7 @@ package ltd.lulz.service import io.github.oshai.kotlinlogging.KotlinLogging +import java.util.UUID import ltd.lulz.model.AccountEntity import ltd.lulz.repository.AccountRepository import org.springframework.stereotype.Service @@ -16,4 +17,7 @@ class AccountService( fun create(entity: AccountEntity): Mono = accountRepository .save(entity) .doOnNext { log.debug { "account created with id: ${it.id}" } } + + fun getById(id: UUID): Mono = accountRepository.findById(id) + .doOnNext { log.debug { "found account by id: ${it.id}" } } } diff --git a/src/test/kotlin/ltd/lulz/service/AccountServiceTest.kt b/src/test/kotlin/ltd/lulz/service/AccountServiceTest.kt index 2817562..4b19be8 100644 --- a/src/test/kotlin/ltd/lulz/service/AccountServiceTest.kt +++ b/src/test/kotlin/ltd/lulz/service/AccountServiceTest.kt @@ -50,4 +50,23 @@ class AccountServiceTest { verify { repository.save(any()) } } + + @Test + fun `get by id`() { + // given + val capture = slot() + every { repository.findById(capture(capture)) } + .answers { Mono.just(AccountEntity(capture.captured, name, amount)) } + + // when stepped + StepVerifier.create(service.getById(uuid)) + .assertNext { result -> + assertThat(result.id).isEqualTo(uuid) + assertThat(result.name).isEqualTo(name) + assertThat(result.amount).isEqualTo(amount) + } + .verifyComplete() + + verify { repository.findById(any(UUID::class)) } + } }