-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
67 additions
and
7 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
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
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
60 changes: 58 additions & 2 deletions
60
java/testing/junit/src/test/java/it/unibo/bank/impl/TestStrictBankAccount.java
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,13 +1,69 @@ | ||
package it.unibo.bank.impl; | ||
|
||
import it.unibo.bank.api.AccountHolder; | ||
import it.unibo.bank.api.BankAccount; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static it.unibo.bank.impl.SimpleBankAccount.*; | ||
import static it.unibo.bank.impl.SimpleBankAccount.ATM_TRANSACTION_FEE; | ||
import static it.unibo.bank.impl.StrictBankAccount.TRANSACTION_FEE; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class TestStrictBankAccount { | ||
|
||
private final static int INITIAL_AMOUNT = 100; | ||
|
||
// 1. Create a new AccountHolder and a StrictBankAccount for it each time tests are executed. | ||
private AccountHolder mRossi; | ||
private BankAccount bankAccount; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
mRossi = new AccountHolder("Mario", "Rossi", 1); | ||
bankAccount = new StrictBankAccount(mRossi, 0.0); | ||
} | ||
|
||
// 2. Test the initial state of the StrictBankAccount | ||
@Test | ||
public void testInitialization() { | ||
assertEquals(0.0, bankAccount.getBalance()); | ||
assertEquals(0, bankAccount.getTransactionsCount()); | ||
assertEquals(mRossi, bankAccount.getAccountHolder()); | ||
} | ||
|
||
|
||
// 3. Perform a deposit of 100€ and check that the correct amount of management fees is applied to this BankAccount. | ||
// 3. Perform a deposit of 100€, compute the management fees, and check that the balance is correctly reduced. | ||
@Test | ||
public void testManagementFees() { | ||
bankAccount.deposit(mRossi.getUserID(), INITIAL_AMOUNT); | ||
assertEquals(INITIAL_AMOUNT, bankAccount.getBalance()); | ||
bankAccount.chargeManagementFees(mRossi.getUserID()); | ||
assertEquals(INITIAL_AMOUNT - TRANSACTION_FEE - MANAGEMENT_FEE, bankAccount.getBalance()); | ||
} | ||
|
||
// 4. Test the withdraw of a negative value | ||
// 4. Test the withdraw of a negative value | ||
@Test | ||
public void testNegativeWithdraw() { | ||
try { | ||
bankAccount.withdraw(mRossi.getUserID(), -INITIAL_AMOUNT); | ||
} catch (IllegalArgumentException e) { | ||
assertNotNull(e.getMessage()); | ||
assertTrue(e.getMessage().length() > 1); | ||
} | ||
} | ||
|
||
// 4. Test withdrawing more money than it is in the account | ||
@Test | ||
public void testWithdrawingTooMuch() { | ||
try { | ||
bankAccount.withdraw(mRossi.getUserID(), INITIAL_AMOUNT); | ||
} catch (IllegalArgumentException e) { | ||
assertNotNull(e.getMessage()); | ||
assertTrue(e.getMessage().length() > 1); | ||
} | ||
} | ||
} |