Skip to content

Commit

Permalink
style(java/testing): improve the test solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
DanySK committed Nov 13, 2023
1 parent d9b2f8b commit 8033125
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

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.SimpleBankAccount.MANAGEMENT_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.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class TestStrictBankAccount {

Expand Down Expand Up @@ -39,20 +37,27 @@ public void testInitialization() {
// 3. Perform a deposit of 100€, compute the management fees, and check that the balance is correctly reduced.
@Test
public void testManagementFees() {
assertTransactionsAre(0);
bankAccount.deposit(mRossi.getUserID(), INITIAL_AMOUNT);
assertTransactionsAre(1);
assertEquals(INITIAL_AMOUNT, bankAccount.getBalance());
bankAccount.chargeManagementFees(mRossi.getUserID());
assertTransactionsAre(0);
assertEquals(INITIAL_AMOUNT - TRANSACTION_FEE - MANAGEMENT_FEE, bankAccount.getBalance());
}

private void assertTransactionsAre(final int expectedTransactions) {
assertEquals(expectedTransactions, bankAccount.getTransactionsCount());
}

// 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);
assertFalse(e.getMessage().isBlank());
}
}

Expand All @@ -63,7 +68,7 @@ public void testWithdrawingTooMuch() {
bankAccount.withdraw(mRossi.getUserID(), INITIAL_AMOUNT);
} catch (IllegalArgumentException e) {
assertNotNull(e.getMessage());
assertTrue(e.getMessage().length() > 1);
assertFalse(e.getMessage().isBlank());
}
}
}

0 comments on commit 8033125

Please sign in to comment.