Skip to content

Commit

Permalink
test cases for TxService
Browse files Browse the repository at this point in the history
  • Loading branch information
teodesson committed Dec 12, 2018
1 parent 56f386b commit 81937c0
Showing 1 changed file with 54 additions and 2 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 81937c0

Please sign in to comment.