From 81937c0e572d800f7b4f0c93cf00c365d9e7c01c Mon Sep 17 00:00:00 2001 From: teodesson Date: Thu, 13 Dec 2018 00:40:18 +0800 Subject: [PATCH] test cases for TxService --- .../bankofjakarta/service/TxServiceTest.java | 56 ++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/dariawan/bankofjakarta/service/TxServiceTest.java b/src/test/java/com/dariawan/bankofjakarta/service/TxServiceTest.java index f9ca3e6..93b36ce 100644 --- a/src/test/java/com/dariawan/bankofjakarta/service/TxServiceTest.java +++ b/src/test/java/com/dariawan/bankofjakarta/service/TxServiceTest.java @@ -3,6 +3,8 @@ import com.dariawan.bankofjakarta.domain.Account; import com.dariawan.bankofjakarta.exception.AccountNotFoundException; import com.dariawan.bankofjakarta.exception.IllegalAccountTypeException; +import com.dariawan.bankofjakarta.exception.InsufficientCreditException; +import com.dariawan.bankofjakarta.exception.InsufficientFundsException; import com.dariawan.bankofjakarta.exception.InvalidParameterException; import java.math.BigDecimal; import static org.junit.Assert.assertNotNull; @@ -36,10 +38,60 @@ private Account getAccount(String accountId) { @Test public void testDeposit() throws InvalidParameterException, AccountNotFoundException, IllegalAccountTypeException { + // as long as not credit account Account acc1 = getAccount("5008"); BigDecimal balanceNow = acc1.getBalance(); - getTxService().deposit(new BigDecimal(100), "Deposit 100", acc1.getAccountId()); + getTxService().deposit(new BigDecimal("100"), "Deposit 100", acc1.getAccountId()); Account acc2 = getAccount("5008"); - assertEquals(acc2.getBalance().toString(), (balanceNow.add(new BigDecimal(100))).toString()); + assertEquals(acc2.getBalance().toString(), (balanceNow.add(new BigDecimal("100"))).toString()); + } + + @Test + public void testWithdraw() throws InvalidParameterException, AccountNotFoundException, IllegalAccountTypeException, InsufficientFundsException { + // as long as not credit account + Account acc1 = getAccount("5008"); + BigDecimal balanceNow = acc1.getBalance(); + getTxService().withdraw(new BigDecimal("230"), "Withdraw 230", acc1.getAccountId()); + Account acc2 = getAccount("5008"); + assertEquals(acc2.getBalance().toString(), (balanceNow.subtract(new BigDecimal("230"))).toString()); + } + + @Test + public void testMakeCharge() throws InvalidParameterException, AccountNotFoundException, IllegalAccountTypeException, InsufficientCreditException { + // as long as not credit account + Account acc1 = getAccount("5007"); + BigDecimal balanceNow = acc1.getBalance(); + getTxService().makeCharge(new BigDecimal("1500"), "Charge 1500", acc1.getAccountId()); + Account acc2 = getAccount("5007"); + assertEquals(acc2.getBalance().toString(), (balanceNow.add(new BigDecimal("1500"))).toString()); + } + + @Test + public void testMakePayment() throws InvalidParameterException, AccountNotFoundException, IllegalAccountTypeException, InsufficientCreditException, InsufficientFundsException, InsufficientFundsException { + // as long as not credit account + Account acc1 = getAccount("5007"); + BigDecimal balanceNow = acc1.getBalance(); + getTxService().makePayment(new BigDecimal("200"), "Payment 200", acc1.getAccountId()); + Account acc2 = getAccount("5007"); + assertEquals(acc2.getBalance().toString(), (balanceNow.subtract(new BigDecimal("200"))).toString()); + } + + @Test + public void testTransferFunds() throws InvalidParameterException, AccountNotFoundException, IllegalAccountTypeException, InsufficientCreditException, InsufficientFundsException { + // as long as not credit account + Account accFrom1 = getAccount("5008"); + BigDecimal balanceFromNow = accFrom1.getBalance(); + + Account accTo1 = getAccount("5007"); + BigDecimal balanceToNow = accTo1.getBalance(); + + getTxService().transferFunds(new BigDecimal("200"), "Transfer 200", accFrom1.getAccountId(), accTo1.getAccountId()); + + Account accFrom2 = getAccount("5008"); + assertEquals(accFrom2.getBalance().toString(), (balanceFromNow.subtract(new BigDecimal("200"))).toString()); + + Account accTo2 = getAccount("5007"); + // because credit account - subtract + assertEquals(accTo2.getBalance().toString(), (balanceToNow.subtract(new BigDecimal("200"))).toString()); } }