Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import junit.framework.TestCase;
- import org.junit.*;
- import static org.junit.Assert.*;
- import put.io.tdd.dusigrosz.BankAccount;
- import put.io.tdd.dusigrosz.IllegalDepositValueException;
- import put.io.tdd.dusigrosz.IllegalInterestRate;
- import put.io.tdd.dusigrosz.IllegalTransferException;
- import put.io.tdd.dusigrosz.IllegalWithdrawValueException;
- import put.io.tdd.dusigrosz.InsufficientFundsException;
- import put.io.tdd.dusigrosz.InterestCapitalizationType;
- import put.io.tdd.dusigrosz.NegativeTransferException;
- public class BankAccountTest {
- private BankAccount account;
- @Before
- public void setUp() throws Exception {
- account = new BankAccount();
- }
- @Test(expected=IllegalInterestRate.class)
- public void testInterest2(){
- account.setInterestRate(-1);
- }
- @Test
- public void testInterest4(){
- account.deposit(1000);
- account.setInterestRate(360);
- account.setCapitalizationType(InterestCapitalizationType.Dzien);
- double balance = account.getBalanceAfterDays(1);
- assertEquals(balance, 1010.0, 0.00001);
- }
- @Test
- public void testInterest3(){
- account.deposit(1000);
- account.setInterestRate(2.4);
- account.setCapitalizationType(InterestCapitalizationType.Miesiac);
- double balance = account.getBalanceAfterDays(360);
- assertEquals(balance, 1024.27, 0.00001);
- }
- @Test
- public void testInterest(){
- account.deposit(1000);
- account.setInterestRate(1.2);
- account.setCapitalizationType(InterestCapitalizationType.Miesiac);
- double balance = account.getBalanceAfterDays(30);
- assertEquals(balance, 1001, 0.00001);
- }
- @Test(expected=IllegalTransferException.class)
- public void testTransfer3() throws IllegalDepositValueException, IllegalTransferException, NegativeTransferException{
- account.deposit(1500);
- BankAccount acc2 = new BankAccount();
- account.transfer(acc2, 2000);
- }
- @Test(expected=NegativeTransferException.class)
- public void testTransfer2() throws IllegalDepositValueException, IllegalTransferException, NegativeTransferException{
- account.deposit(1500);
- BankAccount acc2 = new BankAccount();
- account.transfer(acc2, -500);
- }
- @Test
- public void testTransfer() throws IllegalDepositValueException, IllegalTransferException, NegativeTransferException{
- account.deposit(1500);
- BankAccount acc2 = new BankAccount();
- double balance = acc2.getBalance();
- assertEquals(balance, 0.0, 0.000001);
- balance = account.getBalance();
- assertEquals(balance, 1500.0, 0.000001);
- account.transfer(acc2, 1000);
- balance = acc2.getBalance();
- assertEquals(balance, 1000.0, 0.000001);
- balance = account.getBalance();
- assertEquals(balance, 500.0, 0.000001);
- }
- @Test
- public void testDeposit() throws IllegalDepositValueException {
- account.deposit(5000);
- double balance = account.getBalance();
- assertEquals(balance, 5000.0, 0.000001);
- }
- @Test
- public void testDepositAndWithdraw() throws IllegalWithdrawValueException, InsufficientFundsException, IllegalDepositValueException {
- double balance = account.getBalance();
- assertEquals(balance, 0.0, 0.000001);
- account.deposit(1000);
- account.withdraw(500);
- balance = account.getBalance();
- assertEquals(balance, 500.0, 0.000001);
- }
- @Test(expected=InsufficientFundsException.class)
- public void testDepositAndWithdraw2() throws IllegalDepositValueException, IllegalWithdrawValueException, InsufficientFundsException {
- double balance = account.getBalance();
- assertEquals(balance, 0.0, 0.000001);
- account.deposit(1000);
- account.withdraw(2000);
- }
- @Test
- public void testDeposit2() throws IllegalDepositValueException {
- double balance = account.getBalance();
- assertEquals(balance, 0.0, 0.000001);
- account.deposit(1000);
- balance = account.getBalance();
- assertEquals(balance, 1000.0, 0.000001);
- account.deposit(200);
- balance = account.getBalance();
- assertEquals(balance, 1200.0, 0.000001);
- account.deposit(300);
- balance = account.getBalance();
- assertEquals(balance, 1500.0, 0.000001);
- }
- @Test(expected=IllegalDepositValueException.class)
- public void testNegativeDeposit() throws IllegalDepositValueException {
- account.deposit(-100);
- }
- @Test(expected=IllegalWithdrawValueException.class)
- public void testDepositAndNegativeWithdraw() throws IllegalDepositValueException, IllegalWithdrawValueException, InsufficientFundsException {
- double balance = account.getBalance();
- assertEquals(balance, 0.0, 0.000001);
- account.deposit(1000);
- account.withdraw(-100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement