-
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.
Refactor test for creating a new account with 0 balance (USD) (pass)
- Loading branch information
kamil.jedrzejuk
committed
Oct 2, 2024
1 parent
57e0217
commit 93f65a2
Showing
4 changed files
with
34 additions
and
15 deletions.
There are no files selected for viewing
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
29 changes: 23 additions & 6 deletions
29
src/main/kotlin/camilyed/github/io/currencyexchangeapi/domain/Account.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,16 +1,33 @@ | ||
package camilyed.github.io.currencyexchangeapi.domain | ||
|
||
import java.math.BigDecimal | ||
import java.util.UUID | ||
import java.util.* | ||
|
||
data class Account( | ||
val id: UUID, | ||
val owner: String, | ||
val balancePln: BigDecimal, | ||
val balanceUsd: BigDecimal | ||
class Account( | ||
private val id: UUID, | ||
private val owner: String, | ||
private var balancePln: BigDecimal, | ||
private var balanceUsd: BigDecimal = BigDecimal.ZERO | ||
) { | ||
|
||
init { | ||
require(balancePln >= BigDecimal.ZERO) { "Initial balance cannot be negative" } | ||
require(balanceUsd == BigDecimal.ZERO) { "USD balance must start at 0" } | ||
} | ||
|
||
fun toSnapshot(): AccountSnapshot { | ||
return AccountSnapshot( | ||
id = id, | ||
owner = owner, | ||
balancePln = balancePln, | ||
balanceUsd = balanceUsd | ||
) | ||
} | ||
} | ||
|
||
data class AccountSnapshot( | ||
val id: UUID, | ||
val owner: String, | ||
val balancePln: BigDecimal, | ||
val balanceUsd: BigDecimal | ||
) |
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
9 changes: 5 additions & 4 deletions
9
...est/kotlin/camilyed/github/io/currencyexchangeapi/testing/assertions/AccountAssertions.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