-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified test for creating a new account to check id (pass)
- Loading branch information
kamil.jedrzejuk
committed
Oct 2, 2024
1 parent
d796882
commit 964832f
Showing
5 changed files
with
57 additions
and
5 deletions.
There are no files selected for viewing
13 changes: 10 additions & 3 deletions
13
src/main/kotlin/camilyed/github/io/currencyexchangeapi/application/AccountService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
package camilyed.github.io.currencyexchangeapi.application | ||
|
||
import camilyed.github.io.currencyexchangeapi.domain.Account | ||
import java.util.* | ||
import camilyed.github.io.currencyexchangeapi.domain.AccountRepository | ||
|
||
class AccountService { | ||
class AccountService( | ||
private val repository: AccountRepository | ||
) { | ||
|
||
fun create(command: CreateAccountCommand): Account { | ||
return Account(id = UUID.randomUUID(), owner = command.owner, balancePln = command.initialBalance) | ||
val id = repository.nextAccountId() | ||
return Account( | ||
id = id, | ||
owner = command.owner, | ||
balancePln = command.initialBalance | ||
) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/camilyed/github/io/currencyexchangeapi/domain/AccountRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package camilyed.github.io.currencyexchangeapi.domain | ||
|
||
import java.util.UUID | ||
|
||
interface AccountRepository { | ||
|
||
fun nextAccountId(): UUID | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
.../kotlin/camilyed/github/io/currencyexchangeapi/testing/ability/SetNextAccountIdAbility.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package camilyed.github.io.currencyexchangeapi.testing.ability | ||
|
||
import camilyed.github.io.currencyexchangeapi.testing.fakes.TestingAccountRepository | ||
import java.util.* | ||
|
||
interface SetNextAccountIdAbility { | ||
|
||
fun theNextAccountIdWillBe(id: String) { | ||
accountRepository.setNextId(UUID.fromString(id)) | ||
} | ||
|
||
companion object { | ||
val accountRepository = TestingAccountRepository() | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...t/kotlin/camilyed/github/io/currencyexchangeapi/testing/fakes/TestingAccountRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package camilyed.github.io.currencyexchangeapi.testing.fakes | ||
|
||
import camilyed.github.io.currencyexchangeapi.domain.AccountRepository | ||
import java.util.* | ||
|
||
class TestingAccountRepository : AccountRepository { | ||
|
||
private var nextID: UUID? = null | ||
|
||
override fun nextAccountId(): UUID { | ||
return nextID ?: UUID.randomUUID() | ||
} | ||
|
||
fun setNextId(id: UUID) { | ||
this.nextID = id | ||
} | ||
} |