Skip to content

Commit

Permalink
Updated tests to use getBalance
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelspinto committed Jan 7, 2019
1 parent 57edf92 commit 93b5908
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/main/scala/workshop/payment/CustomWallet.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package workshop.payment

case class CustomWallet(balance: Int, maxAmount: Int = 1000) extends Wallet{
case class CustomWallet(var balance: Int, maxAmount: Int = 1000) extends Wallet{
def remove(amount: Int): Int = {
if(amount > balance) {
throw new NotEnoughFundsException
}

balance - amount
balance -= amount
balance
}

def add(amount: Int): Int = {
Expand All @@ -16,7 +16,8 @@ case class CustomWallet(balance: Int, maxAmount: Int = 1000) extends Wallet{
if(amount > maxAmount) {
throw new MaxAmountExceededException
}
amount + balance
balance += amount
balance
}

override def getBalance: Int = balance
Expand Down
4 changes: 2 additions & 2 deletions src/test/scala/workshop/payment/CustomWalletTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CustomWalletTest extends FunSuite {
val amount = 10
val balance = 11
val wallet: CustomWallet = new CustomWallet(balance)
assert(wallet.add(amount) == balance + amount)
assert(wallet.add(amount) == wallet.getBalance)
}

test("add: if amount is greater than allowed throws MaxAmountExceededException") {
Expand All @@ -45,6 +45,6 @@ class CustomWalletTest extends FunSuite {
val amount = 9
val balance = 11
val wallet: CustomWallet = new CustomWallet(balance)
assert(wallet.remove(amount) == balance - amount)
assert(wallet.remove(amount) == wallet.getBalance)
}
}

0 comments on commit 93b5908

Please sign in to comment.