add account not found exception

- update balance in AccountController with onErrorResume
- update AccountService
  - update getForUpdateById with switchIfEmpty
  - update getById with switchIfEmpty
- add AccountNotFoundException
This commit is contained in:
2025-09-11 18:49:16 +02:00
parent 25f534b6e3
commit e46bf55232
5 changed files with 56 additions and 6 deletions

View File

@@ -4,6 +4,7 @@ import io.mockk.every
import io.mockk.mockk
import java.math.BigDecimal
import java.util.UUID
import ltd.lulz.exception.AccountNotFoundException
import ltd.lulz.model.Account
import ltd.lulz.model.AccountEntity
import ltd.lulz.service.AccountService
@@ -117,7 +118,7 @@ class AccountControllerTest {
@Test
fun `account balance fail`() {
// given
every { accountService.getById(any()) } returns Mono.empty()
every { accountService.getById(any()) } returns Mono.error(AccountNotFoundException())
// when
val result = webTestClient.get()

View File

@@ -6,6 +6,7 @@ import io.mockk.slot
import io.mockk.verify
import java.math.BigDecimal
import java.util.UUID
import ltd.lulz.exception.AccountNotFoundException
import ltd.lulz.model.AccountEntity
import ltd.lulz.repository.AccountRepository
import org.assertj.core.api.Assertions.assertThat
@@ -70,6 +71,19 @@ class AccountServiceTest {
verify { repository.findById(any(UUID::class)) }
}
@Test
fun `get by id - fail`() {
// given
every { repository.findById(any(UUID::class)) } returns Mono.empty()
// when stepped
StepVerifier.create(service.getById(uuid))
.expectError(AccountNotFoundException::class.java)
.verify()
verify { repository.findById(any(UUID::class)) }
}
@Test
fun `get for update by id`() {
// given
@@ -89,6 +103,20 @@ class AccountServiceTest {
verify { repository.findByIdForUpdate(any(UUID::class)) }
}
@Test
fun `get for update by id - fail`() {
// given
every { repository.findByIdForUpdate(any(UUID::class)) } returns Mono.empty()
// when stepped
StepVerifier.create(service.getForUpdateById(uuid))
.expectError(AccountNotFoundException::class.java)
.verify()
verify { repository.findByIdForUpdate(any(UUID::class)) }
}
@Test
fun `save change`() {
// given